HSMCI (SD card) writing directly from internal Flash memory

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Hi there,

 

I'm working on ATSAM4S32C with 1GB SD card writing. My application save ADC reading data set into internal flash memory at every 5 minutes, 

If this size is full of 20 flash blocks (81902 bytes) of last part of internal flash memory, it tries to save this value into SD card through HSMCI with 120MHz clock.

Actual, HSMCI internal clock is set as 30MHz and SDIO (4 bit transfer).

 

When I tried assign new buffer, size 81920 copy flash memory data to RAM buffer, then try to f_write with this buffer, it works fine. However when I assign f_write read direct address of internal flash memory

it looks work, but the saved data as all zeros. One of my guess that ATSAM4 is not allowed to read directly from flash memory with out memcpy or special instruction inside. Another probable case may be

flash memory reading is quite slow or need many clock to start read, but HSMCI PDC (DMA) controller inside f_write toss all of internal buffer value to sd card. 

 

If I need copy flash to RAM with 80KB buffers to read/write to SD card through HSMCI, it looks waste of clock and power. 

 

Any idea and comment will be really helpful to me.

 

The below is my code, you can compare if(0) and if(1) to try different case,

FRESULT FS_writefile2( const char* filename, char* data_buffer, long data_buffer_size ) {

    FIL file_object;

    long bytes_written = 0;

    uint32_t bytecount = 0;

    uint16_t size = 512*8;

    char buf[size];

    FRESULT res;

 

    /* Open the file */

    res = f_open( &file_object, filename, FA_WRITE | FA_CREATE_ALWAYS );

    if (res != FR_OK) {

        printf("-E- f_open %s pb: 0x%X\n\r", filename, res);

        return res;

    }

if(0){

    res = f_write(&file_object,(const void *)(FLASH_START + FLASH_DIVE_PROFILE_START),FLASH_DIVE_BLOCK_NUM*FLASH_BLOCK_SIZE, &bytes_written);

    bytecount += bytes_written;

}else {

    memcpy(buf,FLASH_START + FLASH_DIVE_PROFILE_START, FLASH_DIVE_BLOCK_NUM*FLASH_BLOCK_SIZE);                

        res = f_write(&file_object, buf, FLASH_DIVE_BLOCK_NUM*FLASH_BLOCK_SIZE, &bytes_written);

        bytecount += bytes_written;

    }

}

 

    /* Close the file*/

    res = f_close(&file_object);

    if (res == FR_OK){

        printf("%d bytes write to %s \n", bytecount, filename );

    }else {

        printf("-E- f_close pb: 0x%X\n\r", res);

    }

    return FR_OK;

}

 

 

This figure is the overall block diagram of ATSAM4S32C, the highlighted path is what I want to set up.

 

 

Last Edited: Mon. Nov 29, 2021 - 12:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please see Tip #1 in my signature, below, for how to properly post  source code:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...