Re: [Amforth] Newbie with a mega2560
Hi Michael, Apologies. My memory is failing me. The LED is on D13 for both UNO and MEGA, but D13 is mapped to PB5 (PORTB bit 5) on the UNO and PB7 (PORTB bit 7) on the MEGA. Best wishes, Tristan On 2021-05-21 08:54, tristan wrote: Hi Michael, I do not see the word 'marker' defined. Should it have been part of the basic system, or do I need to pull it from somewhere? It is not part of the basic system, it is defined in this file. avr8/lib/forth2012/core-ext/marker.frt Using marker is efficient/good practice/etc. but it is not a necessary requirement to do below. Then I'd like to see about doing something real simple, like turning an LED on/off. It's sort of a hardware person's approach to 'Hello World!' :) http://amforth.sourceforge.net/TG/recipes/Arduino-HelloWorld.html IIRC the MEGA and UNO have the built-in led on the same pin (port bit). The definitions for the chip can be found in this file avr8/devices/atmega2560/atmega2560.frt These, or extracts from, will need to be loaded into the basic system. So longer term, being able to load forth definition non-interactively from a file is very useful. There are programs in the tools directory - amforth-shell.py being the one I use. Best wishes, Tristan On 2021-05-21 05:25, Michael Picco wrote: Hello, As mentioned earlier, it's now working. I do not see the word 'marker' defined. Should it have been part of the basic system, or do I need to pull it from somewhere? Then I'd like to see about doing something real simple, like turning an LED on/off. It's sort of a hardware person's approach to 'Hello World!' :) Kind regards, Michael K6MLE On 5/20/2021 12:41 PM, Michael Picco wrote: I should add the following changes to Craig Lindley's write-up: Step 3: Under Win10, the correct file location for avrasm2.exe will be: c:\Program Files(86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\avrasm2.exe Also needed in the work directory isatmega256.asm and m2560def.inc The image of the directory structure didn't post to the list, so I'm showing it below (my work directory is called "amforth-ATmega2560-6.9": -- appl -- arm -- avr8 -- common -- doc -- examples -- msp430 -- risc-v -- shared -- tests -- tools -- words atmega256.asm avrasm2.exe device.asm (for the 2560) device.inc (for the 2560) dict_appl.inc dict_appl_core.inc LICENSE.txt m2560def.inc make.bat readme.txt uno.asm Hope this helps! Kind regards, Michael K6MLE On 5/20/2021 11:56 AM, Michael Picco wrote: Hello All! I have finally had success! It turns out that the .eep and .hex files I was flashing into the 2560 were corrupted! I followed Craig Lindley's write-up with modifications for the 2560. Changed the make.bat file to read: avrasm2.exe -fI -o atmega2560.hex -e atmega2560.eep -l atmega2560.lst -I g:\amforth-atmega2560\common -I g:\amforth-atmega2560\avr8 -I g:\amforth-atmega2560\avr8\drivers -I include -v0 atmega256.asm This is the resulting file structure prior to executing make.bat: The fuse setting in Studio 7 were set as follows: E: 0xFF, H: 0xDC, L:0xFF Programmed the fuses; set the new files up in Studio 7 for flash and EEPROM; programmed the .hex and .eep files. Have a nice prompt for "amforth 6.9 ATmega2560 Forthduino" !!! I'm hoping this exercise might help others. Kind regards, Michael K6MLE On 5/18/2021 8:51 AM, tristan wrote: Hello Michael, Getting AmForth up and running from archive hex files on a mega2560 is reasonably straightforward, however, I don't use Microchip Studio version 7 or win10 so I can't help with this tool set. I hope you able to translate the macos/linux to your tools - and if so a write-up would be very welcome! As pointed out you need a programmer (such as usbtiny, usbasp, avrisp2 etc.) and a program to talk to the programmer (such as avrdude). Both atmega2560.hex and atmega2560.eep.hex need to be written to the mega2560's flash/eeprom. Below are the command lines I use with avrdude avrdude -p m2560 -c usbtiny -U flash:w:atmega2560.hex:i avrdude -p m2560 -c usbtiny -U eeprom:w:atmega2560.eep.hex:i Flashing these file will overwrite any existing bootloader. It is worth considering whether you are able to reverse this should you wish to, before flashing the above files. If your mega2560 is an Arduino style board, and the default fuses unchanged, then IIRC there is no need to reprogram the fuses. Once the files have been flashed, you should be able to connect to the mega2560 over serial using 38400 8N1. I use minicom and amforth-shell.py You will need to identify the name of the serial device created by the USB to SERIAL chip on your board/setup to use any serial program. Once connected you have the AmForth interpreter prompt and can interact, compile new words, and generally use the system. However, AmForth is modular and not all functionality is contained in the flashed hex files. For I2C and SPI new words need to be defined. These definitions are already available within the
Re: [Amforth] Newbie with a mega2560
Hi Michael, I do not see the word 'marker' defined. Should it have been part of the basic system, or do I need to pull it from somewhere? It is not part of the basic system, it is defined in this file. avr8/lib/forth2012/core-ext/marker.frt Using marker is efficient/good practice/etc. but it is not a necessary requirement to do below. Then I'd like to see about doing something real simple, like turning an LED on/off. It's sort of a hardware person's approach to 'Hello World!' :) http://amforth.sourceforge.net/TG/recipes/Arduino-HelloWorld.html IIRC the MEGA and UNO have the built-in led on the same pin (port bit). The definitions for the chip can be found in this file avr8/devices/atmega2560/atmega2560.frt These, or extracts from, will need to be loaded into the basic system. So longer term, being able to load forth definition non-interactively from a file is very useful. There are programs in the tools directory - amforth-shell.py being the one I use. Best wishes, Tristan On 2021-05-21 05:25, Michael Picco wrote: Hello, As mentioned earlier, it's now working. I do not see the word 'marker' defined. Should it have been part of the basic system, or do I need to pull it from somewhere? Then I'd like to see about doing something real simple, like turning an LED on/off. It's sort of a hardware person's approach to 'Hello World!' :) Kind regards, Michael K6MLE On 5/20/2021 12:41 PM, Michael Picco wrote: I should add the following changes to Craig Lindley's write-up: Step 3: Under Win10, the correct file location for avrasm2.exe will be: c:\Program Files(86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler\avrasm2.exe Also needed in the work directory isatmega256.asm and m2560def.inc The image of the directory structure didn't post to the list, so I'm showing it below (my work directory is called "amforth-ATmega2560-6.9": -- appl -- arm -- avr8 -- common -- doc -- examples -- msp430 -- risc-v -- shared -- tests -- tools -- words atmega256.asm avrasm2.exe device.asm (for the 2560) device.inc (for the 2560) dict_appl.inc dict_appl_core.inc LICENSE.txt m2560def.inc make.bat readme.txt uno.asm Hope this helps! Kind regards, Michael K6MLE On 5/20/2021 11:56 AM, Michael Picco wrote: Hello All! I have finally had success! It turns out that the .eep and .hex files I was flashing into the 2560 were corrupted! I followed Craig Lindley's write-up with modifications for the 2560. Changed the make.bat file to read: avrasm2.exe -fI -o atmega2560.hex -e atmega2560.eep -l atmega2560.lst -I g:\amforth-atmega2560\common -I g:\amforth-atmega2560\avr8 -I g:\amforth-atmega2560\avr8\drivers -I include -v0 atmega256.asm This is the resulting file structure prior to executing make.bat: The fuse setting in Studio 7 were set as follows: E: 0xFF, H: 0xDC, L:0xFF Programmed the fuses; set the new files up in Studio 7 for flash and EEPROM; programmed the .hex and .eep files. Have a nice prompt for "amforth 6.9 ATmega2560 Forthduino" !!! I'm hoping this exercise might help others. Kind regards, Michael K6MLE On 5/18/2021 8:51 AM, tristan wrote: Hello Michael, Getting AmForth up and running from archive hex files on a mega2560 is reasonably straightforward, however, I don't use Microchip Studio version 7 or win10 so I can't help with this tool set. I hope you able to translate the macos/linux to your tools - and if so a write-up would be very welcome! As pointed out you need a programmer (such as usbtiny, usbasp, avrisp2 etc.) and a program to talk to the programmer (such as avrdude). Both atmega2560.hex and atmega2560.eep.hex need to be written to the mega2560's flash/eeprom. Below are the command lines I use with avrdude avrdude -p m2560 -c usbtiny -U flash:w:atmega2560.hex:i avrdude -p m2560 -c usbtiny -U eeprom:w:atmega2560.eep.hex:i Flashing these file will overwrite any existing bootloader. It is worth considering whether you are able to reverse this should you wish to, before flashing the above files. If your mega2560 is an Arduino style board, and the default fuses unchanged, then IIRC there is no need to reprogram the fuses. Once the files have been flashed, you should be able to connect to the mega2560 over serial using 38400 8N1. I use minicom and amforth-shell.py You will need to identify the name of the serial device created by the USB to SERIAL chip on your board/setup to use any serial program. Once connected you have the AmForth interpreter prompt and can interact, compile new words, and generally use the system. However, AmForth is modular and not all functionality is contained in the flashed hex files. For I2C and SPI new words need to be defined. These definitions are already available within the archive, but need to be loaded onto a "new" AmForth system. I find amforth-shell.py very helpful for automating this process. The cookbook is a great place to see examples of how things can be done http://amforth.sourceforge.