Adding SPI to a project

I am running VSCode with the latest nRF extension. I am on v2.9.1 of the SDK

I created a new app and copied the bluetooth_st_ble_sensor sample project.

I would like to add SPI to this project.

I don't know how.

I tried using KConfig GUI, but it doesn't come up. I have another ticket here for that one.

Parents
  • I am working on this right now, so since there isn't a tutorial I will need some direct help.

    This is the directory structure in the old tutorial:

    I have my app in a new west workspace using 2.9.1. What is the directory structure in the new system?

    It then says to add a new zephyr,customer-bme280.yaml file with some information in it. Do I need the same file in the new system and where does it go?

    It then says to create a new folder in drivers/sensor called custom_bme280 and put the 3 files in it. Do I do that same thing and if so where do I create it and does it contain the exact same files with the exact same things as in the old tutorial?

    I could go on, but basically can someone go through the old tutorial and reply to this ticket with answers to if things stay the same or if they have changed and what those changes are.

    I am glad the new tutorial will be done in the next few weeks, but I am working on this today and am stuck until I have answers.

    If there is another resource that I could use to get these answers, just point the way...

  • Typically it looks like something like this:

    The biggest difference is that there are no child_image folder any more where you keep configurations for child images (such as MCUboot for instance). This is now located inside of the sysbuild folder instead, where you can either have an overlaying or overwriting approach of configuring companion components (the replacement terminology for child_images). https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-8-sysbuild/topic/sysbuild-explained/ goes through this and explains it very well (in my opinion atleast). 

    In addition you can have your board folder with <yourboard>.conf and <yourboard>.overlay, as previous and your drivers, dts and includes should be the same as far as I can see.

    Let me know if the sysbuild lesson allows you to get some further insight and confidence towards the implementation and if you have any follow ups I will revisit the topic and this case early next week

    Kind regards,
    Andreas

  • I created this application using the "copy a sample" option in VSCode. It doesn't have a sysbuild.conf or sysbuild folder. The sample I copied was the Bluetooth Peripheral sample.

    Is that an issue?

    Can I add a custom driver to an application copied from that sample. If so, what are the details of doing that?

    I will do that tutorial on sysbuild as an additional thing so I understand sysbuild better as well.

  • On a related note I have some things building now and ran into an error that may or may not be related to the folder structure or how the project is set up.

    I am getting errors that it can't find my node that I defined in my overlay:

    That image also shows the spi config with the node.

    Here is my ti,cc1101.yaml file:

    # Copyright (c) 2018, Linaro Limited
    # SPDX-License-Identifier: Apache-2.0

    description: Texas Instruments CC1101 wireless transceiver

    compatible: "ti,cc1101"

    include: spi-device.yaml

    properties:
    int_gpios:
    type: phandle-array
    required: true
    description: |
    GPIOs connected to the GDO0 and GDO2 pins of the transceiver.
    cs-gpios:
    type: phandle-array
    description: |
    GPIO connected nCS
    frequency:
    type: int
    description: |
    The carrier frequency, in kHz.
    bitrate:
    type: int
    description: |
    The bitrate in bit per second.
    How do I fix this issue?
  • Tony said:

    I created this application using the "copy a sample" option in VSCode. It doesn't have a sysbuild.conf or sysbuild folder. The sample I copied was the Bluetooth Peripheral sample.

    Is that an issue?

    No, that is not an issue and is the approach we recommend when starting from a sample.

    Most samples does not have a sysbuild folder, since they don't use any companion components. As an example, an exception is the multicore SoCs such as the nRF5340 In those cases the build system detects that if it is an nRF5340 and that it uses BLE, it should automatically add the HCI_IPC companion component so that it has BLE. If you were to make a BLE application for the nRF5340, you would have to do this manually by yourself, i.e add a sysbuild.conf and a sysbuild folder where you add any configurations specific for the hci_ipc image that will run on the netcore.

    But that is just a digression. For your case with the nRF54L15 this will not be relevant for the BLE image since it does not have a network core such as the nRF5340 has. It will however be relevant if you intend to add DFU and MCUboot support. In that case you will have to create a sysbuild.conf and sysbuild folder for the relevant configurations.

    Here's another example of a project that works in sysbuild without any sysbuild related configurations and a custom device binding: https://github.com/NordicDeveloperAcademy/ncs-inter/tree/main/v2.9.0-v2.7.0/l4/l4_e2_sol. It is from lesson 4 in the intermediate course. 

    Tony said:
    I am getting errors that it can't find my node that I defined in my overlay:

    Does this device exist in the device bindings? It has to either be placed within the project as illustrated in the L4E2 solution git link or the device has to be placed in a folder that your project knows about

    Kind regards,
    Andreas

Reply
  • Tony said:

    I created this application using the "copy a sample" option in VSCode. It doesn't have a sysbuild.conf or sysbuild folder. The sample I copied was the Bluetooth Peripheral sample.

    Is that an issue?

    No, that is not an issue and is the approach we recommend when starting from a sample.

    Most samples does not have a sysbuild folder, since they don't use any companion components. As an example, an exception is the multicore SoCs such as the nRF5340 In those cases the build system detects that if it is an nRF5340 and that it uses BLE, it should automatically add the HCI_IPC companion component so that it has BLE. If you were to make a BLE application for the nRF5340, you would have to do this manually by yourself, i.e add a sysbuild.conf and a sysbuild folder where you add any configurations specific for the hci_ipc image that will run on the netcore.

    But that is just a digression. For your case with the nRF54L15 this will not be relevant for the BLE image since it does not have a network core such as the nRF5340 has. It will however be relevant if you intend to add DFU and MCUboot support. In that case you will have to create a sysbuild.conf and sysbuild folder for the relevant configurations.

    Here's another example of a project that works in sysbuild without any sysbuild related configurations and a custom device binding: https://github.com/NordicDeveloperAcademy/ncs-inter/tree/main/v2.9.0-v2.7.0/l4/l4_e2_sol. It is from lesson 4 in the intermediate course. 

    Tony said:
    I am getting errors that it can't find my node that I defined in my overlay:

    Does this device exist in the device bindings? It has to either be placed within the project as illustrated in the L4E2 solution git link or the device has to be placed in a folder that your project knows about

    Kind regards,
    Andreas

Children
  • I do have the bindings file in a dts/bindings folder called ti,cc1101.yaml. Here are the contents:

    ```
    # Copyright (c) 2018, Linaro Limited
    # SPDX-License-Identifier: Apache-2.0

    description: Texas Instruments CC1101 wireless transceiver

    compatible: "ti-cc1101"

    include: spi-device.yaml

    properties:
    int_gpios:
    type: phandle-array
    required: true
    description: |
    GPIOs connected to the GDO0 and GDO2 pins of the transceiver.
    cs-gpios:
    type: phandle-array
    description: |
    GPIO connected nCS
    frequency:
    type: int
    description: |
    The carrier frequency, in kHz.
    bitrate:
    type: int
    description: |
    The bitrate in bit per second.
    ```
    I tried the compatible line with ti,cc1101 and that didn't change anything. I made it a dash (-) because that is how it is in L4E2.
    Here is the relevant section in the overlay file:
    ```
    &spi21 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    pinctrl-0 = <&spi21_default>;
    pinctrl-1 = <&spi21_sleep>;
    pinctrl-names = "default", "sleep";
    cs-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
    cc1101: cc1101@0 {
    reg = <0>;
    compatible = "ti,cc1101";
    spi-max-frequency = <2500000>;
    int_gpios = <&gpio1 7 (GPIO_ACTIVE_LOW)>, <&gpio0 34 (GPIO_ACTIVE_LOW)>;
    frequency = <868300>;
    bitrate = <38368>;
    status = "okay";
    };
    };
    ```
    Here is the error I am getting:
    ```
    .../build/BLETPMSBridge/zephyr/include/generated/zephyr/devicetree_generated.h:14776:31: error: 'DT_N_S_soc_S_peripheral_50000000_S_spi_c7000_S_cc1101_0_P_bitrate' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_50000000_S_spi_c7000_S_cc1101_0_P_status'?
    14776 | #define DT_N_INST_0_ti_cc1101 DT_N_S_soc_S_peripheral_50000000_S_spi_c7000_S_cc1101_0
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ```
  • This is the line I am getting the error on:

    #define SPIOP SPI_WORD_SET(8) | SPI_TRANSFER_MSB
    struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(cc1101), SPIOP, 0);

Related