User Tools

Site Tools


atmega32

How to flash ATmega32

This guide is for the Z80-MBC2 and V20-MBC board.

Programmer Setup

A cheap and easy way to burn the Arduino bootloader is to use an USBasp programmer that is commonly available:


The USBasp is also capable to give the power to the “target” using the VCC pin, but remember to check that the JP1 jumper is set to provide 5V to the target (as shown in the photo).
Please note that the pinout of the USBasp is a little different from the “standard” ICSP (os ISP) pinout:


In the previous picture it is possible see that pins 4 (TXD) and 6 (RXD) are not at GND as expected by the standard ICSP port, and pin 3 is not NC.
See the following picture showing the standard 10 pin ICSP pinout:


So you must consider this when connecting the USBasp to the 6 pins ICSP port (J3) on the Z80-MBC2 (see the schematic):


To avoid problems I suggest to use as GND pin 10 of the USBasp connector, and connect the other pins (VCC, MISO, MOSI,SCK, RST) accordingly. An handy way to connect the USBasp to the 6 pin ICSP port (J3) of the Z80-MBC2 could be to use a commonly available “10pin to 6pin” adapter like this:


but I suggest not to use it “as is” because its internal connections are done for a “standard” ICSP port, and we have seen that the USBasp connector differs from the standard one. The schematic of the adapter shows that isn't compatible “as is” with the UABasp connector:


To use it is a good idea isolate the pins 4, 5 and 6 cutting the trace on the PCB of the adapter that connects those pins together, and then check with a tester.
In the following photo are shown the three cuts (thin red lines inside the green “circle”) to do:


User (GNU/Linux) Setup

For use Arduino IDE as user, is need add your User_name to the groups dialout and uucp, this for enable access to USB programmer and USB serial adapter.

sudo usermod -aG dialout,uucp Name_of_your_user_login

Arduino IDE (GNU/Linux) Setup

To easily burn the bootloader from Arduino IDE follow these “quick and dirty” steps (tested on a openSUSE OS with Arduino IDE 1.8.19):
open Discover tool, search “arduino” and install Arduino IDE.


Now you will see the Arduino IDE icon on your desktop.


this is the main screen of Arduino IDE version 1.8.19


FilePreferences


Click on the button to the right of Additional Boards Manager URLs: as shown in the figure, and enter the following line:

https://mcudude.github.io/MightyCore/package_MCUdude_MightyCore_index.json


Click the OK button, and then click OK again in Preferences.

Now click on ToolsBoardBoards Manager…, search MightyCore and install the version 2.2.2


Extended serial Rx buffer Setup

Because the Z80-MBC2 uses a virtual serial port without handshaking there is a timing problem when dealing with the 128 bytes packets used by the XMODEM protocol.
So the support to the XMODEM protocol has requested changes to extend the serial port RX buffer to 128 bytes.
Thanks to user Hans who pointed me to the right direction, there is a simple way to modify the size of the RX buffer used for the serial port.
Search the file boards.txt related with the MightyCore variant in your Arduino IDE.
The file is located in the hidden directory:

/home/<username>/.arduino15/packages/MightyCore/hardware/avr/2.2.2/ 

Open board.txt with an editor and locate the section related to the Atmega32/A:
go some lines down until you see the 32.menu.LTO.Os.compiler.cpp.extra_flags= line:
then append the string -DSERIAL_RX_BUFFER_SIZE=128 to that line:


Save the edited board.txt file.
All done!
At this point you can recompile with the LTO option disabled and flash the IOS inside the Atmega32A with the extended RX buffer enabled.
Please remember that if you update the MightyCore you will lose the changes. In this case re-apply the previous steps.
Note that IOS checks if this extended buffer is active, and in this case will print a status line during the boot phase:
IOS: Found extended serial Rx buffer

Flash the Bootloader

  1. Connect the 10 pins connector of the USBasp programmer to the 6 pins ICSP port (J3) of the Z80-MBC2 (using wires or a modified adapter as discussed before);
  2. Verify carefully that any other connector of the Z80-MBC2 is not used, and verify that both the SD and RTC modules (if present) are removed from the board;
  3. On ToolsProgrammer select USBasp
  4. Only at this point connect the USB side of the USBasp programmer to an USB port of your workstation;


On Tools → click on Burn Bootloader


The message Done burning bootloader shows that the bootloader was written successfully


Flash the Z80-MBC2 IOS firmware

On ToolsBoardMightyCore click on ATmega32


Clock: External 16 MHz
BOD: BOD disabled
EEPROM: EEPROM retained
Compiler LTO: LTO disabled
Pinout: Standard pinout


On Sketch click on Upload Using Programmer


Uploading…


Done uploading


FIrmware

The sketch for the IOS (with the needed libraries).
Unzip into a folder and open the .ino file (with Arduino IDE).
IOS must be uploaded into the Atmega32A flash.
Adds support for Fuzix OS and the SPP Adapter board.
S220718-R290823_IOS_Z80-MBC2.zip.

atmega32.txt · Last modified: 2025/03/22 17:53 by admin