2019/05/10 03:58:51
Thorben.Z
I just started playing with a project of mine, trying to make a bootloader that loads the new code from an external SPI flash.But I am already failing in getting it to jump to my app.
As a test, to see if my concept works, it reads a memory location, to see if the app loaded correctly, if it did it jump back to it and otherwise just flash a LED. It worked when the app was just another program flashing another other LED, but when i used it with a more complex app, it just resets after executing the first few lines of code.
 
The bootloader is in the boot flash (just after the startup code), with the app starting (as i think it normally would) at the beginning of the program flash. To jump there i have tried both 'jr' (as the startup code does i think) and just 'j 0x9D000000' (program flash), and also put a "j main" command at 0x9D000000 in the app, in case 'main' was located elsewhere.
I have also tried to make the compiler link the startup code for the app to program memory start, but once i include the bootloader as a loadable it complains about overlapping memory locations (multiple ones, including the debug exception vector code, which i don't think i can move).
 
BTW i have not really got any clue about what i am doing here, I'm just trying to learn it, so excuse any wrong assumptions or conclusions about what goes where, or what the compiler does/needs to do before app startup.
I have also been on google for three hours now and haven't found any possible cause of this (probably because i don't really now what to search for :P)
 
EDIT: i found a solution. look down below
2019/05/10 04:13:26
qhb
Why does everyone try to implement a bootloader as their first project, when that is one of the most advanced topics on a microcontroller?
Learn how to program it first, WITHOUT a bootloader, and your experience will be much more enjoyable.
 
2019/05/10 04:19:03
Thorben.Z
qhb
Why does everyone try to implement a bootloader as their first project, when that is one of the most advanced topics on a microcontroller?
Learn how to program it first, WITHOUT a bootloader, and your experience will be much more enjoyable.
 




i've been programming things in C, java and a bit of assembler for only around 9 years now and earning money with it ;)
i just do not know exactly where the compiler links what, as until now somebody else did all the bootloader stuff. Now i just want to learn about those. programming isn't the issue here
2019/05/10 07:18:03
Jim Nickerson
Did you base your bootloader on an app note example ?
2019/05/10 08:55:56
Thorben.Z
JANickerson
Did you base your bootloader on an app note example ?


I started with the example one from AN1388, but since it placed the code into program memory, and even the UART version was too large to fit into the boot section, I started over and wanted to write my own.
 
And it isn't a bootloader yet, at the moment it is just a piece of code, jumping to the app as a test.
I also didn't use the Harmony one because i do want to learn how it works and not just click a button to include it.
2019/05/10 09:08:11
NKurzman
The bootloader and the main application are two separate projects. Each needs its own linker script too locate the two programs in non overlapping and correct memory.
You are using an appnote for a pic32mx.
Is that what you are using.
2019/05/10 09:30:24
Thorben.Z
Yes. I have added my bootloader project to the app as a loadable. But i can only manage to upload if i exclude the startup code from the app (i guessed, that would be the same as the startup code for the bootloader). But no matter which address I put it I get "(944) data conflict at address 1FC00488h" (1FC00488h is the debug exception vector according to the linker).
 
 
2019/05/10 09:47:11
NKurzman
loadable is an optional method.
Does it work that way?
Which PIC do you have.
What did you do for linker scripts?
You can’t exclude start up code from the app, it needs it. The fact that you have to says you linker scripts are wrong.
You can look up my old bootloader posts.
The linker scripts are key, and are not simple.
Things must be in the correct place. The PIC32 has 3 address for each memory location. The linker does always spot overlaps, or give warnings for incorrect addresses.

You could try the Harmony Bootloader. It works for many PICs, but it is not of good quality.
2019/05/10 10:26:39
Thorben.Z
It does work with another app that just blinks an LED.
I'm using a pic32mx170f256b.
In the linker scrips, I changed the defined memory sections:
 
for the App (this was after i tried to move the startup code to program memory):
  kseg0_program_mem (rx) : ORIGIN = 0x9D00F000, LENGTH = 0x30000
  exception_mem : ORIGIN = 0x9D03F000, LENGTH = 0x1000
  debug_exec_mem : ORIGIN = 0x9D000490, LENGTH = 0x760
  kseg0_boot_mem : ORIGIN = 0x9D000490, LENGTH = 0x0
  kseg1_boot_mem : ORIGIN = 0xBD000000, LENGTH = 0x490
 
and for the "bootloader":
  kseg0_program_mem (rx) : ORIGIN = 0x9FC004B0, LENGTH = 0x650
  exception_mem : ORIGIN = 0x9D03F000, LENGTH = 0x1000
/* I wasn't sure where to put exception_mem. I tried both boot mem after the bootloader and program mem*/
  debug_exec_mem : ORIGIN = 0x9FC00AF0, LENGTH = 0x100
  kseg0_boot_mem : ORIGIN = 0x9FC00AF0, LENGTH = 0x0
  kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0x490
 
other than that i didn't change anything about the files, and my bootloader doesn't contain any config words (but i did leave them defined in the linker)
2019/05/13 08:44:23
Thorben.Z
just as an update, in case somebody else has the same issue:
 
i have managed to get it working by putting all of the bootloader code (exceptions, debug and code) into the boot memory and including the app startup code in the program memory before the app. The bootloader then jumps to the the second startup code.
 
Not sure if that's how it should be done but it works for me ;)
12
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account