IMU Integration

Does anyone know of a good starting point for Bosch BHI360 IMU integration into nrf5340 and Zephyr?

Did look at: https://community.bosch-sensortec.com/mems-sensors-forum-jrmujtaw/post/help-with-zephyr-driver-for-bhi360-yxMxLcyQdu19gfD over at Bosch but the actual steps to integrate into 5340 is light.

Is there a reference on how to integrate a Bosch IMU on a reasonably high level, (sensor lib) with low level SPI drivers?

Any hints are appreciated!

Parents
  • Hi,

    There are three alternatives here:

    1. I see that zephyr has drivers and a sample for the Bosch IMU BMI270. While this is not the exact sensor you got, sometimes the interface is similar enough so that you can just use the same driver. Worth a try.

    2. If you want to implement an out-of-tree driver for a new sensor, see DevAcademy Intermediate: Lesson 7 – Device driver model. Adding drivers for a new sensor in Zephyr will require work no matter how you look at it.

    3. Do not use the sensor with a driver, but just make your application use it directly using the SPI. But this is kinda crude and not what you ask for, so no links for that here.

    Regards,
    Sigurd Hellesvik

  • <rant>

    As many others have pointed out the nrf SDK with Zephyr is overly complex and very convoluted.
    The example apps are just a random collection of Zephyr generic examples that likely will not work on any nrf board.
    Most forum posts and github example repos are not for any nrf board, or the SDK info is outdated and they do not work at all with the latest. Many examples are up to 10 years old and are irrelevant.

    This is a last-ditch effort to get this off the ground, we have 4 developers trying, all experiencing the same issues, most around setting up the DTS and accessing peripherals. This would have been so easy for say an NXP platform...

    <end rant>

    This question is specific to nRF5340dk, any custom board is a later problem. SDK is 2.9.0 with the corresponding toolchain.

    The only sample applications that we have brought up successfully are hello world and blinky pwm, and we could add basic gpio for wiggle status LEDs. Beyond this, nothing really works.

    Question: the nRF5340dk board dts file contains all the available and accessible peripherals, right? This appears to be the case.

    Starting from blinky pwm, what is needed to add I2C and SPI support? Basic access only for now. It seems like most example code and even copilot etc use old SDK code, that does not compile on the latest (like DT manipulations)

    I2C: 

    // I2C device configuration
    static const struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c1));
    
    void i2c_sensor_thread(void) {
        if (!device_is_ready(i2c_dev)) {
            LOG_ERR("I2C device not found");
            return;
        }
    
        uint8_t i2c_addr = 0x48;  // Replace with your I2C device address
        uint8_t reg_addr = 0x00;  // Replace with the register address you want to read
        uint8_t data;
    
        while (1) {
            int ret = i2c_reg_read_byte(i2c_dev, i2c_addr, reg_addr, &data);
            if (ret == 0) {
                LOG_INF("Read data: 0x%02x", data);
            } else {
                LOG_ERR("Failed to read data from I2C device");
            }
            k_sleep(K_SECONDS(2));  // Read every 2 seconds
        }
    }

    What else is needed for this basic example?

  • This is the full test app:

    /**
     * @file Multi-threaded PWM, GPIO, and SPI4 sensor example for nRF5340 DK.
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/sys/printk.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/drivers/pwm.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/i2c.h>
    //#include <zephyr/drivers/spi.h>
    
    LOG_MODULE_REGISTER(blinky_pwm, LOG_LEVEL_INF);  
    
    // PWM LED0 configuration
    static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
    #define MIN_PERIOD PWM_SEC(1U) / 128U
    #define MAX_PERIOD PWM_SEC(1U)
    
    // GPIO LED3 configuration
    static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(DT_ALIAS(led3), gpios);
    
    // GPIO LED2 configuration (blinks on SPI activity)
    //static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios);
    
    #define I2C_DEV DEVICE_DT_GET(DT_NODELABEL(i2c1))  // Use I2C0
    #define SLAVE_ADDR_1 0x08  // Example address of first I2C device
    #define SLAVE_ADDR_2 0x09  // Example address of second I2C device
    
    void i2c_sensor_thread(void)
    {
         const struct device *i2c_dev = I2C_DEV;
        if (!device_is_ready(i2c_dev)) {
            printk("Error: I2C device not found\n");
            return;
        }
    
        printk("I2C Example on nRF5340DK\n");
    
        uint8_t tx_data[] = {0x01, 0x02, 0x03, 0x04};
        uint8_t rx_data[4] = {0};
    
        // Write to first I2C slave
        if (i2c_write(i2c_dev, tx_data, sizeof(tx_data), SLAVE_ADDR_1) == 0) {
            printk("Written to slave 1 (0x%02X)\n", SLAVE_ADDR_1);
        } else {
            printk("Failed to write to slave 1\n");
        }
    
        k_sleep(K_MSEC(100));
    
        // Read from first I2C slave
        if (i2c_read(i2c_dev, rx_data, sizeof(rx_data), SLAVE_ADDR_1) == 0) {
            printk("Read from slave 1: ");
            for (int i = 0; i < sizeof(rx_data); i++) {
                printk("0x%02X ", rx_data[i]);
            }
            printk("\n");
        } else {
            printk("Failed to read from slave 1\n");
        }
    
        k_sleep(K_MSEC(100));
    
        // Write to second I2C slave
        if (i2c_write(i2c_dev, tx_data, sizeof(tx_data), SLAVE_ADDR_2) == 0) {
            printk("Written to slave 2 (0x%02X)\n", SLAVE_ADDR_2);
        } else {
            printk("Failed to write to slave 2\n");
        }
    
        k_sleep(K_MSEC(100));
    
        // Read from second I2C slave
        if (i2c_read(i2c_dev, rx_data, sizeof(rx_data), SLAVE_ADDR_2) == 0) {
            printk("Read from slave 2: ");
            for (int i = 0; i < sizeof(rx_data); i++) {
                printk("0x%02X ", rx_data[i]);
            }
            printk("\n");
        } else {
            printk("Failed to read from slave 2\n");
        }
    }
    
    void pwm_blinky_thread(void *arg1, void *arg2, void *arg3) {
        uint32_t max_period;
        uint32_t period;
        uint8_t dir = 0U;
        int ret;
    
        LOG_INF("PWM-based blinky thread started");
    
        if (!pwm_is_ready_dt(&pwm_led0)) {
            LOG_ERR("Error: PWM device %s is not ready", pwm_led0.dev->name);
            return;
        }
    
        max_period = MAX_PERIOD;
        while (pwm_set_dt(&pwm_led0, max_period, max_period / 2U)) {
            max_period /= 2U;
            if (max_period < (4U * MIN_PERIOD)) {
                LOG_ERR("Error: PWM device does not support a period at least %lu", 4U * MIN_PERIOD);
                return;
            }
        }
    
        period = max_period;
        while (1) {
            ret = pwm_set_dt(&pwm_led0, period, period / 2U);
            if (ret) {
                LOG_ERR("Error %d: failed to set pulse width", ret);
                return;
            }
    
            LOG_INF("PWM period set to %d", period);
            printk("PWM period updated to %d\n", period);
    
            period = dir ? (period * 2U) : (period / 2U);
            if (period > max_period) {
                period = max_period / 2U;
                dir = 0U;
            } else if (period < MIN_PERIOD) {
                period = MIN_PERIOD * 2U;
                dir = 1U;
            }
    
            k_sleep(K_SECONDS(4U));
        }
    }
    
    void gpio_blinky_thread(void *arg1, void *arg2, void *arg3) {
        if (!device_is_ready(led3.port)) {
            LOG_ERR("LED3 device not ready");
            return;
        }
    
        gpio_pin_configure_dt(&led3, GPIO_OUTPUT);
    
        LOG_INF("GPIO LED3 blinky thread started");
    
        while (1) {
            gpio_pin_toggle_dt(&led3);
            printk("LED3 toggled!\n");
            LOG_INF("LED3 state changed");
            k_sleep(K_SECONDS(2));  // Blink every 2 seconds
        }
    }
    
    
    
    // Define the PWM, GPIO, and SPI threads (stack size: 1024 bytes, priority: 5)
    K_THREAD_DEFINE(pwm_blinky_tid, 1024, pwm_blinky_thread, NULL, NULL, NULL, 5, 0, 0);
    K_THREAD_DEFINE(gpio_blinky_tid, 1024, gpio_blinky_thread, NULL, NULL, NULL, 5, 0, 0);
    //K_THREAD_DEFINE(spi_sensor_tid, 1024, spi_sensor_thread, NULL, NULL, NULL, 5, 0, 0);
    K_THREAD_DEFINE(i2c_sensor_tid, 1024, i2c_sensor_thread, NULL, NULL, NULL, 5, 0, 0);
    
    void main(void) {
        printk("Starting nRF5340 Multi-Threaded PWM + GPIO + SPI4 Sensor Example!\n");
        LOG_INF("System initialized. Blinky & SPI threads running.");
    }
    

    the full .config file

    SB_CONFIG_BOARD="nrf5340dk"
    SB_CONFIG_BOARD_REVISION=""
    SB_CONFIG_BOARD_NRF5340DK=y
    SB_CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP_NS=y
    SB_CONFIG_BOARD_QUALIFIERS="nrf5340/cpuapp/ns"
    SB_CONFIG_SOC="nrf5340"
    SB_CONFIG_SOC_SERIES="nrf53"
    SB_CONFIG_SOC_FAMILY="nordic_nrf"
    SB_CONFIG_SOC_FAMILY_NORDIC_NRF=y
    SB_CONFIG_SOC_SERIES_NRF53X=y
    SB_CONFIG_SOC_NRF5340_CPUAPP=y
    SB_CONFIG_SOC_NRF5340_CPUAPP_QKAA=y
    
    #
    # Sysbuild image configuration
    #
    
    #
    # Modules
    #
    
    #
    # Available modules.
    #
    
    #
    # nrf (/home/stefan/ncs/v2.9.0/nrf)
    #
    SB_CONFIG_PARTITION_MANAGER=y
    # SB_CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK is not set
    SB_CONFIG_BUILD_OUTPUT_BIN=y
    SB_CONFIG_BUILD_OUTPUT_HEX=y
    SB_CONFIG_BOARD_IS_NON_SECURE=y
    SB_CONFIG_APPCORE_REMOTE_BOARD_TARGET_CPUCLUSTER="cpuapp"
    SB_CONFIG_APPCORE_REMOTE_DOMAIN="CPUAPP"
    SB_CONFIG_SUPPORT_NETCORE=y
    SB_CONFIG_NETCORE_REMOTE_BOARD_TARGET_CPUCLUSTER="cpunet"
    SB_CONFIG_NETCORE_REMOTE_DOMAIN="CPUNET"
    
    #
    # Network core configuration
    #
    SB_CONFIG_SUPPORT_NETCORE_EMPTY=y
    SB_CONFIG_SUPPORT_NETCORE_HCI_IPC=y
    SB_CONFIG_SUPPORT_NETCORE_RPC_HOST=y
    SB_CONFIG_SUPPORT_NETCORE_802154_RPMSG=y
    SB_CONFIG_SUPPORT_NETCORE_MULTIPROTOCOL_RPMSG=y
    SB_CONFIG_SUPPORT_NETCORE_IPC_RADIO=y
    SB_CONFIG_NETCORE_NONE=y
    # SB_CONFIG_NETCORE_EMPTY is not set
    # SB_CONFIG_NETCORE_HCI_IPC is not set
    # SB_CONFIG_NETCORE_RPC_HOST is not set
    # SB_CONFIG_NETCORE_802154_RPMSG is not set
    # SB_CONFIG_NETCORE_MULTIPROTOCOL_RPMSG is not set
    # SB_CONFIG_NETCORE_IPC_RADIO is not set
    # end of Network core configuration
    
    #
    # Secure Bootloader
    #
    # SB_CONFIG_SECURE_BOOT_APPCORE is not set
    # SB_CONFIG_SECURE_BOOT_NETCORE is not set
    # end of Secure Bootloader
    
    SB_CONFIG_SUPPORT_QSPI_XIP=y
    # SB_CONFIG_BT_FAST_PAIR is not set
    # SB_CONFIG_MATTER is not set
    
    #
    # Wi-Fi
    #
    # SB_CONFIG_WIFI_NRF70 is not set
    # end of Wi-Fi
    
    #
    # SUIT
    #
    # SB_CONFIG_SUIT_ENVELOPE is not set
    # SB_CONFIG_SUIT_BUILD_RECOVERY is not set
    # SB_CONFIG_SUIT_BUILD_FLASH_COMPANION is not set
    # end of SUIT
    
    #
    # SDP
    #
    # SB_CONFIG_SDP is not set
    # end of SDP
    
    # SB_CONFIG_APPROTECT_USE_UICR is not set
    # SB_CONFIG_APPROTECT_LOCK is not set
    # SB_CONFIG_APPROTECT_USER_HANDLING is not set
    SB_CONFIG_APPROTECT_NO_SYSBUILD=y
    # SB_CONFIG_SECURE_APPROTECT_USE_UICR is not set
    # SB_CONFIG_SECURE_APPROTECT_LOCK is not set
    # SB_CONFIG_SECURE_APPROTECT_USER_HANDLING is not set
    SB_CONFIG_SECURE_APPROTECT_NO_SYSBUILD=y
    SB_CONFIG_ZEPHYR_NRF_MODULE=y
    # end of nrf (/home/stefan/ncs/v2.9.0/nrf)
    
    SB_CONFIG_ZEPHYR_MCUBOOT_MODULE=y
    SB_CONFIG_ZEPHYR_MBEDTLS_MODULE=y
    SB_CONFIG_ZEPHYR_OBERON_PSA_CRYPTO_MODULE=y
    SB_CONFIG_ZEPHYR_TRUSTED_FIRMWARE_M_MODULE=y
    SB_CONFIG_ZEPHYR_PSA_ARCH_TESTS_MODULE=y
    SB_CONFIG_ZEPHYR_SOC_HWMV1_MODULE=y
    SB_CONFIG_ZEPHYR_CJSON_MODULE=y
    SB_CONFIG_ZEPHYR_AZURE_SDK_FOR_C_MODULE=y
    SB_CONFIG_ZEPHYR_CIRRUS_LOGIC_MODULE=y
    SB_CONFIG_ZEPHYR_OPENTHREAD_MODULE=y
    SB_CONFIG_ZEPHYR_SUIT_GENERATOR_MODULE=y
    SB_CONFIG_ZEPHYR_SUIT_PROCESSOR_MODULE=y
    SB_CONFIG_ZEPHYR_MEMFAULT_FIRMWARE_SDK_MODULE=y
    SB_CONFIG_ZEPHYR_COREMARK_MODULE=y
    SB_CONFIG_ZEPHYR_CANOPENNODE_MODULE=y
    SB_CONFIG_ZEPHYR_CHRE_MODULE=y
    SB_CONFIG_ZEPHYR_LZ4_MODULE=y
    SB_CONFIG_ZEPHYR_NANOPB_MODULE=y
    SB_CONFIG_ZEPHYR_TF_M_TESTS_MODULE=y
    SB_CONFIG_ZEPHYR_ZSCILIB_MODULE=y
    SB_CONFIG_ZEPHYR_CMSIS_MODULE=y
    SB_CONFIG_ZEPHYR_CMSIS_DSP_MODULE=y
    SB_CONFIG_ZEPHYR_CMSIS_NN_MODULE=y
    SB_CONFIG_ZEPHYR_FATFS_MODULE=y
    SB_CONFIG_ZEPHYR_HAL_NORDIC_MODULE=y
    SB_CONFIG_ZEPHYR_HAL_ST_MODULE=y
    SB_CONFIG_ZEPHYR_HAL_WURTHELEKTRONIK_MODULE=y
    SB_CONFIG_ZEPHYR_HOSTAP_MODULE=y
    SB_CONFIG_ZEPHYR_LIBMETAL_MODULE=y
    SB_CONFIG_ZEPHYR_LIBLC3_MODULE=y
    SB_CONFIG_ZEPHYR_LITTLEFS_MODULE=y
    SB_CONFIG_ZEPHYR_LORAMAC_NODE_MODULE=y
    SB_CONFIG_ZEPHYR_LVGL_MODULE=y
    SB_CONFIG_ZEPHYR_MIPI_SYS_T_MODULE=y
    SB_CONFIG_ZEPHYR_NRF_WIFI_MODULE=y
    SB_CONFIG_ZEPHYR_OPEN_AMP_MODULE=y
    SB_CONFIG_ZEPHYR_PICOLIBC_MODULE=y
    SB_CONFIG_ZEPHYR_SEGGER_MODULE=y
    SB_CONFIG_ZEPHYR_TINYCRYPT_MODULE=y
    SB_CONFIG_ZEPHYR_UOSCORE_UEDHOC_MODULE=y
    SB_CONFIG_ZEPHYR_ZCBOR_MODULE=y
    SB_CONFIG_ZEPHYR_NRFXLIB_MODULE=y
    SB_CONFIG_ZEPHYR_NRF_HW_MODELS_MODULE=y
    SB_CONFIG_ZEPHYR_CONNECTEDHOMEIP_MODULE=y
    
    #
    # Unavailable modules, please install those via the project manifest.
    #
    # end of Modules
    
    # SB_CONFIG_WARN_EXPERIMENTAL is not set
    SB_CONFIG_WARN_DEPRECATED=y
    SB_CONFIG_SUPPORT_BOOTLOADER=y
    SB_CONFIG_SUPPORT_BOOTLOADER_MCUBOOT_ZEPHYR=y
    SB_CONFIG_BOOTLOADER_NONE=y
    # SB_CONFIG_BOOTLOADER_MCUBOOT is not set
    
    #
    # Build options
    #
    # SB_CONFIG_COMPILER_WARNINGS_AS_ERRORS is not set
    # end of Build options
    

    current overlay

    &pwm0 {
        status = "disabled";
    };
    
    &sw_pwm {
        status = "okay";
        channel-gpios = <&gpio0 28 PWM_POLARITY_INVERTED>;
    };
    
    &pwm_led0 {
        pwms = <&sw_pwm 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    };
    

Reply
  • This is the full test app:

    /**
     * @file Multi-threaded PWM, GPIO, and SPI4 sensor example for nRF5340 DK.
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/sys/printk.h>
    #include <zephyr/logging/log.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/drivers/pwm.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/i2c.h>
    //#include <zephyr/drivers/spi.h>
    
    LOG_MODULE_REGISTER(blinky_pwm, LOG_LEVEL_INF);  
    
    // PWM LED0 configuration
    static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
    #define MIN_PERIOD PWM_SEC(1U) / 128U
    #define MAX_PERIOD PWM_SEC(1U)
    
    // GPIO LED3 configuration
    static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(DT_ALIAS(led3), gpios);
    
    // GPIO LED2 configuration (blinks on SPI activity)
    //static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios);
    
    #define I2C_DEV DEVICE_DT_GET(DT_NODELABEL(i2c1))  // Use I2C0
    #define SLAVE_ADDR_1 0x08  // Example address of first I2C device
    #define SLAVE_ADDR_2 0x09  // Example address of second I2C device
    
    void i2c_sensor_thread(void)
    {
         const struct device *i2c_dev = I2C_DEV;
        if (!device_is_ready(i2c_dev)) {
            printk("Error: I2C device not found\n");
            return;
        }
    
        printk("I2C Example on nRF5340DK\n");
    
        uint8_t tx_data[] = {0x01, 0x02, 0x03, 0x04};
        uint8_t rx_data[4] = {0};
    
        // Write to first I2C slave
        if (i2c_write(i2c_dev, tx_data, sizeof(tx_data), SLAVE_ADDR_1) == 0) {
            printk("Written to slave 1 (0x%02X)\n", SLAVE_ADDR_1);
        } else {
            printk("Failed to write to slave 1\n");
        }
    
        k_sleep(K_MSEC(100));
    
        // Read from first I2C slave
        if (i2c_read(i2c_dev, rx_data, sizeof(rx_data), SLAVE_ADDR_1) == 0) {
            printk("Read from slave 1: ");
            for (int i = 0; i < sizeof(rx_data); i++) {
                printk("0x%02X ", rx_data[i]);
            }
            printk("\n");
        } else {
            printk("Failed to read from slave 1\n");
        }
    
        k_sleep(K_MSEC(100));
    
        // Write to second I2C slave
        if (i2c_write(i2c_dev, tx_data, sizeof(tx_data), SLAVE_ADDR_2) == 0) {
            printk("Written to slave 2 (0x%02X)\n", SLAVE_ADDR_2);
        } else {
            printk("Failed to write to slave 2\n");
        }
    
        k_sleep(K_MSEC(100));
    
        // Read from second I2C slave
        if (i2c_read(i2c_dev, rx_data, sizeof(rx_data), SLAVE_ADDR_2) == 0) {
            printk("Read from slave 2: ");
            for (int i = 0; i < sizeof(rx_data); i++) {
                printk("0x%02X ", rx_data[i]);
            }
            printk("\n");
        } else {
            printk("Failed to read from slave 2\n");
        }
    }
    
    void pwm_blinky_thread(void *arg1, void *arg2, void *arg3) {
        uint32_t max_period;
        uint32_t period;
        uint8_t dir = 0U;
        int ret;
    
        LOG_INF("PWM-based blinky thread started");
    
        if (!pwm_is_ready_dt(&pwm_led0)) {
            LOG_ERR("Error: PWM device %s is not ready", pwm_led0.dev->name);
            return;
        }
    
        max_period = MAX_PERIOD;
        while (pwm_set_dt(&pwm_led0, max_period, max_period / 2U)) {
            max_period /= 2U;
            if (max_period < (4U * MIN_PERIOD)) {
                LOG_ERR("Error: PWM device does not support a period at least %lu", 4U * MIN_PERIOD);
                return;
            }
        }
    
        period = max_period;
        while (1) {
            ret = pwm_set_dt(&pwm_led0, period, period / 2U);
            if (ret) {
                LOG_ERR("Error %d: failed to set pulse width", ret);
                return;
            }
    
            LOG_INF("PWM period set to %d", period);
            printk("PWM period updated to %d\n", period);
    
            period = dir ? (period * 2U) : (period / 2U);
            if (period > max_period) {
                period = max_period / 2U;
                dir = 0U;
            } else if (period < MIN_PERIOD) {
                period = MIN_PERIOD * 2U;
                dir = 1U;
            }
    
            k_sleep(K_SECONDS(4U));
        }
    }
    
    void gpio_blinky_thread(void *arg1, void *arg2, void *arg3) {
        if (!device_is_ready(led3.port)) {
            LOG_ERR("LED3 device not ready");
            return;
        }
    
        gpio_pin_configure_dt(&led3, GPIO_OUTPUT);
    
        LOG_INF("GPIO LED3 blinky thread started");
    
        while (1) {
            gpio_pin_toggle_dt(&led3);
            printk("LED3 toggled!\n");
            LOG_INF("LED3 state changed");
            k_sleep(K_SECONDS(2));  // Blink every 2 seconds
        }
    }
    
    
    
    // Define the PWM, GPIO, and SPI threads (stack size: 1024 bytes, priority: 5)
    K_THREAD_DEFINE(pwm_blinky_tid, 1024, pwm_blinky_thread, NULL, NULL, NULL, 5, 0, 0);
    K_THREAD_DEFINE(gpio_blinky_tid, 1024, gpio_blinky_thread, NULL, NULL, NULL, 5, 0, 0);
    //K_THREAD_DEFINE(spi_sensor_tid, 1024, spi_sensor_thread, NULL, NULL, NULL, 5, 0, 0);
    K_THREAD_DEFINE(i2c_sensor_tid, 1024, i2c_sensor_thread, NULL, NULL, NULL, 5, 0, 0);
    
    void main(void) {
        printk("Starting nRF5340 Multi-Threaded PWM + GPIO + SPI4 Sensor Example!\n");
        LOG_INF("System initialized. Blinky & SPI threads running.");
    }
    

    the full .config file

    SB_CONFIG_BOARD="nrf5340dk"
    SB_CONFIG_BOARD_REVISION=""
    SB_CONFIG_BOARD_NRF5340DK=y
    SB_CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP_NS=y
    SB_CONFIG_BOARD_QUALIFIERS="nrf5340/cpuapp/ns"
    SB_CONFIG_SOC="nrf5340"
    SB_CONFIG_SOC_SERIES="nrf53"
    SB_CONFIG_SOC_FAMILY="nordic_nrf"
    SB_CONFIG_SOC_FAMILY_NORDIC_NRF=y
    SB_CONFIG_SOC_SERIES_NRF53X=y
    SB_CONFIG_SOC_NRF5340_CPUAPP=y
    SB_CONFIG_SOC_NRF5340_CPUAPP_QKAA=y
    
    #
    # Sysbuild image configuration
    #
    
    #
    # Modules
    #
    
    #
    # Available modules.
    #
    
    #
    # nrf (/home/stefan/ncs/v2.9.0/nrf)
    #
    SB_CONFIG_PARTITION_MANAGER=y
    # SB_CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK is not set
    SB_CONFIG_BUILD_OUTPUT_BIN=y
    SB_CONFIG_BUILD_OUTPUT_HEX=y
    SB_CONFIG_BOARD_IS_NON_SECURE=y
    SB_CONFIG_APPCORE_REMOTE_BOARD_TARGET_CPUCLUSTER="cpuapp"
    SB_CONFIG_APPCORE_REMOTE_DOMAIN="CPUAPP"
    SB_CONFIG_SUPPORT_NETCORE=y
    SB_CONFIG_NETCORE_REMOTE_BOARD_TARGET_CPUCLUSTER="cpunet"
    SB_CONFIG_NETCORE_REMOTE_DOMAIN="CPUNET"
    
    #
    # Network core configuration
    #
    SB_CONFIG_SUPPORT_NETCORE_EMPTY=y
    SB_CONFIG_SUPPORT_NETCORE_HCI_IPC=y
    SB_CONFIG_SUPPORT_NETCORE_RPC_HOST=y
    SB_CONFIG_SUPPORT_NETCORE_802154_RPMSG=y
    SB_CONFIG_SUPPORT_NETCORE_MULTIPROTOCOL_RPMSG=y
    SB_CONFIG_SUPPORT_NETCORE_IPC_RADIO=y
    SB_CONFIG_NETCORE_NONE=y
    # SB_CONFIG_NETCORE_EMPTY is not set
    # SB_CONFIG_NETCORE_HCI_IPC is not set
    # SB_CONFIG_NETCORE_RPC_HOST is not set
    # SB_CONFIG_NETCORE_802154_RPMSG is not set
    # SB_CONFIG_NETCORE_MULTIPROTOCOL_RPMSG is not set
    # SB_CONFIG_NETCORE_IPC_RADIO is not set
    # end of Network core configuration
    
    #
    # Secure Bootloader
    #
    # SB_CONFIG_SECURE_BOOT_APPCORE is not set
    # SB_CONFIG_SECURE_BOOT_NETCORE is not set
    # end of Secure Bootloader
    
    SB_CONFIG_SUPPORT_QSPI_XIP=y
    # SB_CONFIG_BT_FAST_PAIR is not set
    # SB_CONFIG_MATTER is not set
    
    #
    # Wi-Fi
    #
    # SB_CONFIG_WIFI_NRF70 is not set
    # end of Wi-Fi
    
    #
    # SUIT
    #
    # SB_CONFIG_SUIT_ENVELOPE is not set
    # SB_CONFIG_SUIT_BUILD_RECOVERY is not set
    # SB_CONFIG_SUIT_BUILD_FLASH_COMPANION is not set
    # end of SUIT
    
    #
    # SDP
    #
    # SB_CONFIG_SDP is not set
    # end of SDP
    
    # SB_CONFIG_APPROTECT_USE_UICR is not set
    # SB_CONFIG_APPROTECT_LOCK is not set
    # SB_CONFIG_APPROTECT_USER_HANDLING is not set
    SB_CONFIG_APPROTECT_NO_SYSBUILD=y
    # SB_CONFIG_SECURE_APPROTECT_USE_UICR is not set
    # SB_CONFIG_SECURE_APPROTECT_LOCK is not set
    # SB_CONFIG_SECURE_APPROTECT_USER_HANDLING is not set
    SB_CONFIG_SECURE_APPROTECT_NO_SYSBUILD=y
    SB_CONFIG_ZEPHYR_NRF_MODULE=y
    # end of nrf (/home/stefan/ncs/v2.9.0/nrf)
    
    SB_CONFIG_ZEPHYR_MCUBOOT_MODULE=y
    SB_CONFIG_ZEPHYR_MBEDTLS_MODULE=y
    SB_CONFIG_ZEPHYR_OBERON_PSA_CRYPTO_MODULE=y
    SB_CONFIG_ZEPHYR_TRUSTED_FIRMWARE_M_MODULE=y
    SB_CONFIG_ZEPHYR_PSA_ARCH_TESTS_MODULE=y
    SB_CONFIG_ZEPHYR_SOC_HWMV1_MODULE=y
    SB_CONFIG_ZEPHYR_CJSON_MODULE=y
    SB_CONFIG_ZEPHYR_AZURE_SDK_FOR_C_MODULE=y
    SB_CONFIG_ZEPHYR_CIRRUS_LOGIC_MODULE=y
    SB_CONFIG_ZEPHYR_OPENTHREAD_MODULE=y
    SB_CONFIG_ZEPHYR_SUIT_GENERATOR_MODULE=y
    SB_CONFIG_ZEPHYR_SUIT_PROCESSOR_MODULE=y
    SB_CONFIG_ZEPHYR_MEMFAULT_FIRMWARE_SDK_MODULE=y
    SB_CONFIG_ZEPHYR_COREMARK_MODULE=y
    SB_CONFIG_ZEPHYR_CANOPENNODE_MODULE=y
    SB_CONFIG_ZEPHYR_CHRE_MODULE=y
    SB_CONFIG_ZEPHYR_LZ4_MODULE=y
    SB_CONFIG_ZEPHYR_NANOPB_MODULE=y
    SB_CONFIG_ZEPHYR_TF_M_TESTS_MODULE=y
    SB_CONFIG_ZEPHYR_ZSCILIB_MODULE=y
    SB_CONFIG_ZEPHYR_CMSIS_MODULE=y
    SB_CONFIG_ZEPHYR_CMSIS_DSP_MODULE=y
    SB_CONFIG_ZEPHYR_CMSIS_NN_MODULE=y
    SB_CONFIG_ZEPHYR_FATFS_MODULE=y
    SB_CONFIG_ZEPHYR_HAL_NORDIC_MODULE=y
    SB_CONFIG_ZEPHYR_HAL_ST_MODULE=y
    SB_CONFIG_ZEPHYR_HAL_WURTHELEKTRONIK_MODULE=y
    SB_CONFIG_ZEPHYR_HOSTAP_MODULE=y
    SB_CONFIG_ZEPHYR_LIBMETAL_MODULE=y
    SB_CONFIG_ZEPHYR_LIBLC3_MODULE=y
    SB_CONFIG_ZEPHYR_LITTLEFS_MODULE=y
    SB_CONFIG_ZEPHYR_LORAMAC_NODE_MODULE=y
    SB_CONFIG_ZEPHYR_LVGL_MODULE=y
    SB_CONFIG_ZEPHYR_MIPI_SYS_T_MODULE=y
    SB_CONFIG_ZEPHYR_NRF_WIFI_MODULE=y
    SB_CONFIG_ZEPHYR_OPEN_AMP_MODULE=y
    SB_CONFIG_ZEPHYR_PICOLIBC_MODULE=y
    SB_CONFIG_ZEPHYR_SEGGER_MODULE=y
    SB_CONFIG_ZEPHYR_TINYCRYPT_MODULE=y
    SB_CONFIG_ZEPHYR_UOSCORE_UEDHOC_MODULE=y
    SB_CONFIG_ZEPHYR_ZCBOR_MODULE=y
    SB_CONFIG_ZEPHYR_NRFXLIB_MODULE=y
    SB_CONFIG_ZEPHYR_NRF_HW_MODELS_MODULE=y
    SB_CONFIG_ZEPHYR_CONNECTEDHOMEIP_MODULE=y
    
    #
    # Unavailable modules, please install those via the project manifest.
    #
    # end of Modules
    
    # SB_CONFIG_WARN_EXPERIMENTAL is not set
    SB_CONFIG_WARN_DEPRECATED=y
    SB_CONFIG_SUPPORT_BOOTLOADER=y
    SB_CONFIG_SUPPORT_BOOTLOADER_MCUBOOT_ZEPHYR=y
    SB_CONFIG_BOOTLOADER_NONE=y
    # SB_CONFIG_BOOTLOADER_MCUBOOT is not set
    
    #
    # Build options
    #
    # SB_CONFIG_COMPILER_WARNINGS_AS_ERRORS is not set
    # end of Build options
    

    current overlay

    &pwm0 {
        status = "disabled";
    };
    
    &sw_pwm {
        status = "okay";
        channel-gpios = <&gpio0 28 PWM_POLARITY_INVERTED>;
    };
    
    &pwm_led0 {
        pwms = <&sw_pwm 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
    };
    

Children
No Data
Related