Page 1 of 3

Serial Initialization in Dem Crashes on Nucleo STM32F030R8T6

Posted: Wed Oct 15, 2014 7:23 pm
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.

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 9:18 pm
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

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 9:28 pm
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

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 9:59 pm
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

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 10:06 pm
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

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 10:09 pm
by carldong
However, I still get nothing from serial port. Either from USART2, /dev/ttyACM0, or USART1, /dev/ttyUSB0 with a ttl-USB interface.

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 10:37 pm
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

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 10:58 pm
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

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Wed Oct 15, 2014 11:33 pm
by carldong
Actually the Tx/Rx LEDs on my interface board are not even blinking.

Re: Serial Initialization in Dem Crashes on Nucleo STM32F030

Posted: Thu Oct 16, 2014 7:57 am
by Giovanni
Those are problems related to your platform, I never used gentoo so can't help there.

Giovanni