How to program AtMega1284P using AVRISP mkII on macOS?


#1

Hi guys, here is my platformio.ini

[plaformio]
env_default = atmega1284

[env:atmega1284]

platform = atmelavr
board = 1284p8m
framework = arduino
board_build.mcu = atmega1284p
board_build.f_cpu = 8000000L
lib_extra_dirs = ~/Documents/Arduino/libraries
extra_scripts = dist.py
# upload_port=/dev/cu.wchusbserial1410
upload_protocol = stk500v2
; each flag in a new line
upload_flags =
    -Pusb

upload_port = usb

My schematic looks like this but I used 8 MHz crystal and FT232 is not installed yet.

And information about the programmer

AVRISP mkII:

  Product ID:	0x2104
  Vendor ID:	0x03eb  (Atmel Corporation)
  Version:	2.00
  Serial Number:	001D2C991679
  Speed:	Up to 12 Mb/sec
  Manufacturer:	ATMEL
  Location ID:	0x14100000 / 27
  Current Available (mA):	500
  Extra Operating Current (mA):	0

This is compiler/avrdude output:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/zoonman/Projects/cpp/nanodds/cmake-build-debug --target PLATFORMIO_UPLOAD -- -j 4
Processing atmega1284 (framework: arduino; platform: atmelavr; board: 1284p8m)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Atmel AVR > Microduino Core+ (ATmega1284P@8M,3.3V)
SYSTEM: ATMEGA1284P 8MHz 16KB RAM (127KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit ST7735 and ST7789 Library> 1.2.4
|   |-- <SPI> 1.0
|   |-- <Adafruit GFX Library> 1.2.9
|   |   |-- <SPI> 1.0
|-- <Etherkit Si5351> 2.1.2
|   |-- <Wire> 1.0
|-- <Adafruit GFX Library> 1.2.9
|   |-- <SPI> 1.0
Checking size .pioenvs/atmega1284/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   7.2% (used 1185 bytes from 16384 bytes)
PROGRAM: [==        ]  21.9% (used 28536 bytes from 130048 bytes)
Configuring upload protocol...
AVAILABLE: stk500v2
CURRENT: upload_protocol = stk500v2
Looking for upload port...
Use manually specified: usb
*** [upload] could not open port usb: [Errno 2] No such file or directory: 'usb'

Programmer connected through J3.
I am trying to figure out how to specify USB port on macOS Mojave.


#2

After some extensive googling I have the following:

avrdude -p m1284p -c stk500v2 -P usb:16:79 -v

avrdude: Version 6.3, compiled on Dec 20 2018 at 23:10:28
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/opt/local/etc/avrdude.conf"
         User configuration file is "/Users/zoonman/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb:16:79
         Using Programmer              : stk500v2
avrdude: usbdev_open(): Found AVRISP mkII, serno: 001D2C991679
         AVR Part                      : ATmega1284P
         Chip Erase delay              : 55000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10   128    0 no       4096    8      0  9000  9000 0xff 0xff
           flash         65    10   256    0 yes    131072  256    512  4500  4500 0xff 0xff
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500 Version 2.x firmware
         Programmer Model: AVRISP mkII
         Hardware Version: 1
         Firmware Version Master : 1.24
         Vtarget         : 4.9 V
         SCK period      : 4.00 us

avrdude: stk500v2_command(): command failed
avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Unknown status 0x00
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

I had to install avrdude using MacPorts and started running it from command line.
Because I don’t have FT232 installed I suspect it cannot program the controller because RESET line is not pulled up to +5V.
Should I install some resistor and check?


#3

It seems works from time to time but I suspect I have loose connection somewhere.

avrdude -p m1284p -c stk500v2 -P usb:16:79 -v

avrdude: Version 6.3, compiled on Dec 20 2018 at 23:10:28
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/opt/local/etc/avrdude.conf"
         User configuration file is "/Users/zoonman/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb:16:79
         Using Programmer              : stk500v2
avrdude: usbdev_open(): Found AVRISP mkII, serno: 001D2C991679
         AVR Part                      : ATmega1284P
         Chip Erase delay              : 55000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10   128    0 no       4096    8      0  9000  9000 0xff 0xff
           flash         65    10   256    0 yes    131072  256    512  4500  4500 0xff 0xff
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel STK500 Version 2.x firmware
         Programmer Model: AVRISP mkII
         Hardware Version: 1
         Firmware Version Master : 1.24
         Vtarget         : 4.9 V
         SCK period      : 4.00 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude: safemode: hfuse reads as 99
avrdude: safemode: efuse reads as FF

avrdude: safemode: hfuse reads as 99
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:99, L:62)

avrdude done.  Thank you.

#4

Still can’t figure out how to specify usb port for platformio.

upload_protocol = avrsip2
; each flag in a new line
upload_flags =
    -v
    -Pusb:16:79
upload_port = usb:16:79

Doesn’t work for me.


#5

Use the -v option (e.g. pio run -v -t upload) to see what commandline is executed for the upload so that you can adjust your upload_flags to match your previous successful run.


#6

Not really showing me anything special.

<lambda>(["upload"], [".pioenvs/atmega1284/firmware.hex"])
AVAILABLE: avrsip2
CURRENT: upload_protocol = avrsip2
BeforeUpload(["upload"], [".pioenvs/atmega1284/firmware.hex"])
Use manually specified: usb:16:79
*** [upload] could not open port usb:16:79: [Errno 2] No such file or directory: 'usb:16:79'

#7

After enormous amount of research I found https://github.com/maniacbug/mighty-1284p bootloader. It seems works but has a glitch for progmem access. All my PSTR constants have wrong address.

For programming I am using avrdude.

avrdude -p m1284p -c avrisp2 -P usb:16:79 -e -U flash:w:atmega1284/firmware.hex -v

Looks like platformio tool doesn’t work properly with AVRISPMkII.


#8

I am using an avrispmk2 and it works pretty well.

Try upload_protocol/-c “avrispmkii” or “wiring”.


#9

I tried. Didn’t work for me. Sorry.


#10

I figured out that 3.3V power supply supposed to be removed from LCD and after programmer starts working flawlessly.
Looks like ST7735 SDA holds MOSI and it messes up programmer.