2016-12-23 06:23 AM
I'm trying to blink a LED on a Nucleo-L476 with CubeMX and ST's HAL. It worked perfectly on Windows (System Workbench). Now, I'm trying to do the same on Linux with CubeMX and Qt Createor (my favorite IDE) and OpenOCD. I am now able to compile and debug the target.
However, the program crashes during HAL initialization. More precisely, when it tries to access the
SystemCoreClock
variable.
The problem, in general, is that a global function can't be accessed from a function :
uint32_t dummyVar = 123;
void dummyFunc()
{
uint32_t loc = 123;
uint32_t *p = &loc;
p = &dummyVar; // debugger says &dummyVar = 0x20000004 and p = 0x011a3b01 (outside RAM)
__asm('nop');
__asm('nop');
__asm('nop');
loc = dummyVar; // *** crash here (WWDG IRQ) or random value
}
The variable
p
here points outside the RAM, which starts at 0x20000000. The nop instructions make sure
p = &dummyVar;
is really executed and the debugger doesn't fool me.
#hal #linux #memory #gcc
Solved! Go to Solution.
2016-12-28 06:39 AM
So, Clive was right - you compile this as
https://en.wikipedia.org/wiki/Position-independent_code
, as witnessed by 'build_output.txt':/usr/local/gcc-arm-none-eabi-6_2-2016q4/bin/arm-none-eabi-gcc -g -O0 -Wall -Wextra -pipe -fvisibility=default -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -ffunction-sections -g3 -fmessage-length=0 -Wall -c -v
-fPIC
-DUSE_HAL_DRIVER -DSTM32L476xx '-D__weak=__attribute__((weak))' '-D__packed=__attribute__((__packed__))' -DDEBUG=1 -I/home/picard/prog/stm32/L4_blinky/Inc -I/home/picard/prog/stm32/L4_blinky/Drivers/CMSIS/Include -I/home/picard/prog/stm32/L4_blinky/Drivers/CMSIS/Device/ST/STM32L4xx/Include -I/home/picard/prog/stm32/L4_blinky/Drivers/STM32L4xx_HAL_Driver/Inc -c /home/picard/prog/stm32/L4_blinky/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c -o /home/picard/prog/stm32/build-L4_blinky-STM32_gcc_6_2-Debug/qtc_STM32_gc_6615075b-debug/L4-blinky.qtc-STM32-gc-6615075b.dd71dff9/.obj/b730380c1c8c37a8/stm32l4xx_hal_pwr.c.oI'm in no way expert in this but this is some interpretation of what we see:
.got 0x0000000020000010 0x14 load address 0x0000000008001aa0
though it is probably not loaded upon startup, i.e. as it is in RAM it contains some garbage p = &stupidVar
; C statement do this:
As you are not aware of the -fPIC nor is it in files which appear to hold the user settings, it probably had been kindly supplied by the IDE you are using.
JW
2016-12-29 01:34 AM
Where do you disable the watchdog ?
2016-12-30 03:35 PM
Bravo Jan !
You pointed at the right thing ! Indeed, the IDE was doing things in my back. Anyways, once you know where to look, it suddenly gets much easier to find the
https://forum.qt.io/topic/64276/qbs-how-to-remove-fpic-option
. Now, I can see that bloody LED blink !Thank you so much,
David.
2016-12-30 03:40 PM
I have no idea. Your question is off topic.