Skip to content

Commit 8bdbc20

Browse files
committed
stmhal: Make HSE PLL parameters configurable per board.
1 parent 23008db commit 8bdbc20

8 files changed

Lines changed: 47 additions & 4 deletions

File tree

stmhal/boards/CERB40/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#define MICROPY_HW_ENABLE_SPI3 (1)
2121
#define MICROPY_HW_ENABLE_CAN (1)
2222

23+
// HSE is 12MHz
24+
#define MICROPY_HW_CLK_PLLM (12)
25+
#define MICROPY_HW_CLK_PLLN (336)
26+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
27+
#define MICROPY_HW_CLK_PLLQ (7)
28+
2329
// The Cerb40 has No LEDs
2430

2531
// The Cerb40 has No SDCard

stmhal/boards/HYDRABUS/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#define MICROPY_HW_ENABLE_SPI3 (1)
2020
#define MICROPY_HW_ENABLE_CAN (0)
2121

22+
// HSE is 8MHz
23+
#define MICROPY_HW_CLK_PLLM (8)
24+
#define MICROPY_HW_CLK_PLLN (336)
25+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
26+
#define MICROPY_HW_CLK_PLLQ (7)
27+
2228
// USRSW/UBTN (Needs Jumper UBTN) is pulled low. Pressing the button makes the input go high.
2329
#define MICROPY_HW_USRSW_PIN (pin_A0)
2430
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)

stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#define MICROPY_HW_ENABLE_SPI3 (0)
2424
#define MICROPY_HW_ENABLE_CAN (0)
2525

26+
// HSE is 25MHz
27+
#define MICROPY_HW_CLK_PLLM (25)
28+
#define MICROPY_HW_CLK_PLLN (336)
29+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
30+
#define MICROPY_HW_CLK_PLLQ (7)
31+
2632
// USRSW is pulled low. Pressing the button makes the input go high.
2733
#define MICROPY_HW_USRSW_PIN (pin_B11)
2834
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)

stmhal/boards/PYBV10/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#define MICROPY_HW_ENABLE_SPI3 (0)
2121
#define MICROPY_HW_ENABLE_CAN (1)
2222

23+
// HSE is 8MHz
24+
#define MICROPY_HW_CLK_PLLM (8)
25+
#define MICROPY_HW_CLK_PLLN (336)
26+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
27+
#define MICROPY_HW_CLK_PLLQ (7)
28+
2329
// The pyboard has a 32kHz crystal for the RTC
2430
#define MICROPY_HW_RTC_USE_LSE (1)
2531

stmhal/boards/PYBV3/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#define MICROPY_HW_ENABLE_SPI3 (0)
2020
#define MICROPY_HW_ENABLE_CAN (1)
2121

22+
// HSE is 8MHz
23+
#define MICROPY_HW_CLK_PLLM (8)
24+
#define MICROPY_HW_CLK_PLLN (336)
25+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
26+
#define MICROPY_HW_CLK_PLLQ (7)
27+
2228
// The pyboard has a 32kHz crystal for the RTC
2329
#define MICROPY_HW_RTC_USE_LSE (1)
2430

stmhal/boards/PYBV4/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#define MICROPY_HW_ENABLE_SPI3 (0)
2020
#define MICROPY_HW_ENABLE_CAN (1)
2121

22+
// HSE is 8MHz
23+
#define MICROPY_HW_CLK_PLLM (8)
24+
#define MICROPY_HW_CLK_PLLN (336)
25+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
26+
#define MICROPY_HW_CLK_PLLQ (7)
27+
2228
// The pyboard has a 32kHz crystal for the RTC
2329
#define MICROPY_HW_RTC_USE_LSE (1)
2430

stmhal/boards/STM32F4DISC/mpconfigboard.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#define MICROPY_HW_ENABLE_SPI3 (0)
2020
#define MICROPY_HW_ENABLE_CAN (1)
2121

22+
// HSE is 8MHz
23+
#define MICROPY_HW_CLK_PLLM (8)
24+
#define MICROPY_HW_CLK_PLLN (336)
25+
#define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
26+
#define MICROPY_HW_CLK_PLLQ (7)
27+
2228
// USRSW is pulled low. Pressing the button makes the input go high.
2329
#define MICROPY_HW_USRSW_PIN (pin_A0)
2430
#define MICROPY_HW_USRSW_PULL (GPIO_NOPULL)

stmhal/system_stm32f4xx.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
* @{
9292
*/
9393

94+
#include "mpconfigboard.h"
9495
#include "stm32f4xx_hal.h"
9596

9697
void __fatal_error(const char *msg);
@@ -365,10 +366,10 @@ void SystemClock_Config(void)
365366
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
366367
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
367368
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
368-
RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000;
369-
RCC_OscInitStruct.PLL.PLLN = 336;
370-
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
371-
RCC_OscInitStruct.PLL.PLLQ = 7;
369+
RCC_OscInitStruct.PLL.PLLM = MICROPY_HW_CLK_PLLM;
370+
RCC_OscInitStruct.PLL.PLLN = MICROPY_HW_CLK_PLLN;
371+
RCC_OscInitStruct.PLL.PLLP = MICROPY_HW_CLK_PLLP;
372+
RCC_OscInitStruct.PLL.PLLQ = MICROPY_HW_CLK_PLLQ;
372373
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
373374
{
374375
__fatal_error("HAL_RCC_OscConfig");

0 commit comments

Comments
 (0)