High Voltage Coils

electrical and mechanical engineering

Home - low voltage experiments - How to use Atmel’s “atprogram” cli command line interface to program a production file into an xmega

How to use Atmel’s “atprogram” cli command line interface to program a production file into an xmega

Posted on 12. September 2017 in low voltage experiments

Hi all,
a very long headline for this simple task, but it hits the spot! Former Atmel (now Microchip) provides a very powerful back end programmer, intended to be used within a production line, to automate the programming process, without having to use Atmel Studio.

What are the benefits of using a production file? Very simple, have the user signatures, eeprom, flash and fuses combined in a single file. Then write a little batch script to burn this elf image into multiple micro controllers.

 

1.) How to generate a production file?

Open your project with Atmel Studio, then enter the “Device Programming” dialog. There is a own tab called “production file”. Use the lower half of the dialog, below the “Save to ELF production file” line. Choose a valid hex file for the flash, optional a eeprom and user signitures file. Then choose which of the files should be stored from the check boxes. Note that it is also possible to store the fuses and lockbits. If checked, the fuses and lockbits of the currently connected micro controller will be stored, so make sure they are configured correctly. Click on the “Save” button to store the production file.

 

2.) How to flash a production file from Atmel Studio?

Test your production file by using the upper part of the dialog. Enter a filename into “Program device from ELF production file”. Next choose which part of the production file you want to flash, all none existing parts will be grayed out and are not select able! Click on “Program” to flash the whole device with a single mouse click, very handy 😉

 

3.) How to flash a production file from a batch scrip without Atmel Studio?

Create an empty text file and name it “start_flash.bat”. Copy the textfile provided below, alter your device and tool, then start flashing.

@echo off
cd "C:Program Files (x86)AtmelStudio7.0atbackend"
c:
atprogram -t atmelice -i pdi -d atxmega32a4 program -c -fl -fs --verify -f "d:mytestfile.elf"
pause

After execution will result in the following console output.

 

A little bit of explanation:

“@echo off” will silence the console directory output after each script command, when removed, the result will be much more unreadable

“cd” will change the directory to the atbackend path of the Atmel Studio installation folder, make sure this folder matches your installation path

“c:” is just here for the purpose if you start your batch script from a different drive then c:

“atprogram” is used to do the heavy lifting
“-t atmelice” means which tool i want to use, enter “atprogram list”  to see all available tools, for example my output
simulator       No serialnumber found
atmelice        J41800059125
“-i pdi” means i want to use the pdi interface for programming
“-d atxmega32a4” is my target microcontroller

“program” means i want to flash the contents of a file
“-c” perform a chip erase
“-fl” write flash
“-fs” write fuses
“–verify” after programming, memory contents need to match the target file
“-f <filepath>” this is my production file

4.) I want additional information about the features of atprogram!

use the console commands
“atprogram help” to get a full list of features.
It is also possible to get additional information about a single command, for example
“atprogram help program” will give you detailed information about all command line parameters available for the “program” command.

10 thoughts on “How to use Atmel’s “atprogram” cli command line interface to program a production file into an xmega”

  • William Watson says:

    Thanks for posting this. You provided me just the clues I needed to get my Atmel CPU programmed.

    Very best regards,

    William

  • James Bundock says:

    Thanks for the info, I have a need to use the atprogram to write some calibration data to EEPROM space. There is advice regarding this but I am confused as to how to ascertain the address to which my data will actually be written.

    Memory Writing Command Usage
    Usage: atprogram [options] write .
    Information: Write to the memory with values entered on the command line. The values provided will be
    written to all selected address spaces. At least one address space must be provided.
    Options: Execute the atprogram without arguments to list the available options.
    Arguments: -fl –flash: Write to flash. tinyAVR, megaAVR, and AVR XMEGA only.
    -ee –eeprom: Write to EEPROM. tinyAVR, megaAVR, and AVR XMEGA only.
    -us –usersignature: Write to user signature.
    AN2466
    © 2017 Microchip Technology Inc. Application Note DS00002466A-page 9
    -fs –fuses: Write to fuses.
    -lb –lockbits: Write to lockbits.
    –values (value): Hex encoded values to write, e.g.: 0102040A0F.
    -o –offset (offset): Values are written from this offset.
    -v –verify: Verify memory contents after write.

    • atprogram -t atmelice -i ISP -d atmega328pb write -ee –values c0

    would write c0 to the EEPROM — but where? My code needs to access it with something like

    eeprom_read_word(const uint16_t somehexaddress)

    • Michael says:

      Dear James,
      you might write values to the eeprom directly from your sourcecode,
      the address range for this also starts from 0x0000 and ends with your eeprom size,
      for example 2k will end at 0x07FF. if i was in your place, i would try to
      put the values first in the eeprom (via hexfile, via source code, via compiler defines, via binary file etc…), then read a hexfile from the controller.
      if you manage that, it is very easy to program that read hexfile with the command line interface.

      • James Bundock says:

        The idea is I have an instrument that I’ve built and a board tester to calibrate it. I wanted to take an already flashed part and call the atprogram from my C# driven board tester and simply store the calibration values in known locations that the atmega328 could read. I’ve successfully manually wrote the eeprom using atmel studio 7. and my atmega328 cpp code works fine reading the value. But I have 100+ boards that I’d like to test, calibrate (write to eeprom) and retest (verify calibration) in situ. It seems strange that Atmel studio 7 makes it so easy to write the eeprom manually, but there doesn’t appear to be a field to specify the address where one would write the data in CLI

        • Michael says:

          Dear James,
          if you are already on c#, then test your board, store the calibration values in a hex file and then call the CLI. Hexformat is straight forward and very easy to implement.

          I took a quick view on the additional parameters, but for me it looks like there is no easy way to write a single byte / word on the chips.

  • James Bundock says:

    I figured it out … I was looking for the -o parameter which specifies the “offset” address from EEPROM starting 0x0000 address. So the syntax below works …

    atprogram -t atmelice -i ISP -d atmega328p write -ee -o 0x001E –-values 1900002D00

    putting a 16 bit word 1900 at 0x001E, a byte of 00 then another 16 bit word of 2D00 (of course everything is lowbyte highbyte)

    Thank you for your suggestion though. Thought I’d post to help anyone else — I must have been a bit sleepy when using the -help command to have missed the -o parameter.

  • ben says:

    I have a Circuit Playground Express (SAMD21G), that flashes fine using Keil/uLinkPro using command line:

    UV4 -f TestProj.uvprojx -t”TestTgt” -o Output.txt

    But I want to use Atmel, so I’ve copied the pertinent files as identified here,

    https://microchip.secure.force.com/microchipknowledge/articles/en_US/FAQ/atprogram-standalone-utility

    But this doesn’t work, and not sure what’s missing:

    atprogram -t atmelice -i jtag -d SAMD21G program -c -fl -f TestTgt.elf

    • Michael says:

      Dear Ben,
      i would try to install the whole atmel studio and see if you can establish a connection to your controller there. maybe also the order of the parameters you apply has an impact on the functionality?

  • Anh Le says:

    Hi, could someone please help me.
    I want to read back hex file to check specific key number. I can read back by using atmel studio but I don’t know where I did wrong when use command line

    atprogram -t atmelice -i swd -d ATSAMD21E16B read -lb

    an error happen like this
    [Error] An error occurred executing a command (read): No matching segment memory found on the device: None

    please if someone could help me I stuck with it for few days and still not find any solutions

    • Michael says:

      Hi Anh Le,
      my guess is that you want to read back the lockbits of the chip, which the -lb would indicate?

      the spec gives an example for writing:
      atprogram -t atmelice -i ISP -d atmega328pb write -lb –values c0

      In theory your command line should work
      atprogram -t atmelice -i swd -d ATSAMD21E16B read -lb

      but the error message
      No matching segment memory found on the device: None
      could indicate that your device has no lockbits ? or is write only ? Did you check your
      uC Manual on that case?
      maybe the device uses a different kind of protecting the flash,
      but this is just a guess because i have no experiance with SAM, only AVR.

Leave a Reply

Your email address will not be published. Required fields are marked *