bootloader for atmega1284p

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I'm trying to write a bootloader for atmega1284p, for OTA (using wifi ESP8266) updates of the firmware.. I've done quite a few research and trying out but can't seem to get it to work properly. Appreciate any help here. 

I've successfully done the firmware stuff and the wifi works..

Fuses:

Boot flash size=4096, boot address=$F000, enabled HighBootrst

0xFF, 0x98, 0xF7

Flash segment shows=".text=0xF100"

Linker shows 

<-nostartfiles -Wl,-s -Wl,-static -Wl,-Map="$(OutputFileName).map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mrelax -Wl,-section-start=.text=0x1e200  -mmcu=atmega1284p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega1284p" >

 

.hex file shows:

:020000021000EC
:10E2000011C0466C617368204352433D2000417049
:10E2100070204352433D20004156524150007265E8
:10E22000733D0000CF93DF93CDB7DEB763970FB692

 

I based my code around http://spaces.atmel.com/gf/proje... but instead of sd, it would be wifi.

 

Some questions.

I have the following code:

void UART_put(uint8_t c) {
    while (!(UCSR1A & (1 << UDRE1)));
    UDR1 = c;
}

void UART_putstr(uint8_t *pStr)
{
    while(*pStr)
    {
    UART_put(*pStr++);
    }
}

 

UART_put('A') works but the below doesn't

 

const uint8_t * words = "DE";
UART_putstr(words);

Is it because this is in the .text region instead of the .data region?

 

In my wifi.c below, i have the interrupt to receive the data from the wifi but this does not seem to work.

ISR(USART0_RX_vect)
{
	wrxString[wrxIndex++] = UDR0;
}

 

For my firmware application, should i build it with 

-Wl,-section-start=.text=0x200? or something more than 0x000?

 Thanks in advance for any help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice to hear that you are doing this. I am also thinking to do so. but no idea about boot loader. 

UART_put('A') works but the below doesn't 

 

const uint8_t * words = "DE"; UART_putstr(words);

  

I think UART_PUTSTR doesnt implemented properly. I mean conversion of pointer to string and then string to char?  

void UART_put(uint8_t c) {
    while (!(UCSR1A & (1 << UDRE1)));
    UDR1 = c;
}

void UART_putstr(uint8_t *pStr)
{
    while(*pStr)  //I think there is mistake
    {
    UART_put(*pStr++);
    }
}

use like:

 

void UART_putstr(uint8_t *pStr)
{
   uint8_t i;
     while (i=*pStr++)
     UART_put(i);
}

 

Last Edited: Thu. Nov 9, 2017 - 11:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

weeyoung wrote:
In my wifi.c below, i have the interrupt to receive the data from the wifi but this does not seem to work.
No wonder when using -nostartfiles.

Remove that -nostartfiles and make sure your bootloader includes proper IVSEL handling.

 

weeyoung wrote:
For my firmware application, should i build it with

-Wl,-section-start=.text=0x200? or something more than 0x000?

  No!

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

weeyoung wrote:
I based my code around http://spaces.atmel.com/gf/proje... but instead of sd
In my bootloader I was programming to try and get an entire FAT stack into 1K (sometimes 2K) so I had to use -nostartfiles so I wouldn't waste space with an interrupt vector table. But as Stefan says a consequence of it (and my "dummying" of do_copy_data() and do_clear_bss()) is that you cannot use .data or .bss variables. such as your "words" variable.

 

I *think* in the modern compiler you can probably continue to use -nostartfiles if required (but then you cannot use ISR()!!) but don't dummy the do_copy_data and/or do_clear_bss if you plan to use .data or .bss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:

weeyoung wrote:
In my wifi.c below, i have the interrupt to receive the data from the wifi but this does not seem to work.
No wonder when using -nostartfiles.

Remove that -nostartfiles and make sure your bootloader includes proper IVSEL handling.

 

weeyoung wrote:
For my firmware application, should i build it with

-Wl,-section-start=.text=0x200? or something more than 0x000?

  No!

 

Thanks! I removed that (-nostartfiles) and with IVSEL handling and it seems to work.

	MCUCR = (1<<IVCE);
	MCUCR = (1<<IVSEL);
	
	sei();

However, I had another thinking.. I may look to do an OTA (wifi) at the end of the actual application and save any new firmware into a flash... On load of bootloader, it will check the flash only and load the most recent one? Would this flow be better? 

 

Should I load the firmware at 0x0000 and 0x8000? 

sternst wrote:

weeyoung wrote:
In my wifi.c below, i have the interrupt to receive the data from the wifi but this does not seem to work.
No wonder when using -nostartfiles.

Remove that -nostartfiles and make sure your bootloader includes proper IVSEL handling.

 

weeyoung wrote:
For my firmware application, should i build it with

-Wl,-section-start=.text=0x200? or something more than 0x000?

  No!

Why no to this? i saw a few online that does this? Just wonder whats the best practise.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

weeyoung wrote:
Why no to this?
Because the application can't use interrupts then. At least not without extra effort done by the bootloader.

 

weeyoung wrote:
i saw a few online that does this?
Example?

I don't see why one would want to do that in the first place.

Stefan Ernst