Trouble using USART on STM32L051

Hello All, I have a simple app that used USART2 to write out to a shift register. I recently moved from the STM32Cube IDE to PlatformIO to leverage the high-level Arduino libraries, and all of that works great, but for the life of me I cannot get the USART2 to initialize and write data.

I built just this part of the app in STM32 to sanity-check myself, and it works as expected. Here’s what I’ve tried so far:

  • Double-checked that the ClockConfig settings match for my custom variant and for the STM32 generated code.

  • Double-checked that the handle is not null and that it is initilizing correctly.

I’m really at a loss for why it would behave differently in platformio vs cube. Are there any other places I should check? I would really rather not move this project back to STM32Cube, but I’m afraid that’s where I’m headed if I can’t get this issue resolved.

It might also be possible that PlatformIO is not using the same STM32L0 HAL version that you got in the STM32CubeIDE (if you’re using framework = stm32cube in PlatformIO), although that should not per-sé result in a completely broken UART.

You can always try to compare the config registers for UART and the RCC (reset / clock control) between the two. Assuming you already flash via an ST-Link or another debug probe, you can start debugging per this. The bottom should have a “Peripherals” view available. For example, the first breakpoint should be set after the UART initialization, and per reference manual, compare the contents of RCC_APB1ENR (it contains the USART2 EN bit) and the entirety of USART_CR{1,2,3} and USART_BRR for the USART2 register.

If you’re completely stuck, you can try uploading the STM32Cube and PlatformIO projects for someone to have a look at.