cancel
Showing results for 
Search instead for 
Did you mean: 

STM3240G-EVAL in application FLASH programming problem

hermanv
Associate II
Posted on March 27, 2013 at 12:45

Hi all,

I am currently using the STM3240-EVAL kit. 

I am writing a custom bootloader which needs to store some configuration information in the FLASH memory at a specific address. 

I am however experiencing very odd behavior when writing to FLASH. The values I write to FLASH and the actual values written to FLASH differ.

I used the STM Configuration tool XLS document to generate the necessary clock configuration and FLASH enabling and I am unlocking the FLASH before performing any writes. I use the standard peripheral library functions to write to FLASH.

I am running the CPU at 168MHz and according to the documentation the FLASH latency needs to be set to 5 wait states.

Does anyone have an idea what might be wrong or missing?

Thanks,

Herman

#stm32 #linker #stm32 #flawed-code #gcc #flash #flash #flash #stm32f4
5 REPLIES 5
Posted on March 27, 2013 at 14:56

Does anyone have an idea what might be wrong or missing?

Don't know this stuff works for me. You get any error codes? Is it caching the earlier content? Show some code, people with poke sticks at it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hermanv
Associate II
Posted on March 28, 2013 at 07:23

As requested, here is some more detailed info.

Attached are the libhl_flash.c and system_stm32f4xx.c files used in my bootloader.

After all peripherals have been initialized, Iperform a couple of tests of reading an writing to FLASH.

I start by reading 128 bytes from the configuration address I specified in the linker file.

Then I write that address space to 0, which works fine. But when I attempt to fill that address space with another value, it simply does not write to it.

Here is the code used to perform this test:

waddr = 0x080FFF00;
raddr = waddr;
size = 128;
/* initial read */
printThis(''read data from addr:%08X\r\n'', raddr);
retstat = Libhl_Flash_Read(raddr, size, &cfg_info[0]);
printThis(''Libhl_Flash_Read %08X\r\n'', retstat);
for (loop = 0; loop < size; loop++)
{
printThis('' %02X'', cfg_info[loop]);
}
printThis(''\r\n'');
/* contents to 0x00 */
printThis(''set buffer contents to 0\r\n'');
memset(&cfg_info[0], 0x00, size);
printThis(''write data to addr:%08X\r\n'', waddr);
retstat = Libhl_Flash_Write_Addr(waddr, size, &cfg_info[0]);
printThis(''Libhl_Flash_Write_Addr %08X\r\n'', retstat);
printThis(''read data from addr:%08X\r\n'', raddr);
retstat = Libhl_Flash_Read(raddr, size, &cfg_info[0]);
printThis(''Libhl_Flash_Read %08X\r\n'', retstat);
for (loop = 0; loop < size; loop++)
{
printThis('' %02X'', cfg_info[loop]);
}
printThis(''\r\n'');
/* contents to 0x77 */
printThis(''set buffer contents to 0x77\r\n'');
memset(&cfg_info[0], 0x77, size);
printThis(''Libhl_Flash_Write_Addr %08X\r\n'', retstat);
retstat = Libhl_Flash_Write_Addr(waddr, size, &cfg_info[0]);
printThis(''Libhl_Flash_Write_Addr %08X\r\n'', retstat);
retstat = Libhl_Flash_Read(raddr, size, &cfg_info[0]);
printThis(''Libhl_Flash_Read %08X\r\n'', retstat);
for (loop = 0; loop < size; loop++)
{
printThis('' %02X'', cfg_info[loop]);
}
printThis(''\r\n'');

Here is the printout of what the results were: (FYI: the value 2C000000 is the same as return 0)

read data from addr:080FFF00<
CR
><
LF
>
Libhl_Flash_Read 2C000000<
CR
><
LF
>
EA 55 55 AE 01 00 00 00 00 00 00 00 00 00 00 00 
25 03 13 20 00 00 00 08 90 E1 00 08 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 F4 61 00 00<
CR
><
LF
>
set buffer contents to 0<
CR
><
LF
>
write data to addr:080FFF00<
CR
><
LF
>
Libhl_Flash_Write_Addr 2C000000<
CR
><
LF
>
read data from addr:080FFF00<
CR
><
LF
>
Libhl_Flash_Read 2C000000<
CR
><
LF
>
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<
CR
><
LF
>
set buffer contents to 0x77<
CR
><
LF
>
Libhl_Flash_Write_Addr 2C000000<
CR
><
LF
>
Libhl_Flash_Write_Addr 2C000000<
CR
><
LF
>
Libhl_Flash_Read 2C000000<
CR
><
LF
>
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<
CR
><
LF
>

Hope this gives you a better idea of what my problem.

Thanks,

H

________________

Attachments :

libhl_flash_-_Copy.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtX1&d=%2Fa%2F0X0000000aRM%2Fys1CKR5CZJ4m.afn4rxDuZinl46KlTHq_VDCvZ4E_.w&asPdf=false

system_stm32f4xx.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtSD&d=%2Fa%2F0X0000000aQF%2FkUOOQfZm4pa5ZSe4_FY09DRsTh3MoEMUUqiuat0WdLo&asPdf=false
hermanv
Associate II
Posted on April 04, 2013 at 15:50

Hi,

So I managed to figure out my problem with writing to FLASH.

Firstly, before adding data to a sector, it needs to be erased first. Although this might seem obvious, it is not explicitly stated in the programming manual of the STM32F4. I am still awaiting feedback from ST as to why the documentation is incomplete.

Also, some compiler and linker options caused some erratic behaviour. In short, it is best to have the -ffunction-sections compiler option added as well as the --gc-sections linker option added when compiling with GCC.

Enjoy,

H

frankmeyer9
Associate II
Posted on April 04, 2013 at 16:38

Firstly, before adding data to a sector, it needs to be erased first. Although this might seem obvious, ...

 

yes, it should be obvious to some one who knows how Flash works.

... it is not explicitly stated in the programming manual of the STM32F4. I am still awaiting feedback from ST as to why the documentation is incomplete.

 

Might be explained by different expectations about the audience, and their foreknowledge of the topic. And of course, even ST people are just human ...

Also, some compiler and linker options caused some erratic behaviour. In short, it is best to have the -ffunction-sections compiler option added as well as the --gc-sections linker option added when compiling with GCC.

 

Can you go into detail with which toolchain you experienced this problem ?

The options you describe are usually associated with optimisation and dead code elimination.

hermanv
Associate II
Posted on April 09, 2013 at 12:07

With regard to your comments:

  • yes, it should be obvious to some one who knows how Flash works.
  • Might be explained by different expectations about the audience, and their foreknowledge of the topic. And of course, even ST people are just human ...
Next time, keep your comments related to the topic. You are not helping anyone by making sarcastic comments. Go stroke your ego on some other forum!!