FXTH87 Flash Read/Write

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FXTH87 Flash Read/Write

524 Views
lucascooter
Contributor I

I would like to read and write to FLASH memory but am unable to get it working. Any help appreciated. Thanks!

Question 1: How to declare a variable into FLASH?

If I declare a variable as const, the compiler will put the variable into FLASH. It goes to the lower part of FLASH that isn't in the "user range". If I make a custom section of the FLASH in the linker file, it will create a section of FLASH in the map. Then I can use #pragma to designate where in FLASH the variable should be stored. The below code gets placed into 0xDDBF "TEST_ZONE" which is a 512 byte area of FLASH I have designated in the Project.prm file as a READ_WRITE area.

#pragma DATA_SEG TEST_ZONE
const unsigned char myVar3 = 76;
#pragma DATA_SEG DEFAULT‍‍‍

Question 2: How to read variable from FLASH?

When I read a variable from FLASH, the value is 255 no matter what I set it to. Why is that?

if(myVar3 == 73)
{
BlinkLED();
}

Question 3: How to write variable to FLASH?

In the documentation, it lays out the steps to write to FLASH.  It seems to have no effect on the values though.

FSTAT = FSTAT | 0b00010000;  //Clears the flag.
FCDIV=19; // Sets the Flash Clock
TPMS_FLASH_ERASE(myVar3); //Not a pointer, but the variable itself. This returns 0 on success.
TPMS_FLASH_WRITE(‍‍‍‍&myVar3, &myBuffer, 1); //This should replace the value at myVar with the value at myBuffer, 1 byte. It has no effect.
0 Kudos
0 Replies