Skip to content

Commit a023170

Browse files
committed
[feature]: USeparate application and debug output streams.
- Change DEBUG_RP2040_PORT to Serial in the dev environment to route debug output to USB CDC, which is not thread-safe. - Application output remains on Serial1, strictly managed by async context on core 1 for thread safety. - Update main.cpp to initialize Serial (USB CDC) without baud rate and add a short timeout for a robust startup. - Ensures clear separation between thread-safe application output and non-thread-safe debug output. Signed-off-by: Goran Mišković <[email protected]>
1 parent 824fb15 commit a023170

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ platform_packages =
2929
framework-arduinopico@symlink://../arduino-pico
3030
build_flags =
3131
-DESPHOSTSPI=SPI
32-
-DDEBUG_RP2040_PORT=Serial1
32+
-DDEBUG_RP2040_PORT=Serial
3333
-DDEBUG_RP2040_CORE
3434
-DDEBUG_RP2040_WIRE
3535
-Og

src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ void print_board_temperature() {
210210
* @brief Initializes the Wi-Fi connection and asynchronous context on Core 0.
211211
*/
212212
void setup() {
213+
Serial.begin(); // baud rate is ignored for USB CDC
214+
// Wait up to 1 second for Serial to become ready, but do not block indefinitely
215+
for (int i = 0; i < 100; ++i) {
216+
if (Serial) break;
217+
delay(10);
218+
}
213219

214220
Serial1.begin(115200);
215221
while (!Serial1) {

0 commit comments

Comments
 (0)