SPI initialization fails during spim_frequency_valid_check()

Hi,

currently I am struggeling to get my SD card connected to the 54H20 DK. Each time I try to mount the SD Card I get the following error:

*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
uart:~$ fs mount fat /SD:
[00:00:03.267,145] <err> spi_nrfx_spim: Failed to initialize nrfx driver: 0bad0004
[00:00:03.267,157] <err> os: ***** BUS FAULT *****
[00:00:03.267,161] <err> os: Precise data bus error
[00:00:03.267,164] <err> os: BFAR Address: 0x4
[00:00:03.267,177] <err> os: r0/a1: 0x2f0115e8 r1/a2: 0xfffffffb r2/a3: 0x2f012580
[00:00:03.267,183] <err> os: r3/a4: 0x00000000 r12/ip: 0x00000020 r14/lr: 0x0e0b1019
[00:00:03.267,186] <err> os: xpsr: 0x01000000
[00:00:03.267,189] <err> os: Faulting instruction address (r15/pc): 0x0e0bc930
[00:00:03.267,207] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0
[00:00:03.267,221] <err> os: Current thread: 0x2f012030 (shell_uart)
[00:00:03.345,234] <err> os: Halting system

The Error is raised after the call spim_frequency_valid_check() in nrfx_spim.c.

I tried different clock settings but no success so far. Here is the content of my overlay file:

&gpio7 {
    status = "okay";
 };
 
&pinctrl {
    spi120_default_alt: spi120_default_alt {
       group1 {
          psels = <NRF_PSEL(SPIM_SCK, 7, 3)>,
                  <NRF_PSEL(SPIM_MISO, 7, 6)>,
                  <NRF_PSEL(SPIM_MOSI, 7, 7)>;
       };
    };
 
    spi120_sleep_alt: spi120_sleep_alt {
       group1 {
          psels = <NRF_PSEL(SPIM_SCK, 7, 3)>,
                  <NRF_PSEL(SPIM_MISO, 7, 6)>,
                  <NRF_PSEL(SPIM_MOSI, 7, 7)>;
          low-power-enable;
       };
    };
 };

&spi120 {
    compatible = "nordic,nrf-spim";
    status = "okay";
   
    pinctrl-0 = <&spi120_default_alt>;
    pinctrl-1 = <&spi120_sleep_alt>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio7 0 GPIO_ACTIVE_LOW>;  

    /* SD Card interface settings */
    sdhc0: sdhc@0 {
        compatible = "zephyr,sdhc-spi-slot";
        reg = <0>;
        status = "okay";
        spi-max-frequency = <DT_FREQ_K(250)>;

        mmc {
            compatible = "zephyr,sdmmc-disk";
            status = "okay";
        };
    };
};

and proj.conf:

CONFIG_GPIO=y
CONFIG_SPI=y

CONFIG_LOG=y
CONFIG_SHELL_LOG_LEVEL_INF=y

CONFIG_DEBUG_OPTIMIZATIONS=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=16384
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_MAIN_STACK_SIZE=32000
CONFIG_IDLE_STACK_SIZE=8192

CONFIG_SHELL=y
CONFIG_SHELL_STACK_SIZE=16000
CONFIG_FILE_SYSTEM_SHELL=y

# SD Card
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_DISK_ACCESS=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FS_FATFS_LFN=y

Any ideas what I am doing wrong?

Thanks

Parents
  • Hi,

    The spi120 is a high speed SPI which can't go lower than 2MHz. I suspect the issue is caused by this.

    Could you try to connect with any other SPI that's not a high speed SPI?

    Kind regards,
    Andreas

  • Thank you for the hint, this was not clear to me. So I switched over to spi130 on port 0 with the following overlay:

    &gpio0 {
    	status = "okay";
     };
     
    &pinctrl {
    	spi130_default_alt: spi130_default_alt {
    	   group1 {
    		  psels = <NRF_PSEL(SPIM_SCK, 0, 3)>,
    				  <NRF_PSEL(SPIM_MISO, 0, 7)>,
    				  <NRF_PSEL(SPIM_MOSI, 0, 5)>;
    	   };
    	};
     
    	spi130_sleep_alt: spi130_sleep_alt {
    	   group1 {
    		  psels = <NRF_PSEL(SPIM_SCK, 0, 3)>,
    				  <NRF_PSEL(SPIM_MISO, 0, 7)>,
    				  <NRF_PSEL(SPIM_MOSI, 0, 5)>;
    		  low-power-enable;
    	   };
    	};
     };
    
    &spi130 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	
    	pinctrl-0 = <&spi130_default_alt>;
    	pinctrl-1 = <&spi130_sleep_alt>;
    	pinctrl-names = "default", "sleep";	
    	cs-gpios = <&gpio0 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;  
    
    	/* SD Card interface settings */
    	sdhc0: sdhc@0 {
    		compatible = "zephyr,sdhc-spi-slot";
    		reg = <0>;
    		status = "okay";
    		spi-max-frequency = <DT_FREQ_K(400)>;
    
    		mmc {
    			compatible = "zephyr,sdmmc-disk";
    			status = "okay";
    		}; 
    	};
    };

    Now the application does not crash anymore and the spi initialization seems to succeed.

    Unfortunately the SD card is not yet mounted and if I watch the SPI pins, I can not see the CLK line toggeling during the low phase of the CS line.

    Debugging the code it seems that the DMA RAM check fails for the receive buffer in nrfx-spim.c, spim_xfer(), line 777 (NRFX_ERROR_INVALID_ADDR) and raises an error during spi transceive.

  • After further investigation I guess that the definition of the DMA RAM region is missing or needs to be defined additionaly by the user for the SPIMs. In my case the application core accesses the spi130:

    memory-regions = <&cpuapp_dma_region>;

    The resulting overlay looks like follows:

    &gpio0 {
    	status = "okay";
     };
     
    &pinctrl {
    	spi130_default_alt: spi130_default_alt {
    	   group1 {
    		  psels = <NRF_PSEL(SPIM_SCK, 0, 3)>,
    				  <NRF_PSEL(SPIM_MISO, 0, 7)>,
    				  <NRF_PSEL(SPIM_MOSI, 0, 5)>;
    	   };
    	};
     
    	spi130_sleep_alt: spi130_sleep_alt {
    	   group1 {
    		  psels = <NRF_PSEL(SPIM_SCK, 0, 3)>,
    				  <NRF_PSEL(SPIM_MISO, 0, 7)>,
    				  <NRF_PSEL(SPIM_MOSI, 0, 5)>;
    		  low-power-enable;
    	   };
    	};
     };
    
    &spi130 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	max-frequency = <DT_FREQ_K(400)>;
    
    	pinctrl-0 = <&spi130_default_alt>;
    	pinctrl-1 = <&spi130_sleep_alt>;
    	pinctrl-names = "default", "sleep";	
    
    	memory-regions = <&cpuapp_dma_region>;
    	
    	cs-gpios = <&gpio0 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;  
    
    	/* SD Card interface settings */
    	sdhc0: sdhc@0 {
    		compatible = "zephyr,sdhc-spi-slot";
    		reg = <0>;
    		status = "okay";
    		spi-max-frequency = <DT_FREQ_K(400)>;
    
    		mmc {
    			compatible = "zephyr,sdmmc-disk";
    			status = "okay";
    		}; 
    	};
    };

    Now the SD-Card is working as expected.

    Thanks.

  • Hi,

    Glad to hear that you were able to resolve it.

    I'll mark the case as resolved, but please feel free to reopen it or raise new cases if you have new questions

    Kind regards,
    Andreas

Reply Children
No Data
Related