Bootloader for ATmegaS128

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am looking for a BOOTLOADER / PC utility, to program an ATmegaS128 processor, which is an ATMEL RAD-TOLERANT processor.

I am using Atmel Studio 7 under MS Windows 10.

My code is working well both standalone and under Atmel Studio with Atmel ICE, but now we want to be able to update it in the field.

I have done this with an ATxmegaA3U; I was presented a HEX of the bootloader which I setup using ATMEL ICE through a JTAG connection, and then used ATMEL's FLIP software to program my code.

The ATmegaS128 has a serial port, but does not seem to have USB support.

 

I hoped I would find the the same or equivalent prebuilt.

Do I have to build the bootloader HEX? From what source code? Will FLIP work, or do I need another utility?

Do I need to install some code from ATMEL START, or the PACKAGE MANAGER?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In this day and age if you want a bootloader it's perhaps wise to pick something with an Arduino heritage as it guarantees widespread use and support.

 

Now a mega128 (I presume the S is just the RAD version of mega128 ?) is not actually an "Arduino processor" so the "stock" distribution of Arduino does not have a bootloader for mega128. However new (and old!) processors can be added to Arduino by adding a "core" and part of that core will be a bootloader for whatever chip(s) are added. So when you google "mega128 arduino core" you very likely arrive at:

 

https://github.com/MCUdude/MegaCore

 

Digging into that gets you to:

 

https://github.com/MCUdude/MegaC...

 

which is where the bootloaders for "mega core" chips live (and that includes mega128). So you can find a number of pre-built ones for mega128 in:

 

https://github.com/MCUdude/MegaC...

 

The sub-dir you choose is basically the speed you are setting up the mega128 to run at. so if you run at 8MHz (say) then pick:

 

https://github.com/MCUdude/MegaC...

 

Now you get a choice of (a) which UART the bootloader expects traffic on and (b) at what baud rate

 

The "other side" for any Arduino/Optiboot bootloader is generally going to be Avrdude which is available in both Linux and Windows (avrdude.exe) builds. It is a command line tool.

 

Of course I do wonder about RAD hardening - presumably this thing is taking a journey to space is it? (or a trip into a nuclear power station perhaps??). That does rather raise the question of "how is avrdude running on a PC (or whatever) going to "talk" to it?". Is a radio link involved? (I'm guessing a 22,000 mile UARtT cable is out of the question?)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The UART cable is at least remotely* possible.

The folks on the Scorpion series did something even sillier:

A communication cable hanging hanging from a low-flying

jet so that it could be connected to a laptop almost in a car.

 

 

* I do mean remotely.

Moderation in all things. -- ancient proverb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Suit Monkey wrote:
Do I have to build the bootloader HEX?
Yes though ELF could include other required memory spaces (fuses, EEPROM)

Suit Monkey wrote:
From what source code?
There are at least several mega128 bootloaders that would be a fit; Optiboot is first to mind whereas AVR109 may predate.

A bootloader requirement may be compatibility with the STK500v2 protocol (IIRC)

Suit Monkey wrote:
Will FLIP work, ...
No

Suit Monkey wrote:
or do I need another utility?
Yes (loader); AVRDUDE is popular and has been ported to Android.

Suit Monkey wrote:
Do I need to install some code from ATMEL START,
maybe

Suit Monkey wrote:
, or the PACKAGE MANAGER?
indecision

Microchip Gallery has Atmel Studio and Microchip Studio extensions; could remove the FOTA portion of SerialBootloader (iow, retain the UART part)

 

P.S.

Suit Monkey wrote:
ATmegaS128
fyi, radiation-hardened Arm Cortex-M0 are relatively inexpensive.

Microchip Technology has increased their portfolio of radiation-hardened Arm Cortex M.

 


ATmegaS128 - Tolerant Devices

 

https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/optiboot_atmega1280.hex

AN_1644 AVR109: Using Self Programming on tinyAVR and megaAVR devices

AVR068: STK500 Communication Protocol (STK500v2)

 

FLIP (additional resources tab, supported devices)

 

AVR Downloader/UploaDEr - Summary [Savannah] (AVRDUDE)

NuGet Gallery | ArduinoUploader 3.2.0 (C#)

AVRDUDE ported to Android :

ZFlasher AVR - Apps on Google Play

Program work checked with programmer:

...

* STK500v2
* AVR109
* Arduino bootloader

 

https://start.atmel.com/#examples/boot

 

Microchip Gallery | Packages

Microchip Gallery | Bootloader-PC-Tool-Setup 1.2.2.235

AN_8390 AVR2054: SerialBootloader User Guide

 

Vorago Bootloader AN1216

https://octopart.com/search?q=va108&currency=USD&specs=0&manufacturer_id=11050

VORAGO Products — VORAGO Technologies (MCU)

 

edit :

PC Application – Update | AVR231: AES Bootloader

 

edit2 :

The first Wiring board was based on mega128.

Hardware \ Wiring (immediately before mid-page)

https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/stk500v2/stk500boot.c

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Jun 29, 2021 - 10:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Of course I do wonder about RAD hardening - presumably this thing is taking a journey to space is it?
or the stratosphere or mesosphere (sub-orbital)

There will be some radiation exposure in the troposphere due to strong solar flares (high latitudes, passenger jet crew and customers) and micronova (Earth's Sun-facing side)

Radiation tolerance is proportional to temperature tolerance; industrial MCU are in LEO CubeSat along with an external watchdog to cycle power (recover from latch-up)

Flash can be an issue; Arm typically have a boot ROM over UART to load SRAM (external power on, loader/bootloader, built-in-test, ignite the primary battery(s), on internal power, go; similar sequence for geophysical devices into a bore hole)

MRAM have internal ECC and are radiation-tolerant; IIRC, F-RAM is similar.

Some EEPROM have ECC :

 


RIP Opportunity | The Embedded Muse 368

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I  really appreciate the help I have gotten here.

We are working on next generation space suit components.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow!

 

edit :

Consider the bootloader's license as the licenses must be compatible (bootloader, application)

You will be able to find a bootloader that's compatible otherwise DIY given the STK500v2 protocol document and megaS128 datasheet.

 

edit2 :

boot.h | AVR Libc

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Jun 29, 2021 - 10:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am getting a little confused about how to set up AVRDude for my configuration.

My PC is connected to a USB-to-RS485 adapter, which appears as COM3 on the PC.

The RS485 is connected to USART0 of the ATmegaS128.

 

So there is no hardware programmer, such as ATMEL ICE.

The MEGACORE bootstrap must use the ATmegaS128 self-programming command to write to flash memory.

 

I have created a supplementary COLLINS.CONF file, which defines a "programmer" data structure.

I have set fields in the programmer data structure:

    id     = "CollinsCO2";

    desc = "Collins CO2 sensor ATmegaS128"

    type = "serialbb"

    connection_type = serial

    baudrate = 38400

    ;

 

My questions are:

    Should I make the CO2 sensor code jump to the bootloader first by sending a serial command to the CO2 sensor "AVRDUDE -P "com3" -c "CollinsCO2" SEND 0xFF 0xFF 0xFF 0xFF" etc. (There is a 4 byte limit per SEND?)

    Do I need the "type =" statement in COLLINS.CONF? I am not using a hardware programmer.

    I do not have to worry about protocol selection (UDF, FLIP etc)?

 

So far I have gotten AVRDUDE to accept the commands without complaint until the lack of a connection to the ATmegaS128 causes a timeout.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Suit Monkey wrote:
The MEGACORE bootstrap
an instance of the Optiboot bootloader (subset of STK500v1 AVR061)

Suit Monkey wrote:
Should I make the CO2 sensor code jump to the bootloader first by sending a serial command to the CO2 sensor "AVRDUDE ...
That's possible though usually don't go via the loader (AVRDUDE) (iow go via the host complement of the application ... loader <-> bootloader ... operator interface <-> real-time application ... an operator is pseudo real-time (tens of milliseconds neuro-muscular) whereas the application is real-time)

Two of many alternatives to AVRDUDE send is host-side PyUSB and pySerial.

Suit Monkey wrote:
Do I need the "type =" statement in COLLINS.CONF?
Yes though arduino.

Suit Monkey wrote:
I do not have to worry about protocol selection (UDF, FLIP etc)?
No though consider replacing worry with concern; protocol is by 'type'.

 


AN_2525 AVR061: STK500 Communication Protocol

 

copied from line 345 in AVRDUDE 6.3 'avrdude.conf' :

#
# PROGRAMMER DEFINITIONS
#

# http://wiring.org.co/
# Basically STK500v2 protocol, with some glue to trigger the
# bootloader.
programmer
  id    = "wiring";
  desc  = "Wiring";
  type  = "wiring";
  connection_type = serial;
;

programmer
  id    = "arduino";
  desc  = "Arduino";
  type  = "arduino";
  connection_type = serial;

 

Index of /releases/avrdude/

 

edit :

https://github.com/Optiboot/optiboot/blob/master/optiboot/examples/demo_reset/demo_reset.ino#L129

 

edit2 :

Instead of jumping to the bootloader, trip the watchdog; likely have an external watchdog to cycle power to overcome a latch-up.

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Mon. Jul 12, 2021 - 05:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I coded a jump to BOOT into my code.

        // disable interrupts so that nothing gets started by interrupt service
        cli();

        // turn off watchdog because boot mode will not service it
        saved_sreg = SREG;
        wdt_reset();
        wdt_disable();
        SREG = saved_sreg;

        __asm__( "JMP 0x1FC00" );    // go to bootstrap

After I jump to the boot, my application code restarts immediately. It does not stay in the bootloader.

The application code can display the value of MCUCSR and the "source of reset bits" are all zero. Usually I see that one bit is active.

Using the ATMEL Device Programming tool
        I compared FLASH against the OPTIBOOT hex file it failed on the first byte saying it should be 0x02, but its value was 0xFF.
        I read the FLASH memory into a hex file, and compared it to the OPTIBOOT hex file I used, and they agreed.

 

I think I have my fuses set correctly: fuses with    boot 0xFF, 0x95, 0xEF

I believe that I picked the correct OPTIBOOT hex file: M128, 8 MHz crystal 38.4 baud serial port.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Suit Monkey wrote:
        wdt_disable();
Try leaving the watchdog enabled.

Frequently Asked Questions | AVR Libc

[near bottom]

How do I perform a software reset of the AVR?

The canonical way to perform a software reset of non-XMega AVR's is to use the watchdog timer. Enable the watchdog timer to the shortest timeout setting, then go into an infinite, do-nothing loop. The watchdog will then reset the processor.

XMega parts have a specific bit RST_SWRST_bm in the RST.CTRL register, that generates a hardware reset. RST_SWRST_bm is protected by the XMega Configuration Change Protection system.

The reason why using the watchdog timer or RST_SWRST_bm is preferable over jumping to the reset vector, is that when the watchdog or RST_SWRST_bm resets the AVR, the registers will be reset to their known, default settings. Whereas jumping to the reset vector will leave the registers in their previous state, which is generally not a good idea.

CAUTION! Older AVRs will have the watchdog timer disabled on a reset. For these older AVRs, doing a soft reset by enabling the watchdog is easy, as the watchdog will then be disabled after the reset. On newer AVRs, once the watchdog is enabled, then it stays enabled, even after a reset! For these newer AVRs a function needs to be added to the .init3 section (i.e. during the startup code, before main()) to disable the watchdog early enough so it does not continually reset the AVR.

Here is some example code that creates a macro that can be called to perform a soft reset:

For newer AVRs (such as the ATmega1281) also add this function to your code to then disable the watchdog after a reset (e.g., after a soft reset):

 

well, that web doc is missing the embedded source code ... so

How do I perform a software reset of the AVR? | Frequently Asked Questions

 

P.S.

An external watchdog is preferred for when, not if, MCU latch-up.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After I jump to the boot, my application code restarts immediately. It does not stay in the bootloader.

The application code can display the value of MCUCSR and the "source of reset bits" are all zero. Usually I see that one bit is active.

Make sure you completely clear MCUCSR before jumping to the bootloader.  If ANY of the reset cause bits are set, it will interpret the restart as something other than "enter bootloader requested."