Issue with SPM in Bootloader

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

Hello, this is my first post.


Anyway, I've been trying to write to flash with the SPM from a bootloader with an ATmega328p, and so far I've tried multiple examples, including the example function in the boot.h header file, without any luck. To boil the problem down, I wrote the code below, which in theory should write something to the first couple bytes of flash:


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/boot.h>
//F_CPU is defined in the toolchain settings as F_CPU=1000000UL

int main(void)
	DDRC = 0b00000001;
	PORTC = 0b00000001;
	while (1);

Here's what the .hex file looks like that Atmel Studio generates:


Here's my fuse bit settings:

Fuse bit settings image


Alright, so the problem is that nothing is being written to flash. The LED attached to PC0 will light up just fine, so the bootloader code is finishing, it's just that nothing is being written, and all the memory outside of the bootloader is 1's. To prove this, I ran a flash dump with avrdude and got the following:


Raw Data Dump

I pretty new to writing bootloaders, so I'm assuming that there's something obvious that I'm missing. Any help is greatly appreciated. Thanks.


This topic has a solution.
Last Edited: Sun. Jul 26, 2020 - 12:02 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That code is at 3800. You made the classic byte/word error. I'd suggest you'd get a whole lot more mileage at 7000

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

Thanks so much. Setting the start address to 0x7000 like you said fixed things, and now the code runs fine. Problem solved.