File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,12 +47,25 @@ void cppmain() {
4747#endif
4848
4949 // Flash init
50+ // TODO verify why or if flash does not erase or initialize correctly on some new chips
5051 HAL_FLASH_Unlock ();
5152 __HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
53+
5254 if ( EE_Init () != EE_OK){
5355 Error_Handler ();
5456 }
57+ // Check if flash is initialized
58+ uint16_t lastVersion = 0 ;
59+ if (!Flash_Read (ADR_SW_VERSION, &lastVersion)){ // Version never written
60+ Flash_Write (ADR_SW_VERSION, (SW_VERSION_INT[0 ]<<8 ) | SW_VERSION_INT[1 ]);
61+ }
62+ Flash_Read (ADR_SW_VERSION,&lastVersion);
63+ if ((lastVersion & 0xff00 ) != (SW_VERSION_INT[0 ]<<8 )){
64+ EE_Format (); // Major version changed or could not write initial value. force a format
65+ Flash_Write (ADR_SW_VERSION, (SW_VERSION_INT[0 ]<<8 ) | SW_VERSION_INT[1 ]);
66+ }
5567 HAL_FLASH_Lock ();
68+ // ------------------------
5669
5770 TIM_MICROS.Instance ->CR1 = 1 ; // Enable microsecond clock
5871
You can’t perform that action at this time.
0 commit comments