Author Topic: Memory map - Where does my program go?  (Read 2798 times)

xof

  • Newbie
  • *
  • Posts: 2
Memory map - Where does my program go?
« on: July 05, 2015, 07:35:45 am »
Hi,

I would like not to use the (modified) Arduino IDE (on Ubuntu).
I would like to do something like :

$ avr-gcc  -mmcu=attiny85 -o blink.elf blink.c
$ avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
$ micronucleus --run blink.hex

but I am not sure 'What goes Where'...

How do I tell the compiler (linker) that there is a micronucleus firmware on the chip?
Or the answer is just 'Don't care' because the firmware is at the end of the FLASH and won't overwrite itself. And when one does :

$ micronucleus --erase-only

it fills the FLASH with 0xFFFF which behaves like NOP and the AVR will go through until it reaches the bootloader (micronucleus firmware) ( http://www.avrfreaks.net/forum/what-does-opcode-0xffff-actually-do )

Is this correct?  Where is it documented?

Thank you.

xof

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Memory map - Where does my program go?
« Reply #1 on: July 05, 2015, 09:50:43 pm »
Documentation that exists for that type of thing would be found in the micronucleus sources at github.com/micronucleus - likely the issues tracker and source comments will be the main documentation for that stuff.

But how it works is:

Micronucleus is at the end of the flash, when new code is uploaded it is written to the start, but micronucleus knows to make sure it doesn't write over itself - so in summary you don't need to worry about it.

xof

  • Newbie
  • *
  • Posts: 2
Re: Memory map - Where does my program go?
« Reply #2 on: July 06, 2015, 09:18:19 am »
Thank you very much!  (Here is a kind of tutorial  for those who don't want to use the IDE ;) )

I was afraid to brick my Digipark...
I thus wrote a small 'blink.c' program :

#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>

int main(void)
        {
        DDRB  |= _BV(PB3);

        while(1)
                {
                _delay_ms(1000);
                PORTB ^= _BV(PB3);
                }
        }

(edit: As PB3 is used by USB, PB1 is probably a better option (and is the board LED)) and did

$ avr-gcc  -mmcu=attiny85 -Os -o blink.elf blink.c
$ avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
$ micronucleus --run blink.hex

And got a blinking LED on P3 (and was still able to reflash it with another delay or another program).
I was a little bit surprised the clock speed was 16 MHz but it is explained on https://digistump.com/wiki/digispark/tricks .

(I think I just needed

$ sudo apt-get install gcc-avr binutils-avr avr-libc
$ git clone https://github.com/micronucleus/micronucleus.git
$ ...
(I am not quite sure because I already apt-get install arduino))

So, it is easy (easier for me than using the (modified) Arduino IDE) and (probably) foolproof (?).  In fact, I don't know/understand yet how the power-on-reset boot process works on such an AVR but I understand that control is ever given to the micronucleus bootloader firmware  and that I can not change that by mistake using micronucleus (as it is an intricate process, if possible at all (?) or needs 'avrdude' and involves ISP programming).
« Last Edit: July 09, 2015, 09:56:22 am by xof »