cancel
Showing results for 
Search instead for 
Did you mean: 

RWW for Single Bank Flash on STM32

Carl_G
Senior II

I understand you can't erase the same bank you are running code in. Or something like that. But I am confused on the STMG0 because this one only has a single bank. So how do I use Flash to emulate EEPROM if I am using flash to run my code. Everything has been working. not sure what I changed but now when I do an erase I am getting an exception. Maybe I should not do the background interrupt based erase!?

 

Thread #1 [main] 1 [core: 0] (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)	
	HardFault_Handler() at stm32g0xx_it.c:100 0x8013964	
	<signal handler called>() at 0xfffffff1	
	HAL_TIM_IRQHandler() at stm32g0xx_hal_tim.c:3,843 0x80192bc	
	TIM6_DAC_LPTIM1_IRQHandler() at stm32g0xx_it.c:268 0x8013a6c	
	<signal handler called>() at 0xfffffff9	
	HAL_FLASHEx_Erase_IT() at stm32g0xx_hal_flash_ex.c:282 0x8017682	
	DoEEP() at EEPromMgr.cpp:323 0x800208c	
	DoWrite() at EEPromMgr.cpp:280 0x8001f4e	
	DoEEProcess() at EEPromMgr.cpp:217 0x8001dfc	
	main() at main.c:614 0x80136f6	
1 REPLY 1

Debug the Hard Fault normally, determine WHAT it is complaining about, the code or the addresses being referenced.

For example unwritten FLASH.

Perhaps have a handler that outputs register and processor state.

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

The Writes to flash will briefly stall the MCU, the Erase more so, but stuffs wait-states to achieve this, and should case it to fault. The EEPROM Emulation basically journals the writes, so only periodically erases when resources are all consumed.

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