This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FatFs question

I used nRF5_SDK_14.1.0_1dda907.

I used fatfs example.

Wirted data in the same file to sd card.

I discoverd that Max size of the file is 16KB.

Over the max size of file, when i write data to sd card, will be failure.

Can i change the max size to one file, or no limit size ?

Parents
  • I used 8GB sd card.

    If there are two file in the sd card.

    The one is 16KB.

    Another is 14 KB.

    If i write data to 14KB file, will be successful.

    If i write data to 16KB file, will be failure.

  • I need to know how you have initialized the file system, do you have any code, tracelogs, or logs that you can share?

  • I used the code init the fill system.

    void fatfs_init(void)
    {
        static FATFS fs;
        static DIR dir;
        static FILINFO fno;
        static FIL file;
    
        FRESULT ff_result;
        DSTATUS disk_state = STA_NOINIT;
    		
    		uint8_t string_start_init[] = "\r\nSD card init\r\n";
    		uint8_t file_name1[] = "Ant00000.TXT";
    		size_t	string_size;
    
        // Initialize FATFS disk I/O interface by providing the block device.
        static diskio_blkdev_t drives[] =
        {
                DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev), NULL)
        };
    
        diskio_blockdev_register(drives, ARRAY_SIZE(drives));
    
        NRF_LOG_INFO("Initializing disk 0 (SDC)...");
        for (uint32_t retries = 3; retries && disk_state; --retries)
        {
            disk_state = disk_initialize(0);
        }
        if (disk_state)
        {
            NRF_LOG_INFO("Disk initialization failed.");
            return;
        }
    
        uint32_t blocks_per_mb = (1024uL * 1024uL) / m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_size;
        uint32_t capacity = m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_count / blocks_per_mb;
        NRF_LOG_INFO("Capacity: %d MB", capacity);
    
        NRF_LOG_INFO("Mounting volume...");
        ff_result = f_mount(&fs, "", 1);
        if (ff_result)
        {
            NRF_LOG_INFO("Mount failed.");
            return;
        }
    
    	NRF_LOG_RAW_INFO("");
    
    	string_size = sizeof(string_start_init) - 1;
    	SD_card_write_string_in_file(string_start_init, string_size,  file_name1);
        return;
    }

  • Without looking at SD_card_write_string_in_file(), my guess is: Stack overflow.

    Why didn't you post the function that actually fails?

  • static void write_data_to_sd_card_and_determine_file(	uint8_t *data_array,
    																											uint16_t data_array_index)
    {
    	bool file_size_determine;
    
    	file_size_determine = SD_card_for_file_size(data_array_index, file_name, testcount);
    
    	SD_card_write_string_in_file(data_array, data_array_index, file_name);
    	
    	testcount++;
    }
    
    
    void SD_card_write_string_in_file(uint8_t* string, size_t string_size, uint8_t* file_name_array)
    {
    	  static FIL file;
    
        uint32_t bytes_written;
        FRESULT ff_result;
    	
    		NRF_LOG_INFO("Writing to file %s ...", file_name_array);
    		ff_result = f_open(&file, file_name_array, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    		if (ff_result != FR_OK)
    		{
    			    NRF_LOG_INFO("ff_result: %d .",ff_result);
    				NRF_LOG_INFO("Unable to open or create file: %s .", file_name_array);
    				return;
    		}
    
    		ff_result = f_write(&file, string, string_size, (UINT *) &bytes_written);
    		if (ff_result != FR_OK)
    		{
    				NRF_LOG_INFO("Write failed\r\n.");
    		} 
    		else
    		{
    				NRF_LOG_INFO("%d bytes written.", bytes_written);
    		}
    		 (void) f_close(&file);
    }
    
    

    Error message :

    I added line is 25.

Reply
  • static void write_data_to_sd_card_and_determine_file(	uint8_t *data_array,
    																											uint16_t data_array_index)
    {
    	bool file_size_determine;
    
    	file_size_determine = SD_card_for_file_size(data_array_index, file_name, testcount);
    
    	SD_card_write_string_in_file(data_array, data_array_index, file_name);
    	
    	testcount++;
    }
    
    
    void SD_card_write_string_in_file(uint8_t* string, size_t string_size, uint8_t* file_name_array)
    {
    	  static FIL file;
    
        uint32_t bytes_written;
        FRESULT ff_result;
    	
    		NRF_LOG_INFO("Writing to file %s ...", file_name_array);
    		ff_result = f_open(&file, file_name_array, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    		if (ff_result != FR_OK)
    		{
    			    NRF_LOG_INFO("ff_result: %d .",ff_result);
    				NRF_LOG_INFO("Unable to open or create file: %s .", file_name_array);
    				return;
    		}
    
    		ff_result = f_write(&file, string, string_size, (UINT *) &bytes_written);
    		if (ff_result != FR_OK)
    		{
    				NRF_LOG_INFO("Write failed\r\n.");
    		} 
    		else
    		{
    				NRF_LOG_INFO("%d bytes written.", bytes_written);
    		}
    		 (void) f_close(&file);
    }
    
    

    Error message :

    I added line is 25.

Children
Related