STM32L412 uart not working

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
Steve Dvoracek
Posts: 3
Joined: Fri Aug 14, 2020 3:00 pm

STM32L412 uart not working

Post by Steve Dvoracek »

Hello, it is my first post here. I have a custom board (essentially QFN32 adaptor) with STM32L412K8T6. I could program the board via USB in DFU mode, but the firmware didn't run until I soldered external crystal.
For the project I am using uart and I2C ports. I have tested the I2C on pins 29(PB6) and 30(PB7) and it works.
However I can't get the Serial to work. According to the datasheet it should be on pins PA9 and PA10. I tried also Software serial and I couldn't get it to work.
Can anyone see what could be the problem?
Also is there any chance of running the MCU without external crystal with Arduino?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32L412 uart not working

Post by fpiSTM »

Hi,
seems to me you have an issue with the clock config.
Which clock config you used ? Which variant you used for your custom board ?

DFU used the clock config from the built in boot loader, I2C compute the timing to be inline with the clock config so it seems fine that they worked.
About Serial, I guess if you have an issue it is linked to this and probably it works but with an other baudrate.
PA9/PA10 are ok and linked to USART1.
Steve Dvoracek
Posts: 3
Joined: Fri Aug 14, 2020 3:00 pm

Re: STM32L412 uart not working

Post by Steve Dvoracek »

Ok, so to clarify. I just found out that the default Serial.write is linked to USART2_TX on pin PA2 and Serial.read to USART2_RX on pin PA15 as Alternate function. Wire works with I2C1 pins PB6/7. This is really confusing. Is there any resource to the pin mapping on various Arduino compatible MCUs?

As to the clock config - I didn't change anything, I just use the default configuration for Nucleo L412KB in STM32Cores. I have some experience with bare metal programming on the STM32 platform, but I just wanted to try this approach for this project. I tried adding #define USE_HSI_CLOCK 1, but after removing the crystal the board doesn't run.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32L412 uart not working

Post by fpiSTM »

All infos are in the variant:
https://github.com/stm32duino/Arduino_C ... LEO_L412KB

I didn't see anything confusing, as the variant is defined for the Nucleo L412. Serial is linked to USART2 (connected to the STLink to have the CDC) and Wire on D4/D5.

You can change it if you want or declare your own instance. For other AF you can refers to the PeripheralPins.c.

About USE_HSI_CLOCK this is not a definition used by the core.
The variant.cpp define the system clock config and it enable the LSE, I guess this is why you have an issue.
You can redefine your own clock config at sketch level as it is a weaked function.

Code: Select all

extern "C" void SystemClock_Config(void) {
....
}
Steve Dvoracek
Posts: 3
Joined: Fri Aug 14, 2020 3:00 pm

Re: STM32L412 uart not working

Post by Steve Dvoracek »

Hey, thanks a lot, I have been able to switch to HSI with Cube generated clock config.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32L412 uart not working

Post by fpiSTM »

Steve Dvoracek wrote: Wed Aug 19, 2020 10:51 am Hey, thanks a lot, I have been able to switch to HSI with Cube generated clock config.
Welcome, and is it ok now ?
Post Reply

Return to “General discussion”