Hi, I’m trying to send a serial command that would open the USB storage device of the XIAO SAMD21 board. The idea is to have a GUI button that would send a serial message to the microcontroller so that it would open the flash drive. This way the firmware could be updated without the double tap on the physical hardware, making it easier for the end user.
This code resets the board, but the flash drive doesn’t get opened, any help?
#include <sam.h>
#define DBL_TAP_MAGIC 0x07738135
#define DBL_TAP_PTR ((volatile uint32_t *)0x20007FFC) // Specific memory address for magic number
#define RESET_SYSTEM NVIC_SystemReset() // Macro to reset the microcontroller
void enterBootloader() {
// Write the magic number to the reserved memory location
*DBL_TAP_PTR = DBL_TAP_MAGIC;
// Perform a system reset to trigger the bootloader
RESET_SYSTEM;
}
void setup() {
Serial.begin(9600);
while (!Serial) {
// Wait for Serial to be ready
}
Serial.println("Device ready. Send 'bootloader' command to enter bootloader mode.");
}
void loop() {
// Check if data is available on the Serial port
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n'); // Read the command until a newline character
// Trim whitespace
command.trim();
// Check if the received command matches "bootloader"
if (command == "bootloader") {
Serial.println("Entering bootloader mode...");
enterBootloader();
} else {
Serial.println("Unknown command. Send 'bootloader' to enter bootloader mode.");
}
}
}