0

I tried writing a value to the Flash memory, initially i wrote 0x0000 to the position i mentioned in code it was successfully written but after that i'm not able to overwrite or erase the data in that position.So for the First time i could write to Flash successfully but after that i couldn't write /erase data in that location .What may be issue? I've pinned the memory stack image also.


  uint32_t pageAddress = 0x08008000;
  uint16_t buffer = 0xdddd;          // data buffer
  HAL_HAL_StatusTypeDef  status;

  while(1)
  { 
     HAL_FLASH_Unlock();              // unlock the flash memory in ST
     //FLASH_PageErase(pageAddress); 
     status=HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, pageAddress, 
     buffer);
     HAL_FLASH_Lock();                // Flash memory locked
  }

Memory stack -Debug

  • What error code is returned be the erase and/or program function? – kkrambo Nov 19 '17 at 04:08
  • i didn't check that..how to get the error message? –  Nov 19 '17 at 05:12
  • ok..i checked..its showing HAL_ERROR,0x01 –  Nov 19 '17 at 05:44
  • I also tried changing the pager address at some locations its showing can't cases memory location in command window.Do you know the range of memory locations that we can use? –  Nov 19 '17 at 06:01
  • Possible duplicate of [Can't write to flash memory after erase](https://stackoverflow.com/questions/28498191/cant-write-to-flash-memory-after-erase) – followed Monica to Codidact Nov 19 '17 at 09:42
  • Not duplicate..I wanted to continuously write and erase memory..I referred the above link before for writing in flash. –  Nov 19 '17 at 11:08
  • My issue is that I 'm able to write to flash only once in a address after that not able to perform erase or write to that location... –  Nov 19 '17 at 11:10
  • 1
    The main issue is the "great" HAL library. Expect more problems, frustration and errors. – 0___________ Nov 19 '17 at 15:11
  • you have faced the same issue before?whether you were able to solve it? –  Nov 19 '17 at 15:17
  • read the st documentation and simply talk to the flash controller...as needed go back or in parallel read the HAL library and see how or if it compares to the st documentation for that part. – old_timer Nov 19 '17 at 17:00
  • can other tools, stlink+SWD, etc erase and write this memory? – old_timer Nov 19 '17 at 17:00
  • I read stm32F0 Datasheet they don't clearly specify the process instead i tried going through HAL_Flash.c file,in that they give brief info on the methods to be called for reading,writing,unlocking,locking. –  Nov 19 '17 at 17:08
  • Is there a range of memory address in Fash that can be used?In most of the Examples its given 0x08000000 as the page address.! –  Nov 19 '17 at 17:10
  • Have you commented out the erase because it did not work, or because you are not using it? It won't erase if you don't call the function, and if you are calling the function, then that is the code you should post - not some other code that is a bit like but not quire the code you are talking about! – Clifford Nov 19 '17 at 18:58
  • 1
    @GOKUL : The datasheet is the wrong document - that just gives electrical charactaristics and a breif of the peripherals and pinout for a specific part. You need to read the [_Reference Manual_](http://www.st.com/resource/en/reference_manual/dm00091010.pdf). Some STM32 parts have a separate flash programming manual, though not in this case. – Clifford Nov 19 '17 at 19:12
  • 3
    Realise also that continuously programming and erasing will destroy the flash cell. The flash endurance for this part is only 1000 cycles. It could take as little as 30 seconds to destroy it (based of 30ms erase time). Perhaps that has already happened if this code has previously been allowed to run. – Clifford Nov 19 '17 at 19:15
  • 1
    You need to edit your code to attempt some *valid* or at least *non-destructive* test/goal if you want any respect for your difficulty. At present, as Clifford points out, you basically have a flash memory destroyer, which is a silly enough goal that the question of it working or failing is moot. – Chris Stratton Nov 19 '17 at 20:08
  • @clifford-In this code i'm writing/erasing alternatively by removing the comments.Erase function i have commented because i'as writing when i posted the question.Both didn't work. –  Nov 20 '17 at 02:17
  • @Clifford : I didn't know that continuously writing and erasing is going to destroy my flash.Thanks for pointing out. Only 1000 cycles?!!! because we are planing to design a product that takes user input and store in flash..So if user does 1000 times controller flash would get damaged? –  Nov 20 '17 at 02:23
  • Think about an external EEPROM. They are cheap, small and can be attached by a serial interface (I2C or SPI). – A.K. Nov 20 '17 at 05:17
  • Or maybe an SD card. They probably don't have more erase cycles but you can spread the writes over much larger space, and they are replaceable. Or better tell us your requirements. – A.K. Nov 20 '17 at 05:28
  • 1
    @GOKUL consider switching to the STM32L0 series, they have internal EEPROM, with maybe 100000 guaranteed erase cycles. – followed Monica to Codidact Nov 20 '17 at 07:15
  • @berendi thanks for the info.Actually we completed the project 80%..and flash writing was the last modification.If no other way ,thats the only way to go. –  Nov 20 '17 at 08:39
  • @GOKUL FYI F030 and L071 seem to be pin-compatible, and the peripherals are mainly compatible too. – followed Monica to Codidact Nov 20 '17 at 09:23
  • @Clifford-i agree that flash endurance for i single location is 1000 time but i will not do that..instead i will write into the entire Flash space and at the end i will erase it all together.with this i think about some 1L operation is possible? –  Nov 20 '17 at 09:59
  • today i got an issue..i just erased a page by giving page address but after that i'm not able to burn code again..its showing internal command error...anyone has any idea on this error –  Dec 03 '17 at 08:48

1 Answers1

1

I found answer to my question ,the issue is that Flash can handle 2 values either "0000" or "FFFF" so user will be able to write to the location only if the value at that location is "FF" if its "00" user will not be able to write to it unless that location is Erased.In my case i wrote "00" to that location so i could not write again to that location with different values.

Earlier in comments it was told that Flash can handle 1000 write/erase cycles.its true so its better you utilize the entire sector(1 kB) for writing once and erase if 1 kB is over.By doing this STM32 can handle much more Flash operations