Skip to content

Commit 49a22b0

Browse files
authored
Merge pull request #3320 from hierophect/stm32-meowbit-fix
STM32: Fix Meowbit startup and associated bugs
2 parents 24fb08d + 7720525 commit 49a22b0

File tree

7 files changed

+14
-47
lines changed

7 files changed

+14
-47
lines changed

ports/stm/boards/meowbit_v121/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void board_init(void) {
106106
&pin_PB03,
107107
NO_BRIGHTNESS_COMMAND,
108108
1.0f, // brightness (ignored)
109-
true, // auto_brightness
109+
false, // auto_brightness
110110
false, // single_byte_bounds
111111
false, // data_as_commands
112112
true, // auto_refresh

ports/stm/boards/meowbit_v121/mpconfigboard.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
3737

3838
#define HSE_VALUE ((uint32_t)12000000U)
39-
#define LSE_VALUE ((uint32_t)32000U)
40-
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
39+
#define BOARD_HAS_LOW_SPEED_CRYSTAL (0)
4140

4241
#define BOARD_NO_VBUS_SENSE (1)
4342
#define BOARD_VTOR_DEFER (1) //Leave VTOR relocation to bootloader

ports/stm/boards/meowbit_v121/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ OPTIMIZATION_FLAGS = -Os
1818

1919
LD_COMMON = boards/common_default.ld
2020
LD_FILE = boards/STM32F401xe_boot.ld
21-
# use for internal flash
21+
# For debugging - also comment BOOTLOADER_OFFSET and BOARD_VTOR_DEFER
2222
# LD_FILE = boards/STM32F401xe_fs.ld

ports/stm/common-hal/pwmio/PWMOut.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,14 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
239239
HAL_TIM_PWM_Stop(&self->handle, self->channel);
240240
}
241241
reset_pin_number(self->tim->pin->port,self->tim->pin->number);
242-
self->tim = NULL;
243242

244243
//if reserved timer has no active channels, we can disable it
245244
if (!reserved_tim[self->tim->tim_index - 1]) {
246245
tim_frequencies[self->tim->tim_index - 1] = 0x00;
247246
stm_peripherals_timer_free(self->handle.Instance);
248247
}
248+
249+
self->tim = NULL;
249250
}
250251

251252
void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) {

ports/stm/peripherals/stm32f4/clocks.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void stm32_peripherals_clocks_init(void) {
4949
RCC_ClkInitTypeDef RCC_ClkInitStruct;
5050
RCC_OscInitTypeDef RCC_OscInitStruct;
5151
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
52-
bool lse_failure = false;
5352

5453
// Set voltage scaling in accordance with system clock speed
5554
__HAL_RCC_PWR_CLK_ENABLE();
@@ -76,15 +75,9 @@ void stm32_peripherals_clocks_init(void) {
7675
#endif
7776

7877
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
79-
// Failure likely means a LSE issue - attempt to swap to LSI, and set to crash
80-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
81-
RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_LSI;
82-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
83-
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
84-
// No HSE means no USB, so just fail forever
85-
while(1);
86-
}
87-
lse_failure = true;
78+
// Clock issues are too problematic to even attempt recovery.
79+
// If you end up here, check whether your LSE settings match your board.
80+
while(1);
8881
}
8982

9083
// Configure bus clock sources and divisors
@@ -113,8 +106,4 @@ void stm32_peripherals_clocks_init(void) {
113106
#endif
114107

115108
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
116-
117-
if (lse_failure) {
118-
reset_into_safe_mode(HARD_CRASH); //TODO: make safe mode category CLOCK_FAULT?
119-
}
120109
}

ports/stm/peripherals/stm32f7/clocks.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void stm32_peripherals_clocks_init(void) {
4040
RCC_ClkInitTypeDef RCC_ClkInitStruct;
4141
RCC_OscInitTypeDef RCC_OscInitStruct;
4242
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
43-
bool lse_failure = false;
4443

4544
// Configure LSE Drive
4645
HAL_PWR_EnableBkUpAccess();
@@ -68,15 +67,9 @@ void stm32_peripherals_clocks_init(void) {
6867
RCC_OscInitStruct.PLL.PLLQ = CPY_CLK_PLLQ;
6968

7069
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
71-
// Failure likely means a LSE issue - attempt to swap to LSI, and set to crash
72-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
73-
RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_LSI;
74-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
75-
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
76-
// No HSE means no USB, so just fail forever
77-
while(1);
78-
}
79-
lse_failure = true;
70+
// Clock issues are too problematic to even attempt recovery.
71+
// If you end up here, check whether your LSE settings match your board.
72+
while(1);
8073
}
8174

8275
/* Activate the OverDrive to reach the 216 MHz Frequency */
@@ -111,8 +104,4 @@ void stm32_peripherals_clocks_init(void) {
111104
#endif
112105

113106
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
114-
115-
if (lse_failure) {
116-
reset_into_safe_mode(HARD_CRASH); //TODO: make safe mode category CLOCK_FAULT?
117-
}
118107
}

ports/stm/peripherals/stm32h7/clocks.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ void stm32_peripherals_clocks_init(void) {
3737
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
3838
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
3939
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
40-
bool lse_failure = false;
4140

4241
// Set voltage scaling in accordance with system clock speed
4342
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
@@ -73,15 +72,9 @@ void stm32_peripherals_clocks_init(void) {
7372
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
7473
RCC_OscInitStruct.PLL.PLLFRACN = 0;
7574
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
76-
// Failure likely means a LSE issue - attempt to swap to LSI, and set to crash
77-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
78-
RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_LSI;
79-
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
80-
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
81-
// No HSE means no USB, so just fail forever
82-
while(1);
83-
}
84-
lse_failure = true;
75+
// Clock issues are too problematic to even attempt recovery.
76+
// If you end up here, check whether your LSE settings match your board.
77+
while(1);
8578
}
8679

8780
// Configure bus clock sources and divisors
@@ -116,8 +109,4 @@ void stm32_peripherals_clocks_init(void) {
116109

117110
// Enable USB Voltage detector
118111
HAL_PWREx_EnableUSBVoltageDetector();
119-
120-
if (lse_failure) {
121-
reset_into_safe_mode(HARD_CRASH); //TODO: make safe mode category CLOCK_FAULT?
122-
}
123112
}

0 commit comments

Comments
 (0)