Serial via RAKDAP1 and Platform.io

I have a RAK4631 core and a RAK19010 base. I’m trying to send a “Hello World” message to the platformio monitor. I am able to use the RAKDAP1 to flash to the RAK4631 but I am unable to receive serial print statements in the platformio monitor. My current code is as follows (ignore the RS485 and modbus library imports those are for future use):

#include <Arduino.h>
#include "Adafruit_TinyUSB.h"
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>


void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial1.begin(115200);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  Serial1.println("Hello World");
}

Building the file receives no errors but when I click Upload or Upload and Monitor I get the following log:


Processing MODBUS (board: wiscore_rak4631; platform: nordicnrf52; framework: arduino)
----------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/wiscore_rak4631.html
PLATFORM: Nordic nRF52 (10.4.0) > WisCore RAK4631 Board
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-arduinoadafruitnrf52 @ 1.10600.0 (1.6.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-adafruit-nrfutil @ 1.503.0 (5.3)
 - tool-bossac-nordicnrf52 @ 1.10901.201022 (1.9.1) 
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-sreccat @ 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoModbus @ 1.0.9
|-- Adafruit TinyUSB Library
|-- ArduinoRS485 @ 1.0.5
Building in release mode
Checking size .pio\build\MODBUS\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"  
RAM:   [          ]   3.0% (used 7480 bytes from 248832 bytes)
Flash: [=         ]   5.5% (used 44772 bytes from 815104 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, nrfjprog, nrfutil, stlink
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\MODBUS\firmware.hex
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

[nrf52.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
** Programming Started **
Warn : Adding extra erase range, 0x00030ee4 .. 0x00030fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
======================= [SUCCESS] Took 6.37 seconds =======================
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder RDTM: C:\Users\lukaj\.platformio\penv\Scripts\platformio.exe run --target upload --environment MODBUS 

Processing MODBUS (board: wiscore_rak4631; platform: nordicnrf52; framework: arduino)
----------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/wiscore_rak4631.html
PLATFORM: Nordic nRF52 (10.4.0) > WisCore RAK4631 Board
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-arduinoadafruitnrf52 @ 1.10600.0 (1.6.0)
 - framework-cmsis @ 2.50700.210515 (5.7.0)
 - tool-adafruit-nrfutil @ 1.503.0 (5.3)
 - tool-bossac-nordicnrf52 @ 1.10901.201022 (1.9.1)
 - tool-openocd @ 3.1200.0 (12.0)
 - tool-sreccat @ 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoModbus @ 1.0.9
|-- Adafruit TinyUSB Library
|-- ArduinoRS485 @ 1.0.5
Building in release mode
Checking size .pio\build\MODBUS\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.1% (used 7820 bytes from 248832 bytes)
Flash: [=         ]   5.8% (used 46992 bytes from 815104 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, nrfjprog, nrfutil, stlink
CURRENT: upload_protocol = cmsis-dap
Uploading .pio\build\MODBUS\firmware.hex
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

[nrf52.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
** Programming Started **
Warn : Adding extra erase range, 0x00031790 .. 0x00031fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
======================= [SUCCESS] Took 6.53 seconds =======================
 *  Terminal will be reused by tasks, press any key to close it. 
type or paste code here

I’m not sure if this will point to the issue or not. chasing the "[nrf52.cpu] halted due to debug-request, current mode: Thread " line hasn’t lead to anything beneficial yet.

I have tried all variations of Serial, Serial1, and Serial2. I have the U_TX and U_RX pins of the RAKDAP1 connected to the TX0 and RX0 pins on the board. Swapping the connections doesn’t change anything. I have used a voltmeter and tested continuity between both the soldered TX0 and RX0 pins and the corresponding UART1_TX and UART1_RX pins on the RAK4631. When I accidentally touched the RX pin on the RAKDAP1 to RS485-B pin on my RAK5802 module random symbols appeared on the platformio monitor so I’m assuming that it is possible to achieve what I want, I’m just unsure how. Any pointers would be greatly appreciated.

Do you have enabled debug over RAKDAP1 in the platformio.ini.
I remember that the debugger stops the app at internal main function and you have to restart it from the debugging interface to go on.

I don’t currently have debug enabled, but I did have it in the .ini on a previous version of the code I flashed. Here is my platformio.ini:

[env:MODBUS]
board = wiscore_rak4631
platform = nordicnrf52
framework = arduino
upload_protocol = cmsis-dap
monitor_speed = 115200
monitor_filters = default
lib_deps = arduino-libraries/ArduinoModbus@^1.0.9

What do you get when you open in VSC the “Run and Debug”?

I am not sure what is happening here.

Here is the debug console output:

Reading symbols from C:\Users\lukaj\Documents\PlatformIO\Projects\RDTM\.pio\build\MODBUS\firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = cmsis-dap
PlatformIO: Initializing remote target...
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : tcl server disabled
Info : telnet server disabled
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: FW Version = 0254
Info : CMSIS-DAP: Serial# = 0700000100330014340000184e543352a5a5a5a597969908
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : [nrf52.cpu] Cortex-M4 r0p1 processor detected
Info : [nrf52.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for nrf52.cpu on pipe
Info : accepting 'gdb' connection from pipe
[nrf52.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x0002da9a psp: 0x20007748
Info : nRF52840-xxAA(build code: D0) 1024kB Flash, 256kB RAM
0x0002da9a in ada_callback_init (stack_sz=<optimized out>) at C:\Users\lukaj\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\utility\AdaCallback.c:148
148	}
[nrf52.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
Loading section .text, size 0xbb84 lma 0x26000
Loading section .ARM.exidx, size 0x8 lma 0x31b84
Loading section .data, size 0x304 lma 0x31b8c
[nrf52.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
Start address 0x2d374, load size 48784
Transfer rate: 13 KB/sec, 9756 bytes/write.
[nrf52.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
[nrf52.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000a80 msp: 0x20000400
Temporary breakpoint 1 at 0x2d3f8: file C:\Users\lukaj\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\main.cpp, line 79.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.

Temporary breakpoint 1, main () at C:\Users\lukaj\.platformio\packages\framework-arduinoadafruitnrf52\cores\nRF5\main.cpp:79
79	{


It seems there is a temporary breakpoint right when the code enters the main function of the nRF5 core main.cpp. When I click continue there are no more breakpoints and the code appears to run. While debugging the D2 light on the RAKDAP1 stay solid while the D1 light blinks. Both lights stop when debugging is ended.

I’ll continue to experiment with it but I’m truly lost as to the cause of this issue. Is there a preferred serial monitor program to use with the RAKDAP1 I can use to test it?

Quick follow up, If i put a break point on lines 18 and 20 the led stays on or off depending on which breakpoint it pauses at and I can continue the code. So debugging is working properly.

I never found out why there is a default breakpoint when you use the debugger. It is a little bit annoying, but seems to be intentional.

Is it possible there’s a JSON file with pin definitions for Serial2? It might be incorrectly set up. I’m not sure where I would locate those configurations though.

Serial2 is defined in C:\Users\<YOUR_NAME>\AppData\Local\Arduino15\packages\rakwireless\hardware\nrf52\1.3.3\variants\WisCore_RAK4631_Board\variant.h

image

Serial2 is working for me with these settings.

Strange, those are the same settings I have. Could it be something to do with the RAK4631 itself?

I don’t think so. It is a long time since I used Serial2, but it worked.

Where and how do you connect to Serial2?

I connect the TX0 and RX0 pins on the board to the U_TX and U_RX pins on the RAKDAP1 and then plug the RAKDAP1 into my computer. I also have the 3V3, SWDIO, SWCLK, and GND pins on the RAK4631 connected to the 3V3, TMS/IO, TCK/CK, and GND pins on the RAKDAP1 respectively. Aside from that there’s no other connected pins. Here’s an image:

Here’s my code to show I’m calling on Serial2 and not another serial:

#include <Arduino.h>
#include "Adafruit_TinyUSB.h"
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>


void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial2.begin(115200);
  //RS485.begin(115200);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
  Serial2.println("Hello World");
}

Also, here’s how platformio is detecting the RAKPDAP1 if its helpful to see:

On your photo you connect to TX1/RX1 == Serial1, not TX0/RX0
image

I figured it out now. I feel like an idiot haha. I just needed to plug the RX0 pin of the board into the U_TX of the RAKDAP1.

In response to your picture, on the board itself it calls those pins RX0 and TX0. Serial2 is correct.

Thank you so much for your help, gotta love when the solution was so simple and you end up trying all these different crazy things :rofl: