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 19:52

>> Seems working. Why?

Perhaps you're not erasing code that is executing? Perhaps there is something else going on?

May be you can do some analysis and debugging to pin point why you get failures?

If the software Hard Faults, it is typically because the processor is being asked to touch some address it shouldn't, or you're attempting to execute broken/missing code.

Things I normally do when testing examples : 1) Add code to output printf() via SWV or USART, 2) Have a Hard Fault Handler that outputs diagnostic messages about internal register states should it fault. This allows me to quickly determine what's going on inside the black box.

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