Arduino to Atmel Studio 7 external programmers, ISP and serial programming

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

Hopefully this will help someone on a similar transition from Arduino to AS7, took a couple days to piece this together from various sources.

 

Moving from Arduino to AS7.

For me it was not immediately clear how to program with the hardware that I had, which is a USB FTDI cable for serial upload, and a sparkfun pocket programmer.

The pocket programmer can be used to burn fuses, upload an entire sketch, or a bootloader like optiboot.

With a bootloader burned, the FTDI cable can load a program over serial in AS7 just like Arduino.

 

 

in AS7

Tools-> External tools

Enter these items for atmega 328 programming.

Of course tools, fuse values, and chips can be changed, refer to avrdude documentation to adjust arguments.

 

generic

title: "name of programmer"

command: " location of avrdude.exe"

arguments: " avrdude command line arguments including fuses if desired"

 

particular

This is for ISP programming with no bootloader and the Sparkfun pocket programmer.

Title: PocketAVR m328p 4.3v 

Command: G:\AVRDude\avrdude.exe  

arguments: c usbtiny -p m328p -v -v -v -U flash:w:$(TargetDir)$(TargetName).hex:i -c usbtiny -p m328p -v -U efuse:w:0xFC:m -c usbtiny -p m328p -v -U lfuse:w:0xF7:m -c usbtiny -p m328p -v -U hfuse:w:0xD6:m

These particular arguments program a 328p with the current project and sets e l h fuse values.

 

This is for programming a 328p that has optiboot loaded on it already using USB FTDI cable

Title: FTDI serial uploader for Optiboot

Command: G:\AVRDude\avrdude.exe

arguments: -C  "G:\AVRdude\avrdude.conf"  -v -v -v  -p atmega328p -c arduino -P\\.\COM3 -b 115200 -D -U flash:w:$(TargetDir)$(TargetName).hex:i

*my ftdi cable mounts to COM3, yours may differ

 

This is for burning the optiboot bootloader and fuses on a 328p

Title: Burn Bootloader Optiboot m328 4.3v

Command: G:\AVRDude\avrdude.exe

arguments: -c usbtiny -p m328p -v -v -v -U flash:w:"G:\AVRdude\optiboot_atmega328.hex":i -c usbtiny -p m328p -v -U efuse:w:0xFC:m -c usbtiny -p m328p -v -U lfuse:w:0xF7:m -c usbtiny -p m328p -v -U hfuse:w:0xD6:m

 

Note that the bootloader argument includes the path to the optiboot hex file.

Compiled optiboot hex files available on github.

Adjust fuse values to suit your needs.

 

These tools are not integrated with AS7 and to program with them click on them in the Tools menu after compiling.

Sure eventually I will get an Atmel Microchip programmer but this was a pretty easy way to get going for low $$.

 

later

 

 

 

 

Attachment(s): 

Last Edited: Mon. Aug 6, 2018 - 01:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A candidate for the Tutorial Forum, +1! 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
https://www.onegold.com/join/7134f67c2b814c5ca8144a458eccfd61

 

 

 

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

Hi BugMaster,

I've seen a more universal solution on mikrocontroller.net when searching how to flash Leonardo from AS. It's a python script and seem to work with all the boards, however, it needs Arduino IDE and Python to be installed.  Here is my slightly modified version:

import sys
import subprocess as sub
from time import sleep
 
# command line arguments are:
# first is the arduino IDE installation dir
# second is the arduino board type
# third is the .hex file
# fourth is the upload port
# fifth *** only used if Leonardo; omit otherwise *** serial port used to put leonardo into bootloader mode 
 
arduinoPath = sys.argv[1]
boardType = sys.argv[2]
hexFile = sys.argv[3]
port2 = sys.argv[4]
 
if(boardType == 'leonardo'): #TODO check for Micro (also 32u4 based)
   import serial
   port = sys.argv[len(sys.argv)-1]
 
avrconf = arduinoPath + '/hardware/tools/avr/etc/avrdude.conf'
avrdude = arduinoPath + '/hardware/tools/avr/bin/avrdude'
avrsize = arduinoPath + '/hardware/tools/avr/bin/avr-size'
 
boardsFile = open(arduinoPath + '/hardware/arduino/avr/boards.txt',
   'rb').readlines()
 
boardSettings = {}
 
for line in boardsFile:
    if(line.startswith(boardType)):
          # strip board name, period and \n
        setting = line.replace(boardType + '.', '', 1).strip()
        [key, sign, val] = setting.rpartition('=')
        boardSettings[key] = val
 
    # check program size against maximum size
p = sub.Popen([avrsize,hexFile], stdout=sub.PIPE, stderr=sub.PIPE)#, shell=True)
output, errors = p.communicate()
if errors != "":
    print 'avr-size error: ' + errors + '\n'
    exit
 
    print ('Progam size: ' + output.split()[7] +
    ' bytes out of max ' + boardSettings['upload.maximum_size'] + '\n')
 
programCommand = [avrdude,
    '-C'+avrconf,
     '-F' ,
     '-p'+boardSettings['build.mcu'] ,
     '-c'+ boardSettings['upload.protocol'] ,
     '-b' + boardSettings['upload.speed'] ,
     '-P'+port2,
     '-Uflash:w:'+hexFile+':i']
 
    # open and close serial port at 1200 baud. This resets the Arduino Leonardo
if(boardType == 'leonardo'):
    ser = serial.Serial(port, 1200)
    ser.close()
    sleep(4)  # give the bootloader time to start up
 
p = sub.Popen(programCommand, stdout=sub.PIPE, stderr=sub.PIPE)#, shell=True)
output, errors = p.communicate()
# avrdude only uses stderr, append it
print errors

So in your External tools for Arduino Leonardo you should have smth like

Command: C:\Python27\python.exe

Arguments: "D:\coding\mcu\arduinoUpload.py" "C:\Program Files (x86)\Arduino" leonardo "$(ProjectDir)Debug\$(TargetName).hex" COM16 COM14