User Tools

Site Tools


flash_the_atmega

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
flash_the_atmega [2013/10/03 15:00] – created breaker27flash_the_atmega [2023/03/01 19:40] (current) – [Using flash scripts] breaker27
Line 1: Line 1:
-===== Get the firmware =====+====== Get the firmware ======
  
-You can either take a pre-built firmware package from [[http://www.smarthomatic.org/builds/builds.html]] or build your own firmware. If you take the prebuilt package, extract it and continue with "Flashing the controller".+You can either take a pre-built firmware package from [[http://www.smarthomatic.org/builds/builds.html]] or [[build your own firmware|build your own firmware]]. If you take the prebuilt package, extract it to a directory of your choice.
  
-===== Build your own firmware =====+====== Three different storage areas ======
  
-Get a copy of the project, if you haven't already. When you're running Debian (or another Linuxthis will do the job<code>git clone git://github.com/breaker27/smarthomatic</code> +Every microcontroller has three parts that can be flashed (written):
-Go into the base station firmware directory, build the firmware+
  
-<code>pi@ninjablock ~/test $ cd smarthomatic/firmware/shc_basestation/ +  * Three **fuse bytes** contains microcontroller specific configuration bits. These should only be set once. 
-pi@ninjablock ~/test/smarthomatic/firmware/shc_basestation $ make +  * The **flash memory** contains the firmware. It can be overwritten about 10.000 times
-avr-gcc -c -gdwarf-2 -DF_CPU=20000000UL -DUART_BAUD_RATE=19200UL -DUART_RX=1UL -Os -mmcu=atmega328 -I -fdata-sections -ffunction-sections -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wundef -std=c99  -Wa,-adhlns=build/ +  * The **EEPROM memory** contains (firmware) configuration dataIt is also written to by the device in normal operationIt can we overwritten about 100.000 times.
-[...] +
-avr-objdump -h -S build/shc_basestation.elf > build/shc_basestation.lss +
-avr-nm -n build/shc_basestation.elf > build/shc_basestation.sym+
  
-Fuses: +{{danger.gif}} **In general, it's a good idea to only flash what you need to, because of the limited amount of possible write cycles.**
-  LFUSE = 0xF7 +
-  HFUSE = 0xD1 +
-  EFUSE = 0x07+
  
-Image size: +====== Programming fuses ====== 
-   text    data     bss     dec     hex filename + 
-  17264      33     739   18036    4674 build/shc_basestation.elf +===== Using a make rule ===== 
-pi@ninjablock ~/test/smarthomatic/firmware/shc_basestation $+ 
 +If you build your binaries by yourself with "make", your fuse settings should be available as files **lfuse.bin**, **hfuse.bin** and **efuse.bin** in the bin subdirectory **of the device you want to flash**. You can write these fuses with: 
 + 
 +<code> 
 +make program_fuses
 </code> </code>
  
-===== Flashing the controller =====+Be sure about the fuse settings you want to write in your microcontroller. With wrong fuse settings, your microcontroller might not be accessible anymore! 
 + 
 +===== Calling avrdude directly ===== 
 + 
 +If you are creating a new or modified SHC device, you may want to write other than the default fuses. You can do so with: 
 + 
 +<code> 
 +avrdude -p ATMEGA328P -U lfuse:w:0x??:
 +</code> 
 + 
 +(replace ?? by the hex value for the needed fuse settings and use "lfuse", "hfuse" or "efuse" accordingly). 
 + 
 +===== Strange avrdude error messages ===== 
 + 
 +Some fuses only use a part of their bits. If you set such a fuse, avrdude may complain at verification that it read out another value than it wrote. 
 + 
 +Writing the EFuse of the ATMega168 or 328 returns a value of only the last 3 bits (upper 5 unused), so a value of xxxxxyyy is read out as 00000yyy. Example: 
 + 
 +<code> 
 +avrdude: verification error, first mismatch at byte 0x0000 
 +         0xfc != 0x04 
 +avrdude: verification error; content mismatch 
 +</code> 
 + 
 +Don't worry. The warning is only returned because avrdude does not know that the upper 5 bits are always 1 (as per spec). 
 + 
 +====== Flashing the firmware / eeprom ====== 
 + 
 +===== Using flash scripts ===== 
 + 
 +After setting up avrdude, you can flash the firmware by calling the flash scripts 
 + 
 +  * **flash.cmd** / **flash.sh** for flashing firmware, eeprom and fuses 
 +  * **flash_firmware.cmd** / **flash_firmware.sh** for flashing only the firmware 
 + 
 +===== Using a make rule ===== 
 + 
 +If you have the source code on your machine, you can flash the firmware with the following command from the firmware subdirectory: 
 + 
 +<code> 
 +make program 
 +</code> 
 + 
 +===== Calling avrdude directly ===== 
 + 
 +If you want to call avrdude by hand you can flash everything with:
  
 <code> <code>
-pi@ninjablock ~/test/smarthomatic/firmware/shc_basestation $ avrdude -P /dev/ttyACM0 -c STK500 -p m328p -U flash:w:bin/ohc_basestation.hex -U lfuse:w:0xf7:-U hfuse:w:0xd1:-U efuse:w:0x07:m+avrdude -p m328p -U flash:w:shc_basestation.hex -U eeprom:w:shc_basestation.e2p:-U lfuse:w:lfuse.bin:-U hfuse:w:hfuse.bin:-U efuse:w:efuse.bin:r
 </code> </code>
  
 +(leave one part "-U ..." out to flash only a part).
flash_the_atmega.1380805231.txt.gz · Last modified: 2013/10/04 18:56 (external edit)