cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler in writing 64bit to Flash

varani luciano
Associate III

I'm using a Stm32f429VI, and I try to write in 64bit mode to the flash.

The system goes every time to HardFault_Handler.

In 32bit mode I have no problems.

I think there is a bug in FLASH_Program_DoubleWord() function ( in

stm32f4xx_it.c) :

the function writes first 32 bit and IMMEDIATLY writes seconds 32 bit not attendig if the prevoius operation is terminated.

I solved the problem as you can see, writing two 32bit words.

What did you think?

static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)

{

 /* Check the parameters */

 assert_param(IS_FLASH_ADDRESS(Address));

 /* If the previous operation is completed, proceed to program the new data */

 CLEAR_BIT(FLASH->CR, FLASH_CR_PSIZE);

 FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD;

 FLASH->CR |= FLASH_CR_PG;

//ORIGINAL

 /* Program the double-word */

 //*(__IO uint32_t*)Address = (uint32_t)Data;

 //*(__IO uint32_t*)(Address+4) = (uint32_t)(Data >> 32);

//NEW

 FLASH_Program_Word(Address,Data);

 Data>>=32;

 FLASH_Program_Word(Address+4, Data);

}

4 REPLIES 4
Uwe Bonnes
Principal III

Did you read the find manual (rm0090) and apply external programming voltage? External VPP is neede for 64 bit programming!

The optimizer likely folded the writes in the first case, and that would be sensitive to address alignment issues.

I'd have to see the faulting instructions and the registers too properly understand the issue.

What tool chain are you using?

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

The operating voltage is 3.3V. Before a write, obiously,I do an erase of sector; in that moment I specify the voltage; do you think I do repepeat? (excuse italian names...)

Erasing :

......

   HAL_FLASH_Unlock();

   EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; // a sectors to be erased

   EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; //operating range: 2.7V to 3.6

   EraseInitStruct.Sector = numeroSettoreStart;         //starting sector

   EraseInitStruct.NbSectors = numeroSettori;           //number of sectors

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

.......

I'm using Atollic True studio 9.0. Example:

 uint64_t data=0x0807060504030201;

uint32_t flash_ptr=0x80080000;

.......

//(I delete sector 2)

 HAL_FLASH_Unlock();

   EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; // a sectors to be erased

   EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; //operating range: 2.7V to 3.6

   EraseInitStruct.Sector =2;

   EraseInitStruct.NbSectors = 1;

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

.......

//I try to write

HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, flash_ptr, data);

in this moment the system ,goes IMMEDIATLY to HardFault_Handler.

What register are of your interst?

Many thanks (The work goes on, as I say I solved the question writing TWO 32bit word)

Varani