Skip to main content Skip to local navigation

Exploring RISC-V Options: the RP2350 (Part 4 -- Serial Monitor Tooling)

It's easy to get caught in weird assembler errors. This is made more difficult if you don't have a background debugger and need to use a boot loader / serial monitor to debug your system. Sometimes that's all you have.

So here is a suggestion for a C++ and Assembler file pair to check to see if you're both entering and exiting the Assembler function using the Arduino IDE and its serial monitor. If all is well you should see the monitor do this:

Serial monitor informing you that you have entered and then exited the assembler function.

Here are the two files: riscv_standalone_asm_serialmonitor.ino and myAsmFunction.S:

// riscv_standalong_asm_serialmonitor.ino
// Have the Arduino IDE provide messaages to the serial monitor as we enter and exit the assembler function
extern "C" void myAsmFunction(void); // define the assembler function's name.

void setup() {
  Serial.begin(9600);
  while (!Serial) { ; }
  Serial.println("Entering the assembler...");

  // put your setup code here, to run once:
  myAsmFunction();
  
  Serial.println("Exited the assembler...");
}

void loop() {
  // after the assembler runs, catch in infinite loop...
  Serial.println(".");
  delay(200);
}

and then the assembler file:

# myAsmFunction.S
#
# By James Andrew Smith; Dec 10, 2025
# 
# Just count down a few times and return to C++ code.
# -----------------------------------------------
.section .data
# nothing in here.
.section .text
.global myAsmFunction
myAsmFunction:
# Set up number of times to count down in register t4
  li    t4, 5           # replace 5 with desired  count
# -------------- loop a few times -------------------
my_loop:
    # Decrement  count
    addi t4, t4, -1
    bnez t4, my_loop
# ------------- end of loop ----------------------
# ------- EXIT - Return to Arduino C++ ------------
	ret