cancel
Showing results for 
Search instead for 
Did you mean: 

How to safely write to external flash while using TouchGFX?

manto.1
Senior

I am using external flash (16Mb) for TouchGFX resources (normaly in memory mapped mode). I would also like to save some parameters to external flash in runtime while using the application.

Bellow is current code handeling writing to external flash (using EEPROM) library. eepromCtrl function is called in separate task every 25ms. inside I check the queue if there are some things to save to external flash. If there is something then I call

  • taskENTER_CRITICAL();,
  • disable some interrupts,
  • exit memory mapped mode,
  • write paramter to external flash
  • starting back memory maped mode
  • enabeling interupts
  • taskEXIT_CRITICAL();

This works ~90% of the time but sometimes crashes. What can I do better?

void eepromCtrl(){
	uint8_t EEpromQueueFillLevel = uxQueueMessagesWaiting(Queue_To_EEpromHandle);
	if((EEpromQueueFillLevel <= 0) ||  !enableEEpromWriting){
		return;
	}
	eepromWriteCount++;
	baseType = xQueueReceive(Queue_To_EEpromHandle, &eepromQueueMsg, 1);
	if ((baseType == pdPASS) && (eepromQueueMsg.id > 0)) {
		taskENTER_CRITICAL();
		NVIC_DisableIRQ(DMA2D_IRQn);
		NVIC_DisableIRQ(LTDC_IRQn);
		NVIC_DisableIRQ(TIM5_IRQn);
		stat = ExtFlash_Abort(&hqspi);
		if(stat == EXT_FLASH_OK){
			ee_status = EE_WriteVariable32bits(eepromQueueMsg.id,eepromQueueMsg.value);
		}
 
		if (ee_status == EE_CLEANUP_REQUIRED) {
			if (EE_CleanUp() != EE_OK) {
			};
		}
		stat = ExtFlash_MemoryMap(&hqspi);
		NVIC_EnableIRQ(TIM5_IRQn);
		NVIC_EnableIRQ(DMA2D_IRQn);
		NVIC_EnableIRQ(LTDC_IRQn);
		taskEXIT_CRITICAL();
 
	}
 
}

 
_legacyfs_online_stmicro_images_0693W00000bkwEQQAY.png

0 REPLIES 0