Here’s what I’m trying to do.
I have a rather large array defined const unsigned char varName[] = {...}
so that it will be placed into the flash memory on the Core. I would like to now modify this data.
I tried to use FLASSH_ProgramHalfWord since this is the function used to write to the virtual EEPROM but no dice. I also tried memcpy but it produced a hard fault Below is my code. Suggestions? What’s the proper way to do this?
#include "application.h"
SYSTEM_MODE(MANUAL);
const unsigned char flashVar[] = {0xFF, 0x00, 0x99};
char buff[100];
int test = 3;
/* This function is called once at start up ----------------------------------*/
void setup()
{
Serial.begin(9600);
while(!Serial.available()) Spark.process();
Serial.println("Program Start - Version 1.5");
Serial.print("Flash Var Address: ");
sprintf(buff,"The memory address of 'test' is: %p\n", (void*) &test);
Serial.println(buff);
sprintf(buff,"The memory address of 'flashVar[0]' is: %p and the value is '%x'\n", (void*) &flashVar[0], flashVar[0]);
Serial.println(buff);
sprintf(buff,"The memory address of 'flashVar[1]' is: %p and the value is '%x'\n", (void*) &flashVar[1], flashVar[1]);
Serial.println(buff);
sprintf(buff,"The memory address of 'flashVar[2]' is: %p and the value is '%x'\n", (void*) &flashVar[2], flashVar[2]);
Serial.println(buff);
uint32_t EepromAddress = (uint32_t)&flashVar[0];
uint16_t EepromData = 0xeeee;
sprintf(buff,"The memory address of 'flashVar[0]' is: %x and the data to be written is '%x'\n", EepromAddress, EepromData);
Serial.println(buff);
// This doesn't seem to do anything
FLASH_ProgramHalfWord(EepromAddress, EepromData);
// This causes a hard fault
memcpy((void *)EepromAddress,&EepromData,1);
sprintf(buff,"The memory address of 'flashVar[0]' is: %p and the value is '%x'\n", (void*) &flashVar[0], flashVar[0]);
Serial.println(buff);
sprintf(buff,"The memory address of 'flashVar[1]' is: %p and the value is '%x'\n", (void*) &flashVar[1], flashVar[1]);
Serial.println(buff);
sprintf(buff,"The memory address of 'flashVar[2]' is: %p and the value is '%x'\n", (void*) &flashVar[2], flashVar[2]);
Serial.println(buff);
}
/* This function loops forever --------------------------------------------*/
void loop()
{
//This will run in a loop
}