2015-11-01 03:43 PM
Hi,
I'm using FLASH to store some data. Everything works great when I write in an empty address. When I try to write in a already used memory position, the stored value becomes to zero!I tried erase the sector before call the write function but the uC crashes. Here it follows:FLASH_Unlock();FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); FLASH_EraseSector(ADDR_FLASH_SECTOR_4,VoltageRange_3);FLASH_ProgramWord(ADDR_FLASH_SECTOR_4, data);FLASH_Lock();Anyone can help me? I'm using FreeRTOS.Thanks in advance,--Guilherme2015-11-01 04:27 PM
And does any code fall in the 0x08010000..0x0801FFFF range?
2015-11-01 11:55 PM
Hello!
No clive1... no code at this memory interval. I already experimented another sectors at higher position. Always I call the FlashErase function, the uController crashes.I'm using IAR... I don't know if I need to take care about something else.Thanks,--Guilherme2015-11-02 07:34 AM
> When I try to write in a already used memory position, the stored value becomes to zero!
That is documented behaviour: physically you can only program bits from 1 to zero, and erasing does a bulk-set of all the bits. When you try to program an already programmed (i.e. not-0xff) location, the hardware will prevent ''mixes'' of the programmed data to show up and will program the location to zero for you. Otherwise programming a location to 0xaa and then programming it to 0xcc would result in a combination of the two: 0x88. (I personally don't like this feature. If you know how the flash works, you can make use of its features. So other MCUs allow you for example to implement a linear counter (every bit counts as 1), at 8 bits/counts per byte. ST limits this to 1 bit/count per byte....)2015-11-02 07:50 AM
2015-11-02 08:24 AM
Flash is not designed to over-write, depending on the implementation there may also be ecc/parity preventing things changing. You can journal your writes, where the structures gets written end-on-end, and you read back the last structure written. When the sector/block is exhausted you do the erase operation. Flash has a finite life.
Do you look at the status returned by any of these functions? Does it ''crash'' in to the Hard Fault Handler? If you stop the debugger, where is the code executing? Define crash a bit more clearly.2015-11-02 08:36 AM
Ok clive1! I understand that flash has a finite life however the operations that I need to to are very sporadic!
I can't give more details about the crash because when I stop the debbuger isn't clear ''where the code stops'' and I can't check the returned erase function value...I know that exists the SRAM but it's volatile and requires a battery and external oscillator. I'm using a STM32F4 DISCO evaluation board that has the VBat pin connected to +3V3. I don't want modify the hardware.Is it possible to use the FLASH as I want? Any operation required? any trick?Thanks by the help!--Guilherme2015-11-02 08:50 AM
The parameter to FLASH_EraseSector() in NOT an address.
Use FLASH_Sector_4 for memory at ADDR_FLASH_SECTOR_4 Review STM32F4-Discovery_FW_V1.1.0\Project\Peripheral_Examples\FLASH_Program\main.c Consider ways you can debug and trouble-shoot your code, either via a debugger, or by outputting diagnostic information.2015-11-02 09:26 AM
As I have mentioned in the first post, I know that FLASH_EraseSector() is NOT an address!
''FLASH_EraseSector(ADDR_FLASH_SECTOR_4,VoltageRange_3);
''I already looked to the example and I'm following the instructions by there. The problem is that my FLASH_EraseSector function causes the crash...I already tested with other sectors but always happens the same. In a step-by-step debug approach, I can follow until the end of EraseSector function. After the return I lost control... Do you have any suggestion to diagnose the problem?Best regards,--Guilherme2015-11-02 10:00 AM
Ok, so you posted the wrong code on purpose? Your first doesn't indicate you understand the parameter is an index#
Does the example code work? Does THIS code work? FLASH_Unlock(); FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); FLASH_EraseSector(FLASH_Sector_4,VoltageRange_3); FLASH_ProgramWord(ADDR_FLASH_SECTOR_4, data); FLASH_Lock();