startup and retarget

hello all,

what is the work of startup and retarget files?i’m using keil compiler,without these two files,my code dosen’t work.why?

The world doesn’t really start with main(). It’s a dirty lie fed to you by ‘Da Man’. But the startup code is one of the ugliest parts of getting a micro project up and running (arduino has an audience because it hides all of that).

The startup code does two critical things… and will usually do a lot more very useful things as well…

  1. It defines the vector table. This is a list of addresses the micro will jump to on events (like reset).

  2. It defines the very first code to run after a reset (the code at the reset vector). This usually clears the RAM, sets up the stack and heap etc, and for it’s last action will call main().

That’s when your project will start. So the startup code is fairly essential.

IDE’s are pretty good now at generating all the startup code for your project automatically. And if your lucky, you’ll never have to worry about it (I’ve never been that lucky :roll: ), just leave it in your project.

Cheers

thank you eva.now i unterstood.

I also have a question about startup files.

Lets say you have Flash at address 0x00000000 and RAM at address 0x02000000.

A bootloader is stored at the startup address of 0x00000000. The application program is stored somewhere inside the flash as well.

During bootup, the bootloader takes your application program, loads it at 0x02000000 (RAM) and executes the application program.

Is the startup file still necessary with the application program even if you have a bootloader already?

Thanks,

Nullz

Effectively you have three, very important, programs…

Startup clears the ram, initialises variables and memory. It is very light and fast. It calls the first application entry point.

Your bootloader. Runs first and presumably checks for some trigger to hold execution and load firmware. If the trigger does not exist, it jumps to the place in memory where your app is.

Your App. Does that voodoo it does so well - and never returns.

So unless your boot-loader does the necessary initialisation work then you still need to startup code. And why would you bother since the startup files are already there and it is very light.

Normally the vector addresses (needed to run ISRs, Reset, etc) is at 0x00000000. The startup code will be close to this, then your bootloader and app and any ISRs you have written. Your program doesn’t get written to RAM to run (unless you tell it to). When the bootloader calls your application it just jumps to the address in flash where your program is located.

Think of it as just another function call. Your program could implement a bootloader as simply as…

void main()

{

//

//Do Bootloader Stuff

//No trigger? Well then jump to App

//

App(); //This never returns

}

That wouldn’t be a very good bootloader but you get the idea. :wink: