Wifi on core 1? #1257
-
Hi, to test multicore I separated wifi stuff (HTTPUpdateServer) from the real work (blinking LED) by moving it to setup1() and loop1(). This did not work well. Led blinked on core 0 and wifi connected on core 1. If I switch cores by renaming setup1 to setup and loop1 to loop and vice versa all is working fine. I only found a restriction that Wifi needs to run on one core but not that it has to be core 0. I use this in platformio.ini, so I guess I use this arduino core: platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipicow My code, in case it matters: main.cpp #include <Arduino.h>
#define LED_PIN 9
#define TOGGLE_DELAY 300
bool serialStarted = false; // tell other core if printing is ok
void setup1() {
Serial.begin(115200);
serialStarted = true;
Serial.print("\nOTA Test");
pinMode(LED_PIN, OUTPUT);
}
void loop1() {
// blink led
const static uint32_t interval = TOGGLE_DELAY;
static uint32_t prev_ms = 0;
uint32_t now = millis();
if (now - prev_ms > interval)
{
prev_ms = now;
digitalWrite(LED_PIN, digitalRead(LED_PIN) ? LOW : HIGH);
Serial.printf("%u: Toggle LED\n", now);
}
} wifi.cpp #include <Arduino.h>
#define HTTP_PORT 80
#define PICO_HOST "pico"
#include <WiFi.h>
#include <WebServer.h>
#include <LEAmDNS.h>
#include <HTTPUpdateServer.h>
static WebServer httpServer(HTTP_PORT);
static HTTPUpdateServer httpUpdater;
extern bool serialStarted;
void setup() {
while( !serialStarted ); // wait until other core initialized Serial
Serial.println("Wifi core starting");
WiFi.mode(WIFI_STA);
WiFi.setHostname(PICO_HOST);
WiFi.begin(MY_SSID, MY_PASS);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
rp2040.restart();
}
Serial.printf("Host %s IP %s\n", WiFi.getHostname(), WiFi.localIP().toString().c_str());
MDNS.begin(WiFi.getHostname());
httpUpdater.setup(&httpServer);
httpServer.begin();
MDNS.addService("http", "tcp", HTTP_PORT);
Serial.printf("Firmware update on http://%s:%u/update\n", WiFi.getHostname(), HTTP_PORT);
}
void loop() {
httpServer.handleClient();
MDNS.update();
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That's not going to end well. The problem is the variant is initialized on core0 (initting the CYW43 chip), so the Ethernet and LWIP processing needs to be done there or the locking will go nuts. Keep the WiFi/LWIP stuff on core0 and any processing/etc. on core1, that's the only safe way. |
Beta Was this translation helpful? Give feedback.
That's not going to end well. The problem is the variant is initialized on core0 (initting the CYW43 chip), so the Ethernet and LWIP processing needs to be done there or the locking will go nuts. Keep the WiFi/LWIP stuff on core0 and any processing/etc. on core1, that's the only safe way.