I am having some issues with the Thingy91 and SPI. I want to configure GPIO0 8 as GPIO_OUTPUT pin.
This is my source code:
#include <stdio.h> #include <stdlib.h> #include <zephyr/kernel.h> #include <zephyr/drivers/spi.h> #include <zephyr/device.h> #include <zephyr/drivers/gpio.h> #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(main); // Define the CS pin #define CS_PIN 8 const struct device *gpio_dev; int main(void) { int err; printk("Program started \n"); gpio_pin_configure(gpio_dev, CS_PIN, GPIO_OUTPUT); if (err < 0) { printk("GPIO pin configure failed with error %d\n", err); return 0; } k_msleep(1000); printk("getting into while loop \n"); return 0; }
You can also access my code at github:
https://github.com/krupis/thingy91_spi_test
gpio_configure_bug branch.
It is also important to mention that on the Thing91 nRF52840, Connectivity Bridge application is running. I am only interested in programming nRF9160.
I have read about how to configure CS pin as GPIO from the following post:
Is it possible to control SPI chip select pin with Zephyr GPIO API?
and basically copy and pasted the code that has been suggested.
But for me it does not seem to work. The code just halts when gpio_pin_configure(gpio_dev, CS_PIN, GPIO_OUTPUT); is called. I have tried looking at the serial monitor but no logs are coming out even though I have added multiple printk statements.
After launching debugger, I have discovered that the Securefault_hanlder is triggered when the gpio_pin_configure is called:
I have 2 questions
- Am I configuring the GPIO correctly? (gpio0 8). If not, could you suggest an alternative way?
- Why am I not seeing a single printk statement being printed to the serial console? I have printk("Program started \n"); statement before the gpio_pin_configure call but that never gets printed.