cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with bootloader and bank switch

Posted on January 18, 2010 at 07:20

Problem with bootloader and bank switch

25 REPLIES 25
Posted on May 17, 2011 at 09:47

I've a problem with bank switch in STR912FAW44...

I would like to have a bootloader in bank 1 (the secondary flash) and then switch to bank 0, where the application code is placed.

With ST JTAG Programmer:

- Flash bank 0 (Main Flash, 512kB) is located at 0x0

- Flash bank 1 (Secondary Flash, 32kB) is located at 0x80000

- at power-up, CPU boot from Secondary Flash.

Then, these are code operations:

- In the main program, when I press a button, I call Reset_Function (located in RAM)

- The reset function simply jump to Application Code located in 0x0 (i.e. bank 0)

But code doesn't work!

Anyone have the answer? I'm working with IAR Embedded Workbench 5.0.

Thanks!

Fabio

Posted on May 17, 2011 at 09:47

I found a solution for my problem: I've lost to uncomment FMI_Bank1_Remap in 91x_fmi.h and others several small errors...

Fabio

Posted on May 17, 2011 at 09:47

Dear krasty,

what's your problem?

4310239955_stm1_st
Associate II
Posted on May 17, 2011 at 09:47

Hi Fabio,

Could you please post/send a working sample of your solution. We are trying to do the exact same thing with FA chip, but our program doesn't work.

JK

id2
Associate II
Posted on May 17, 2011 at 09:47

Hi Fabio,

I am experiencing the same problem with bank switching:

I use: Keil Compiler, STR912FAW44X6 rev H and ULINK2.

Bank 0: Main program (FMI not configured)

Bank 1: Bootloader (FMI: NBBank 512K, 0x80000, BBank 32K 0x0). The RemapBank 1 is uncommented from 91x_fmi.h

Hardware remap using CSX bit activated to boot always from bank 1.

I start from Bank 1, and jump to Bank 0 using the following function stored in RAM:

FMI->BBSR = 0; //Size 32K

FMI->NBBSR = 6; //Size 512K

FMI->NBBADR = 0x0 >> 2 ;

FMI->BBADR = 0x80000 >> 2;

FMI->CR |= 0x18;

Jump_To_Application = (pFunction) 0x00;

Jump_To_Application();

The program gets blocked. If I press reset or power-off the program starts again from bank 1, but never jumps to bank 0.

Trick: I load a program on bank 0 with FMI BBank: 512K, 0x0, NBBank 32K, 0x80000 and then load again the same program on Bank 0 with the FMI not configured. In this case the jump from Bank 1 to 0 is done OK. If I press reset, the program starts again from Bank 1 and the jump is always done OK.

The problem is that when I disconnect the power, the program starts again from Bank 1 but gets blocked when jumping to 0. It seems that some register stored the first time I loaded the program on bank 0 with FMI, is mantained until the power is switched off. And when switching off, the FMI on bank 0 is not configured and this is why it crashes (not sure about that).

Please I need some help to resolve this problem and find the correct FMI configuration to switch between banks.

Thank you very much,

XS

jmullens
Associate II
Posted on May 17, 2011 at 09:47

I am having the a similar problem as well, and I'm not sure if I'm thinking about my problems correctly.

I've compiled two separate executables. One sits in bank 0, and another sits in bank 1. I have modified the lnkarm_flash.xcl file to specify where in the flash the bank1 program should load from e.g.

-DROMSTART=0x00080000 // -DROMSTART=0x00000000

-DROMEND=0x00087FFF // -DROMEND=0x0007FFFF

In 91x_init.s, I commented out

; --- Remap Flash Bank 0 at address 0x0 and Bank 1 at address 0x80000,

; when the bank 0 is the boot bank, then enable the Bank 1.

/*

LDR R6, =0x54000000

LDR R7, =0x4

STR R7, [R6]

LDR R6, =0x54000004

LDR R7, =0x3

STR R7, [R6]

LDR R6, =0x5400000C

LDR R7, =0x0

STR R7, [R6]

LDR R6, =0x54000010

LDR R7, =0x20000

STR R7, [R6]

LDR R6, =0x54000018

LDR R7, =0x18

STR R7, [R6]

*/

and in main(), I commented out FMI_BankRemapConfig() from IO_Init()... and kept Remap_Bank_1 commented out.

I was able to get a simple program working this way, but as soon as I increased the complexity a little bit, it wouldn’t work.

I'm having a hard time getting my compiler, IAR4.41A, to debug from bank 1, but I was recently told that the version 5.11 does. I can run a very simple program that blinks some LED's, but when I make it slightly more complicated, the program hangs. The only means I have currently is using the JLinkSTR912.exe to switch banks. The initializations for both the working and nonworking programs are exactly the same.

I’ve also had a hard time using the Jflash utility from Segger. Writing above 0x80000 is problematic, so much so, that I’ve been using my bank 0 application to parse an intel extended hex format file, and load my bank1 program into bank1. I’ve been considering other debuggers from Hitex, etc, that may work out easier. How does the rest of this community handle debugging bank1 vs bank0 code?

I put my bank switching routine in bank 0. Ideally, I will always start at bank 1, run a 32bit checksum of bank0, and only jump to bank 1 if the memory check passes. I want to make a very robust firmware upload utility, one that allows me to disconnect the power at any time, and not be dead in the field. I only want the bank1 code to be written through JTAG, but the bank0 code can be upgraded. As such, I have bank switching code in bank 0, and bank 1. I am under the impression that I can’t erase and write over other memory segments while I’m sitting in bank 0, so I want to start a smaller program sitting in bank 1 to erase and program bank 0. If I stayed in bank0, I could try temporarily remapping the code to RAM, using the __ramfunc compiler intrinsic, but this would involve moving too much code for my application.

To begin with, while running in bank0, I tried to jump to bank 1. By adding print statements, I could tell that the processor hung when it execute “FMI_BankRemapConfig(0, 6,0x80000, 0)�?. It never got to “Jump_To_Application = (pFunction) 0x00�?. From your debug environment, are you sure you executed this line?

If I execute a “FMI_BankRemapConfig(4, 2, 0, 0x80000)�?, and a “Jump_To_Application = (pFunction) 0x00; Jump_To_Application()�?,

the processor resets.

I can tell that FMI_BankRemapConfig works.. As a test, I tried “FMI_BankRemapConfig(4, 2, 0, 0x90000)�?. The data at “FMI_ReadWord(0x877b0)�? before this remapping, matched “FMI_ReadWord(0x977b0)�?, as I would expect.

Any insight or suggestions would be greatly appreciated. I have been taking an inexorable amount of time trying to figure this out.

pm9341
Associate II
Posted on May 17, 2011 at 09:47

@jmullens:

have same problems, remapping and execute wont run. Have no more ideas.

jmullens
Associate II
Posted on May 17, 2011 at 09:47

Please note, for those reading this thread, that I figured out how to make my bios routine work in bank1, but I haven't figured out how to do bank switching yet. I don't want people to be further confused by my post when trying to figure out bank switching.

I was surprised that the ST supplied firmware download examples didn't work because they were missing some code.

I had to change the 91x_init.s file supplied with the USB and Ethernet download examples for bank1 operation and add the lines:

LDR R6, =0x54000000

LDR R7, =0x0

STR R7, [R6]

Before these other lines:

LDR R6, =0x54000004 ; non boot bank size

LDR R7, =0x6 ; 512K

STR R7, [R6]

LDR R6, =0x5400000C ; boot bank address = Bank 1

LDR R7, =0x0 ; 0x0

STR R7, [R6]

LDR R6, =0x54000010 ; non boot bank address = Bank 0

LDR R7, =0x20000 ; 0x80000 >> 2

STR R7, [R6]

LDR R6, =0x54000018 ; enable both banks.

LDR R7, =0x18

STR R7, [R6]

Without it, my code did not work . Also, adding the IAR compiler intrinsic function __ramfunc() to the beginning of FMI_Config() in the 91x_fmi.c library, made this function work after I remapped the flash, otherwise I get a fatal exception.

You must also make sure that you linker file, lnkarm_flash.xcl, beings at

-DROMSTART=0x0

-DROMEND =0x7FFF

pm9341
Associate II
Posted on May 17, 2011 at 09:47

@jmullens:Thanks for the replay.

I cant believe there is no sample bootloder binary that boots up with bank1 and than switches to bank0.

Can someone explain the difference between a boot from bank0 and flash remap with PC set to 0x0