cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496ZG flash program issue

Dick Lin
Senior
Posted on June 21, 2018 at 00:57

Hi,

I am working on STM32 flash program using a sample program from V1.11. The program is pretty straight forward. Erase ADDR_FLASH_PAGE_16 to ADDR_FLASH_PAGE_255 then program.

The program stuck in HardFault_Handler doing HAL_FLASHEx_Erase in the first page erase FLASH_PageErase(page_index, pEraseInit->Banks);

HAL_FLASH_Program()

 also failed on FLASH_Program_DoubleWord().

Anyone experienced same issue? Doesn't this supposed to be working without any changes? 

Thx

STM32Cube_FW_L4_V1.11.0\Projects\NUCLEO-L496ZG\Examples\FLASH\FLASH_EraseProgram

if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)

{

while (1)

{

BSP_LED_On(LED3);

}

}

Address = FLASH_USER_START_ADDR;

while (Address < FLASH_USER_END_ADDR)

{

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, DATA_64) == HAL_OK)

{

Address = Address + 8;

}

else

{

/* Error occurred while writing data in Flash memory.

User can add here some code to deal with this error */

while (1)

{

BSP_LED_On(LED3);

}

}

}

HAL_FLASH_Lock();

Address = FLASH_USER_START_ADDR;

MemoryProgramStatus = 0x0;

while (Address < FLASH_USER_END_ADDR)

{

data32 = *(__IO uint32_t *)Address;

if (data32 != DATA_32)

{

MemoryProgramStatus++;

}

Address = Address + 4;

}

/*Check if there is an issue to program data*/

if (MemoryProgramStatus == 0)

{

/* No error detected. Switch on LED1*/

BSP_LED_On(LED1);

}

else

{

/* Error detected. Switch on LED2*/

BSP_LED_On(LED2);

}
10 REPLIES 10
Posted on June 21, 2018 at 01:11

>>Doesn't this supposed to be working without any changes? 

How large is the executable image your tool chain is generating? More than 16KB perhaps?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 21, 2018 at 01:20

The .elf file is pretty big - 1883 KB. What's the limit of the board?

Posted on June 21, 2018 at 01:44

Why the flash HAL function failure has anything to do with code size?

Posted on June 21, 2018 at 02:26

>>The .elf file is pretty big - 1883 KB. What's the limit of the board?

No, not the ELF file, the code in the FLASH, look at the .MAP or the reporting coming out of the linker.

The chip can hold 1MB of code/data in FLASH

>>Why the flash HAL function failure has anything to do with code size?

You are trying to erase some of the memory in the part, ponder for a second why the size of what you are running is consequential.

0690X00000604aDQAQ.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 21, 2018 at 17:36

Over 1M.

Memory Configuration

Name Origin Length Attributes

FLASH 0x08000000 0x00100000 xr

RAM 0x20000000 0x00040000 xrw

RAM2 0x10000000 0x00010000 rw

MEMORY_B1 0x60000000 0x00000000 xr

*default* 0x00000000 0xffffffff
Posted on June 21, 2018 at 17:52

Looks more like the linker script settings rather than the stats for the project as built. You are looking for usage/utilization numbers.

Ok, so change the limits in the linker script and see if it fits

FLASH 0x08000000 0x8000

Perhaps consider instrumenting the code so it outputs progress via a serial port, rather than attempting to single-step flash programming code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 21, 2018 at 18:31

There is a MEMORY section in .ld file describe the ORIGIN and LENGTH. How to change the limits in linker script?

If the code exceed 1024K, how does the FLASH starts address change help?

/* Specify the memory areas */

MEMORY

{

(rx) : ORIGIN = 0x08000000, LENGTH = 1024K

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K

RAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 64K

MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K

}
Posted on June 21, 2018 at 18:48

>>How to change the limits in linker script?

(rx) : ORIGIN = 0x08000000, LENGTH = 32K

>>If the code exceed 1024K, how does the FLASH starts address change help?

You are erasing a large HOLE in the middle of this 1024K. It is going to be important not to put any code that needs to continue functioning inside that hole, right?

As you can't find the statistics output by the linker, the alternative is to tell the linker what space is actually safe to use, then hopefully it will throw an error if you step into the hole.

0690X00000604gaQAA.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 21, 2018 at 19:03

I changed the start/end address to PAGE_500/511. Seems working. Why?

&sharpdefine FLASH_USER_START_ADDR ADDR_FLASH_PAGE_500 /* Start @ of user Flash area */

&sharpdefine FLASH_USER_END_ADDR ADDR_FLASH_PAGE_511 + FLASH_PAGE_SIZE - 1 /* End @ of user Flash area */