2018-06-20 03:57 PM
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); }2018-06-20 04:11 PM
>>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?
2018-06-20 06:20 PM
The .elf file is pretty big - 1883 KB. What's the limit of the board?
2018-06-20 06:44 PM
Why the flash HAL function failure has anything to do with code size?
2018-06-20 07:26 PM
>>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.
2018-06-21 10:36 AM
Over 1M.
Memory Configuration
Name Origin Length Attributes
FLASH 0x08000000 0x00100000 xrRAM 0x20000000 0x00040000 xrwRAM2 0x10000000 0x00010000 rwMEMORY_B1 0x60000000 0x00000000 xr*default* 0x00000000 0xffffffff2018-06-21 10:52 AM
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.
2018-06-21 11:31 AM
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}2018-06-21 11:48 AM
>>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.
2018-06-21 12:03 PM
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 */