I have a problem when trying to access the WiFi Nina module from my Rust application. I have recreated all the steps that are required to boot the module:
let mut nina_gpio0 = pins.pa27.into_push_pull_output();
let nina_ack = pins.pa28.into_floating_input();
let mut nina_reset = pins.pb08.into_push_pull_output();
let mut nina_cs = pins.pa14.into_push_pull_output();
nina_gpio0.set_high();
nina_cs.set_high();
nina_reset.set_low();
delay.delay_ms(10_u16);
nina_reset.set_high();
delay.delay_ms(750_u16);
nina_gpio0.set_low();
let _ = nina_gpio0.into_floating_input();
This basically follows what I found in Arduino's WiFi Nina library:
pinMode(SLAVESELECT, OUTPUT);
pinMode(SLAVEREADY, INPUT);
pinMode(SLAVERESET, OUTPUT);
pinMode(NINA_GPIO0, OUTPUT);
However I am getting no luck when waiting for the ACK pin (GPIO33 on Nina's side, PA28 on the MCU):
hprintln!("Waiting for ACK low").unwrap();
while self.busy.is_high().map_err(SpiError::Busy)? {}
self.cs.set_low().map_err(SpiError::ChipSelect)?;
while self.busy.is_low().map_err(SpiError::Busy)? {}
The equivalent code works in the WiFi Nina library.
When testing with Arduino IDE, the module works correctly, I have even logged the pinout (although I do not understand how the defines correspond to the real pinout):
10:19:54.546 -> MOSI: 8
10:19:54.546 -> MISO: 10
10:19:54.546 -> SCK: 9
10:19:54.546 -> SS: 4
10:19:54.546 -> NINA_GPIO0: 30
10:19:54.546 -> NINA_RESETN: 31
10:19:54.546 -> NINA_ACK: 3
Would anybody know what I am doing wrong?
Thanks in advance for your answers or suggestions.
I am using an Arduino MKR 1010 WiFi board (but I have replaced the original firmware with my Rust app). To test if the Nina chip works fine I reprogrammed (several times) the original bootloader to be able to test the board with Arduino IDE (I got the pinout trace from there, using Serial.print()).
I will check the post you suggested, but normally GPIO0 is used by my software as explained here:
To me more clear - I do not want to touch the firmware on Nina, I want to program the main ATSAMD21G18A MCU to communicate with the original firmware that has been flashed on Nina.
That is correct, yes. I have found a library (GitHub - dflemstr/wifi-nina), but it does not seem to handle this particular PCB/configuration (e.g. GPIO0 is not managed by it). Do you understand what I am missing when starting the communication with Nina?
What I see is that the NINA_ACK pin is high until Nina is reset, then it stays low.
Then, before sending any command, the library does this:
WAIT_FOR_SLAVE_SELECT()
SpiDrv::waitForSlaveReady();
SpiDrv::spiSlaveSelect();
which boils down to:
wait for NINA_ACK to be low (OK)
set SPI CS to low (OK)
wait for NINA_ACK to be high (NOK)
Basically, setting the Chip Select pin to low does not make NINA_ACK to become high. What can it mean?
OK, found them (below). So I can confirm that I use the correct pins (PA12 = MOSI, PA13 = MISO, PA14 = CS, PA15 = SCK, NINA_GPIO0 = PA27, NINA_RESETN = PB08) on the correct sercom (4).
What is strange are still the pins logged by Arduino IDE (they clearly correspond to SPI0 - and the sketch works with NINA!). The program is still stuck while waiting for NINA_ACK to be high...
Also, when you look at the variant header file you provided: #define SPIWIFI_SS PIN_SPI1_SS #define SPIWIFI_ACK NINA_ACK #define SPIWIFI_RESET (~NINA_RESETN) // fixme! Inverted logic