is this bootloader jump C code correct?

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

Hi,

just a simple question,
in my C code, I wrote the following for jump from application section to bootloader section, I use mega1281 and 4K word of bootloader size now

void (*start_bootloader)(void) = 0x1E000;
...
...
start_bootloader();

Then when I compile this code, I got the warning:

Quote:

warning: initialization makes pointer from integer without a cast

Then I thought maybe it should be 0xF000 instead of 0x1E000, but then I tried 0xF000 and got the same warning.

I use the similar code for jump to the start of flash, by changing the address to 0x0000 and it was working, so what's the problem with this warning then?

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

The warning comes not from setting the jump address. You simply try to write an integer value to a pointer. But you shall only write an address to a pointer, the compiler reckognizes it
and warns you about a possible wrong operation.

You need to typecast the integer value into an address to make the compiler happy:

void (*start_bootloader)(void) = (void *) 0xF000;

Since the program counter works in word steps, 0xF000 should be the right address.

Regards
Sebastian

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

ok, thanks, Sebastian

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

now I'm using

void (*start_bootloader)(void) = (void *)BOOTLOADER_ADDRESS; 
...
...
start_bootloader();

and this is the asm code for start_bootloader();

 a78:	ff 95 00 f8 	call	0x7ff000 <__stack+0x7fdf01>

Then I'm confused, the cpu is mega1281, so shouldn't the value after call < 64K ?
Cos mega1281 just has 128KB of flash and 16bits PC, so what's this 0x7ff000 all about??