How to read a large file (About 240MB) from SD card

Hello all, I hope you are doing well. 

I Have a project on NRF52840 in which I have multiple sensors connected to the NRF52 and the sensor data are storing in the SD card in the form of a CSV file of size 240 MB. I want to read this large file from the SD card and then send it to the mobile app using ble_periperhial. I have used This example and modified it, but the problem is that I can only read 220000 bytes from the SD card in the buffer at once and when I am trying to increase 

   #define FILE_SIZE_MAX (Maximum size in bytes of the file to be read from SDCARDgreater than 220000, while the following;

                                            static uint8_t file_buffer[FILE_SIZE_MAX]; 

                                           ff_result = f_read(&file, file_buffer, FILE_SIZE_MAX, (UINT *) &bytes_read);

 Then it gives the following error:

                                      .bss is too large to fit in RAM1 memory segment
                                     .heap is too large to fit in RAM1 memory segment
                                      section .heap overlaps absolute placed section .stack
                                      section .stack VMA [000000002003e000,000000002003ffff] overlaps section .bss VMA [0000000020002c64,0000000020224b08]   

                                               

I don't know about this error and how to solve it. Simply I want to read the whole file (234MB) from the SD card at once and then send it in chunks to the mobile app, Is this possible or do I have to read in chunks from the SD card too? 

Any help regarding this will be highly appreciated.

  • Hi Sami

    Samiulhaq said:
    Can you please direct me to a thread/example where they have implemented this logic? I am unable to find TX COMPLETE interrupt in my example.

    The nrf52-ble-image-transfer-demo I mentioned earlier follows this approach. 

    The TX COMPLETE event is handled here

    The implementation is a bit complicated unfortunately, in hindsight I should have optimized the ble_image_transfer_service.c implementation a bit to make it easier to understand how the data is sent. 

    Samiulhaq said:
    currently, I am able to send 2284066 bytes in 23-25 seconds (using 2M PHY). 

    What phone are you using for this test?

    This is around 760kbps, which is actually quite good throughput when connected to a phone. Many phones will be limited to slower rates than this, including the iPhone which doesn't allow you to send BLE packets for more than 50% of the time. 

    The best phones for throughput in my experience is the Samsung Android phones, which can go as high as ~1200kbps in some cases. 

    Best regards
    Torbjørn

  • Hello Torbjørn, I hope you are doing well.

    Sir, I have tried my best but can't make the two operations execute in parallel. Can you please help me with the code snippet based on my code? I will be very grateful to you. I have checked the TX_COMPLETE event of the ble_image_transfer_demo example but can't understand its logic. 

    Best Regards,

    Sami

  • Hi Sami

    I spent some time today on an example for you. It is almost ready, but needs a bit of cleanup and testing before I can share it. 

    I will do my best to get it to you by tomorrow. 

    Best regards
    Torbjørn

  • Hi Torbjorn Sir, thank you for the reply.

    I spent some time today on an example for you. It is almost ready, but needs a bit of cleanup and testing before I can share it. 

    Thank you so much for your effort. Okay no problem, take time and send me whenever it is ready.

    Once again thank you so much.

    Best Regrds,

    Sami

  • Hi Sami

    I have shared the project here:
    https://github.com/too1/nrf52-ble-app-uart-error-resources

    I guess the main takeaway is to keep the state machine as simple as possible, and make sure to run as much as possible of the application logic from the main context, rather than directly in the event handlers. 

    Most of the code you can find in the for loop in main()

    In order to test the demo you just have to connect to the device (using the nRF Connect mobile app for instance), enable notifications on the TX characteristic, and send anything on the RX characteristic (what you send doesn't matter). 

    Best regards
    Torbjørn

Related