How to swap two memory regions of FLASH memory in STM32L475?
Hi,
I am working on STM32L475 ARM Cortex M4 board and writing code for it on STM32Cube IDE. I want to swap two memory regions of FLASH memory in my BootLoader program when some conditions are met. I already tried swapping using the normal method but it was not successful. Here is my code for swapping:-
#define APPLICATION_ADDRESS 0x0800C000
#define APPLICATION2_ADDRESS 0x08076400
boolean swap(void)
{
char *app_1=( char*) APPLICATION_ADDRESS; //points to the 1st address of application1
char *app_2=(char*) APPLICATION2_ADDRESS ;//points to the 1st address of application2
int mem1= getMemorySize((unsigned char*)APPLICATION_ADDRESS);//returns the number of bytes in Application1
int mem2= getMemorySize((unsigned char*)APPLICATION2_ADDRESS);//returns the number of bytes in Application2
int limit;
if(mem1>mem2)
limit= mem1;
else
limit= mem2;
char swap;
for(int i=1; i<=limit; i++,app_1++,app_2++)
{
swap = *app_1;
*app_1 = *app_2;
*app_2 = swap
}
return TRUE;
}
Do I have to unlock or enable FLASH read/write using some functions or is there some other way to do it?
Thanks,
Shetu