cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303 WHEN WRITE IN INTERNAL FLASH GET HARDWARE FAULT

omid hamdi
Senior
6 REPLIES 6

So probably not configuring it properly, or using the right mechanisms to write to the memory.

Need to make sure the word is blank/erased, you have one chance to write content.

Having just a title in ALL CAPS isn't very enlightening to what you are actually doing to cause this.

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

Search this forum for the many, many, many posts about hardware faults. Recently, @Community member​ even posted example fault handler code to help figure out why and where the fault occurs. If you need help understanding the fault registers, post the values here. You will need the STM32F3 series Cortex M4 programming manual (PM0214), which also covers the F4, L4 and L4+ devices. Look for the CFSR and related registers.

HI

I USED EXAMPLE ST

void WRITE_FLASH(void)

{

 HAL_FLASH_Unlock();

 uint32_t  Address=ADDR_FLASH_PAGE_254,PageError = 0;

 __IO uint32_t data32 = 0 ;

 /*Variable used for Erase procedure*/

 static FLASH_EraseInitTypeDef EraseInitStruct;

 EraseInitStruct.TypeErase  = FLASH_TYPEERASE_PAGES;

 EraseInitStruct.PageAddress = Address;

 EraseInitStruct.NbPages    = 1;

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

 {

   /*

     Error occurred while page erase.

     User can add here some code to deal with this error.

     PageError will contain the faulty page and then to know the code error on this page,

     user can call function 'HAL_FLASH_GetError()'

   */

   CALIBRATION_STATUS=64; /* send calibration ok and finish write problem */

 }

 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, CALIBRATION_K) != HAL_OK)

 {

    CALIBRATION_STATUS=64; /* send calibration ok and finish write problem */

 }

 if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (Address+4), CALIBRATION_ZERO) != HAL_OK)

 {

    CALIBRATION_STATUS=64; /* send calibration ok and finish write problem */

 }

 HAL_FLASH_Lock();

 data32 = *(__IO uint32_t *)0;

 if (data32!=CALIBRATION_K){CALIBRATION_STATUS=64;}

 data32 = *(__IO uint32_t *)4;

 if (data32!=CALIBRATION_ZERO){CALIBRATION_STATUS=64;}

}

Ok, and which example file did this come out of?

Which specific routine faulted?

Why did you not exit if the erase fails, you plough forward.

Reading address 0 and 4 doesn't seem like a good plan.

What specific part do you have, provide a fully qualified part#.

How much flash does that have?

What specifically is the address being written here?

Suggest you use a serial port and output values and progress so you can observe it.

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

I GOT IT PROBLE

I USED 303RB FLASH LOWER THAN ZE ADDRESS PROBLEM

Yes, that has 128KB, and you're working at the north end of the 512KB memory space. The STM32 will fault if you access undefined memory.

data32 = *(__IO uint32_t *)(Address + 0); // Read where you actually wrote

 if (data32!=CALIBRATION_K){CALIBRATION_STATUS=64;}

 data32 = *(__IO uint32_t *)(Address + 4);

 if (data32!=CALIBRATION_ZERO){CALIBRATION_STATUS=64;}

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