AnsweredAssumed Answered

STM32L4 : can't read global variables

Question asked by PICARD.David on Dec 23, 2016
Latest reply on Dec 30, 2016 by PICARD.David

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.

Attachments

Outcomes