To watch what happens inside #NuttX's SPI Driver for #BL602 ... Turn on SPI Debug Logging
https://github.com/lupyuen/incubator-nuttx/blob/spi_test/arch/risc-v/src/bl602/bl602_spi.c
Now we see every byte transferred by #NuttX's SPI Driver for #BL602!
https://github.com/lupyuen/incubator-nuttx/blob/spi_test/drivers/rf/spi_test_driver.c
How to verify the #NuttX SPI Output? We sniff the #BL602 SPI Bus with a Logic Analyser
https://lupyuen.github.io/articles/spi#appendix-troubleshoot-bl602-spi-with-logic-analyser
#NuttX's SPI Pins match the #BL602 Reference Manual: MOSI = GPIO 1, MISO = GPIO 0 ... But we're about to witness a BL602 SPI Quirk
https://github.com/bouffalolab/bl_docs/tree/main/BL602_RM/en
Logic Analyser connected to #BL602 shows that MISO and MOSI are swapped! This happens in BL602 IoT SDK ... Also in #NuttX!
https://lupyuen.github.io/articles/spi#spi-data-pins-are-flipped
We can swap MISO and MOSI on #BL602 by setting a Hardware Register ... Let's do this on #NuttX
https://lupyuen.github.io/articles/pinedio#spi-pins-are-swapped
Let's test #NuttX SPI with #BL602 and Semtech SX1262 LoRa Transceiver
https://www.semtech.com/products/wireless-rf/lora-core/sx1262
We implement the Read Operation for our #NuttX SPI Driver ... So that we can fetch the SPI Response from SX1262
https://github.com/lupyuen/incubator-nuttx/blob/spi_test/drivers/rf/spi_test_driver.c#L210-L233
Our #NuttX App transmits an SPI Command to SX1262 ... And reads the SPI Response from SX1262
#BL602 SPI Chip Select has a problem ... It goes High after EVERY byte ... Which is no-no for SX1262 ... Solution: We control Chip Select via GPIO
For #NuttX on #BL602, we use SPI Mode 1 instead of Mode 0 ... To work around the SPI Mode Quirk
https://github.com/lupyuen/incubator-nuttx/blob/spi_test/drivers/rf/spi_test_driver.c#L51-L57
Our #NuttX App now reads the SX1262 Register correctly! 🎉
https://github.com/lupyuen/incubator-nuttx-apps/blob/spi_test/examples/spi_test2/spi_test2_main.c
Here are the #NuttX Pin Definitions for PineDio Stack BL604 with onboard SX1262 ... As derived from the schematic
Our #NuttX App runs OK on PineDio Stack BL604 with onboard SX1262! 🎉
https://github.com/lupyuen/incubator-nuttx-apps/blob/spi_test/examples/spi_test2/spi_test2_main.c
How we transmit and receive data over SPI on Apache #NuttX OS ... And what's inside the SPI Driver ... All shall be explained here
To test the #NuttX SPI Functions, we create an App and a Device Driver
https://lupyuen.github.io/articles/spi2?3#spi-test-app-and-driver
#NuttX Apps can't call the SPI Driver directly ... Here's why
https://lupyuen.github.io/articles/spi2?3#spi-test-app-and-driver
Here's how we create a #NuttX App
https://lupyuen.github.io/articles/spi2?4#appendix-create-a-nuttx-app
How we create a Device Driver in #NuttX ... The copy-n-paste way
https://lupyuen.github.io/articles/spi2?5#appendix-create-a-nuttx-device-driver
During #NuttX Startup, we register our Device Driver
https://lupyuen.github.io/articles/spi2?8#register-device-driver
Our Custom Device Driver appears as "/dev/spitest0" in #NuttX
https://lupyuen.github.io/articles/spi2?9#verify-device-driver
Why we chose to clone the "dat-31r5-sp" driver in #NuttX ... Yep we did a Quantitative Analysis of NuttX Drivers!
https://lupyuen.github.io/articles/spi2?10#verify-device-driver
What's inside our SPI Test Driver for #NuttX
https://lupyuen.github.io/articles/spi2?11#inside-the-spi-test-driver
Every #NuttX Device Driver defines a list of File Operations ... Here are the operations for our SPI Test Driver
Checking that our SPI Test Driver has been loaded in #NuttX
https://lupyuen.github.io/articles/spi2?19#load-the-spi-test-driver
Running our #NuttX App to transmit and receive data over SPI
https://lupyuen.github.io/articles/spi2?21#run-the-spi-test-app
How we test #NuttX SPI with a Logic Analyser
https://lupyuen.github.io/articles/spi2?22#test-with-logic-analyser
Here's why we control SPI Chip Select ourselves on #NuttX
https://lupyuen.github.io/articles/spi2?23#control-chip-select-with-gpio
Controlling SPI Chip Select with GPIO Output on #NuttX
https://lupyuen.github.io/articles/spi2?24#gpio-output-as-chip-select
Testing #NuttX on #BL602 and #ESP32 with Semtech SX1262
https://lupyuen.github.io/articles/spi2?25#test-with-semtech-sx1262
Testing Apache #NuttX OS on #PineDio Stack BL604 @PINE64
https://lupyuen.github.io/articles/spi2?28#test-with-pinedio-stack
Yep Apache #NuttX OS works great on #PineDio Stack BL604! 🎉
https://lupyuen.github.io/articles/spi2?30#run-nuttx-on-pinedio-stack
#BL602's SPI Mode has an odd quirk ... Here's the workaround for #NuttX OS
https://lupyuen.github.io/articles/spi2?31#appendix-spi-mode-quirk
What's inside the SPI Interface on #NuttX OS
https://lupyuen.github.io/articles/spi2?34#appendix-nuttx-spi-interface
#BL602 MISO and MOSI are swapped ... Will submit a PR for #NuttX OS 👍
https://lupyuen.github.io/articles/spi2?32#appendix-miso-and-mosi-are-swapped
Here's how we Transmit and Receive data over SPI on Apache #NuttX OS ... By coding a NuttX Device Driver
How our #NuttX App transfers data over SPI
https://lupyuen.github.io/articles/spi2?20#inside-the-spi-test-app