Loading trinket m0 remotely from command line?

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
chrisjx
 
Posts: 103
Joined: Mon Aug 09, 2010 6:17 am

Loading trinket m0 remotely from command line?

Post by chrisjx »

Using a trinket m0 to drive some LEDs. All works fine in the arduino IDE; I never have to press the reset buttons prior to loading code.

Now I'm trying to use bossac 1.9.1, but it seems it requires the physical button 2-press reset. avrdude did not. So imagine my surprise at this revelation. Sadly, this won't do for remote installations where I don't have physical access to the trinket.

I'm executing this:

Code: Select all

bossac -e -w -v -R --offset=0x2000 --port=/dev/ttyACM0 LED_Status_uC_rgb_neo_4.2.1.ino.bin
and unless I press the reset button twice, bossac does not see the trinket's USB port:

Code: Select all

No device found on /dev/ttyACM0
I tried some hacky/trickery like this in an attempt to remotely set it to loader mode:

Code: Select all

  
  if (Serial.available() > 0) {
    String command = Serial.readStringUntil('\n');

    if (command == "bloader") {
      // Trigger the bootloader
      // Sets a magic value and triggers a software reset
      *((uint32_t *)(0x20000000 + 0x000008)) = 0x50484352;
      NVIC_SystemReset();
    }
    ...
But that just resets/reboots the trinket.

This is kind of a deal breaker if there's no way to remotely update firmware.

Any tips appreciated,
Chris.

User avatar
chrisjx
 
Posts: 103
Joined: Mon Aug 09, 2010 6:17 am

Re: Loading trinket m0 remotely from command line?

Post by chrisjx »

This seems to be working... on Raspi, bookworm

Log in to your default pi user.

Install bossa:

Code: Select all

sudo apt install bossa-cli
Create a file named... load_code.sh, and paste this code

Code: Select all

#!/bin/bash

# Define the target device and firmware file
DEVICE="/dev/ttyACM0"
FIRMWARE="myledcode.ino.bin"

# Step 1: Open the device at 1200 baud to trigger bootloader mode
echo "Triggering bootloader mode on $DEVICE..."
stty -F $DEVICE 1200

# Step 2: Wait for the device to reset and reappear
echo "Waiting for $DEVICE to reappear in bootloader mode..."
sleep 2  # Allow time for the device to enter bootloader mode

# Step 3: Check if device is back (it may briefly disappear and return as ttyACM0)
until [ -e "$DEVICE" ]; do
    sleep 1
done

# Step 4: Upload the firmware with bossac
echo "Uploading firmware to $DEVICE..."
bossac -e -w -v -R --offset=0x2000 --port=$DEVICE $FIRMWARE

# Step 5: Confirm the result
if [ $? -eq 0 ]; then
    echo "Firmware upload successful."
else
    echo "Firmware upload failed."
fi
Run chmod to make your code executable:

Code: Select all

chmod +x automate_bossac_upload.sh
Execute the code:

Code: Select all

./load_code.sh
The trick seems to be in the stty command opens the serial port at 1200 baud, which causes the Trinket M0 to reset into bootloader mode.

Next, I need to make sure I can get it to work on centos 8 stream.

Hope this helps someone else.

User avatar
chrisjx
 
Posts: 103
Joined: Mon Aug 09, 2010 6:17 am

Re: Loading trinket m0 remotely from command line?

Post by chrisjx »

Just another tidbit... about deploying

When creating the code and compiling it, I just used the arduino IDE and loaded the appropriate libs for leds and the trinketm0. You'll need to round up those misc components up for your project as needed.

This is a good iterative setup to build your code; write it, compile & upload it, test, try again.

When you're ready to deploy/update the compiled code, go to the Sketch > Export Compiled Binary menu and if it is successful, you'll find the artifacts (.bin, .hex, etc.) under your arduino project folder (e.g., /Users/chris/Documents/Arduino). This you'll copy to where ever it needs to be.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”