I’m working with an STM32WLE5 microcontroller, using code generated by STM CubeMX. My project incorporates LoRaWAN modules, follows the EndNode skeleton, and utilizes FreeRTOS (CMSIS V2.0). The common tasks—such as sensor readings and data transmission—work correctly. However, I encounter problems when writing to flash memory. After sending a LoRa frame with information and saving it to flash, subsequent frame transmission and reception stop functioning.
Problem Details:
After executing LmHandlerSend(&AppData_send, LmHandlerParams->IsTxConfirmed, true);, the status variable holds the value LORAMAC_HANDLER_COMPLIANCE_RUNNING.
The issue seems related to the second condition in the following code snippet:
#if (defined(LORAMAC_VERSION) && (LORAMAC_VERSION == 0x01000300))
if ((LmHandlerPackages[PACKAGE_ID_COMPLIANCE]->IsRunning() == true) &&
(appData->Port != LmHandlerPackages[PACKAGE_ID_COMPLIANCE]->Port) &&
(appData->Port != 0))
{
return LORAMAC_HANDLER_COMPLIANCE_RUNNING;
}
Additional Context (Flash Writing Task):
I have a separate FreeRTOS task responsible for flash memory writes. This task runs with maximum priority.
Flash memory address where I’m storing data: 0x0803E000 with a page size of 2 KB
The flash writing task is implemented as follows:
/* USER CODE BEGIN Header_flashWriteTask */
/**
* @brief Function implementing the flashWrite thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_flashWriteTask */
void flashWriteTask(void *argument)
{
__flash_read_write_t data_flash_write = {0};
/* Infinite loop */
for (;;)
{
osMessageQueueGet(flashWriteQueueHandle, &data_flash_write, 0, osWaitForever);
// Check that the data size is a multiple of 8 (uint64_t)
if (data_flash_write.numberofwords % 8 != 0)
{
data_flash_write.numberofwords += 8 - (data_flash_write.numberofwords % 8);
}
osKernelLock();
FLASH_IF_StatusTypedef erase_flash_sts = FLASH_IF_Erase((void *)data_flash_write.StartPageAddress, data_flash_write.numberofwords);
if (FLASH_IF_OK == erase_flash_sts)
{
FLASH_IF_Write((void *)data_flash_write.StartPageAddress, data_flash_write.Data, data_flash_write.numberofwords);
}
osKernelUnlock();
}
}
I’d appreciate any insights or suggestions on how to resolve this issue. What could be causing the conflict between flash memory writes and LoRa frame handling?
I have conducted debugging, but unfortunately, I haven’t arrived at any concrete conclusions.