Skip to content

Commit 0ffbf3e

Browse files
committedSep 8, 2023
fix(clock): handle HSE TCXO when available
Signed-off-by: Frederic Pillon <[email protected]>
·
2.10.12.7.0
1 parent 0c69f37 commit 0ffbf3e

File tree

1 file changed

+7
-2
lines changed
  • libraries/SrcWrapper/src/stm32

1 file changed

+7
-2
lines changed
 

‎libraries/SrcWrapper/src/stm32/clock.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,15 @@ void enableClock(sourceClock_t source)
129129
}
130130
break;
131131
case HSE_CLOCK:
132-
__HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
132+
#if defined(RCC_HSE_BYPASS_PWR) && defined(LORAWAN_BOARD_HAS_TCXO) && (LORAWAN_BOARD_HAS_TCXO == 1)
133+
uint32_t HSEState = RCC_HSE_BYPASS_PWR;
134+
#else
135+
uint32_t HSEState = RCC_HSE_ON;
136+
#endif
137+
__HAL_RCC_HSE_CONFIG(HSEState);
133138
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
134139
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
135-
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
140+
RCC_OscInitStruct.HSEState = HSEState;
136141
}
137142
break;
138143
default:

8 commit comments

Comments
 (8)

ellensp commented on Sep 8, 2023

@ellensp

@fpistm

This breaks things

.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src/stm32/clock.c:135:7: error: a label can only be part of a statement and a declaration is not a statement
  135 |       uint32_t HSEState = RCC_HSE_ON;
      |       ^~~~~~~~

Using braces fixes it.

    case HSE_CLOCK: {
#if defined(RCC_HSE_BYPASS_PWR) && defined(LORAWAN_BOARD_HAS_TCXO) && (LORAWAN_BOARD_HAS_TCXO == 1)
      uint32_t HSEState = RCC_HSE_BYPASS_PWR;
#else
      uint32_t HSEState = RCC_HSE_ON;
#endif
      __HAL_RCC_HSE_CONFIG(HSEState);
      if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
        RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_HSE;
        RCC_OscInitStruct.HSEState = HSEState;
      }
      break;
    }
    default:

fpistm commented on Sep 9, 2023

@fpistm
MemberAuthor

Seems strange as ci does not have error and I've tested with my nucleo WL55JC to use HSE for RTC.
Seems linked to pio. Maybe gcc version?

ellensp commented on Sep 9, 2023

@ellensp

Not sure what is going on, It may be related to C standard being used... but has been confirmed by several Marlin firmware users

Here is how to reproduce it using Marlin firmware on vscode/platformio (sorry I don't have a small eg to trigger it)

git clone https://github.com/MarlinFirmware/Marlin.git
in vscode open up the directory with platformio.ini file in it so vscode knows this is a platformio project

Edit Configuration.h
Find and set the following:
#define MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V3_0
#define SERIAL_PORT 1

Edit platformio.ini
Find and set the following:
set default_envs = STM32G0B1RE_btt

Delete the .platformio folder in your home directory and restart vscode (forces a full platformio and framework reinstall to ensure you get the latest Arduino_Core_STM32)

Allow it to install and reload vscode as prompted, give it time to get all it needs.
Click Plafromio: Build button on bottom launch bar. (or use pio run)

I have attached a full log of a build
buildlog.txt

fpistm commented on Sep 9, 2023

@fpistm
MemberAuthor

Unfortunately I don't use pio and will not test this. Weird thing is I could not reproduce on my side with Arduino IDE. Will try on monday.

fpistm commented on Sep 9, 2023

@fpistm
MemberAuthor

@ellensp I think it is linked to std 11. With arduino we use 17. If you can try to change it to confirm?

ellensp commented on Sep 9, 2023

@ellensp

Sadly using -std=gnu17 made no difference

arm-none-eabi-gcc -o .pio/build/STM32G0B1RE_btt/SrcWrapper/src/stm32/clock.c.o -c -std=gnu17 -g3 -fmax-errors=5 -mcpu=cortex-m0plus -mthumb -Os -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=60111 -DSTM32G0xx -DSTM32G0B1xx -D__MARLIN_FIRMWARE__ -DNDEBUG -DHAL_STM32 -DPLATFORM_M997_SUPPORT -DUSBCON -DUSBD_USE_CDC -DTIM_IRQ_PRIO=13 -DADC_RESOLUTION=12 -DPIN_SERIAL4_RX=PC_11 -DPIN_SERIAL4_TX=PC_10 -DSERIAL_RX_BUFFER_SIZE=1024 -DSERIAL_TX_BUFFER_SIZE=1024 -DTIMER_SERVO=TIM3 -DTIMER_TONE=TIM4 -DSTEP_TIMER_IRQ_PRIO=0 -DBOARD_F_CPU=64000000L -DUSART_RX_BUF_SIZE=1024 -DUSART_TX_BUF_SIZE=1024 -DSTM32G0xx -DARDUINO=10808 -DARDUINO_ARCH_STM32 -DARDUINO_MARLIN_STM32G0B1RE -DBOARD_NAME=\"MARLIN_STM32G0B1RE\" -DHAL_UART_MODULE_ENABLED -DUSE_FULL_LL_DRIVER -DVARIANT_H=\"variant_MARLIN_STM32G0B1RE.h\" -D__CORTEX_SC=0 -DHAL_PCD_MODULE_ENABLED -DVECT_TAB_OFFSET=0x2000 -DSTM32_FLASH_SIZE=512 -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/avr -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32 -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/LL -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/OpenAMP -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/hid -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/cdc -I/home/username/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32G0xx_HAL_Driver/Inc -I/home/username/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32G0xx_HAL_Driver/Src -I/home/username/.platformio/packages/framework-arduinoststm32/system/STM32G0xx -I/home/username/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc -I/home/username/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src -I/home/username/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP -I/home/username/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/open-amp/lib/include -I/home/username/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/libmetal/lib/include -I/home/username/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/virtual_driver -I/home/username/.platformio/packages/framework-cmsis/CMSIS/Core/Include -I/home/username/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32G0xx/Include -I/home/username/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/gcc -I/home/username/.platformio/packages/framework-cmsis/CMSIS/DSP/Include -I/home/username/.platformio/packages/framework-cmsis/CMSIS/DSP/PrivateInclude -I/home/username/.platformio/packages/framework-arduinoststm32/cores/arduino -I/home/username/.platformio/packages/framework-arduinoststm32/variants/MARLIN_G0B1RE /home/username/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src/stm32/clock.c
/home/username/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src/stm32/clock.c: In function 'enableClock':
/home/username/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src/stm32/clock.c:135:7: error: a label can only be part of a statement and a declaration is not a statement
  135 |       uint32_t HSEState = RCC_HSE_ON;
      |       ^~~~~~~~

fpistm commented on Sep 9, 2023

@fpistm
MemberAuthor

Hum... weird... I will try to understand.

fpistm commented on Sep 11, 2023

@fpistm
MemberAuthor

OK. I've reproduced by downgrading my arm-none-eab-gcc version.
You got the issue because PIO uses arm-non-eabi-gcc 10.3.1 while in Arduino we used 12.2.1.
I saw that a request was made to update it:
platformio/platform-ststm32#720
Seems it brings some issues with gdb anyway it seems you can update it manually.

Please sign in to comment.