Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
5e11d2b3
Commit
5e11d2b3
authored
Aug 04, 2015
by
Dave Hylands
Committed by
Damien George
Aug 05, 2015
Browse files
stmhal: Enable SPI support for F7 MCUs.
parent
34fe5a30
Changes
4
Hide whitespace changes
Inline
Side-by-side
stmhal/boards/STM32F7DISC/mpconfigboard.h
View file @
5e11d2b3
...
...
@@ -13,7 +13,7 @@
#define MICROPY_HW_ENABLE_TIMER (1)
#define MICROPY_HW_ENABLE_SERVO (0)
#define MICROPY_HW_ENABLE_DAC (0)
#define MICROPY_HW_ENABLE_SPI1 (
1
)
#define MICROPY_HW_ENABLE_SPI1 (
0
)
#define MICROPY_HW_ENABLE_SPI2 (1)
#define MICROPY_HW_ENABLE_SPI3 (0)
#define MICROPY_HW_ENABLE_CAN (1)
...
...
@@ -60,6 +60,12 @@ void STM32F7DISC_board_early_init(void);
#define MICROPY_HW_I2C_BAUDRATE_DEFAULT 100000
#define MICROPY_HW_I2C_BAUDRATE_MAX 100000
// SPI
#define MICROPY_HW_SPI2_NSS (pin_I0)
#define MICROPY_HW_SPI2_SCK (pin_I1)
#define MICROPY_HW_SPI2_MISO (pin_B14)
#define MICROPY_HW_SPI2_MOSI (pin_B15)
// USRSW is pulled low. Pressing the button makes the input go high.
#define MICROPY_HW_USRSW_PIN (pin_I11)
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)
...
...
stmhal/main.c
View file @
5e11d2b3
...
...
@@ -472,9 +472,7 @@ soft_reset:
#endif
i2c_init0
();
#if !defined(STM32F7) // Temp hack
spi_init0
();
#endif
pyb_usb_init0
();
// Initialise the local flash filesystem.
...
...
stmhal/modpyb.c
View file @
5e11d2b3
...
...
@@ -590,9 +590,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_LED
),
(
mp_obj_t
)
&
pyb_led_type
},
#endif
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_I2C
),
(
mp_obj_t
)
&
pyb_i2c_type
},
#if !defined(STM32F7) // Temp hack
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_SPI
),
(
mp_obj_t
)
&
pyb_spi_type
},
#endif
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_UART
),
(
mp_obj_t
)
&
pyb_uart_type
},
#if MICROPY_HW_ENABLE_CAN
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_CAN
),
(
mp_obj_t
)
&
pyb_can_type
},
...
...
stmhal/spi.c
View file @
5e11d2b3
...
...
@@ -37,9 +37,29 @@
#include
"spi.h"
#include MICROPY_HAL_H
#if !defined(STM32F7)
// The STM32F7 has the SPI pins mapped differently. Need to figure this out
// before enabling SPI for the F7
// The following defines are for compatability with the '405
#if !defined(MICROPY_HW_SPI1_NSS)
// X-skin: X5=PA4=SPI1_NSS, X6=PA5=SPI1_SCK, X7=PA6=SPI1_MISO, X8=PA7=SPI1_MOSI
#define MICROPY_HW_SPI1_NSS (pin_A4)
#define MICROPY_HW_SPI1_SCK (pin_A5)
#define MICROPY_HW_SPI1_MISO (pin_A6)
#define MICROPY_HW_SPI1_MOSI (pin_A7)
#endif
#if !defined(MICROPY_HW_SPI2_NSS)
// Y-skin: Y5=PB12=SPI2_NSS, Y6=PB13=SPI2_SCK, Y7=PB14=SPI2_MISO, Y8=PB15=SPI2_MOSI
#define MICROPY_HW_SPI2_NSS (pin_B12)
#define MICROPY_HW_SPI2_SCK (pin_B13)
#define MICROPY_HW_SPI2_MISO (pin_B14)
#define MICROPY_HW_SPI2_MOSI (pin_B15)
#endif
#if !defined(MICROPY_HW_SPI3_NSS)
#define MICROPY_HW_SPI3_NSS (pin_A4)
#define MICROPY_HW_SPI3_SCK (pin_B3)
#define MICROPY_HW_SPI3_MISO (pin_B4)
#define MICROPY_HW_SPI3_MOSI (pin_B5)
#endif
/// \moduleref pyb
/// \class SPI - a master-driven serial protocol
...
...
@@ -140,24 +160,22 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
if
(
0
)
{
#if MICROPY_HW_ENABLE_SPI1
}
else
if
(
spi
->
Instance
==
SPI1
)
{
// X-skin: X5=PA4=SPI1_NSS, X6=PA5=SPI1_SCK, X7=PA6=SPI1_MISO, X8=PA7=SPI1_MOSI
self
=
&
pyb_spi_obj
[
0
];
pins
[
0
]
=
&
pin_A4
;
pins
[
1
]
=
&
pin_A5
;
pins
[
2
]
=
&
pin_A6
;
pins
[
3
]
=
&
pin_A7
;
pins
[
0
]
=
&
MICROPY_HW_SPI1_NSS
;
pins
[
1
]
=
&
MICROPY_HW_SPI1_SCK
;
pins
[
2
]
=
&
MICROPY_HW_SPI1_MISO
;
pins
[
3
]
=
&
MICROPY_HW_SPI1_MOSI
;
GPIO_InitStructure
.
Alternate
=
GPIO_AF5_SPI1
;
// enable the SPI clock
__SPI1_CLK_ENABLE
();
#endif
#if MICROPY_HW_ENABLE_SPI2
}
else
if
(
spi
->
Instance
==
SPI2
)
{
// Y-skin: Y5=PB12=SPI2_NSS, Y6=PB13=SPI2_SCK, Y7=PB14=SPI2_MISO, Y8=PB15=SPI2_MOSI
self
=
&
pyb_spi_obj
[
1
];
pins
[
0
]
=
&
pin_B12
;
pins
[
1
]
=
&
pin_B13
;
pins
[
2
]
=
&
pin_B14
;
pins
[
3
]
=
&
pin_B15
;
pins
[
0
]
=
&
MICROPY_HW_SPI2_NSS
;
pins
[
1
]
=
&
MICROPY_HW_SPI2_SCK
;
pins
[
2
]
=
&
MICROPY_HW_SPI2_MISO
;
pins
[
3
]
=
&
MICROPY_HW_SPI2_MOSI
;
GPIO_InitStructure
.
Alternate
=
GPIO_AF5_SPI2
;
// enable the SPI clock
__SPI2_CLK_ENABLE
();
...
...
@@ -165,10 +183,10 @@ void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
#if MICROPY_HW_ENABLE_SPI3
}
else
if
(
spi
->
Instance
==
SPI3
)
{
self
=
&
pyb_spi_obj
[
2
];
pins
[
0
]
=
&
pin_A4
;
pins
[
1
]
=
&
pin_B3
;
pins
[
2
]
=
&
pin_B4
;
pins
[
3
]
=
&
pin_B5
;
pins
[
0
]
=
&
MICROPY_HW_SPI3_NSS
;
pins
[
1
]
=
&
MICROPY_HW_SPI3_SCK
;
pins
[
2
]
=
&
MICROPY_HW_SPI3_MISO
;
pins
[
3
]
=
&
MICROPY_HW_SPI3_MOSI
;
GPIO_InitStructure
.
Alternate
=
GPIO_AF6_SPI3
;
// enable the SPI clock
__SPI3_CLK_ENABLE
();
...
...
@@ -670,5 +688,3 @@ const mp_obj_type_t pyb_spi_type = {
.
make_new
=
pyb_spi_make_new
,
.
locals_dict
=
(
mp_obj_t
)
&
pyb_spi_locals_dict
,
};
#endif // STM32F7
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment