This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI Controller initialization error in Zephyr

Description:

I try to initialize a SPI device in my nRF52DK through the Zephyr‘s driver(drivers/spi.h).

Code seems correct when compile and I got no error when build the whole project.

But when turn to debug, SPI can not initialize as expection.I have tried several initializations in my project.

Situation 1: spi1 compatible = "nordic,nrf-spi"; - when debug, the code will stuck at Exception Stack Frame (ESF)

Situation 2: spi1 compatible = "nordic,nrf-spim"; - when debug, the initialization seem to be fail.

Development environments:

1.OS : Ubuntu 20.04

2.NCS in VsCode (sdk:1.7.1)

3.HW:nRF52DK

Attachments(key code):

main.c:

dts file:

Parents
  • Could you test the sample <ncs location>/zephyr/tests/drivers/spi/spi_loopback/ with the board nrf52dk_nrf52832. It will apply the configs from nrf52dk_nrf52832.conf and prj.conf. It is a loopback sample and you need to connect MISO to MOSI, and since SPI_1 is used, which uses the pins 29 and 30 as MISO and MOSI by default, you need to connect these together.

    You should get this output if everything works correctly:

    *** Booting Zephyr OS build v2.6.99-ncs1-1  ***
    Running test suite test_spi
    ===================================================================
    START - test_spi_loopback
    I: SPI test on buffers TX/RX 0x200001ad/0x2000095a
    I: SPI test slow config
    I: Start complete multiple
    I: Passed
    I: Start complete loop
    I: Passed
    I: Start null tx
    I: Passed
    I: Start half start
    I: Passed
    I: Start half end
    I: Passed
    I: Start every 4
    I: Passed
    I: Start async call
    I: Passed
    I: SPI test fast config
    I: Start complete multiple
    I: Passed
    I: Start complete loop
    I: Passed
    I: Start null tx
    I: Passed
    I: Start half start
    I: Passed
    I: Start half end
    I: Passed
    I: Start every 4
    I: Passed
    I: Start async call
    I: Passed
    I: Start complete loop
    I: Passed
    I: Start complete loop
    I: Passed
    I: All tx/rx passed
     PASS - test_spi_loopback in 0.60 seconds
    ===================================================================
    Test suite test_spi succeeded
    ===================================================================
    PROJECT EXECUTION SUCCESSFUL
    

    When you get this to work, you can inspect the code to get an understanding of how to use the SPI in NCS/zephyr and remove everything related to testing.

    I see that the compatible "nordic,nrf-spi" is used by default for the spi1. If you want to use SPI with EasyDMA (and the compatible "nordic,nrf-spim") you need to enable CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, see the following note:

    https://github.com/nrfconnect/sdk-zephyr/blob/83f7974bc454e7ff719bd0f32c2ce45317b5c7e7/drivers/spi/Kconfig.nrfx#L39-L41

    Best regards,

    Simon

Reply
  • Could you test the sample <ncs location>/zephyr/tests/drivers/spi/spi_loopback/ with the board nrf52dk_nrf52832. It will apply the configs from nrf52dk_nrf52832.conf and prj.conf. It is a loopback sample and you need to connect MISO to MOSI, and since SPI_1 is used, which uses the pins 29 and 30 as MISO and MOSI by default, you need to connect these together.

    You should get this output if everything works correctly:

    *** Booting Zephyr OS build v2.6.99-ncs1-1  ***
    Running test suite test_spi
    ===================================================================
    START - test_spi_loopback
    I: SPI test on buffers TX/RX 0x200001ad/0x2000095a
    I: SPI test slow config
    I: Start complete multiple
    I: Passed
    I: Start complete loop
    I: Passed
    I: Start null tx
    I: Passed
    I: Start half start
    I: Passed
    I: Start half end
    I: Passed
    I: Start every 4
    I: Passed
    I: Start async call
    I: Passed
    I: SPI test fast config
    I: Start complete multiple
    I: Passed
    I: Start complete loop
    I: Passed
    I: Start null tx
    I: Passed
    I: Start half start
    I: Passed
    I: Start half end
    I: Passed
    I: Start every 4
    I: Passed
    I: Start async call
    I: Passed
    I: Start complete loop
    I: Passed
    I: Start complete loop
    I: Passed
    I: All tx/rx passed
     PASS - test_spi_loopback in 0.60 seconds
    ===================================================================
    Test suite test_spi succeeded
    ===================================================================
    PROJECT EXECUTION SUCCESSFUL
    

    When you get this to work, you can inspect the code to get an understanding of how to use the SPI in NCS/zephyr and remove everything related to testing.

    I see that the compatible "nordic,nrf-spi" is used by default for the spi1. If you want to use SPI with EasyDMA (and the compatible "nordic,nrf-spim") you need to enable CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, see the following note:

    https://github.com/nrfconnect/sdk-zephyr/blob/83f7974bc454e7ff719bd0f32c2ce45317b5c7e7/drivers/spi/Kconfig.nrfx#L39-L41

    Best regards,

    Simon

Children
No Data
Related