How to handle asynchronous (data size of 240000 bytes) data from MQTT in STM32

Viewed 81

I am using STM32L475 dev board and SIM7600 4g module. I have implemented MQTT communication in this project. I can successfully connect to MQTT broker and also able to receive the data. But the problem is size of data is large (240000 bytes ie 234.375KB).RAM available in this Dev board is 128 KiloBytes. I WANT TO STORE THIS DATA IN EXTERNAL FLASH MEMORY.

I am using UART with DMA. So whenever I get data on UART from SIM7600 module, MCU goes interrupt routine and there I can copy the content of rx_buffer into any other buffer for further processing.

I can see in debugger window, the "next_size" variable which counts the incoming data showing me size 244824 ie 240000 bytes plus the MQTT headers.

But when I call the functions of QSPI to store this data in External flash memory, MCU does not download the packets after first 512 bytes.MCU takes time(I assume) and It misses the other data. I can see "next_size" does not increase.

function in code is as below


void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) {
    if (huart->Instance == UART4) {
        new_size = Size + prev_size;
        prev_size = new_size;
        /*
         * BSP_QSPI_Write this function writes data to external flash 
            memory
         * uint8_t BSP_QSPI_Write(uint8_t *pData, uint32_t WriteAddr, 
            uint32_t Size)
         */
        memcpy((uint8_t*) copy_buf, (uint8_t*) rx_buf, Size);
        if (BSP_QSPI_Write(copy_buf, (WRITE_READ_ADDR + next_address),Size) != QSPI_OK) {
            printf("QSPI WRITE : FAILED.\n");
            //printf("QSPI Test Aborted.\n");
        }
        else {
            //printf("data written to flash\r\n");
            next_address = next_address + Size;
        }
        /* start the DMA again */
        HAL_UARTEx_ReceiveToIdle_DMA(&huart4, rx_buf, rx_buf_size);
        __HAL_DMA_DISABLE_IT(&hdma_uart4_rx, DMA_IT_HT);

        if (network_init_flag == 0) { //stops printing when large data 
                                      //starts downloading
            printf("Response=%s \r\n", rx_buf);
        }
    }
}
0 Answers
Related