SPI-based SD card interface on my nRF5340DK using NCS v2.7.0 when connecting mosi to P1.0 and miso to P1.1

I am experiencing issues configuring an SPI-based SD card interface on my nRF5340DK using NCS v2.7.0. The SD card is not initializing correctly, and I am receiving repeated error messages related to CMD8 support and storage initialization failure.

Board and SDK Information

  • Board: nRF5340DK
  • SoC: nRF5340
  • SDK Version: NCS v2.7.0
  • Sample Used: samples/subsys/fs/fat_fs

Error Log

*** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
*** Using Zephyr OS v3.6.99-100befc70c74 ***
[00:00:00.265,625] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.273,010] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.280,364] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.287,719] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.295,074] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.302,429] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.309,814] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.317,169] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.324,523] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.331,878] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.339,233] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.345,855] <inf> sd: Card does not support CMD8, assuming legacy card
[00:00:00.354,980] <err> main: Storage init ERROR!
[00:00:00.365,631] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.373,016] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.380,371] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.387,725] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.395,080] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.402,435] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.409,790] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.417,175] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.424,530] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.431,884] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.439,239] <inf> sd: Legacy card detected, no CMD8 support
[00:00:00.445,861] <inf> sd: Card does not support CMD8, assuming legacy card
[00:00:00.454,986] <err> fs: fs mount error (-5)
Error mounting disk.
[00:00:00.462,188] <err> fs: fs not mounted (mp == 0x20010000)


When connecting the nRF5340 DK, we noticed that P1.0 and P1.1 were connected to the JTAG interface. To free up these pins, we cut the trace to disconnect them from JTAG.

Later, we found out that the Network Core was also using P1.0 and P1.1, so we disabled it by adding the following configurations:

&arduino_serial {
    status = "disabled";
};

&gpio_fwd {
    status = "disabled";
};

 

However, after making these changes, we are still unable to get the SD card working.

Interestingly, when switching to other pins, the SD card works out of the box without any issues. We're unsure why this is happening.

Any insights or suggestions on how to resolve this would be greatly appreciated!




dozee_ballista_bigsection: &uart0 {
	status = "okay";
	current-speed = <115200>;
	pinctrl-0 = <&uart0_default>;
	pinctrl-1 = <&uart0_sleep>;
	pinctrl-names = "default", "sleep";
};

// dozee_sheet_smallsection: &uart1 {
// 	status = "okay";
// 	current-speed = <115200>;
// 	pinctrl-0 = <&uart2_default>;
// 	pinctrl-1 = <&uart2_sleep>;
// 	pinctrl-names = "default", "sleep";
// };

dozee_ballista_rtc: &i2c3 {
	status = "okay";
	compatible = "nordic,nrf-twim";
	label = "I2C_3";
	pinctrl-0 = <&i2c3_default>;
	pinctrl-1 = <&i2c3_sleep>;
	pinctrl-names = "default", "sleep";
	clock-frequency = <1000000>; 
};

dozee_ballista_usb: &zephyr_udc0 {
	cdc_acm_uart0: cdc_acm_uart0 {
		compatible = "zephyr,cdc-acm-uart";
	};
};

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi2_default_alt>;
	pinctrl-1 = <&spi2_sleep_alt>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio1 5 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 = <4000000>;
	};
};

&pinctrl {
	i2c3_default: i2c3_default{
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 1, 2)>,
				<NRF_PSEL(TWIM_SCL, 1, 3)>;
			// bias-pull-up;
		};
	};

	i2c3_sleep: i2c3_sleep{
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 1, 2)>,
				<NRF_PSEL(TWIM_SCL, 1, 3)>;
			low-power-enable;
		};
	};

	uart0_default: uart0_default {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 31)>;
		};
		group2 {
			psels = <NRF_PSEL(UART_RX, 1, 10)>;
			bias-pull-up;
		};
	};

	uart0_sleep: uart0_sleep {
		group1 {
			psels = <NRF_PSEL(UART_TX, 0, 31)>,
				<NRF_PSEL(UART_RX, 1, 10)>;
			low-power-enable;
		};
	};

	// uart2_default: uart2_default {
	// 	group1 {
	// 		psels = <NRF_PSEL(UART_TX, 1, 14)>;
	// 	};
	// 	group2 {
	// 		psels = <NRF_PSEL(UART_RX, 1, 15)>;
	// 		bias-pull-up;
	// 	};
	// };
	// 
	// uart2_sleep: uart2_sleep {
	// 	group1 {
	// 		psels = <NRF_PSEL(UART_TX, 1, 14 )>,
	// 			<NRF_PSEL(UART_RX, 1, 15)>;
	// 		low-power-enable;
	// 	};
	// };

	spi2_default_alt: spi2_default_alt{
		group1 {
            psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
		<NRF_PSEL(SPIM_MOSI, 1, 0)>,
                <NRF_PSEL(SPIM_MISO, 1, 1)>;
		};
	};

	spi2_sleep_alt: spi2_sleep_alt{
		group1 {
            psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
		<NRF_PSEL(SPIM_MOSI, 1, 0)>,
                <NRF_PSEL(SPIM_MISO, 1, 1)>;
		low-power-enable;
		};
	};

};

/ {
	aliases {
		led1 = &led1;
		led2 = &led2;
		led3 = &led3;
		sw1 = &button1;
		sw2 = &button2;
		bgsection = &bigsection_mux;
		smsection = &smallsection_mux;
		sdcardplug = &sdcard_plug;
		sheetdetectpin = &sheet_detect_pin;
	};

	chosen {
		zephyr,console = &uart0;
		// zephyr,console = &cdc_acm_uart0;
		// zephyr,code-partition = &slot0_partition;
		// zephyr,flash = &flash0;
		// zephyr,uart-mcumgr = &uart2;
		// mcuboot-button0 = &button1;
		// mcuboot-led0 = &led1;
	};

	leds {
		compatible = "gpio-leds";

		led1: led_1 {
			gpios = <&gpio1 13 GPIO_ACTIVE_LOW>;
			label = "Green_LED_1";
		};
		led2: led_2 {
			gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
			label = "Green_LED_2";
		};
		led3: led_3 {
			gpios = <&gpio1 11 GPIO_ACTIVE_LOW>;
			label = "Green_LED_3";
		};
	};

	buttons {
		compatible = "gpio-keys";
		
		button1: button_1 {
			gpios = <&gpio0 4 (GPIO_ACTIVE_LOW)>;
			label = "Push_button_1";
		};

		button2: button_2 {
			gpios = <&gpio0 5 (GPIO_ACTIVE_HIGH)>;
			label = "Push_button_2";
		};
	};

	sheetsections {
		compatible = "gpio-keys";
		bigsection_mux: bigsection_mux {
			gpios = <&gpio0 22 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
					<&gpio0 17 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
					<&gpio0 16 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
		};

		smallsection_mux: smallsection_mux {
			gpios = <&gpio1 15 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
					<&gpio1 5 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>,
					<&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
		};
	};

	sdcardplug {
		compatible = "gpio-keys";
		sdcard_plug: sdcard_plug {
			gpios = < &gpio0 7 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
		};
	};

	sheetdetectpin {
		compatible = "gpio-keys";
		sheet_detect_pin: sheet_detect_pin
		{
			gpios = <&gpio0 22 GPIO_ACTIVE_LOW>;
			label = "SHEET DETECT PIN";
		};
	};

};	

&i2c1 {
    status = "disabled";
};

&qspi {
	status = "okay";
};

&arduino_serial {
	status = "disabled";
};

&adc {
    status = "okay";
    compatible = "nordic,nrf-saadc";
};

&gpiote {
    status = "okay";
};


&mx25r64{
	status = "disabled";
};

// &uart1 {
// 	status = "disabled";
// };


// /delete-node/ &boot_partition;
// /delete-node/ &slot0_partition;
// /delete-node/ &slot0_ns_partition;
// /delete-node/ &slot1_partition;
// /delete-node/ &slot1_ns_partition;
// /delete-node/ &storage_partition;
//
//
// &flash0 {
// 	status = "okay";
// 	partitions {
// 		compatible = "fixed-partitions";
// 		#address-cells = <1>;
// 		#size-cells = <1>;
//
// 		boot_partition: partition@0 {
// 			label = "mcuboot";
// 			reg = <0x00000000 0x00010000>; // 64KB
// 		};
// 		slot0_partition: partition@10000 {
// 			label = "image-0";
// 			reg = <0x00010000 0x70000>;  // 448KB
// 		};
// 		slot1_partition: partition@80000 {
// 			label = "image-1";
// 			reg = <0x00080000 0x70000>;  // 448KB
// 		};
// 		/* 0xf0000 to 0xf7fff reserved for TF-M partitions */
// 		storage_partition: partition@f8000 {
// 			label = "storage";
// 			reg = <0x000f8000 0x00008000>; // 32KB
// 		};
// 	};
// };


/*  for disabling the SDCard pins forwarding to the network core! */
&gpio_fwd {
	status = "disabled";
};



prj.conf

CONFIG_DISK_ACCESS=y
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_BUFFER_SIZE=10240
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_PRINTK=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES=y

CONFIG_POSIX_API=y
CONFIG_POSIX_FS=y


CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_SPI=y
CONFIG_SDMMC_STACK=y
CONFIG_SD_LOG_LEVEL_DEFAULT=y
CONFIG_SDMMC_SUBSYS=y



build cmd
west build -d ./build -p -b nrf5340dk/nrf5340/cpuapp/ns --no-sysbuild  -- -DNCS_TOOLCHAIN_VERSION=2.7.0

Related