Page 1 of 1

dangerous relocation: l32r: literal placed after use

Posted: Tue Jan 21, 2025 11:14 am
by brebisson
Hello,

The following 3 lines in my code generate the following error (esp-idf esp32-C3 in visual studio code)
"dangerous relocation: l32r: literal placed after use"

These lines are in the same function, but at different locations....

I think that I have a clue as to what might be happening for the 2 bottom ones, but the first one is less obvious.
Even less obvious is how to fix it!

Can anyone help me?
Thanks,
Cyrille

Code: Select all

        uint32_t newDeltaBetweenSteps= 1000000 / (Abs(currentSpd));
        *((uint32_t*)GPIO_OUT_W1TS_REG)=1<<stp; stpVal= 1;
        *((uint32_t*)GPIO_OUT_W1TC_REG)=1<<stp; stpVal= 0;

Re: dangerous relocation: l32r: literal placed after use

Posted: Tue Jan 21, 2025 12:39 pm
by MicroController
Is that code in an IRAM function?

Potentially helpful information, albeit not a full solution: https://stackoverflow.com/questions/195 ... error-mean

Re: dangerous relocation: l32r: literal placed after use

Posted: Tue Jan 21, 2025 1:04 pm
by brebisson
Hello,

Yes, it is an IRAM_ATTR function.

I tried adding: idf_build_set_property(COMPILE_OPTIONS "-mtext-section-literals" APPEND)
in mymakefile, But it did not work...


It first seemed to work.. But then it did not compile on 2nd test!

No clue why:-(

Cyrille

Re: dangerous relocation: l32r: literal placed after use

Posted: Tue Jan 21, 2025 4:02 pm
by MicroController
https://docs.espressif.com/projects/esp ... de-in-iram
constants inside an IRAM_ATTR function may not be placed in RAM automatically. It is possible to use DRAM_ATTR attributes to mark these, or using the linker script method will cause these to be automatically placed correctly.