cancel
Showing results for 
Search instead for 
Did you mean: 

Flash @ STM32F429VIT6

gui2
Associate II
Posted on November 02, 2015 at 00:43

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,

--

Guilherme 
11 REPLIES 11
Posted on November 02, 2015 at 01:27

And does any code fall in the 0x08010000..0x0801FFFF range?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gui2
Associate II
Posted on November 02, 2015 at 08:55

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,

--

Guilherme 

re.wolff9
Senior
Posted on November 02, 2015 at 16:34

> 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....)

gui2
Associate II
Posted on November 02, 2015 at 16:50

Thank you wolff.roger!

Any solution for this? If I have already written in position, how can I change the value that is there?

Thanks in advance!

--

Guilherme 

Posted on November 02, 2015 at 17:24

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gui2
Associate II
Posted on November 02, 2015 at 17:36

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!

--

Guilherme  

Posted on November 02, 2015 at 17:50

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gui2
Associate II
Posted on November 02, 2015 at 18:26

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,

--

Guilherme 

Posted on November 02, 2015 at 19:00

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();

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