Getting your Bootloader working

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
TimC
Posts: 12
Joined: 25 January 2006, 7:22 AM
Location: Boston, MA

Getting your Bootloader working

Post by TimC »

Hi All,
At first I had a lot of difficulties getting the boot loader on Generic Targets to work with the IDE. Now it's easier so I wanted to share what I found. First there is lots of DOC's already here but to those who are just starting here is the basic list on what you have to do:

1 - Make the bootloader selecting the Chip, clock speed, maybe others using MAKEBOOT.BAT
2 - Set Fuse Bits (i.e. Low, High, maybe Extended) using microchip studio or other programs
3 - Flash your new bootloader .hex File using a hardware programmer like AVRISP
4 - Set Lock Bits using microchip studio again or maybe atprogram.exe
5 - Check IDE settings Options --> Serial Port ATN Period = 10mills, ATN Duty Cycle 4% or more
6 - Troubleshooting tips to test you bootloader and circuit
7 - Within your code add Options to define the chip you are using to the compiler.
8 - Add the file SciTEUser.properties (open local options file) to automate the GO command

--------------------------
1- Make the bootloader
This has been covered before. The gotcha in windows is having to move the directory away from c:\Program Files
Just make a few edits to makeboot and run. Good idea to rename the .hex file created with the xtal speed for future reference.

--------------------------
2- Set fuses
Using microchip studio and a hardware programmer and a small development board supplying power and connections to the programmer.
This was tricky at first but I made some changes that make sense.
Example is for ATMega32:
Boot size < 128k 1k. (512k words) BIG chips its 2K (1K words)
CKOPT - checked for more power
CKSEL - Ext Crystal Osc 8.0 - 20MHz 1K clock + 4ms
For example the ATMega32 might be High:xC2 Low:x8F
The ATMega 1284P might be High:xD4 Low: xD7 Extended: xFd

--------------------------
3. Flash you new bootloader you just made in step 1 using your hardware device like Atmel-ICE or STK500

--------------------------
4. Set lock bits
Just like you did in step 2. Actually Steps 2-4 can all be done through Microchip Studio or via 3 lines of ATprogram.exe
Lock Bits:xCF or x0F depending on chip

--------------------------
5. Check ZBASIC IDE settings: Options --> Serial Port Options
1% duty cycle may not be enough. The DTR circuit is Documented in the ZX-40 circuit using a 2N3904.
4% duty cycle worked with all the chips I tried.

--------------------------
6 - Troubleshooting tips:
Use a serial port monitor program to see what the device is actually sending. The application note AN-101 describes the protocol and details what you should see (in particular, Section 5.0). Getting the "%" prompt is a big first step. Getting the Chip ID is another.

Is the bootloader responding properly to the DTR toggling? If the ZBasic GUI does not think that the device is responding properly. It gives an error stating:
Device failed to respond to ATN signal on COM1.

Command line Test with zload -i


--------------------------
7 - Add Options in your code to define the chip:
Option TargetDevice ATmega328P
Option DeviceParameter package "PDIP-28"
Option DeviceParameter clockFrequency 16000000
Option DeviceParameter ZBasicBootloader True
at a minimum

--------------------------
8 - Add the the SciTEUser.properties. (open local options file) Here an example using ATprogram and macros. This will help connecting to the Bootloader and downloading your new compiled edits.

'--- Macros that assist with changes and syntax
atprogram.begin="C:\Program Files\Atmel\Studio\7.0\atbackend\atprogram.exe" -d $(target_device)
atprogram.ispmk2=-t avrispmk2 -i isp
atprogram.oneJ=-t avrone -i jtag
atprogram.FLload=-v program -c -fl -f "$(project.base).hex"
atprogram.EEPload=program --format hex -ee -f "$(project.base).eep"

'--- Origional atprogram command line for reference
'command.project.avr.go="C:\Program Files\Atmel\Studio\7.0\atbackend\atprogram.exe" -d $(target_device) -t avrispmk2 -i isp -v program -c -fl -f "$(project.base).hex" program --format hex -ee -f "$(project.base).eep"

'--- un-comment the line you want to use
'command.project.avr.go=$(atprogram.begin) $(atprogram.ispmk2) $(atprogram.FLload)
'command.project.avr.go=$(atprogram.begin) $(atprogram.ispmk2) $(atprogram.FLload) $(atprogram.EEPload)
'command.project.avr.go=$(atprogram.begin) $(atprogram.ispmk2) info


------------------------------------------------
Good luck a lot can go wrong. It may be easier to run without a bootloader at first for experience. Being able to talk to the bootloader through the async terminal proves you are almost there.

Regards
Tim





Docs:
http://www.zbasic.net/doc/ZBasicRef.php?page=130
Also useful:
http://www.zbasic.net/arduino.php
Post Reply