Skip to content

Commit 46129e3

Browse files
committed
add stm32f412cx micro to cpy
1 parent bfd56d4 commit 46129e3

File tree

10 files changed

+501
-0
lines changed

10 files changed

+501
-0
lines changed

ports/stm/peripherals/periph.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ typedef struct {
8282
#include "stm32f4/stm32f411xe/periph.h"
8383
#endif
8484

85+
#ifdef STM32F412Cx
86+
#define HAS_DAC 0
87+
#define HAS_TRNG 1
88+
#define HAS_BASIC_TIM 1
89+
#include "stm32f4/stm32f412cx/periph.h"
90+
#endif
91+
8592
#ifdef STM32F412Zx
8693
#define HAS_DAC 0
8794
#define HAS_TRNG 1

ports/stm/peripherals/pins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ extern const mp_obj_type_t mcu_pin_type;
8282
#ifdef STM32F411xE
8383
#include "stm32f4/stm32f411xe/pins.h"
8484
#endif
85+
#ifdef STM32F412Cx
86+
#include "stm32f4/stm32f412cx/pins.h"
87+
#endif
8588
#ifdef STM32F412Zx
8689
#include "stm32f4/stm32f412zx/pins.h"
8790
#endif

ports/stm/peripherals/stm32f4/clocks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#ifdef STM32F411xE
3636
#include "stm32f4/stm32f411xe/clocks.h"
3737
#endif
38+
#ifdef STM32F412Cx
39+
#include "stm32f4/stm32f412cx/clocks.h"
40+
#endif
3841
#ifdef STM32F412Zx
3942
#include "stm32f4/stm32f412zx/clocks.h"
4043
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Lucian Copeland for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "stm32f4xx_hal.h"
28+
29+
// Chip: STM32F412Cx
30+
// Line Type: Access Line
31+
// Speed: 100MHz (MAX)
32+
33+
// Note - uses the I2S PLL for USB to enable full 100MHz operation, since USB
34+
// can't get the right divisors from 100MHz PLL settings.
35+
36+
// Defaults:
37+
#ifndef CPY_CLK_VSCALE
38+
#define CPY_CLK_VSCALE (PWR_REGULATOR_VOLTAGE_SCALE1)
39+
#endif
40+
#ifndef CPY_CLK_PLLN
41+
#define CPY_CLK_PLLN (200)
42+
#endif
43+
#ifndef CPY_CLK_PLLP
44+
#define CPY_CLK_PLLP (RCC_PLLP_DIV2)
45+
#endif
46+
#ifndef CPY_CLK_PLLQ
47+
#define CPY_CLK_PLLQ (7)
48+
#endif
49+
#ifndef CPY_CLK_AHBDIV
50+
#define CPY_CLK_AHBDIV (RCC_SYSCLK_DIV1)
51+
#endif
52+
#ifndef CPY_CLK_APB1DIV
53+
#define CPY_CLK_APB1DIV (RCC_HCLK_DIV2)
54+
#endif
55+
#ifndef CPY_CLK_APB2DIV
56+
#define CPY_CLK_APB2DIV (RCC_HCLK_DIV1)
57+
#endif
58+
#ifndef CPY_CLK_FLASH_LATENCY
59+
#define CPY_CLK_FLASH_LATENCY (FLASH_LATENCY_3)
60+
#endif
61+
#ifndef CPY_CLK_USB_USES_AUDIOPLL
62+
#define CPY_CLK_USB_USES_AUDIOPLL (1)
63+
#endif
64+
#ifndef BOARD_HSE_SOURCE
65+
#define BOARD_HSE_SOURCE (RCC_HSE_ON)
66+
#endif
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "peripherals/gpio.h"
28+
#include "common-hal/microcontroller/Pin.h"
29+
30+
void stm32_peripherals_gpio_init(void) {
31+
32+
__HAL_RCC_GPIOA_CLK_ENABLE();
33+
__HAL_RCC_GPIOB_CLK_ENABLE();
34+
__HAL_RCC_GPIOC_CLK_ENABLE();
35+
36+
// Never reset pins
37+
never_reset_pin_number(0,13); // PA13 SWDIO
38+
never_reset_pin_number(0,14); // PA14 SWCLK
39+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/obj.h"
28+
#include "py/mphal.h"
29+
#include "peripherals/pins.h"
30+
#include "peripherals/periph.h"
31+
32+
// I2C
33+
34+
I2C_TypeDef *mcu_i2c_banks[I2C_BANK_ARRAY_LEN] = {I2C1, I2C2, I2C3};
35+
36+
const mcu_periph_obj_t mcu_i2c_sda_list[I2C_SDA_ARRAY_LEN] = {
37+
PERIPH(1, 4, &pin_PB07),
38+
PERIPH(1, 4, &pin_PB09),
39+
PERIPH(2, 9, &pin_PB03),
40+
PERIPH(2, 9, &pin_PB09),
41+
PERIPH(3, 9, &pin_PB04),
42+
PERIPH(3, 9, &pin_PB08)
43+
};
44+
45+
const mcu_periph_obj_t mcu_i2c_scl_list[I2C_SCL_ARRAY_LEN] = {
46+
PERIPH(1, 4, &pin_PB06),
47+
PERIPH(1, 4, &pin_PB08),
48+
PERIPH(2, 4, &pin_PB10),
49+
PERIPH(3, 4, &pin_PA08)
50+
};
51+
52+
// SPI
53+
54+
SPI_TypeDef *mcu_spi_banks[SPI_BANK_ARRAY_LEN] = {SPI1, SPI2, SPI3, SPI4, SPI5};
55+
56+
const mcu_periph_obj_t mcu_spi_sck_list[SPI_SCK_ARRAY_LEN] = {
57+
PERIPH(1, 5, &pin_PA05),
58+
PERIPH(1, 5, &pin_PB03),
59+
PERIPH(2, 5, &pin_PB10),
60+
PERIPH(2, 5, &pin_PB13),
61+
PERIPH(3, 6, &pin_PB03),
62+
PERIPH(3, 7, &pin_PB12),
63+
PERIPH(4, 6, &pin_PB13),
64+
PERIPH(5, 6, &pin_PB00)
65+
};
66+
67+
const mcu_periph_obj_t mcu_spi_mosi_list[SPI_MOSI_ARRAY_LEN] = {
68+
PERIPH(1, 5, &pin_PA07),
69+
PERIPH(1, 5, &pin_PB05),
70+
PERIPH(2, 5, &pin_PB15),
71+
PERIPH(3, 6, &pin_PB05),
72+
PERIPH(4, 5, &pin_PA01),
73+
PERIPH(5, 6, &pin_PA10),
74+
PERIPH(5, 6, &pin_PB08)
75+
};
76+
77+
const mcu_periph_obj_t mcu_spi_miso_list[SPI_MISO_ARRAY_LEN] = {
78+
PERIPH(1, 5, &pin_PA06),
79+
PERIPH(1, 5, &pin_PB04),
80+
PERIPH(2, 5, &pin_PB14),
81+
PERIPH(3, 6, &pin_PB04),
82+
PERIPH(4, 6, &pin_PA11),
83+
PERIPH(5, 6, &pin_PA12)
84+
};
85+
86+
const mcu_periph_obj_t mcu_spi_nss_list[SPI_NSS_ARRAY_LEN] = {
87+
PERIPH(1, 5, &pin_PA04),
88+
PERIPH(1, 5, &pin_PA15),
89+
PERIPH(2, 5, &pin_PB09),
90+
PERIPH(2, 5, &pin_PB12),
91+
PERIPH(3, 6, &pin_PA04),
92+
PERIPH(3, 6, &pin_PA15),
93+
PERIPH(4, 6, &pin_PB12),
94+
PERIPH(5, 6, &pin_PB01)
95+
};
96+
97+
// UART
98+
99+
USART_TypeDef *mcu_uart_banks[MAX_UART] = {USART1, USART2, USART3, NULL, NULL, USART6};
100+
bool mcu_uart_has_usart[MAX_UART] = {true, true, true, false, false, true};
101+
102+
const mcu_periph_obj_t mcu_uart_tx_list[UART_TX_ARRAY_LEN] = {
103+
PERIPH(1, 7, &pin_PA09),
104+
PERIPH(1, 7, &pin_PA15),
105+
PERIPH(1, 7, &pin_PB06),
106+
PERIPH(2, 7, &pin_PA02),
107+
PERIPH(3, 7, &pin_PB10),
108+
PERIPH(6, 8, &pin_PA11)
109+
};
110+
111+
const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN] = {
112+
PERIPH(1, 7, &pin_PA10),
113+
PERIPH(1, 7, &pin_PB03),
114+
PERIPH(1, 7, &pin_PB07),
115+
PERIPH(2, 7, &pin_PA03),
116+
PERIPH(6, 8, &pin_PA12)
117+
};
118+
119+
// Timers
120+
// TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
121+
TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, TIM9, TIM10,
122+
TIM11, TIM12, TIM13, TIM14};
123+
124+
// TIM8
125+
const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = {
126+
TIM(1, 1, 1, &pin_PA08),
127+
TIM(1, 1, 2, &pin_PA09),
128+
TIM(1, 1, 3, &pin_PA10),
129+
TIM(1, 1, 4, &pin_PA11),
130+
TIM(2, 1, 1, &pin_PA00),
131+
TIM(2, 1, 1, &pin_PA05),
132+
TIM(2, 1, 1, &pin_PA15),
133+
TIM(2, 1, 2, &pin_PA01),
134+
TIM(2, 1, 2, &pin_PB03),
135+
TIM(2, 1, 3, &pin_PA02),
136+
TIM(2, 1, 3, &pin_PB10),
137+
TIM(2, 1, 4, &pin_PA03),
138+
TIM(3, 2, 1, &pin_PA06),
139+
TIM(3, 2, 1, &pin_PB04),
140+
TIM(3, 2, 2, &pin_PA07),
141+
TIM(3, 2, 2, &pin_PB05),
142+
TIM(3, 2, 3, &pin_PB00),
143+
TIM(3, 2, 4, &pin_PB01),
144+
TIM(4, 2, 1, &pin_PB06),
145+
TIM(4, 2, 2, &pin_PB07),
146+
TIM(4, 2, 3, &pin_PB08),
147+
TIM(4, 2, 4, &pin_PB09),
148+
TIM(5, 2, 1, &pin_PA00),
149+
TIM(5, 2, 2, &pin_PA01),
150+
TIM(5, 2, 3, &pin_PA02),
151+
TIM(5, 2, 4, &pin_PA03),
152+
TIM(9, 3, 1, &pin_PA02),
153+
TIM(9, 3, 2, &pin_PA03),
154+
TIM(10, 3, 1, &pin_PB08),
155+
TIM(11, 3, 1, &pin_PB09),
156+
TIM(12, 9, 1, &pin_PB14),
157+
TIM(12, 9, 2, &pin_PB15),
158+
TIM(13, 9, 1, &pin_PA06),
159+
TIM(14, 9, 1, &pin_PA07)
160+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F412CX_PERIPH_H
28+
#define MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F412CX_PERIPH_H
29+
30+
// I2C
31+
#define I2C_BANK_ARRAY_LEN 3
32+
#define I2C_SDA_ARRAY_LEN 6
33+
#define I2C_SCL_ARRAY_LEN 4
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];
37+
38+
39+
// SPI
40+
#define SPI_BANK_ARRAY_LEN 5
41+
#define SPI_SCK_ARRAY_LEN 8
42+
#define SPI_MOSI_ARRAY_LEN 7
43+
#define SPI_MISO_ARRAY_LEN 6
44+
#define SPI_NSS_ARRAY_LEN 8
45+
extern SPI_TypeDef *mcu_spi_banks[SPI_BANK_ARRAY_LEN];
46+
extern const mcu_periph_obj_t mcu_spi_sck_list[SPI_SCK_ARRAY_LEN];
47+
extern const mcu_periph_obj_t mcu_spi_mosi_list[SPI_MOSI_ARRAY_LEN];
48+
extern const mcu_periph_obj_t mcu_spi_miso_list[SPI_MISO_ARRAY_LEN];
49+
extern const mcu_periph_obj_t mcu_spi_nss_list[SPI_NSS_ARRAY_LEN];
50+
51+
// UART
52+
#define UART_TX_ARRAY_LEN 6
53+
#define UART_RX_ARRAY_LEN 5
54+
extern USART_TypeDef *mcu_uart_banks[MAX_UART];
55+
extern bool mcu_uart_has_usart[MAX_UART];
56+
extern const mcu_periph_obj_t mcu_uart_tx_list[UART_TX_ARRAY_LEN];
57+
extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN];
58+
59+
// Timers
60+
#define TIM_BANK_ARRAY_LEN 14
61+
#define TIM_PIN_ARRAY_LEN 34
62+
extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN];
63+
extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
64+
65+
#endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F412CX_PERIPH_H

0 commit comments

Comments
 (0)