Skip to main content
JJoy.1
Associate III
August 3, 2021
Solved

I am using STM32H7 board and integrated an SD card using SPI and able to mount it in "/". I am storing a file inside the SD card.

HAL_Delay (500);

 fresult = f_mount(&fs, "/", 1);

  if (fresult != FR_OK)

   Serial_PutString ("ERROR!!! in mounting SD CARD...\n\n");

  else

  {

   Serial_PutString("\n\r SD CARD mounted successfully...\n\n");

  fresult = f_open (&fil, "zephyr_20210506_nbiot_quad_12ec59.bin", FA_READ);

 result = Ymodem_Transmit(&fil, (const uint8_t*)"zephyr_20210506_nbiot_quad_12ec59.bin", 5601949);

My requirement is to pass the start address of the file stored in SD card to the function "Ymodem_Transmit" and transfer file using Y MODEM protocol to some other microcontroller connected to STM32. I used SD card because the above mentioned file is of large size which cannot fit in internal flash of STM.

Remaining small files i am putting in flash and reading by giving the address in flash as below

result = Ymodem_Transmit((uint8_t*)APPLICATION_ADDRESS, (const uint8_t*)"sbl_7243i_v1.0_test.bin", size);

where #define APPLICATION_ADDRESS   (uint32_t)0x08100000 

Complete implementation is given in the attached code.

I am not getting the starting address of file by giving like this.

 result = Ymodem_Transmit(&fil, (const uint8_t*)"zephyr_20210506_nbiot_quad_12ec59.bin", 5601949);

Is by passing &fil will get the address of file stored in SD card?

Or otherwise what i need to get access the file in SD card.

Waiting for the reply. Please help...

Thanks,

Jestina

This topic has been closed for replies.
Mike_ST
Mike_STBest answer
ST Technical Moderator
August 3, 2021

Hello

"fil" is a file descriptor, it is not an address pointing on the file's data.

You have to use "f_read" function after "f_open" to get your data.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 

5 replies

Mike_ST
Mike_STBest answer
ST Technical Moderator
August 3, 2021

Hello

"fil" is a file descriptor, it is not an address pointing on the file's data.

You have to use "f_read" function after "f_open" to get your data.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
JJoy.1
JJoy.1Author
Associate III
August 3, 2021

Hi,

Thanks for the answer.

#define BUFFER_SIZE 5601949

unsigned char buffer[BUFFER_SIZE]; 

fresult = f_read (&fil, buffer, f_size(&fil), &br);

My file is of size 5601949. When i compiled the code, I am getting an error like "region `RAM' overflowed by 5490600 bytes"

How can I solve the issue and store the received data?

Jestina

JJoy.1
JJoy.1Author
Associate III
August 3, 2021

I need the complete data all in once.

Mike_ST
ST Technical Moderator
August 3, 2021

You're exceeding the maximum chip memory.

You cannot store all your file in the STM32 memory, unless you have external RAM.

You have to declare a smaller array and make a loop to read and transmit the file piece after piece.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
JJoy.1
JJoy.1Author
Associate III
August 3, 2021

OK Thank you.