I am trying to write in STM32L476's flash memory using a JTAG ST-Link/V2 on Windows 7. No software has to be uploaded, I only need to write data in a non-volatile place where it can be read and deleted.
As a newbie regarding hardware and being efficient only when programming non-embedded regular C, I am afraid I might harm or modify irrevocably the flash memory. Also, I am not really sure regarding what I can or cannot do.
I have figured out reading the manual that writing in 0x08000000 memory place seemed to be a good idea. Using C code to make calls to ST-Link_Utility :
const char CMD_ACCESS_ST_UTILITY[] = "cd C:/Program Files (x86)/STMicroelectronics/STM32 ST-LINK Utility/ST-LINK Utility&&ST-LINK_CLI.exe ";
bool STLINKWriteSystemCalls(void)
{
char cmd[200] = "";
strcpy(cmd, CMD_ACCESS_ST_UTILITY); // cmd to access utility
strcat(cmd, "-c"); // Then connect with ST-Link
if (system(cmd) != 0)
return false; // If failed exit
strcpy(cmd, CMD_ACCESS_ST_UTILITY);
strcat(cmd, "-r8 0x08000000 0x100"); // Read to check if there is data already
// I haven't managed yet how I'll compare the result of read
// To FFFF but that's not the main issue
if (system(cmd) != 0)
return false; // If failed exit
strcpy(cmd, CMD_ACCESS_ST_UTILITY);
strcat(cmd, "-w8 0x08000000 0x00"); // Write data into 0x080000000
if (system(cmd) != 0)
return false; // If failed exit
return true;
}
Is there a better way to do this regarding where to write and how to write (errors checking, ressource used etc) ?