Skip to content

Commit 8a93a81

Browse files
committed
Chip specific code.
1 parent 5dbdf72 commit 8a93a81

File tree

6 files changed

+193
-64
lines changed

6 files changed

+193
-64
lines changed

ports/stm/common-hal/busio/UART.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,11 @@ STATIC void uart_clock_enable(uint16_t mask) {
443443
#endif
444444
#ifdef USART3
445445
if (mask & (1 << 2)) {
446+
#ifndef STM32F412Cx
446447
__HAL_RCC_USART3_FORCE_RESET();
447448
__HAL_RCC_USART3_RELEASE_RESET();
448449
__HAL_RCC_USART3_CLK_ENABLE();
450+
#endif
449451
}
450452
#endif
451453
#ifdef UART4
@@ -516,9 +518,11 @@ STATIC void uart_clock_disable(uint16_t mask) {
516518
#endif
517519
#ifdef USART3
518520
if (mask & (1 << 2)) {
521+
#ifndef STM32F412Cx
519522
__HAL_RCC_USART3_FORCE_RESET();
520523
__HAL_RCC_USART3_RELEASE_RESET();
521524
__HAL_RCC_USART3_CLK_DISABLE();
525+
#endif
522526
}
523527
#endif
524528
#ifdef UART4

ports/stm/peripherals/stm32f4/periph.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
#include "stm32f4xx_hal.h"
3434
#include "stm32f4/pins.h"
3535

36-
// I2C
36+
// I2C
3737
// TODO: these objects should be condensed into a single 'periph_pin' unless we
38-
// find a compelling reason to store more unique data in them.
38+
// find a compelling reason to store more unique data in them.
3939

4040
typedef struct {
4141
uint8_t i2c_index:4; // Index of the I2C unit (1 to 3)
@@ -44,8 +44,8 @@ typedef struct {
4444
} mcu_i2c_sda_obj_t;
4545

4646
typedef struct {
47-
uint8_t i2c_index:4;
48-
uint8_t altfn_index:4;
47+
uint8_t i2c_index:4;
48+
uint8_t altfn_index:4;
4949
const mcu_pin_obj_t * pin;
5050
} mcu_i2c_scl_obj_t;
5151

@@ -64,9 +64,9 @@ typedef struct {
6464
.pin = scl_pin, \
6565
}
6666

67-
// SPI
67+
// SPI
6868
// TODO: these objects should be condensed into a single 'periph_pin' unless we
69-
// find a compelling reason to store more unique data in them.
69+
// find a compelling reason to store more unique data in them.
7070

7171
typedef struct {
7272
uint8_t spi_index:4; //Up to 6 SPI units
@@ -75,20 +75,20 @@ typedef struct {
7575
} mcu_spi_sck_obj_t;
7676

7777
typedef struct {
78-
uint8_t spi_index:4;
79-
uint8_t altfn_index:4;
78+
uint8_t spi_index:4;
79+
uint8_t altfn_index:4;
8080
const mcu_pin_obj_t * pin;
8181
} mcu_spi_mosi_obj_t;
8282

8383
typedef struct {
84-
uint8_t spi_index:4;
85-
uint8_t altfn_index:4;
84+
uint8_t spi_index:4;
85+
uint8_t altfn_index:4;
8686
const mcu_pin_obj_t * pin;
8787
} mcu_spi_miso_obj_t;
8888

8989
typedef struct {
90-
uint8_t spi_index:4;
91-
uint8_t altfn_index:4;
90+
uint8_t spi_index:4;
91+
uint8_t altfn_index:4;
9292
const mcu_pin_obj_t * pin;
9393
} mcu_spi_nss_obj_t;
9494

@@ -101,17 +101,17 @@ typedef struct {
101101

102102
// UART
103103
// TODO: these objects should be condensed into a single 'periph_pin' unless we
104-
// find a compelling reason to store more unique data in them.
104+
// find a compelling reason to store more unique data in them.
105105

106106
typedef struct {
107-
uint8_t uart_index:4;
108-
uint8_t altfn_index:4;
107+
uint8_t uart_index:4;
108+
uint8_t altfn_index:4;
109109
const mcu_pin_obj_t * pin;
110110
} mcu_uart_tx_obj_t;
111111

112112
typedef struct {
113-
uint8_t uart_index:4;
114-
uint8_t altfn_index:4;
113+
uint8_t uart_index:4;
114+
uint8_t altfn_index:4;
115115
const mcu_pin_obj_t * pin;
116116
} mcu_uart_rx_obj_t;
117117

@@ -124,8 +124,8 @@ typedef struct {
124124

125125
//Timers
126126
typedef struct {
127-
uint8_t tim_index:4;
128-
uint8_t altfn_index:4;
127+
uint8_t tim_index:4;
128+
uint8_t altfn_index:4;
129129
uint8_t channel_index:4;
130130
const mcu_pin_obj_t * pin;
131131
} mcu_tim_pin_obj_t;
@@ -154,6 +154,13 @@ typedef struct {
154154
#include "stm32f411xe/periph.h"
155155
#endif
156156

157+
#ifdef BOARD_THUNDERPACK_STM32F412
158+
#define HAS_DAC 0
159+
#define HAS_TRNG 1
160+
#define HAS_BASIC_TIM 1
161+
#include "stm32f412cx_thunderpack/periph.h"
162+
#endif
163+
157164
#ifdef STM32F412Zx
158165
#define HAS_DAC 0
159166
#define HAS_TRNG 1

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

Lines changed: 122 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,56 +31,133 @@
3131

3232
// I2C
3333

34-
I2C_TypeDef * mcu_i2c_banks[3] = {I2C1, NULL, NULL};
34+
I2C_TypeDef * mcu_i2c_banks[3] = {I2C1, I2C2, I2C3};
3535

3636
const mcu_i2c_sda_obj_t mcu_i2c_sda_list[8] = {
3737
I2C_SDA(1, 4, &pin_PB07),
38+
I2C_SDA(1, 4, &pin_PB09),
39+
I2C_SDA(2, 4, &pin_PB11), //not on LQFP100
40+
I2C_SDA(2, 9, &pin_PB09),
41+
I2C_SDA(2, 9, &pin_PB03),
42+
I2C_SDA(3, 4, &pin_PC09),
43+
I2C_SDA(3, 9, &pin_PB04),
44+
I2C_SDA(3, 9, &pin_PB08)
3845
};
3946

4047
const mcu_i2c_scl_obj_t mcu_i2c_scl_list[4] = {
4148
I2C_SCL(1, 4, &pin_PB06),
49+
I2C_SCL(1, 4, &pin_PB08),
50+
I2C_SCL(2, 4, &pin_PB10),
51+
I2C_SCL(3, 4, &pin_PA08)
4252
};
4353

4454
// SPI
4555

46-
SPI_TypeDef * mcu_spi_banks[5] = {SPI1, NULL, NULL, NULL, NULL};
56+
SPI_TypeDef * mcu_spi_banks[5] = {SPI1, SPI2, SPI3, SPI4, SPI5};
4757

4858
const mcu_spi_sck_obj_t mcu_spi_sck_list[15] = {
4959
SPI(1, 5, &pin_PA05),
60+
SPI(1, 5, &pin_PB03),
61+
SPI(2, 5, &pin_PB10),
62+
SPI(2, 5, &pin_PB13),
63+
SPI(2, 5, &pin_PC07),
64+
SPI(2, 5, &pin_PD03),
65+
SPI(3, 6, &pin_PB03),
66+
SPI(3, 7, &pin_PB12),
67+
SPI(3, 6, &pin_PC10),
68+
SPI(4, 6, &pin_PB13),
69+
SPI(4, 5, &pin_PE02),
70+
SPI(4, 5, &pin_PE12),
71+
SPI(5, 6, &pin_PB00),
72+
SPI(5, 6, &pin_PE02),
73+
SPI(5, 6, &pin_PE12)
5074
};
5175

5276
const mcu_spi_mosi_obj_t mcu_spi_mosi_list[14] = {
5377
SPI(1, 5, &pin_PA07),
5478
SPI(1, 5, &pin_PB05),
79+
SPI(2, 5, &pin_PB15),
80+
SPI(2, 5, &pin_PC03),
81+
SPI(3, 6, &pin_PB05),
82+
SPI(3, 6, &pin_PC12),
83+
SPI(3, 5, &pin_PD06),
84+
SPI(4, 5, &pin_PA01),
85+
SPI(4, 5, &pin_PE06),
86+
SPI(4, 5, &pin_PE14),
87+
SPI(5, 6, &pin_PA10),
88+
SPI(5, 6, &pin_PB08),
89+
SPI(5, 6, &pin_PE06),
90+
SPI(5, 6, &pin_PE14)
5591
};
5692

5793
const mcu_spi_miso_obj_t mcu_spi_miso_list[12] = {
5894
SPI(1, 5, &pin_PA06),
95+
SPI(1, 5, &pin_PB04),
96+
SPI(2, 5, &pin_PB14),
97+
SPI(2, 5, &pin_PC02),
98+
SPI(3, 6, &pin_PB04),
99+
SPI(3, 6, &pin_PC11),
100+
SPI(4, 6, &pin_PA11),
101+
SPI(4, 5, &pin_PE05),
102+
SPI(4, 5, &pin_PE13),
103+
SPI(5, 6, &pin_PA12),
104+
SPI(5, 6, &pin_PE05),
105+
SPI(5, 6, &pin_PE13)
59106
};
60107

61108
const mcu_spi_nss_obj_t mcu_spi_nss_list[12] = {
62109
SPI(1, 5, &pin_PA04),
110+
SPI(1, 5, &pin_PA15),
111+
SPI(2, 5, &pin_PB09),
112+
SPI(2, 5, &pin_PB12),
113+
SPI(3, 6, &pin_PA04),
114+
SPI(3, 6, &pin_PA15),
115+
SPI(4, 6, &pin_PB12),
116+
SPI(4, 5, &pin_PE04),
117+
SPI(4, 5, &pin_PE11),
118+
SPI(5, 6, &pin_PB01),
119+
SPI(5, 6, &pin_PE04),
120+
SPI(5, 6, &pin_PE11)
63121
};
64122

65123
//UART
66124

67-
USART_TypeDef * mcu_uart_banks[MAX_UART] = {USART1, NULL, NULL, NULL, NULL, NULL};
68-
bool mcu_uart_has_usart[MAX_UART] = {true, false, false, false, false, false};
125+
USART_TypeDef * mcu_uart_banks[MAX_UART] = {USART1, USART2, USART3, NULL, NULL, USART6};
126+
bool mcu_uart_has_usart[MAX_UART] = {true, true, true, false, false, true};
69127

70128
const mcu_uart_tx_obj_t mcu_uart_tx_list[11] = {
129+
UART(2, 7, &pin_PA02),
71130
UART(1, 7, &pin_PA09),
131+
UART(1, 7, &pin_PA15),
132+
UART(6, 8, &pin_PA11),
72133
UART(1, 7, &pin_PB06),
134+
UART(3, 7, &pin_PB10),
135+
UART(6, 8, &pin_PC06),
136+
UART(3, 7, &pin_PC10),
137+
UART(2, 7, &pin_PD05),
138+
UART(3, 7, &pin_PD08),
139+
UART(6, 8, &pin_PG14),
73140
};
74141

75142
const mcu_uart_rx_obj_t mcu_uart_rx_list[12] = {
143+
UART(2, 7, &pin_PA03),
76144
UART(1, 7, &pin_PA10),
145+
UART(6, 8, &pin_PA12),
146+
UART(1, 7, &pin_PB03),
77147
UART(1, 7, &pin_PB07),
148+
UART(3, 7, &pin_PB11),
149+
UART(3, 7, &pin_PC05),
150+
UART(6, 8, &pin_PC07),
151+
UART(3, 7, &pin_PC11),
152+
UART(2, 7, &pin_PD06),
153+
UART(3, 7, &pin_PD09),
154+
UART(6, 8, &pin_PG09),
78155
};
79156

80157
//Timers
81158
//TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
82-
TIM_TypeDef * mcu_tim_banks[14] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, NULL, TIM9, NULL,
83-
NULL, NULL, TIM13, TIM14};
159+
TIM_TypeDef * mcu_tim_banks[14] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, TIM9, TIM10,
160+
TIM11, TIM12, TIM13, TIM14};
84161

85162
const mcu_tim_pin_obj_t mcu_tim_pin_list[60] = {
86163
TIM(2,1,1,&pin_PA00),
@@ -101,7 +178,46 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[60] = {
101178
TIM(1,1,2,&pin_PA09),
102179
TIM(1,1,3,&pin_PA10),
103180
TIM(1,1,4,&pin_PA11),
181+
TIM(2,1,1,&pin_PA15),
182+
TIM(3,2,3,&pin_PB00),
183+
TIM(3,2,4,&pin_PB01),
184+
TIM(2,1,2,&pin_PB03),
185+
TIM(3,2,1,&pin_PB04),
104186
TIM(3,2,2,&pin_PB05),
105187
TIM(4,2,1,&pin_PB06),
106188
TIM(4,2,2,&pin_PB07),
189+
TIM(4,2,3,&pin_PB08),
190+
TIM(10,2,1,&pin_PB08),
191+
TIM(4,2,4,&pin_PB09),
192+
TIM(11,2,1,&pin_PB09),
193+
TIM(2,1,3,&pin_PB10),
194+
TIM(2,1,4,&pin_PB11),
195+
TIM(12,9,1,&pin_PB14),
196+
TIM(12,9,2,&pin_PB15),
197+
TIM(3,2,1,&pin_PC06),
198+
TIM(3,2,2,&pin_PC07),
199+
TIM(3,2,3,&pin_PC08),
200+
TIM(3,2,4,&pin_PC09),
201+
TIM(8,3,1,&pin_PC06),
202+
TIM(8,3,2,&pin_PC07),
203+
TIM(8,3,3,&pin_PC08),
204+
TIM(8,3,4,&pin_PC09),
205+
TIM(4,2,1,&pin_PD12),
206+
TIM(4,2,2,&pin_PD13),
207+
TIM(4,2,3,&pin_PD14),
208+
TIM(4,2,4,&pin_PD15),
209+
TIM(9,3,1,&pin_PE05),
210+
TIM(9,3,2,&pin_PE06),
211+
TIM(1,1,1,&pin_PE09),
212+
TIM(1,1,2,&pin_PE11),
213+
TIM(1,1,3,&pin_PE13),
214+
TIM(1,1,4,&pin_PE14),
215+
TIM(10,3,1,&pin_PF06),
216+
TIM(11,3,1,&pin_PF07),
217+
TIM(13,9,1,&pin_PF08),
218+
TIM(14,9,1,&pin_PF09),
219+
TIM(5,2,1,&pin_PF03),
220+
TIM(5,2,2,&pin_PF04),
221+
TIM(5,2,3,&pin_PF05),
222+
TIM(5,2,4,&pin_PF10),
107223
};

ports/stm/peripherals/stm32f4/stm32f412cx_thunderpack/pins.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ const mcu_pin_obj_t pin_PC13 = PIN(2, 13, NO_ADC); //anti-tamp
3838
const mcu_pin_obj_t pin_PC14 = PIN(2, 14, NO_ADC); //OSC32_IN
3939
const mcu_pin_obj_t pin_PC15 = PIN(2, 15, NO_ADC); //OSC32_OUT
4040

41-
const mcu_pin_obj_t pin_PF00 = PIN(5, 0, NO_ADC); // 144 only
42-
const mcu_pin_obj_t pin_PF01 = PIN(5, 1, NO_ADC); // 144 only
43-
const mcu_pin_obj_t pin_PF02 = PIN(5, 2, NO_ADC); // 144 only
44-
const mcu_pin_obj_t pin_PF03 = PIN(5, 3, NO_ADC); // 144 only
45-
const mcu_pin_obj_t pin_PF04 = PIN(5, 4, NO_ADC); // 144 only
46-
const mcu_pin_obj_t pin_PF05 = PIN(5, 5, NO_ADC); // 144 only
47-
const mcu_pin_obj_t pin_PF06 = PIN(5, 6, NO_ADC); // 144 only
48-
const mcu_pin_obj_t pin_PF07 = PIN(5, 7, NO_ADC); // 144 only
49-
const mcu_pin_obj_t pin_PF08 = PIN(5, 8, NO_ADC); // 144 only
50-
const mcu_pin_obj_t pin_PF09 = PIN(5, 9, NO_ADC); // 144 only
51-
const mcu_pin_obj_t pin_PF10 = PIN(5, 10, NO_ADC); // 144 only
41+
const mcu_pin_obj_t pin_PF00 = PIN(5, 0, NO_ADC); // 144 only
42+
const mcu_pin_obj_t pin_PF01 = PIN(5, 1, NO_ADC); // 144 only
43+
const mcu_pin_obj_t pin_PF02 = PIN(5, 2, NO_ADC); // 144 only
44+
const mcu_pin_obj_t pin_PF03 = PIN(5, 3, NO_ADC); // 144 only
45+
const mcu_pin_obj_t pin_PF04 = PIN(5, 4, NO_ADC); // 144 only
46+
const mcu_pin_obj_t pin_PF05 = PIN(5, 5, NO_ADC); // 144 only
47+
const mcu_pin_obj_t pin_PF06 = PIN(5, 6, NO_ADC); // 144 only
48+
const mcu_pin_obj_t pin_PF07 = PIN(5, 7, NO_ADC); // 144 only
49+
const mcu_pin_obj_t pin_PF08 = PIN(5, 8, NO_ADC); // 144 only
50+
const mcu_pin_obj_t pin_PF09 = PIN(5, 9, NO_ADC); // 144 only
51+
const mcu_pin_obj_t pin_PF10 = PIN(5, 10, NO_ADC); // 144 only
5252

5353
const mcu_pin_obj_t pin_PC00 = PIN(2, 0, ADC_INPUT(ADC_1,10));
5454
const mcu_pin_obj_t pin_PC01 = PIN(2, 1, ADC_INPUT(ADC_1,11));
@@ -71,14 +71,14 @@ const mcu_pin_obj_t pin_PB00 = PIN(1, 0, ADC_INPUT(ADC_1,8));
7171
const mcu_pin_obj_t pin_PB01 = PIN(1, 1, ADC_INPUT(ADC_1,9));
7272
const mcu_pin_obj_t pin_PB02 = PIN(1, 2, NO_ADC);
7373

74-
const mcu_pin_obj_t pin_PF11 = PIN(5, 11, NO_ADC); // 144 only
75-
const mcu_pin_obj_t pin_PF12 = PIN(5, 12, NO_ADC); // 144 only
76-
const mcu_pin_obj_t pin_PF13 = PIN(5, 13, NO_ADC); // 144 only
77-
const mcu_pin_obj_t pin_PF14 = PIN(5, 14, NO_ADC); // 144 only
78-
const mcu_pin_obj_t pin_PF15 = PIN(5, 15, NO_ADC); // 144 only
74+
const mcu_pin_obj_t pin_PF11 = PIN(5, 11, NO_ADC); // 144 only
75+
const mcu_pin_obj_t pin_PF12 = PIN(5, 12, NO_ADC); // 144 only
76+
const mcu_pin_obj_t pin_PF13 = PIN(5, 13, NO_ADC); // 144 only
77+
const mcu_pin_obj_t pin_PF14 = PIN(5, 14, NO_ADC); // 144 only
78+
const mcu_pin_obj_t pin_PF15 = PIN(5, 15, NO_ADC); // 144 only
7979

80-
const mcu_pin_obj_t pin_PG00 = PIN(6, 0, NO_ADC); // 144 only
81-
const mcu_pin_obj_t pin_PG01 = PIN(6, 1, NO_ADC); // 144 only
80+
const mcu_pin_obj_t pin_PG00 = PIN(6, 0, NO_ADC); // 144 only
81+
const mcu_pin_obj_t pin_PG01 = PIN(6, 1, NO_ADC); // 144 only
8282

8383
const mcu_pin_obj_t pin_PE07 = PIN(4, 7, NO_ADC);
8484
const mcu_pin_obj_t pin_PE08 = PIN(4, 8, NO_ADC);

0 commit comments

Comments
 (0)