cancel
Showing results for 
Search instead for 
Did you mean: 

I am booting from bank 1 but program code is in the bank 0

vaclav2
Associate II
Posted on April 03, 2008 at 17:10

I am booting from bank 1 but program code is in the bank 0

14 REPLIES 14
vaclav2
Associate II
Posted on May 17, 2011 at 09:36

Hi

I have a question. What have I to do when I want to boot from bank 1 and to jump into the bank 0 where is the program code and run it? :-]

Probably, It isn't simple question.

amira1
Associate II
Posted on May 17, 2011 at 09:36

Hi Vendelin,

To boot from bank 1 you have to :

-change the boot bank using CAPS (hardware remapping) following these steps:

*in additional settings ->Configuration: select secondary flash->apply

*in program device ->select region: select 2nd flash

->select operation: select program only and select execute

-change the remapping (software remapping) using: FMI_BankRemapConfig to indicate FMI_BootBankSize, FMI_NonBootBankSize, boot bank address and non boot bank address.

And finally jump to the address of your code to execute it.

Best regards

mirou

vaclav2
Associate II
Posted on May 17, 2011 at 09:36

Hi Mirou

Thanks You for your help

But I don't know how I can jump. I used LDR, MOV, B, BL ,BLX, BX, SUB... very many instructions and methods but program counter didn't want to jump to the bank 0.

I can jump only from begin to end of bank 1 (0-7FFF). When I want to jump elsewhere, the STR9 resets and runs program from bank 1.

There is the loader via RS232 in the bank 1. Loading of program is O.K. into the bank 0 , but I don't know how I run it.

There are two programs with different main() functions. I need to end the program which is in bank1 and start program in bank 0 without the reset.

The debugger from Raisonance showed that program counter jumped on the begin of program in bank 1 when I used the Real machine mode. But the jump on the address into the bank 0 is executed when I use the virtual machine mode.

Have You any example( C code), which is solving jump from program into other program?

Should I do the changes in linker script files and start up code for solving this problem?

What should I do for generating of the HEX file that is without main() function? (Main function will be in bank1 and some functions will be in bank0)

Best regards.

Vendelin

Please excuse my English 😉

[ This message was edited by: Vendelin on 13-02-2007 09:24 ]

najoua
Associate II
Posted on May 17, 2011 at 09:36

Hi Vendelin,

- As it was said by Mirou, to boot from Bank1, it should be hardware remapped at address 0x00 using CAPS tool.

- In your application which will be downloaded in the Bank0 using the code already downloaded in the Bank1, Interrupts can be used so the interrupts vector must be located at address 0x00.

So, a software remapping of Bank0 at address 0x00 should be done just before jumping to the loaded application:

typedef void (*pFunction)(void);

void execute_application (void)

{

pFunction Jump_To_Application;

/*--------------------------------------------------------------------*/

/* Configure bank 0 as 512KB and bank 1 as 32KB */

/* Remap bank 0 at address 0x0 and bank 1 at address 0x80000 */

/*--------------------------------------------------------------------*/

FMI->BBSR = 0x0;

FMI->NBBSR = 0x6;

FMI->BBADR = 0x80000 >> 2;

FMI->NBBADR = 0x0 ;

/* Jump to the user application and execute it */

Jump_To_Application = (pFunction) 0x00;

Jump_To_Application();

}

The function execute_application() must be executed from RAM.

I hope this solves your problem.

You can refer to the AN2475 'STR9 In-Application Programming'available on the following link:

http://www.st.com/stonline/products/literature/anp/12951.pdf

It shows how downloading a user application in Bank0 using a code in Bank1 and then jumping to it for execution. (This similar to what you are doing).

Please let us know how it goes.

Best regards,

Najoua.

vaclav2
Associate II
Posted on May 17, 2011 at 09:36

Hi Najoua

I am working with Raisonance RIDE IDE.

I don´t use Bootloader from ST. I wrote my own for intel hex32. The bootloader from ST is written for IaR and the function Jump_To_Applikation is defined in an object file (I haven't source code). When I debug it, code of Jump_TO_Applikcation is only

Jump_To_Application = (pFunction) 0x00;

MOV R0,#0x0

Jump_To_Application();

BLX R0

I was attempt to load my bootloader to the RAM (all is OK) but the jump (after remap by FMI_BankRemapConfig();) didn't go.

My code for example :

#include ''91x_lib.h''

int main()

{

#ifdef DEBUG

debug();

#endif

/*

some program code which is loading image into the bank0

(it works well)

Bla

Bla

Bla

Bla

*/

// I want jump to the bank 0

FMI_BankRemapConfig(0x0,0x6,0x80000,0x0);

/*

FMI->BBSR = 0x0;

FMI->NBBSR = 0x6;

FMI->BBADR = 0x80000 >> 2;

FMI->NBBADR = 0x0 ;

*/

//asm(''MOV pc,#0x0'');

//asm(''SUB pc, pc, pc''); (I was very unlucky here)

//asm(''B 0x0'');

//asm(''LDR pc,=0x0'');

asm(''MOV R0,#0x0'');

asm(''BLX R0'');

while(1);

}

To 12951.pdf:

The IAP must be programmed by the user in the Flash bank1 after being hardware remaped at address 0x00...............I agree.

(bank 0 is hardware remapped at address 0x80000)..........It shouldn't be only 0x8000?

When I boot from bank 1 memory model is this?

Bank 1....32k........Bank 0....512k

0---------------7FFF 8000------87FFF

or

Bank 1....32k..................................... Bank 0....512k

0---------------7FFF.............nothing...........80000------FFFFF

I attempted three possibilities:

1)

I link the program with default start up and linker script.

I can run this program which is loaded by my bootloader.

It is made by CAPS. I have to change boot flash from bank 1 back to the bank 0.

This way isn't good. I don't want to reset STR9 by using CAPS and I don't want to use the RLink.

2)

When I make some changes in the linker script file section_Flash.ld I can link the program with address offset 0x8000. I load this program to the bank 0 by my loader. I don't change configuration of merory. I want only jump to the adrress 0x8000 where bank 0 and my program begin. (I link the program with adress offset 0x8000).But Program Counter doesn't jump to the adrress 0x8000.

3)

I attempted to use RAM for my bootloader and remapping boot flash. But without efect.

PC went back to the start of bank1 and after it jumped to the RAM.

I don't attempt IAR because I haven't J link

My problem is that I can't put the PC from bank1 to the bank 0.

Probably, I make something badly. But I don't know what.

Best regards

[ This message was edited by: Vendelin on 13-02-2007 14:16 ]

najoua
Associate II
Posted on May 17, 2011 at 09:36

Hi again Vendelin,

Please let me clarify the following point:

When you boot from Bank1, the memory model is:

Bank 1....32k..................................... Bank 0....512k

0-----------7FFF.............Reserved..............80000--------

This is FMI specification related. If you have a look to the STR9 Flash Programming Manual, pages 27 & 28, it is mentioned that ''the base address must be at a 32KB boundary for Bank1. For Bank0, it must be at a 512KB boundary (STR91xFxx4) or at a 256KB boundary (STR91xFxx2)''.

This means that Bank0 base addresses can be: 0x00, 0x80000, 0x100000, etc.. and Bank1 base addresses can be: 0x00, 0x8000, 0x10000 etc...

I hope this is clear.

Now, below are my commentaries regarding the possibilities that you had tried:

1/ CAPS is only used at the beginning when hardware remapping the two banks.

There is no need to hardware remap again the banks to the default state. A software remapping is sufficient just before jumping to the loaded code in Bank0. And the function performing the Software remapping and the jump operation should be executed from RAM.

I have a couple of questions:

- Does the code loaded in Bank0 contain interrupts? If no, did you try to jump to it without changing the two banks' mappings before jumping to the code loaded in Bank0 (I mean Bank1 remains at address 0x00 and Bank0 at address 0x80000) i.e jump to address 0x80000?

- Could you please describe the code downloaded in Bank0? I mean is it an executable file (Hex, Binary etc..) output from a single compiled project? If this is the case, the Banks shouldn't be remapped again in the Start-up file (For IAR for example in 91x_init.s)

2/ As it was said, 0x8000 is a reserved location.

I hope this helps you.

Please let me know how it goes.

Best regards,

Najoua.

[ This message was edited by: Najoua on 28-02-2007 09:39 ]

vaclav2
Associate II
Posted on May 17, 2011 at 09:36

Hi Najoua

Thanks for Your help.

I have it.

Code in bank 1.

(Default start up and script file)

/* main.c*/

#include ''91x_lib.h''

#pragma long_calls //enable long jump

void __attribute__((section(''.data''))) skok(void) //function into the RAM

{

asm(''ldr R0, =0x54000000''); //remaping flash

asm(''ldr R7, =0x0'');

asm(''str R7, [R0]'');

asm(''ldr R0, =0x54000004'');

asm(''ldr R1, =0x6'');

asm(''str R1, [R0]'');

asm(''ldr R0, =0x5400000C'');

asm(''ldr R1, =0x20000'');

asm(''str R1, [R0]'');

asm(''ldr R0, =0x54000010'');

asm(''ldr R1, =0x0'');

asm(''str R1, [R0]'');

asm(''ldr R0, =0x54000018'');

asm(''ldr R1, =0x18'');

asm(''str R1, [R0]'');

asm(''LDR pc,=0x0''); // jump to reset vector of code in bank 0

asm(''NOP''); // NOPs for clearing of pipeline

asm(''NOP'');

asm(''NOP'');

asm(''NOP'');

asm(''NOP'');

asm(''NOP'');

}

int main(void)

{

static void (*pramfunc)(void) = skok;

#ifndef DEBUG

debug();

#endif

//calling of function, that is in RAM

(*pramfunc)();

while(1);

}

Best Regards

[ This message was edited by: Vendelin on 28-02-2007 10:46 ]

dibacco2
Associate II
Posted on May 17, 2011 at 09:36

I used your code, loading it to Bank1 but when trying to start application in Bank 0 I receive an abort exception.

Any idea?

vaclav2
Associate II
Posted on May 17, 2011 at 09:36

Hi

You can try other start-up of the program that is into non boot bank (bank 0 for you?)

This start up has deleted the sequence that remaps banks. ( /****VYRAZENO***/)

I work with RIDE IDE and I had problem with it.

If You will to have problems , I will send complete project in RIDE.