STM32CubeWL icon indicating copy to clipboard operation
STM32CubeWL copied to clipboard

Discrepancy MX Codebase Flash_if.c

Open joembedded opened this issue 2 months ago • 3 comments

"Flash_if.c" has changed from V1-3-1 to V1-4-0. This is MX-Code, but in "lora_app.c" the Init-Code is placed in a user-region:

/* USER CODE BEGIN LoRaWAN_Init_1 */ if (FLASH_IF_Init( FLASH_RAM_buffer /* fomerly NULL*/ ) != FLASH_IF_OK) { Error_Handler(); } ... with NULL as argument Context-Storing fails.

Also: FLASH_IF_Read()/Write() in "lora_at.c" should issue an error if it fails? The discrete Event shows "NVM CONTEXT RESTORED" even on Failure.

joembedded avatar Dec 12 '25 14:12 joembedded

Hello @joembedded,

Thank you for your report. If I correctly understood your issue, the FLASH_IF_Read/Write() functions are not checking their return status when invoked?

BR, Mohamed Chaker.

MKISTM avatar Dec 16 '25 16:12 MKISTM

in lora_at.c the result for FLASH_IF_Write() is not checked. I added the "DEBUG"-Parts, but these will disappear if re-generated by CubeMX:

The Reson for the Failure is the wrong call of FLASH_If_init() as mentioned previously, as inherrited from FW 1.3.1:

void AT_event_OnStoreContextRequest(void *nvm, uint32_t nvm_size) {
	/* store nvm in flash */
	if (FLASH_IF_Erase(LORAWAN_NVM_BASE_ADDRESS, FLASH_PAGE_SIZE)
			== FLASH_IF_OK) {
#ifdef DEBUG // Kann entfernt werden von MX
	FLASH_IF_StatusTypedef fstat =
#endif
		FLASH_IF_Write(LORAWAN_NVM_BASE_ADDRESS, (const void*) nvm, nvm_size);
#ifdef DEBUG
		AT_PRINTF("Flash-Write to: 0x%X[%u]->0x%X: %d\r\n",nvm,nvm_size,LORAWAN_NVM_BASE_ADDRESS,fstat);
		//mem_dump("NVM_RAM",nvm,nvm_size);
		//mem_dump("FLASH",LORAWAN_NVM_BASE_ADDRESS,nvm_size);
#endif
	}
}

void AT_event_OnRestoreContextRequest(void *nvm, uint32_t nvm_size) {
#ifdef DEBUG // Kann entfernt werden von MX
	FLASH_IF_StatusTypedef fstat =
#endif
	FLASH_IF_Read(nvm, LORAWAN_NVM_BASE_ADDRESS, nvm_size);
#ifdef DEBUG
		AT_PRINTF("Flash-Read from: 0x%X[%u]<-0x%X: %d\r\n",nvm,nvm_size,LORAWAN_NVM_BASE_ADDRESS,fstat);
		//mem_dump("NVM_RAM",nvm,nvm_size);
#endif
}

joembedded avatar Dec 16 '25 17:12 joembedded

Hello @joembedded,

I don't see the reason for the failure, if it was due to the wrong call of FLASH_If_init() in FW 1.3.1, it has been updated in FW 1.4.0.

BR, Mohamed Chaker.

MKISTM avatar Dec 18 '25 13:12 MKISTM

Hello @joembedded,

Regarding the call to the FLASH_If_init() function, it is normal to call it inside the user code section because we are within the LoRaWAN_Init() function. The MX tool generates only functions related to LoRaWAN, and if the user needs additional functionality, it should be called within the user section.

Regarding the calls to FLASH_IF_Read() and FLASH_IF_Write(), you want to add a check on their return values, If I correctly understood you need to add this check on our code!?

BR, Mohamed Chaker.

MKISTM avatar Dec 26 '25 16:12 MKISTM

Its just a suggestion for a fix of a inconsistency: if you put FLASH_IF_init() in a usercode area (not maintained by CubeMX), you should encapsulat _erase/_write() also as usercode to allow checks for errors, but CubeMX will overwrite it and also flash_if.c is maintained by MX.

joembedded avatar Dec 26 '25 22:12 joembedded

Hello @joembedded,

You can check the error within FLASH_IF_Read/Write() in user section, so i think you just add your modification inside FLASH_IF_Read/Write() functions to check the error without overwriten by CubeMX

BR, Mohamed Chaker.

MKISTM avatar Dec 29 '25 11:12 MKISTM

Hello @joembedded,

If you do not have any updates, please allow to close this issue.

BR, Mohamed Chaker.

MKISTM avatar Jan 06 '26 10:01 MKISTM

Hi Mohamed, it was just a suggestion. Feel free to continue aa you like. Best Regards, Jo

joembedded avatar Jan 06 '26 11:01 joembedded