NRF52840 fs_sample SD fs_close error on NCS 2.7.0

I am getting an fs_close() -5 error (-EIO) when I write to an SD card using fatfs. I determined this error was associated with FR_DISK_ERR in fat_fs.c.

Additional info

  • I'm using a custom board.
  • I didn't have these problems with NCS 2.5.0
  • The contents are actually being written to the card.
  • The file closes successfully If I open the file but don't write to it.

DTS

/**
 * The NRF52 documentation states that SPIM0-2 are limited to 8Mbps
 * datarates. SPIM3 is used because its capable of a max throughput
 * of 32 Mbps (32 MHZ).
 */
&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi3_default>;
	pinctrl-1 = <&spi3_sleep>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
	sdhc0: sdhc@0 {
		compatible = "zephyr,sdhc-spi-slot";
		reg = <0>;
		status = "okay";
		mmc {
			compatible = "zephyr,sdmmc-disk";
			status = "okay";
		};
		spi-max-frequency = <32000000>;
		pwr-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
	};
};

prj.conf

CONFIG_DISK_ACCESS=y
CONFIG_LOG=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_PRINTK=y
CONFIG_MAIN_STACK_SIZE=2048

CONFIG_SPI=y
CONFIG_DISK_DRIVER_SDMMC=y


Parents Reply
  • HI Maria,

    I seem to have the same situation:

    • Code based on the fs_sample
    • Worked on NCS 2.5.0
    • Broken after moving to NCS 2.7.0
    • Custom board but it is ultimately an sd card on the SPI port.
    • fs_open() succeeds
    • fs_write() fails with -13 the file is created but the content is not written
    • fs_close() fails with -5
    • fs_mkdir() also returns an error. The directory is created.

    The write process fails on line 4032 of ff.c.

    if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED);    
    fp->flag is 0x58
    FA_WRITE is 0x2

    flag is set to 0x58 in f_open(), (called by fs_open(&file, path, FS_O_CREATE)). It is set via mode (line 3863) however the steps to this point are optimised out.
    Thanks,
    Tom
Children
Related