2012-06-05 07:28 AM
Hello All,
I have been trying to write into the flash(certain user data), but when i debug it i see the values being written elsewhere in other locations and sometimes in the location i have specified.The function i have used is as posted below.uint32_t FLASH_Pot_StartingAddress=((uint32_t)0x0807f800);void Flash_ADCPot_Log(void){FLASH_Unlock();FLASH_Pot_StartingAddress=FLASH_Pot_StartingAddress+2);FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR );FLASH_ProgramHalfWord(FLASH_Pot_StartingAddress, ADC_Result);FLASH_Lock();}ADC_Result is a 16 bit value.Any help would be appreciated, thanks2012-06-05 08:26 AM
You need to make sure that the flash array is erased, and check the return/failure code from the FLASH_ProgramHalfWord()
What tool chain are you using?2012-06-05 09:10 AM
Thanks for the reply. I will erase the sector and try it out:)
BTW, i am usil Keil IDE.2012-06-06 06:41 AM
Is there noway i could write data in the ROM without having to erase the page/sector? I do not want to loose the data everytime i reset the microcontroller.
I am also trying to write to the NOR flash on board the MCBSTM32F200 board. I intialize the FSMC to write in bank1 of the NOR but when i write to it (using the same function i use to write on the onboard flash) it does not seem to work.I am a beginner so any help would be appreciated.Thanks2012-06-06 07:26 AM
You get to write each location once after erasing. Roll your data across the page, and use multiple pages.
The FLASH_xxx API functions are for internal flash, for NOR you'll need to review the documentation for the parts in question.2012-06-06 07:40 AM
But in the stm32f2x std peripheral library file, stm32f2xx_fsmc.c there is no API function to write to the NOR. That is why i was wondering how i could write to the NOR Flash.
2012-06-06 09:46 AM
But in the stm32f2x std peripheral library file, stm32f2xx_fsmc.c there is no API function to write to the NOR. That is why i was wondering how i could write to the NOR Flash.
The FSMC manifests the NOR memory device within the linear memory the Cortex-M3, once there you just read/write to the memory addresses as you would to any other device. The magic sequences of address and data required for the NOR chip would be documented in the data sheet for the part in question. There are typically commands to unlock, erase, and program, as well as spinning and waiting. for erase/program to complete. Most would use a CFI protocol, or some precursor to that.
http://en.wikipedia.org/wiki/Common_Flash_Memory_Interface
http://www.delorie.com/agenda/specs/29220404.pdf
http://www.spansion.com/Support/Application Notes/Quick_Guide_to_CFI_AN.pdf
Read the manual for the NOR Flash part you are using.2012-06-07 01:23 AM
2012-06-07 02:43 AM
2012-06-07 07:17 AM
The address range you're using is a 128KB sector (0x08060000 - 0x0807FFFF). You should start at the beginning and use all of it, otherwise you're just wasting resources.
If you don't want to lose the data already recorded you will need to scan through the sector and find where you stopped last time. You only need to erase to recover the memory. You could use two sectors and ping/pong between them, but either way you need to come up with some intelligent strategy for writing the data, and erasing, and to limit the erase/write cycles so you don't damage the memory. The erase time for 128KB sectors is several seconds. If you are running from FLASH, this will stall out the processor while the erase or programming occurs. Depending on the size of you data storage requirements a small sector may be more appropriate.