Serial Initialization in Dem Crashes on Nucleo STM32F030R8T6

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Serial Initialization in Dem Crashes on Nucleo STM32F030R8T6

Post by carldong »

Hello,

I just tried to put the demo for STM32F030 Nucleo board, but I found that usart_init() causes the controller to crash into Hard Fault.

It seems to crash on this line:

Code: Select all

 
/* serial_lld.c:96 */
 u->BRR = (uint16_t)(sdp->clock / config->speed);


I tried initializing the USART directly:

Code: Select all

USART2->BRR = 1250


Or somewhat indirectly:

Code: Select all

USART_TypeDef *u = USART2;
u->BRR = 1250;


And I tried -O0, -O2, -Os options, and on USART1 port (USART2 is already used by ST-Link, and I don't think I can get anything out there. I might be wrong) but it crashes only when I try to use sdStart(), not when I initialize directly. I suspect that it is a stack overflow, so I tried printing __main_stack_size__, and GDB prints something like this:

Code: Select all

(gdb) p __main_stack_size__
$1 = 98 'b'


If I try to increase from 0x400 to 0x500, I get:

Code: Select all

(gdb) p __main_stack_size__
$1 = -105 '\227'


I don't understand linker scripts, so I can't understand these. At least I suppose that a Demo should work out of the box... If I comment out everything serial, the LED blinks correctly.
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by carldong »

I tried the demo for STM32F103 Nucleo, and the LED blinks as usual. However, I get nothing from serial port (/dev/ttyACM0), which is kind of expected because it is taken by mbed. Probably it was stack overflow
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by Giovanni »

I just retested the demo in version 2.6.6, it works here, including the serial port.

What toolchain are you using? this could be a compiler problem. If in doubt try ChibiStudio, it is a single package including everything required.

Giovanni
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by carldong »

Actually I built the toolchain. I would probably try CodeSourcery

Giovanni wrote:I just retested the demo in version 2.6.6, it works here, including the serial port.

What toolchain are you using? this could be a compiler problem. If in doubt try ChibiStudio, it is a single package including everything required.

Giovanni
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by carldong »

Well, actually, yes my toolchain does not work but CodeSourcery one works... I don't know why because I can't find a good instruction on testing toolchains. I heard that the CodeSourcery one has a big newlib that is not suitable for such small device, what should I do about that?

carldong wrote:Actually I built the toolchain. I would probably try CodeSourcery

Giovanni wrote:I just retested the demo in version 2.6.6, it works here, including the serial port.

What toolchain are you using? this could be a compiler problem. If in doubt try ChibiStudio, it is a single package including everything required.

Giovanni
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by carldong »

However, I still get nothing from serial port. Either from USART2, /dev/ttyACM0, or USART1, /dev/ttyUSB0 with a ttl-USB interface.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by Giovanni »

About toolchain, use this one: https://launchpad.net/gcc-arm-embedded
Stay with 4.7 because 4.8 has a problem with LTO.

You have to press the blue button in order to see something on the serial.

Giovanni
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by carldong »

I use gentoo... Well, my toolchain was 4.8, so that might be the problem. I tried pressing buttons, but neither USART1 nor USART2 work for me. Are you working on linux? I heard that Virtual Com port on Nucleo breaks on Linux, but I am not sure. However, that does not explain why my interface fails too.
Giovanni wrote:About toolchain, use this one: https://launchpad.net/gcc-arm-embedded
Stay with 4.7 because 4.8 has a problem with LTO.

You have to press the blue button in order to see something on the serial.

Giovanni
carldong
Posts: 62
Joined: Wed Oct 15, 2014 6:08 pm
Has thanked: 1 time
Been thanked: 1 time

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by carldong »

Actually the Tx/Rx LEDs on my interface board are not even blinking.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Post by Giovanni »

Those are problems related to your platform, I never used gentoo so can't help there.

Giovanni
Post Reply