Changing Start-up address for S12zvca

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing Start-up address for S12zvca

2,496 Views
kiranbhat
Contributor III

Hi

I am using MC9S12ZVC evaluation board and Code warrior 10.6 for development of boot loader. Currently i am facing issue in startup address change. By default the statrup adddress is

VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */

but i want to change this address to 0xFE90D0 which is a location in the flash memory. So i changed it  like

VECTOR ADDRESS 0xFE90D0 _Startup.

The code is just to blink led. PRM and code files attached.

When code is flashed with debug then works for first time and when restarted the controller no operation happens. If flah the code with run option then no operation from the beginning.

Original Attachment has been moved to: main.c.zip

Original Attachment has been moved to: mc9s12zvca192.prm.zip

Labels (1)
Tags (2)
8 Replies

1,485 Views
kiranbhat
Contributor III

Hi Radek

Can you Please tell me how to move interrupt vector table. And why is it necessary to move interrupt vector table. In bootloader i am not using any interrupt. In applicaion i am using different interrupts. Does this scenario requires to move the vector table.

Regards

Kiran Bhat

0 Kudos

1,485 Views
kiranbhat
Contributor III

Hi Radek

No i am not following N4723 S12Z MagniV Bootloader as the reference. My requirement is to flash through CAN with some diagnostics implementation and customized tool.

I think i found one issue but not sure what exactly it is. Let me tell you in detail.

1)For boot loader Vector is default i.e VECTOR 0 _Startup

2)For application Vector is Vector Address 0xFDE090

3)While switching from Bootloader to application main i am (void)(*JMP_Ptr)(void)  = *(void(**)(void))0xFDE090 (This points correctly to the Startup of the application.)

4) I run in dissassembly and check the status untill the switching is fine. Once switching happens startup of the application is executed.

5) In startup there are three functions one Startup(), DoZeroOut(); and   DoCopyDown();

6) In dissassembly i observed that startup is executed and DoZeroOut(); is called and successsfully executed but when DoCopyDown(); is callled theres a problem, Inside the function there is a instruction

LD D6, (Y+)/* load the size */

Once this instrucction is executed the PC gets lost or goes to 0xFFFFFF.

I am not able understand whats happening. Each time the above instruction executed PC goes to 0xFFFFFF. address.

Please suggest.

Regards

Kiran Bhat

0 Kudos

1,485 Views
RadekS
NXP Employee
NXP Employee

Hi Kiran,

This is probably the just misunderstanding.

The command VECTOR ADDRESS 0xFE90D0 _Startup will store _Startup code address into position 0xFE90D0.

If you want to start your code at address 0xFE90D0 after reset, please use linker command VECTOR 0 0xFE90D0. This will store 0xFE90D0 number into reset vector (at address 0xFFFFFC).

The reset vector cannot by moved to any different address – it will be always at address 0xFFFFFC. The interrupt vectors may be relocated inside Flash/RAM by change IVBR register (content is set to default during reset). The vector base is a 24-bit address which is accumulated from the contents of the interrupt vector base register (IVBR, used as the upper 15 bits of the address) and 0x000 (used as the lower 9 bits of the address).

So, you could place vector table into any available aligned 512byte area in the memory map.

Default IVBR is 0xFFFE which specifies vectors located at 0xFFFE00–0xFFFFFF. The next IVBR value smaller than default is 0xFFFC (vectors located at 0xFFFC00–0xFFFDFF). The LSB bit in IVBR register is log0.

The vector order is fixed and cannot be modified, therefore, the related vector must be at appropriate address (e.g. vector base+0xF4 for Port AD interrupt). So, relocated vector have to be at address for example 0xFFFCF4 with IVBR=0xFFFC.

I hope it helps you.

Have a great day,

Radek

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,485 Views
kiranbhat
Contributor III

Hi Radek

Thank you for the reply. Yes there is a bit confusion. What i want exactly is i flash the boot loader with BDM. Then i flash the application using my flashed bootloader. Application and bootloader are different projects. So application PRM i changed the command to store the startup at 0xFE90D0 and bootloader kept default so that after power on or reset bootloader is executed first. And from bootloader main i am pointing 0xFE90D0 address to jump to application startup. It is not working.

But instead of this if i point to the application main function address directly it works. I want to jump from my bootloader main to application startup. How it can  be done. I am using can for flashing without any interrupt.

0 Kudos

1,485 Views
RadekS
NXP Employee
NXP Employee

Hi Kiran,

Thank you for clarification.

You are right, that we need some fixed point between two independent projects - Bootloader and Application. The standard way is that bootloader starts always as first and it jumps into the application which starts at fix address. The most logic address is the first address in flash.

Unfortunately there is problem in fact that default application project will place DoZeroOut() and DoCopyDown() functions as first prior _Startup() function. In that case, the address of _Startup() function isn't fixed.

Please look at this thread for more details:

https://community.nxp.com/message/655960

There were mentioned at least two possible workarounds:

1. You may change the position of _Startup() function in starts12z.c file – place it prior DoZeroOut() and DoCopyDown() functions and add DoZeroOut() and DoCopyDown() functions declaration.

In that case, the _Startup() function will be placed as first into flash and we could have fix address for application start. See starts12z.c file in ZVML128-BootloaderApplication2-CW106.zip attachment.

2. The second approach updates application linker file where we add simply jump code on first address of flash. So, bootloader jumps into first address in flash where is another jump, but target _Startup() address is already managed by application project. See mc9s12zvml128.prm.zip attachment.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,485 Views
kiranbhat
Contributor III

Hi Radek

From the above post what i followed is,

1) Bootloader Linker file vector points to default i.e VECTOR 0 _Startup

2) No startup.c file change in bootloader project.

3) In application project, linker file modified to VECTOR ADDRESS 0xFE90D0 _Startup (So that 0xFE90D0 holds the _Startup address and from bootloader using double pointer, jump to the startup address)

4) Change the sequence of startup.c in application project.

Nothing executed. But in step 3 instead of _Startup if give main the code works fine. But it works only for a small code like blinky where there is not much variables used. But my actual application is running on scheduler and there are lots resources used. Can you suggest something on this.

Regards

Kiran Bhat

0 Kudos

1,485 Views
kiranbhat
Contributor III

Hi Radek

Can you please explain me the sequence of execution after reset what happens, what are the functions invoked, interrupt vector handling.

Regars

Kiran Bhat

0 Kudos

1,485 Views
RadekS
NXP Employee
NXP Employee

Hi Kiran,

I suppose that you use AN4723 S12Z MagniV Bootloader as the reference. Is it correct?

http://www.nxp.com/files/microcontrollers/doc/app_note/AN4723.pdf

http://www.nxp.com/files/microcontrollers/doc/app_note/AN4723_SW.zip

The Bootloader and Applications have his own Starts12z.c files and _Startup() functions.

The bootloader typically occupies the highest part of flash with reset and default interrupt vector table. The bootloader example defines application start address as 0xFE0000 (first byte of flash) in main.h file. At this address, the application’s _Startup() function should be placed.

We have to modify default application project to start at that address.

Note: any other address may be used, but the first byte of flash is the most logical choice. I suppose for now that you use S12ZVC192 derivative and this address should be 0xFD0000. Please update main.h file in your bootloader according to that.

I described two option how to manage that application will start at the first byte of flash. Please use just one of these solutions:

  1. Change _Startup(), DoZeroOut() and DoCopyDown() location in application’s Starts12z.c file that _Startup() function will be placed into flash as first (at first byte of the flash).
  2. Define JMP instruction at 0xFD0000 address followed by vector with address to application’s _Startup() function (0xFD0000 filed by 0xBA, VECTOR ADDRESS 0xFD0001 _Startup).

The application code should have his own interrupt vector table placed somewhere in Flash/RAM (aligned to 512B block) and command for modifying IVBR register at the start of an application.