Skip to content

Commit 40886d1

Browse files
authored
Merge pull request #4385 from hierophect/stm32-f407-can
STM32: add all F405 modules to F407
2 parents a32359b + 0b73c7a commit 40886d1

File tree

7 files changed

+394
-298
lines changed

7 files changed

+394
-298
lines changed

ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ LD_DEFAULT = boards/STM32F405_default.ld
1515
# UF2 boot option
1616
LD_BOOT = boards/STM32F405_boot.ld
1717
UF2_OFFSET = 0x8010000
18+
19+
CIRCUITPY_RGBMATRIX ?= 1

ports/stm/boards/pyboard_v11/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ MCU_PACKAGE = LQFP64
1111

1212
LD_COMMON = boards/common_default.ld
1313
LD_FILE = boards/STM32F405_fs.ld
14+
15+
CIRCUITPY_RGBMATRIX ?= 1

ports/stm/mpconfigport.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ LONGINT_IMPL ?= MPZ
33
INTERNAL_LIBM ?= 1
44
USB_SERIAL_NUMBER_LENGTH ?= 24
55

6-
ifeq ($(MCU_VARIANT),STM32F405xx)
6+
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F405xx STM32F407xx))
77
CIRCUITPY_CANIO = 1
88
CIRCUITPY_FRAMEBUFFERIO ?= 1
9-
CIRCUITPY_RGBMATRIX ?= 1
109
CIRCUITPY_SDIOIO ?= 1
1110
# Number of USB endpoint pairs.
1211
USB_NUM_EP = 4

ports/stm/peripherals/stm32f4/stm32f407xx/periph.c

Lines changed: 137 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,57 @@
2929
#include "peripherals/pins.h"
3030
#include "peripherals/periph.h"
3131

32-
// I2C
32+
I2C_TypeDef * mcu_i2c_banks[I2C_BANK_ARRAY_LEN] = {I2C1, I2C2, I2C3};
3333

34-
I2C_TypeDef * mcu_i2c_banks[3] = {I2C1, I2C2, I2C3};
35-
36-
const mcu_periph_obj_t mcu_i2c_sda_list[4] = {
34+
const mcu_periph_obj_t mcu_i2c_sda_list[I2C_SDA_ARRAY_LEN] = {
3735
PERIPH(1, 4, &pin_PB07),
3836
PERIPH(1, 4, &pin_PB09),
3937
PERIPH(2, 4, &pin_PB11),
4038
PERIPH(3, 4, &pin_PC09),
39+
PERIPH(2, 4, &pin_PF00),
40+
PERIPH(2, 4, &pin_PH05),
41+
PERIPH(3, 4, &pin_PH08),
4142
};
42-
43-
const mcu_periph_obj_t mcu_i2c_scl_list[4] = {
43+
const mcu_periph_obj_t mcu_i2c_scl_list[I2C_SCL_ARRAY_LEN] = {
44+
PERIPH(3, 4, &pin_PA08),
4445
PERIPH(1, 4, &pin_PB06),
4546
PERIPH(1, 4, &pin_PB08),
4647
PERIPH(2, 4, &pin_PB10),
47-
PERIPH(3, 4, &pin_PA08)
48+
PERIPH(2, 4, &pin_PF01),
49+
PERIPH(2, 4, &pin_PH04),
50+
PERIPH(3, 4, &pin_PH07),
4851
};
4952

50-
SPI_TypeDef * mcu_spi_banks[3] = {SPI1, SPI2, SPI3};
53+
SPI_TypeDef * mcu_spi_banks[SPI_BANK_ARRAY_LEN] = {SPI1, SPI2, SPI3};
5154

52-
const mcu_periph_obj_t mcu_spi_sck_list[7] = {
55+
const mcu_periph_obj_t mcu_spi_sck_list[SPI_SCK_ARRAY_LEN] = {
5356
PERIPH(1, 5, &pin_PA05),
5457
PERIPH(1, 5, &pin_PB03),
58+
PERIPH(3, 6, &pin_PB03),
5559
PERIPH(2, 5, &pin_PB10),
5660
PERIPH(2, 5, &pin_PB13),
57-
PERIPH(2, 5, &pin_PC07),
58-
PERIPH(3, 6, &pin_PB03),
5961
PERIPH(3, 6, &pin_PC10),
62+
PERIPH(2, 5, &pin_PI01),
6063
};
61-
62-
const mcu_periph_obj_t mcu_spi_mosi_list[6] = {
64+
const mcu_periph_obj_t mcu_spi_mosi_list[SPI_MOSI_ARRAY_LEN] = {
6365
PERIPH(1, 5, &pin_PA07),
6466
PERIPH(1, 5, &pin_PB05),
67+
PERIPH(3, 6, &pin_PB05),
6568
PERIPH(2, 5, &pin_PB15),
6669
PERIPH(2, 5, &pin_PC03),
67-
PERIPH(3, 6, &pin_PB05),
6870
PERIPH(3, 6, &pin_PC12),
71+
PERIPH(2, 5, &pin_PI03),
6972
};
70-
71-
const mcu_periph_obj_t mcu_spi_miso_list[6] = {
73+
const mcu_periph_obj_t mcu_spi_miso_list[SPI_MISO_ARRAY_LEN] = {
7274
PERIPH(1, 5, &pin_PA06),
7375
PERIPH(1, 5, &pin_PB04),
76+
PERIPH(3, 6, &pin_PB04),
7477
PERIPH(2, 5, &pin_PB14),
7578
PERIPH(2, 5, &pin_PC02),
76-
PERIPH(3, 6, &pin_PB04),
7779
PERIPH(3, 6, &pin_PC11),
80+
PERIPH(2, 5, &pin_PI02),
7881
};
79-
80-
const mcu_periph_obj_t mcu_spi_nss_list[6] = {
82+
const mcu_periph_obj_t mcu_spi_nss_list[SPI_NSS_ARRAY_LEN] = {
8183
PERIPH(1, 5, &pin_PA04),
8284
PERIPH(1, 5, &pin_PA15),
8385
PERIPH(2, 5, &pin_PB09),
@@ -89,7 +91,7 @@ const mcu_periph_obj_t mcu_spi_nss_list[6] = {
8991
USART_TypeDef * mcu_uart_banks[MAX_UART] = {USART1, USART2, USART3, UART4, UART5, USART6};
9092
bool mcu_uart_has_usart[MAX_UART] = {true, true, true, false, false, true};
9193

92-
const mcu_periph_obj_t mcu_uart_tx_list[12] = {
94+
const mcu_periph_obj_t mcu_uart_tx_list[UART_TX_ARRAY_LEN] = {
9395
PERIPH(4, 8, &pin_PA00),
9496
PERIPH(2, 7, &pin_PA02),
9597
PERIPH(1, 7, &pin_PA09),
@@ -103,8 +105,7 @@ const mcu_periph_obj_t mcu_uart_tx_list[12] = {
103105
PERIPH(3, 7, &pin_PD08),
104106
PERIPH(6, 8, &pin_PG14),
105107
};
106-
107-
const mcu_periph_obj_t mcu_uart_rx_list[12] = {
108+
const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN] = {
108109
PERIPH(4, 8, &pin_PA01),
109110
PERIPH(2, 7, &pin_PA03),
110111
PERIPH(1, 7, &pin_PA10),
@@ -121,74 +122,120 @@ const mcu_periph_obj_t mcu_uart_rx_list[12] = {
121122

122123
//Timers
123124
//TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
124-
TIM_TypeDef * mcu_tim_banks[14] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, TIM9, TIM10,
125+
TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, TIM9, TIM10,
125126
TIM11, TIM12, TIM13, TIM14};
126127

127-
const mcu_tim_pin_obj_t mcu_tim_pin_list[56] = {
128-
TIM(2,1,1,&pin_PA00),
129-
TIM(5,2,1,&pin_PA00),
130-
TIM(2,1,2,&pin_PA01),
131-
TIM(5,2,2,&pin_PA01),
132-
TIM(2,1,3,&pin_PA02),
133-
TIM(5,2,3,&pin_PA02),
134-
TIM(2,1,4,&pin_PA03),
135-
TIM(5,2,4,&pin_PA03),
136-
TIM(9,3,1,&pin_PA02),
137-
TIM(9,3,2,&pin_PA03),
138-
TIM(3,2,1,&pin_PA06),
139-
TIM(13,9,1,&pin_PA06),
140-
TIM(3,2,2,&pin_PA07),
141-
TIM(14,9,1,&pin_PA07),
142-
TIM(1,1,1,&pin_PA08),
143-
TIM(1,1,2,&pin_PA09),
144-
TIM(1,1,3,&pin_PA10),
145-
TIM(1,1,4,&pin_PA11),
146-
TIM(2,1,1,&pin_PA15),
147-
TIM(3,2,3,&pin_PB00),
148-
TIM(3,2,4,&pin_PB01),
149-
TIM(2,1,2,&pin_PB03),
150-
TIM(3,2,1,&pin_PB04),
151-
TIM(3,2,2,&pin_PB05),
152-
TIM(4,2,1,&pin_PB06),
153-
TIM(4,2,2,&pin_PB07),
154-
TIM(4,2,3,&pin_PB08),
155-
TIM(10,2,1,&pin_PB08),
156-
TIM(4,2,4,&pin_PB09),
157-
TIM(11,2,1,&pin_PB09),
158-
TIM(2,1,3,&pin_PB10),
159-
TIM(2,1,4,&pin_PB11),
160-
TIM(12,9,1,&pin_PB14),
161-
TIM(12,9,2,&pin_PB15),
162-
TIM(3,2,1,&pin_PC06),
163-
TIM(3,2,2,&pin_PC07),
164-
TIM(3,2,3,&pin_PC08),
165-
TIM(3,2,4,&pin_PC09),
166-
TIM(8,3,1,&pin_PC06),
167-
TIM(8,3,2,&pin_PC07),
168-
TIM(8,3,3,&pin_PC08),
169-
TIM(8,3,4,&pin_PC09),
170-
TIM(4,2,1,&pin_PD12),
171-
TIM(4,2,2,&pin_PD13),
172-
TIM(4,2,3,&pin_PD14),
173-
TIM(4,2,4,&pin_PD15),
174-
TIM(9,3,1,&pin_PE05),
175-
TIM(9,3,2,&pin_PE06),
176-
TIM(1,1,1,&pin_PE09),
177-
TIM(1,1,2,&pin_PE11),
178-
TIM(1,1,3,&pin_PE13),
179-
TIM(1,1,4,&pin_PE14),
180-
TIM(10,3,1,&pin_PF06),
181-
TIM(11,3,1,&pin_PF07),
182-
TIM(13,9,1,&pin_PF08),
183-
TIM(14,9,1,&pin_PF09),
184-
// TIM(12,9,1,&pin_PH06), //TODO: include these when pin map is expanded
185-
// TIM(12,9,2,&pin_PH09),
186-
// TIM(5,2,1,&pin_PH10),
187-
// TIM(5,2,2,&pin_PH11),
188-
// TIM(5,2,3,&pin_PH12),
189-
// TIM(5,2,4,&pin_PI00),
190-
// TIM(8,3,4,&pin_PI02),
191-
// TIM(8,3,1,&pin_PI05),
192-
// TIM(8,3,2,&pin_PI06),
193-
// TIM(8,3,3,&pin_PI07),
128+
const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
129+
TIM(2, 1, 1, &pin_PA00),
130+
TIM(5, 2, 1, &pin_PA00),
131+
TIM(2, 1, 2, &pin_PA01),
132+
TIM(5, 2, 2, &pin_PA01),
133+
TIM(2, 1, 3, &pin_PA02),
134+
TIM(5, 2, 3, &pin_PA02),
135+
TIM(9, 3, 1, &pin_PA02),
136+
TIM(2, 1, 4, &pin_PA03),
137+
TIM(5, 2, 4, &pin_PA03),
138+
TIM(9, 3, 2, &pin_PA03),
139+
TIM(2, 1, 1, &pin_PA05),
140+
TIM(3, 2, 1, &pin_PA06),
141+
TIM(13, 9, 1, &pin_PA06),
142+
TIM(3, 2, 2, &pin_PA07),
143+
TIM(14, 9, 1, &pin_PA07),
144+
TIM(1, 1, 1, &pin_PA08),
145+
TIM(1, 1, 2, &pin_PA09),
146+
TIM(1, 1, 3, &pin_PA10),
147+
TIM(1, 1, 4, &pin_PA11),
148+
TIM(2, 1, 1, &pin_PA15),
149+
TIM(3, 2, 3, &pin_PB00),
150+
TIM(3, 2, 4, &pin_PB01),
151+
TIM(2, 1, 2, &pin_PB03),
152+
TIM(3, 2, 1, &pin_PB04),
153+
TIM(3, 2, 2, &pin_PB05),
154+
TIM(4, 2, 1, &pin_PB06),
155+
TIM(4, 2, 2, &pin_PB07),
156+
TIM(4, 2, 3, &pin_PB08),
157+
TIM(10, 3, 1, &pin_PB08),
158+
TIM(4, 2, 4, &pin_PB09),
159+
TIM(11, 3, 1, &pin_PB09),
160+
TIM(2, 1, 3, &pin_PB10),
161+
TIM(2, 1, 4, &pin_PB11),
162+
TIM(12, 9, 1, &pin_PB14),
163+
TIM(12, 9, 2, &pin_PB15),
164+
TIM(3, 2, 1, &pin_PC06),
165+
TIM(8, 3, 1, &pin_PC06),
166+
TIM(3, 2, 2, &pin_PC07),
167+
TIM(8, 3, 2, &pin_PC07),
168+
TIM(3, 2, 3, &pin_PC08),
169+
TIM(8, 3, 3, &pin_PC08),
170+
TIM(3, 2, 4, &pin_PC09),
171+
TIM(8, 3, 4, &pin_PC09),
172+
TIM(4, 2, 1, &pin_PD12),
173+
TIM(4, 2, 2, &pin_PD13),
174+
TIM(4, 2, 3, &pin_PD14),
175+
TIM(4, 2, 4, &pin_PD15),
176+
TIM(9, 3, 1, &pin_PE05),
177+
TIM(9, 3, 2, &pin_PE06),
178+
TIM(1, 1, 1, &pin_PE09),
179+
TIM(1, 1, 2, &pin_PE11),
180+
TIM(1, 1, 3, &pin_PE13),
181+
TIM(1, 1, 4, &pin_PE14),
182+
TIM(10, 3, 1, &pin_PF06),
183+
TIM(11, 3, 1, &pin_PF07),
184+
TIM(13, 9, 1, &pin_PF08),
185+
TIM(14, 9, 1, &pin_PF09),
186+
TIM(12, 9, 1, &pin_PH06),
187+
TIM(12, 9, 2, &pin_PH09),
188+
TIM(5, 2, 1, &pin_PH10),
189+
TIM(5, 2, 2, &pin_PH11),
190+
TIM(5, 2, 3, &pin_PH12),
191+
TIM(5, 2, 4, &pin_PI00),
192+
TIM(8, 3, 4, &pin_PI02),
193+
TIM(8, 3, 1, &pin_PI05),
194+
TIM(8, 3, 2, &pin_PI06),
195+
TIM(8, 3, 3, &pin_PI07),
196+
};
197+
198+
//SDIO
199+
SDIO_TypeDef * mcu_sdio_banks[1] = {SDIO};
200+
201+
const mcu_periph_obj_t mcu_sdio_clock_list[1] = {
202+
PERIPH(1, 12, &pin_PC12),
203+
};
204+
const mcu_periph_obj_t mcu_sdio_command_list[1] = {
205+
PERIPH(1, 12, &pin_PD02),
206+
};
207+
const mcu_periph_obj_t mcu_sdio_data0_list[1] = {
208+
PERIPH(1, 12, &pin_PC08),
209+
};
210+
const mcu_periph_obj_t mcu_sdio_data1_list[1] = {
211+
PERIPH(1, 12, &pin_PC09),
212+
};
213+
const mcu_periph_obj_t mcu_sdio_data2_list[1] = {
214+
PERIPH(1, 12, &pin_PC10),
215+
};
216+
const mcu_periph_obj_t mcu_sdio_data3_list[1] = {
217+
PERIPH(1, 12, &pin_PC11),
218+
};
219+
220+
//CAN
221+
CAN_TypeDef * mcu_can_banks[2] = {CAN1, CAN2};
222+
223+
const mcu_periph_obj_t mcu_can_tx_list[6] = {
224+
PERIPH(1, 9, &pin_PA11),
225+
PERIPH(1, 9, &pin_PB08),
226+
PERIPH(1, 9, &pin_PD00),
227+
PERIPH(1, 9, &pin_PI09),
228+
229+
PERIPH(2, 9, &pin_PB12),
230+
PERIPH(2, 9, &pin_PB05),
231+
};
232+
233+
const mcu_periph_obj_t mcu_can_rx_list[6] = {
234+
PERIPH(1, 9, &pin_PA12),
235+
PERIPH(1, 9, &pin_PB09),
236+
PERIPH(1, 9, &pin_PD01),
237+
PERIPH(1, 9, &pin_PH13),
238+
239+
PERIPH(2, 9, &pin_PB13),
240+
PERIPH(2, 9, &pin_PB06),
194241
};

ports/stm/peripherals/stm32f4/stm32f407xx/periph.h

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,54 @@
2828
#define MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PERIPH_H
2929

3030
//I2C
31-
extern I2C_TypeDef * mcu_i2c_banks[3];
32-
33-
extern const mcu_periph_obj_t mcu_i2c_sda_list[4];
34-
extern const mcu_periph_obj_t mcu_i2c_scl_list[4];
31+
#define I2C_BANK_ARRAY_LEN 3
32+
#define I2C_SDA_ARRAY_LEN 7
33+
#define I2C_SCL_ARRAY_LEN 7
34+
extern I2C_TypeDef * mcu_i2c_banks[I2C_BANK_ARRAY_LEN];
35+
extern const mcu_periph_obj_t mcu_i2c_sda_list[I2C_SDA_ARRAY_LEN];
36+
extern const mcu_periph_obj_t mcu_i2c_scl_list[I2C_SCL_ARRAY_LEN];
3537

3638
//SPI
37-
extern SPI_TypeDef * mcu_spi_banks[3];
38-
39-
extern const mcu_periph_obj_t mcu_spi_sck_list[7];
40-
extern const mcu_periph_obj_t mcu_spi_mosi_list[6];
41-
extern const mcu_periph_obj_t mcu_spi_miso_list[6];
42-
extern const mcu_periph_obj_t mcu_spi_nss_list[6];
39+
#define SPI_BANK_ARRAY_LEN 3
40+
#define SPI_SCK_ARRAY_LEN 7
41+
#define SPI_MOSI_ARRAY_LEN 7
42+
#define SPI_MISO_ARRAY_LEN 7
43+
#define SPI_NSS_ARRAY_LEN 6
44+
extern SPI_TypeDef * mcu_spi_banks[SPI_BANK_ARRAY_LEN];
45+
extern const mcu_periph_obj_t mcu_spi_sck_list[SPI_SCK_ARRAY_LEN];
46+
extern const mcu_periph_obj_t mcu_spi_mosi_list[SPI_MOSI_ARRAY_LEN];
47+
extern const mcu_periph_obj_t mcu_spi_miso_list[SPI_MISO_ARRAY_LEN];
48+
extern const mcu_periph_obj_t mcu_spi_nss_list[SPI_NSS_ARRAY_LEN];
4349

4450
//UART
51+
#define UART_TX_ARRAY_LEN 12
52+
#define UART_RX_ARRAY_LEN 12
4553
extern USART_TypeDef * mcu_uart_banks[MAX_UART];
4654
extern bool mcu_uart_has_usart[MAX_UART];
47-
48-
extern const mcu_periph_obj_t mcu_uart_tx_list[12];
49-
extern const mcu_periph_obj_t mcu_uart_rx_list[12];
55+
extern const mcu_periph_obj_t mcu_uart_tx_list[UART_TX_ARRAY_LEN];
56+
extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN];
5057

5158
//Timers
5259
#define TIM_BANK_ARRAY_LEN 14
53-
#define TIM_PIN_ARRAY_LEN 56
60+
#define TIM_PIN_ARRAY_LEN 67
5461
extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
5562
extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
5663

64+
//SDIO
65+
extern SDIO_TypeDef * mcu_sdio_banks[1];
66+
67+
extern const mcu_periph_obj_t mcu_sdio_clock_list[1];
68+
extern const mcu_periph_obj_t mcu_sdio_command_list[1];
69+
extern const mcu_periph_obj_t mcu_sdio_data0_list[1];
70+
extern const mcu_periph_obj_t mcu_sdio_data1_list[1];
71+
extern const mcu_periph_obj_t mcu_sdio_data2_list[1];
72+
extern const mcu_periph_obj_t mcu_sdio_data3_list[1];
73+
74+
// CAN
75+
extern CAN_TypeDef * mcu_can_banks[2];
76+
77+
extern const mcu_periph_obj_t mcu_can_tx_list[6];
78+
extern const mcu_periph_obj_t mcu_can_rx_list[6];
79+
80+
5781
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PERIPH_H

0 commit comments

Comments
 (0)