Skip to content

Commit 9764006

Browse files
committed
add F401 pin definition
1 parent 256abf5 commit 9764006

File tree

7 files changed

+593
-0
lines changed

7 files changed

+593
-0
lines changed

ports/stm32f4/peripherals/stm32f4/periph.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ typedef struct {
140140

141141
//Starter Lines
142142

143+
#ifdef STM32F411xE
144+
#define HAS_DAC 0
145+
#include "stm32f401xe/periph.h"
146+
#endif
147+
143148
#ifdef STM32F411xE
144149
#define HAS_DAC 0
145150
#include "stm32f411xe/periph.h"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/*
3+
* This file is part of the Micro Python project, http://micropython.org/
4+
*
5+
* The MIT License (MIT)
6+
*
7+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
#include "stm32f4xx_hal.h"
28+
29+
void stm32f4_peripherals_clocks_init(void) {
30+
//System clock init
31+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
32+
RCC_OscInitTypeDef RCC_OscInitStruct;
33+
34+
/* Enable Power Control clock */
35+
__HAL_RCC_PWR_CLK_ENABLE();
36+
37+
/* The voltage scaling allows optimizing the power consumption when the device is
38+
clocked below the maximum system frequency, to update the voltage scaling value
39+
regarding system frequency refer to product datasheet. */
40+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
41+
42+
/* Enable HSE Oscillator and activate PLL with HSE as source */
43+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
44+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
45+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
46+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
47+
RCC_OscInitStruct.PLL.PLLM = 8;
48+
RCC_OscInitStruct.PLL.PLLN = 336;
49+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
50+
RCC_OscInitStruct.PLL.PLLQ = 7;
51+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
52+
53+
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
54+
clocks dividers */
55+
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
56+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
57+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
58+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
59+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
60+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 "stm32f4xx_hal.h"
28+
#include "stm32f4/gpio.h"
29+
#include "common-hal/microcontroller/Pin.h"
30+
31+
void stm32f4_peripherals_gpio_init(void) {
32+
//Enable all GPIO for now
33+
GPIO_InitTypeDef GPIO_InitStruct = {0};
34+
/* GPIO Ports Clock Enable */
35+
__HAL_RCC_GPIOA_CLK_ENABLE();
36+
__HAL_RCC_GPIOB_CLK_ENABLE();
37+
__HAL_RCC_GPIOC_CLK_ENABLE();
38+
__HAL_RCC_GPIOD_CLK_ENABLE();
39+
__HAL_RCC_GPIOE_CLK_ENABLE();
40+
__HAL_RCC_GPIOH_CLK_ENABLE();
41+
42+
//Never reset pins
43+
never_reset_pin_number(2,13); //PC13 anti tamp
44+
never_reset_pin_number(2,14); //PC14 OSC32_IN
45+
never_reset_pin_number(2,15); //PC15 OSC32_OUT
46+
never_reset_pin_number(0,13); //PA13 SWDIO
47+
never_reset_pin_number(0,14); //PA14 SWCLK
48+
}
49+
50+
//LEDs are inverted on F411 DISCO
51+
void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) {
52+
}
53+
54+
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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 "stm32f4/pins.h"
30+
#include "stm32f4/periph.h"
31+
32+
// I2C
33+
34+
I2C_TypeDef * mcu_i2c_banks[3] = {I2C1, I2C2, I2C3};
35+
36+
const mcu_i2c_sda_obj_t mcu_i2c_sda_list[5] = {
37+
I2C_SDA(1, 4, &pin_PB07),
38+
I2C_SDA(1, 4, &pin_PB09),
39+
I2C_SDA(2, 9, &pin_PB03),
40+
I2C_SDA(3, 4, &pin_PC09),
41+
I2C_SDA(3, 9, &pin_PB04),
42+
};
43+
44+
const mcu_i2c_scl_obj_t mcu_i2c_scl_list[4] = {
45+
I2C_SCL(1, 4, &pin_PB06),
46+
I2C_SCL(1, 4, &pin_PB08),
47+
I2C_SCL(2, 4, &pin_PB10),
48+
I2C_SCL(3, 4, &pin_PA08)
49+
};
50+
51+
// SPI
52+
53+
SPI_TypeDef * mcu_spi_banks[4] = {SPI1, SPI2, SPI3, SPI4};
54+
55+
const mcu_spi_sck_obj_t mcu_spi_sck_list[9] = {
56+
SPI(1, 5, &pin_PA05),
57+
SPI(1, 5, &pin_PB03),
58+
SPI(2, 5, &pin_PB10),
59+
SPI(2, 5, &pin_PB13),
60+
SPI(2, 5, &pin_PD03),
61+
SPI(3, 6, &pin_PB03),
62+
SPI(3, 6, &pin_PC10),
63+
SPI(4, 5, &pin_PE02),
64+
SPI(4, 5, &pin_PE12),
65+
};
66+
67+
const mcu_spi_mosi_obj_t mcu_spi_mosi_list[9] = {
68+
SPI(1, 5, &pin_PA07),
69+
SPI(1, 5, &pin_PB05),
70+
SPI(2, 5, &pin_PB15),
71+
SPI(2, 5, &pin_PC03),
72+
SPI(3, 6, &pin_PB05),
73+
SPI(3, 6, &pin_PC12),
74+
SPI(3, 5, &pin_PD06),
75+
SPI(4, 5, &pin_PE06),
76+
SPI(4, 5, &pin_PE14),
77+
};
78+
79+
const mcu_spi_miso_obj_t mcu_spi_miso_list[8] = {
80+
SPI(1, 5, &pin_PA06),
81+
SPI(1, 5, &pin_PB04),
82+
SPI(2, 5, &pin_PB14),
83+
SPI(2, 5, &pin_PC02),
84+
SPI(3, 6, &pin_PB04),
85+
SPI(3, 6, &pin_PC11),
86+
SPI(4, 5, &pin_PE05),
87+
SPI(4, 5, &pin_PE13),
88+
};
89+
90+
const mcu_spi_nss_obj_t mcu_spi_nss_list[9] = {
91+
SPI(1, 5, &pin_PA04),
92+
SPI(1, 5, &pin_PA15),
93+
SPI(2, 5, &pin_PB09),
94+
SPI(2, 5, &pin_PB12),
95+
SPI(3, 6, &pin_PA04),
96+
SPI(3, 6, &pin_PA15),
97+
SPI(4, 6, &pin_PB12),
98+
SPI(4, 5, &pin_PE04),
99+
SPI(4, 5, &pin_PE11),
100+
};
101+
102+
USART_TypeDef * mcu_uart_banks[MAX_UART] = {USART1, USART2, NULL, NULL, NULL, USART6};
103+
bool mcu_uart_has_usart[MAX_UART] = {true, true, false, false, false, true};
104+
105+
const mcu_uart_tx_obj_t mcu_uart_tx_list[6] = {
106+
UART(2, 7, &pin_PA02),
107+
UART(1, 7, &pin_PA09),
108+
UART(6, 8, &pin_PA11),
109+
UART(1, 7, &pin_PB06),
110+
UART(6, 8, &pin_PC06),
111+
UART(2, 7, &pin_PD05),
112+
};
113+
114+
const mcu_uart_rx_obj_t mcu_uart_rx_list[6] = {
115+
UART(2, 7, &pin_PA03),
116+
UART(1, 7, &pin_PA10),
117+
UART(6, 8, &pin_PA12),
118+
UART(1, 7, &pin_PB07),
119+
UART(6, 8, &pin_PC07),
120+
UART(2, 7, &pin_PD06),
121+
};
122+
123+
//Timers
124+
//TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins
125+
TIM_TypeDef * mcu_tim_banks[14] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, NULL, TIM9, TIM10,
126+
TIM11, NULL, NULL, NULL};
127+
128+
const mcu_tim_pin_obj_t mcu_tim_pin_list[44] = {
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(2,1,4,&pin_PA03),
136+
TIM(5,2,4,&pin_PA03),
137+
TIM(9,3,1,&pin_PA02),
138+
TIM(9,3,2,&pin_PA03),
139+
TIM(3,2,1,&pin_PA06),
140+
TIM(3,2,2,&pin_PA07),
141+
TIM(1,1,1,&pin_PA08),
142+
TIM(1,1,2,&pin_PA09),
143+
TIM(1,1,3,&pin_PA10),
144+
TIM(1,1,4,&pin_PA11),
145+
TIM(2,1,1,&pin_PA15),
146+
TIM(3,2,3,&pin_PB00),
147+
TIM(3,2,4,&pin_PB01),
148+
TIM(2,1,2,&pin_PB03),
149+
TIM(3,2,1,&pin_PB04),
150+
TIM(3,2,2,&pin_PB05),
151+
TIM(4,2,1,&pin_PB06),
152+
TIM(4,2,2,&pin_PB07),
153+
TIM(4,2,3,&pin_PB08),
154+
TIM(10,2,1,&pin_PB08),
155+
TIM(4,2,4,&pin_PB09),
156+
TIM(11,2,1,&pin_PB09),
157+
TIM(2,1,3,&pin_PB10),
158+
TIM(3,2,1,&pin_PC06),
159+
TIM(3,2,2,&pin_PC07),
160+
TIM(3,2,3,&pin_PC08),
161+
TIM(3,2,4,&pin_PC09),
162+
TIM(4,2,1,&pin_PD12),
163+
TIM(4,2,2,&pin_PD13),
164+
TIM(4,2,3,&pin_PD14),
165+
TIM(4,2,4,&pin_PD15),
166+
TIM(9,3,1,&pin_PE05),
167+
TIM(9,3,2,&pin_PE06),
168+
TIM(1,1,1,&pin_PE09),
169+
TIM(1,1,2,&pin_PE11),
170+
TIM(1,1,3,&pin_PE13),
171+
TIM(1,1,4,&pin_PE14),
172+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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_STM32F4_PERIPHERALS_STM32F411VE_PERIPH_H
28+
#define MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411VE_PERIPH_H
29+
30+
//I2C
31+
extern I2C_TypeDef * mcu_i2c_banks[3];
32+
33+
extern const mcu_i2c_sda_obj_t mcu_i2c_sda_list[5];
34+
extern const mcu_i2c_scl_obj_t mcu_i2c_scl_list[4];
35+
36+
//SPI
37+
extern SPI_TypeDef * mcu_spi_banks[4];
38+
39+
extern const mcu_spi_sck_obj_t mcu_spi_sck_list[9];
40+
extern const mcu_spi_mosi_obj_t mcu_spi_mosi_list[9];
41+
extern const mcu_spi_miso_obj_t mcu_spi_miso_list[8];
42+
extern const mcu_spi_nss_obj_t mcu_spi_nss_list[9];
43+
44+
//UART
45+
extern USART_TypeDef * mcu_uart_banks[MAX_UART];
46+
extern bool mcu_uart_has_usart[MAX_UART];
47+
48+
extern const mcu_uart_tx_obj_t mcu_uart_tx_list[6];
49+
extern const mcu_uart_rx_obj_t mcu_uart_rx_list[6];
50+
51+
//Timers
52+
#define TIM_BANK_ARRAY_LEN 14
53+
#define TIM_PIN_ARRAY_LEN 44
54+
TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN];
55+
const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN];
56+
57+
#endif // MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411VE_PERIPH_H

0 commit comments

Comments
 (0)