I got the code USB secondary ISP bootloader for LPC23xx from NXP working fine with none RTX kernel but It does not working with RTX kernel. If anyone know more detail please help.
Thank you.
Hi noom noise, I had the same problem on lpc2378. I've made my project work with non-RTX bootloader and my RTX project. I'll try to explain what I've donne:
1. Bootloader project is the one from NXP site: www.standardics.nxp.com/.../an10759.zip
All values in the bootloader project are at their default. Just unpack USBMem folder. Leave the other one. Alas, no RTX there. Compile, Flash->Erase, Flash->Download. A window displaying your device as mass storage device under windows should appear at your screen.
2. In my RTX project I've changed following:
A) Project->Options for target->Target: IROM1 start:0x2000 size:0x7E000. (from 0x0 to 0x1FFF is bootloader) (size = IROM1_size - 0x2000)
IRAM1 start:0x40001000 size:0x7000 (I was playing with bootloader IRAM1_size. And in my case, bootloader needs somewhere around 0xDFF of RAM. So in order not to overlap it's area, my IRAM1 starts at 0x40001000. Moshe Tal suggested 0x40000100 for his lpc2368 - not enough in my case. Try playing with IRAM1_size in bootloader project to determine your minimum...)
B) Project->Options for target->Linker: Misc.controls: --entry 0x2000 (that is of course, where your IROM1 starts)
C) Project->Options for target->User: Run user programs after build/rebuild: fromelf --bin .\out\my_project.axf -o .\out\firmware.bin (that way firmware.bin will be created, which you can copy to the device from PC over USB)
D)Project->Options for target->Output: check create hex file
E) Right click on your startup file: options->Asm->ConditionalAssembyControSymbols: RAM_INTVEC REMAP RAM_MODE ( This is Keil's description of what should happen: ; * RAM_INTVEC: when set the startup code copies exception vectors ; * from on-chip Flash to on-chip RAM. ; * ; * REMAP: when set the startup code initializes the register MEMMAP ; * which overwrites the settings of the CPU configuration pins. The ; * startup and interrupt vectors are remapped from: ; * 0x00000000 default setting (not remapped) ; * 0x40000000 when RAM_MODE is used ; * 0x80000000 when EXTMEM_MODE is used ; * ; * EXTMEM_MODE: when set the device is configured for code execution ; * from external memory starting at address 0x80000000. ; * ; * RAM_MODE: when set the device is configured for code execution ; * from on-chip RAM starting at address 0x40000000. )
F) Finally, I had to Copy my interupt vector table from declared beginning of my application's IROM1 to the actuall beginning of IROM1: Put this at the beginning of your RTX's main(): memcpy((char *)0x00000000, (char *)(0x00002000), 64);
(it seems that even though I used remapping (step E), code always jumps to IVT of the bootloader, that is, from 0x0..., so not exactly what you may expect after remaping to RAM... And thats why I had to copy my IVT from 0x2000 to 0x0).
G) I also had some problems with interrupts which were happening before my RTX-application's main(). I was debugging something with interrupt driven UART before the main(). When I cleared those printf functions, everything worked well. So maybe it would be wise to disable interrupts before your main()...
Also, just to mention, as RTX uses SWIs, I have SWI_Table.s file included in my RTX project.
And that's all I had to do. My RTX application works perfectly with non-RTX bootloader that NXP supplied.
NOTE: Here I have one MCB2300 board whith lpc2378 revision '-' on it. There was no chance to make the bootloader work with it. Not even with MAM disabled. I made it work only on my prototype which uses revision 'B' of lpc2378... So if you are not using revision 'B', maybe that could be the problem... Although I'm not quite shure...
I hope this helps...
I found more problem with startup file when running after bootloader, that required workaround. In startup file (LPC2300.S) there is code that setup stacks for each ARM mode. To do that the program is trying to enter each mode with MSR instruction and changing the value of SP (stack) register.
But, after bootloader this code will not work, and all special mode stacks will remain as setup by the boot loader, and probably will overwrite program memory every time the ARM enter to special mode (For example - every IRQ call and every task switching).
This problem seem to occurs because MSR instruction (switch ARM mode) doesn't work when ARM is in User mode, only when ARM in special (supervisor) mode.
After ARM reset the MCU run in Supervisor mode, so this code run well. but after bootloader the ARM run in User mode.
My solution was to force ARM to enter supervisor mode before running stacks setup code by calling to SWI. This require changing of SWI vector, that was easy after remapping vector table to RAM.
Here the updated code:
; Setup Stack for each mode ---------------------------------------------------- ; Stack setup code will not run when MCU in User mode ; as occur when this code run after secondary boot loader ; The following code will do fake calling to Software interrupt to enter Supervisor mode ; so stacks init code will work properly. SWI_RAM_ADDR EQU 0x40000028 LDR R8, =SWI_RAM_ADDR ; LDR R7, [R8] ;Save SWI_Handler address LDR R9, =Stack_Set_Addr STR R9, [R8] ;Replace SWI_Handler (for next command) with Stack_Set_Addr SWI 11 ;Just jump to Stack_Set_Addr in Supervisor mode Stack_Set_Addr DCD Stack_Setup Stack_Setup STR R7, [R8] ;Restore SWI_Handler address ;End of edit LDR R0, =Stack_Top
yes you are right - of the jump to the application can be done in a SWI function.
How can you change the SWI vector in bootloader?
is the bootloader performs a SWI, and the application later remaps the vector using the macros, does it matter?
View all questions in Keil forum