cancel
Showing results for 
Search instead for 
Did you mean: 

Flash - writing help

hidethecheeze
Associate
Posted on March 25, 2011 at 19:58

I am new to all of this. I got the board from a classmate.

I am trying to store accelerometer data in the flash during an experiment. Then, retrieve it when I plug the board into the computer via the USB. I am struggling to completely understand the Flash Programming Manual and the Flash examples in Atollic.

1. What line(s) of code will write a specific number value from the accelerometer to the flash?

2. How do I have it write to the next slot (page?), since the code runs in a loop?

3. How would I retrieve the data?

Thank you

#flash
1 REPLY 1
Posted on March 25, 2011 at 20:12

Reading out via USB will be a challenge since that's connected to the ST-LINK device, not the STM32VL device.

The minimum granularity for writing is 16-bits, on even addresses. The memory needs to be erased to write to it.

void Flash_WriteTest(u32 FlashAddr, u16 FlashWord)

{

    FLASH_Status FLASHStatus;

    printf(''FLSH WriteTest %08X -> %08X %04X\n'', FlashAddr, *((DWORD *)FlashAddr), FlashWord);

    FLASH_Unlock();

    FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

  FLASHStatus = FLASH_ProgramHalfWord(FlashAddr, FlashWord);

    if (FLASHStatus != FLASH_COMPLETE)

        printf(''FLSH : ?? WriteTest %d\r\n'',FLASHStatus);

    printf(''FLSH WriteTest %08X %04X\n'',*((DWORD *)FlashAddr), FlashWord);

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..