Showing results for 
Search instead for 
Did you mean: 

Usage of PCROP and RDP in application

Associate II

Greetings. I am developing a LoRaWAN application running on the STM32WL5, the application does work and makes use of the flash memory to store the application eui/network key (so that it is not necessary to recompile the firmware each time), the keys are fetched from flash memory by using a custom loader script and a few calls to memcpy to store them in a couple of temporary arrays used for validation and then, should the keys be correct, in the LoRaWAN related structures normally populated via macro by se-identity.h

I decided to give the PCROP option byte a shot and, after flashing the program, i used STM32CubeProgrammer to, in this order:

-write the keys to the flash area

-enable RDP (level 1) and PCROP on the flash area not used by the keys (ie: as the key area uses the last 2kb page of memory, PCROP1A_START and END are respectively 0x00 and 0xFB)

However this, for some reason, caused the program to no longer run. Intrigued by this i brought the option bytes to their default settings (RDP level 0, PCROP1A_START/END=0xff/0x00) and tried again, flashing the program (but not writing the keys) and setting only the RDP at level 1 with, in this case the program worked normally.

The third attempt was with RDP at level 0 and with the PCROP enabled as before (0x00/0xFB), again the program stopped working (read: didn't even appear to start)

For the fourth and final test i tried, mostly out of curiosity, to invert the PCROP, so protecting only the memory area containing the keys (PCROP1A_START=0xFB END=0xFF), while the application did work, the memcpys used to fetch the key information from flash returned garbage rather than 0xFF (as the keys had been deleted due to downgrading of RDP and not rewritten after the 1st test), as i would have expected since such area would have been marked as "execute only" so no read would have been possible (though looking back on it. such access should have caused a fault)

The question is: what am i doing wrong in this case? The documentation says that (at least for Keil) i need to use a special flag, is this the case even for GCC? Or perhaps i've simply set up the option bytes incorrectly?

Thanks in advance

ST Employee

Hi @IFant.1​ ,

on GCC/CubeIDE the option to use to generate a code working with PCROP is "-mpure-code".

The AN4758 should contain further details.



To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.