I am not sure what you are doing wrong but I am using Keil tools and able to do the IAP bank load. If you haven't already, check out Keil's Blinky-B0B1 example, all of it, to sucessfully boot from bank1 or bank0. Did you set the bank0 #define in the ST FMI library functions and rebuild that library? Make sure you're changing the 91x_fmi.h file that gets used in the library. I don't use IRAM2 so I don't know what you are doing with it. I only use IRAM1, IROM1 and IROM2.

I have documented all this for my own sake. Below is what I wrote about the bootloader, it is specific to my project, called Gap, but if it helps, here goes. I use the Keil startup file. I use the ST lib functions as little as possible. A lot of this is specific to the Keil IDE.

The Gap Bootloader Application:
• IROM1 is 32K, starting at 0, default
• IROM2 is 512K, starting at 0x40.0000
• So the code is built in one continuous chunk of code starting at address 0.
• This code uses bank1 as the boot bank. Set the CFG bit in STR91xCFG.s, it’s the only thing set.
• In STR91x.s, FMI is checked. The boot bank is enabled at 32K starting at 0. The non-boot bank is enabled at 512K starting at 0x40.0000.
• Add define for ‘BOOT_BANK1’ in the ASM options. This gets referenced in STR91x.s (See the file in the Blinky-B0B1 example – need all banking/fmi related code in this file).
• In the Flash Download Setup, check ‘erase sectors’ and ‘program’. For the algorithms, use Flash Bank1 ICP/ 32K/ starting at 0, and CFG and Security ICP/ 16/ starting at 520000H. By doing this, every flash download sets the CFG bit for boot bank1 so you can switch between this code and code that runs with boot bank0.
• In the Download Options for Debug Settings, do not verify code download.
• The bootloader code does a checksum over bank0 code (plus the trailing checksum), starting at 0x40.0000. It gets the code size at 0x40.0020. (Application code was built with code size at 0x20).
• To write to the flash in bank0, used ST’s library, functions from 91x_fmi.c. Used a local copy of 91x_fmi.h to set the #define for bank1 mapping. (Code below is from ST’s IAP UART example. All config/init was done via Keil’s STR91x.s, a la Blinky-B0B1, not from the ST example).

• To execute code in bank0, remap and jump to 0. This function is in a separate file assigned to IRAM1. That means it gets copied to ram and executed from there. The compiler and linker take care of this, just put it in IRAM1. This function must also be executed as a software interrupt in order to set the processor back to Supervisor mode. It needs to be in Supervisor mode to begin executing the application code as if the application code had started from reset. The application code’s STR91x.s does stuff, like setting stacks for other processor modes, which require the processor to be in Supervisor mode. If the SWI were not done (as in the ST IAP UART example), the processor would be starting the application code in User mode and some of the init’ing would not work. Code below:

Hope you caught the error disabling the VIC ints. The code should be
VIC0->INTECR = 0xff;
VIC1->INTECR = 0xff;

Another issue: In Keil's str91x.s the flash config register is set by writing to Bank1. This is ok from reset/powerup but if you restart this code by jumping to 0, and this is done while executing from Bank1, and you have changed the default wait states, it will fail. To fix, execute this code from ram. I removed this code from the startup file, created another file for ram-executed code, and did the flash config there. Basically, I used ST's FMI_Config function, only with just the writes to the flash config register.

When jumping to zero, watch the peripherals to make sure they restart ok. It would be nice to use the WDOG timer to force a reset with reset'ed registers but it doesn't preserve the FMI banking registers.

When I import SWI_Table.s and try to compile I get messages that _SWI_0 throug _SWI_7 is undefined.
That is of cause because I don't use RTL. and have no plans of using it in bootloader section.
what is your suggestion : use __SWI_0? or just provide dummy entrances for __SWI_0 through SWI_7 ?

And, here's the stripped down project files referenced in my documentation along with a few relevant config files. You should be able to see the project settings in here. Please keep in mind that there are probably lots of ways to do all this, I just found a way that works and stuck with it.

If it helps anyone, here's my complete documentation on how to do the code banking-bootloader-IAP stuff in .doc and .rtf formats. The code has been running fine for a while so I think I got it all. It is specific to my project. IAP updates by the end user are done via USB but not using the USB on the STR9. To the CPU it's just a serial interface.

I'm also trying to boot from bank1 and then try to jump to another application in bank0. I followed the steps mentioned above, but i can't get it to work. My question is how do you create an application for bank0? Do you also insert a startup file. And in Keil, what memory settings must be used for this bank0 application. Do you need to remap the banks? I'm able to run both applications just by toggling the CSX bit. But i still can't jump.

JJ, can i also get a copy of your uVision project? Because i'm stuck here.

Hi again, i changed something and i can upload the .bin file now. The changes
* options -> target -> code generation -> thumb mode (I was trying in ARM-Mode before)
* Disable the PLL and change the PLL_PDIV from 2 to 3.
I attach the working code.
But I had a new problem. The .bin file which i upload by bootloader is not working. I think i had a mistake when switching bank.
I use uVision, and the code i have changed is done in IAR (the application AN2475 in ST's website). The IAR code use __ramfunc to work the code in RAM when switching, but i could not find equivalent of this command.

Hello everyone,
I have been working about iap, but could not success yet.I modified the IAR source for my project in KEIL (on MCBSTR9 board). I used a button instead of joystick to jump the menu. Then I hit "1" for sending the .bin file. And I take "verification failed". I attach my project. Can anyone help me ?
Thanks.

i read the keil's ram usage and changed my iap code...
http://keil.com/support/docs/3228.htmthe uploaded prog. has not worked yet. but i did not consider the config of the prog. which i want to upload ?
now, i dont know if iap works correct or may be the config of the upload prog wrong ???
anybody give me an advise ???

mikhailm, i follow the KEIL's instruction:
http://www.keil.com/support/docs/3347.htmThen i can boot from bank1. My iap application is working from bank1 now.
(i attached it before in this title.)
I also have to ask KEIL support about limitations.
Thanks.

I think that is exactly what your problem is..... I don't remember exactly what the issue with "free" version of uVision is, but I couldn't make anything to run from Bank1.
even the LED blink demo.......

EDIT:
and I remember that I even received an email from Keil confurming such limitation on limited version

if nothing else you still have no files loaded into RAM.
other note:
you still using .h files from standard library location. Since you have to modify 91x_fmi.h for bootloader one way and for "real" program other way this isn't a good idea.
You want to copy all "modifiable" .h files into the corresponding project folders.
I also don't see BOOT_BANK1 defined for assembly files...

I suggest you reread everything that was posted in this thread. I was following the advice and managed to make it work...... through ENET, not serial port.

I changed my code following the KEIL's instruction before, but i could not attached at that time. Now, i attached it.
The .h files are in standart libarary location, it is correct. But when i want to compile "real" program, i uncomment #define Remap_Bank_1. So, i understood your advice but i think the problem is not about that.
Can you give me some advice about the real program config ? Or may be a sample project.