linguini1 opened a new pull request, #16428:
URL: https://github.com/apache/nuttx/pull/16428

   ## Summary
   
   This implements an interrupt-based SPI driver for the BCM2711 SPI interfaces 
(excluding auxiliary SPI interfaces). Only tested on SPI0 since proprietary 
firmware does not initialize any other SPI interfaces, and doing so will 
require reverse engineering.
   
   ## Impact
   
   This PR impacts the BCM2711 chip support code and subset of the build 
system. Now users can enable SPI interfaces 0-6 for the BCM2711 and will be 
able to use SPI on at least SPI0.
   
   SPI1 & SPI2 currently throw compiler errors since they were left 
unimplemented. They are auxiliary interfaces and thus require a different 
implementation.
   
   SPI3-6 were not tested since it appears that the proprietary `start4.elf` 
firmware initialization does not enable these interfaces by default, nor when 
using the overlays provided by Raspberry Pi. I have not been able to find a 
solution to this issue so I am putting this driver in under the caveat that 
only SPI0 is tested, this is noted in the docs.
   
   ## Testing
   
   As mentioned, testing was performed using only SPI0 (marked GPIO pins for 
this interface are listed as MISO, MOSI, SCLK, CSE0 on this image 
https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fuelectronics.com%2Fwp-content%2Fuploads%2F2019%2F09%2FAR1099-Raspberry-4-B-PINOUT-min.jpg&f=1&nofb=1&ipt=691d4ea7c6e08fc730fbf54219e6d4a9d409ac370f1011cf840a381c05f35b51)
 with only CSE0 being used.
   
   I used the MCP3008 ADC driver to test the SPI implementation since that is 
the only device I have on hand. It appears to work just fine, I was able to 
read the different channel voltages with the `adc` example.
   
   Here are the logs, you can see that channel 0, 2 and 6 stay constant. 0 & 2 
have 3.3V power connected to them and therefore read quite high (out of 1024), 
while channel 6 is tied to ground. The other channels have changing values due 
to noise:
   
   ```
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 999                                                    
   2: channel: 1 value: 124                                                    
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 119                                                    
   5: channel: 4 value: 120                                                    
   6: channel: 5 value: 124                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 999                                                    
   2: channel: 1 value: 120                                                    
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 112                                                    
   5: channel: 4 value: 119                                                    
   6: channel: 5 value: 120                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 1007                                                   
   2: channel: 1 value: 119                                                    
   3: channel: 2 value: 999                                                    
   4: channel: 3 value: 126                                                    
   5: channel: 4 value: 193                                                    
   6: channel: 5 value: 119                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 1006                                                   
   2: channel: 1 value: 120                                                    
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 112                                                    
   5: channel: 4 value: 119                                                    
   6: channel: 5 value: 120                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 1006                                                   
   2: channel: 1 value: 111                                                    
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 112                                                    
   5: channel: 4 value: 115                                                    
   6: channel: 5 value: 120                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 1007                                                   
   2: channel: 1 value: 112                                                    
   3: channel: 2 value: 999                                                    
   4: channel: 3 value: 123                                                    
   5: channel: 4 value: 124                                                    
   6: channel: 5 value: 112                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 999                                                    
   2: channel: 1 value: 0                                                      
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 0                                                      
   5: channel: 4 value: 0                                                      
   6: channel: 5 value: 0                                                      
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 999                                                    
   2: channel: 1 value: 112                                                    
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 123                                                    
   5: channel: 4 value: 124                                                    
   6: channel: 5 value: 112                                                    
   7: channel: 6 value: 0                                                      
   nsh> adc                                                                    
   adc_main: g_adcstate.count: 1                                               
   adc_main: Hardware initialized. Opening the ADC device: /dev/adc0           
   Reading                                                                     
   Read 35                                                                     
   Sample:                                                                     
   1: channel: 0 value: 999                                                    
   2: channel: 1 value: 123                                                    
   3: channel: 2 value: 1007                                                   
   4: channel: 3 value: 119                                                    
   5: channel: 4 value: 126                                                    
   6: channel: 5 value: 123                                                    
   7: channel: 6 value: 0  
   ```
   
   I would appreciate if there is anyone with a Pi 4B and some SPI device on 
hand that would like to try testing as well to verify on another device, 
although it might not be necessary.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to