Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISC: update to zephyr master and add initial wifi support #17

Open
wants to merge 17 commits into
base: arduino
Choose a base branch
from

Conversation

facchinm
Copy link
Member

@facchinm facchinm commented Dec 18, 2024

When merged, #12 should be tackled

Extra info for the brave:

  • after pulling the PR, run west update ;
  • pip install -r ../zephyr/scripts/requirements-base.txt && west blobs fetch hal_nxp to test WiFi on RW612

Easiest method to test WiFi APIs is to use a board where WiFi is already supported :)
Comes with its own set of issues:
* pyocd is not supported, use JLink to flash instead
* The .dfu.bin file should be flashed at 0x18323000
* Debug UART (printk) on JLink port, Serial on native USB
There's no way to convince the compiler to consider the provided flags
when linking modern c++ code (std::).
Get rid of the useless symbols in the linker and add the (then) missing
implementations in abi.cpp
Tested with NTPClient and ArduinoMDNS

TODO: properly test multicast
connect() temporarily accepts a third parameter with a PEM encoded certificate

Cleanest way to add it is via raw strings

const char * certificate = R"(-----BEGIN CERTIFICATE-----
....
-----END CERTIFICATE-----)";
@KurtE
Copy link

KurtE commented Dec 20, 2024

being somewhat brave ;) I checked out the PR and I am starting to play with it.
Ran into one compile issue, where, the one ILI9341 display code is not compiling:

#ifndef ILI9341_swap
#define ILI9341_swap(a, b)                                                     \
  {                                                                            \
    typeof(a) t = a;                                                           \
    a = b;                                                                     \
    b = t;                                                                     \
  }
#endif

Some of the errors:

In file included from /home/kurte/Arduino/libraries/ILI9341_GIGA_zephyr/src/ILI9341_GIGA_zephyr.cpp:54:
/home/kurte/Arduino/libraries/ILI9341_GIGA_zephyr/src/ILI9341_GIGA_zephyr.cpp: In member function 'void ILI9341_GIGA_n::drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t)':
/home/kurte/Arduino/libraries/ILI9341_GIGA_zephyr/src/ILI9341_GIGA_zephyr.h:904:5: error: 'typeof' was not declared in this scope; did you mean 'typedef'?
  904 |     typeof(a) t = a;                                                           \
      |     ^~~~~~
/home/kurte/Arduino/libraries/ILI9341_GIGA_zephyr/src/ILI9341_GIGA_zephyr.h:904:5: note: in definition of macro 'ILI9341_swap'
  904 |     typeof(a) t = a;                                                           \
      |     ^~~~~~
/home/kurte/Arduino/libraries/ILI9341_GIGA_zephyr/src/ILI9341_GIGA_zephyr.h:906:9: error: 't' was not declared in this scope
  906 |     b = t;                                                                     \
      |         ^

Nothing major, will work around, but I know some other libraries have this as well.
Not sure what changed, with this build?

@KurtE
Copy link

KurtE commented Dec 21, 2024

I thought I would mention that I pulled in my SPI changes and changed the sizes in the .conf file for the GIGA.
And updated my sketch to split the display off from the SD, as on my Linux machine I am using one of the ILI9341 displays that do not properly buffer MISO line. And after a bit of remembering the wiring of the SD it worked:
image

I then thought I would use a modified version of a pin test sketch that I often use for the Teensy. This one was modified
for the UNOR4... And does compile for the MBED GIGA.

But it does not compile on the GIGA: In particular: NUM_DIGITAL_PINS
Is not defined.

Also the precompiler stuff to convert the .ino to a .cpp is not properly adding in forward references for different functions, that are used that are later on in the sketch.
The sketch is up at: https://github.com/KurtE/UNOR4-stuff/blob/main/test_sketches/uno_r4_HiLowTest/uno_r4_HiLowTest.ino

For example in the sketch we have:


void loop() {
    allPinTest( );
}

uint32_t pinLast[NUM_DIGITAL_PINS];
void allPinTest() {
  uint32_t ii;
  Serial.print("PULLUP Start Vals:\n  ");
  Serial.print("PULLUP :: TEST to GND\n  ");

And the error list includes:

      |   ^~~~~~~~~~~~~
C:\Users\kurte\Documents\Arduino\Arduino_UNOR4\uno_r4_HiLowTest\uno_r4_HiLowTest.ino: In function 'void loop()':
C:\Users\kurte\Documents\Arduino\Arduino_UNOR4\uno_r4_HiLowTest\uno_r4_HiLowTest.ino:17:5: error: 'allPinTest' was not declared in this scope
   17 |     allPinTest( );
      |     ^~~~~~~~~~

Question: Would you prefer these as different issues...

EDIT: I was able to edit the sketch to make it compile... Borrowing a little
from SPI.h.

#define NUM_DIGITAL_PINS                                                        \
  DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios,            \
                           INTERRUPT_HELPER, (+))

extern void allPinTest();
extern void testForShorts();

I have not completed running through all of the pins: But did some and it appears
better, will comment on the issue: #7
So far the only pins I see off are SCL1/SDA1 where on the Full pinout shows them
as pins 101, 102, but they are ringing out as 95 and 96

@mjs513
Copy link

mjs513 commented Dec 22, 2024

@facchinm

Ok figured it out. Using the following sketch:

/*
 This example connects to an unencrypted WiFi network.
 Then it prints the MAC address of the WiFi module,
 the IP address obtained, and other network details.

 Circuit:
 * GIGA R1 WiFi

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 modified 22 March 2023
 by Karl Söderby
 */

#include <SPI.h>
#include <WiFi.h>

void  printCurrentNet();
void  printWifiData();
void  printMacAddress(byte mac[]);

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = "";        // your network SSID (name)
char pass[] = "";    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the WiFi radio's status

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();

}

void loop() {
  // check the network connection once every 10 seconds:
  delay(10000);
  printCurrentNet();
}

void printWifiData() {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  printMacAddress(mac);
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  printMacAddress(bssid);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  //byte encryption = WiFi.encryptionType();
  //Serial.print("Encryption Type:");
  //Serial.println(encryption, HEX);
  Serial.println();
}

void printMacAddress(byte mac[]) {
  for (int i = 5; i >= 0; i--) {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    Serial.print(mac[i], HEX);
    if (i > 0) {
      Serial.print(":");
    }
  }
  Serial.println();
}

Had to comment out encryptionType since it wasn't defined anywhere. Once I did that it loaded compiled and loaded but hung with the following error:

�[m
�[1;32muart:~$ �[msketch
[00:00:12.740,000] �[1;31m<err> llext: Undefined symbol with no entry in symbol table strtok, offset 2400, link section 11�[0m
[00:00:12.741,000] �[1;31m<err> llext: Failed to link, ret -61�[0m
Failed to load sketch, rc -61
�[1;32muart:~$ �[m

Which I believe means the following should be added to llext_exports.c

EXPORT_SYMBOL(strtok);

quick question - if I add it does that mean I have to recompile

UPDATE: Added the symbol and recompiled but now getting:

[00:00:11.567,000] �[1;31m<err> llext: Undefined symbol with no entry in symbol table strtol, offset 2180, link section 10�[0m
[00:00:11.567,000] �[1;31m<err> llext: Failed to link, ret -61�[0m
Failed to load sketch, rc -61

think maybe you should just add all the stdlib symbols to be on the safe side

@mjs513
Copy link

mjs513 commented Dec 23, 2024

@facchinm -- @KurtE

Ok I updated the llext_exports.c with a few more symbols
llext_exports.zip

this time the sketch ran but got message that it failed to start wifi:

[00:00:06.788,000] �[1;33m<wrn> usb_device: USB device support already enabled�[0m
Communication with WiFi module failed!

Merry Christmas
Mike

EDIT: Gues RW612 is not the wifi chip on the giga?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants