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.
is the bootloader performs a SWI, and the application later remaps the vector using the macros, does it matter?
How can you change the SWI vector in bootloader?
yes you are right - of the jump to the application can be done in a SWI function.
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
This is the final version of the example, all works as it should:
rapidshare.com/.../non_RTX_bootloader_with_RTX_application_for_lpc2378.rar
(all other links from above are deleted...)
You're welcome.
Ave, Tamir!
This gave me a lot of headache! Startup file when I started my project was 20k. Today it is 37k. I jus needeed to copy .s file from "Keil\ARM\Startup\Philips\" to my project over old one and now everything is defined. I've read a bunch of documents searching why those macros won't work :)
Thanks once more!
don't forget to bless your "rapidshare" clients with your findings :-)
if you look at the lastest released LPC2400.s, line 61 looks like this:
RAM_BASE EQU 0x40000000
Exactly, that is missing! I copied this file from Keil... RAM_BASE, is undefined in my project. Can you please tell me from where did you copy your .s file? This one is Keil's, but is obviously missing something...
wait a minute. the following instructions should reside in your startup file, just above the code you quoted:
; Copy Exception Vectors to Internal RAM --------------------------------------- IF :DEF:RAM_INTVEC ADR R8, Vectors ; Source LDR R9, =RAM_BASE ; Destination LDMIA R8!, {R0-R7} ; Load Vectors STMIA R9!, {R0-R7} ; Store Vectors LDMIA R8!, {R0-R7} ; Load Handler Addresses STMIA R9!, {R0-R7} ; Store Handler Addresses ENDIF
I am using the remapping macros without a problem.
Corrected version of above file is: rapidshare.com/.../non_RTX_bootloader_with_RTX_application_for_lpc2378.rar (This works with new RTX (from v3.40) of uVision). Old version is deleted from rapidshare.
Please note that in my case (in this example)
RAM_INTVEC REMAP RAM_MODE
ASM option for startup file does not remap IVT as Tamir Michael suggested. I have to say
memcpy((char *)0x40000000, (char *)(0x00002000), 64);
(see __rt_entry...)
This is part of startup file that has to do with those macros:
; Memory Mapping (when Interrupt Vectors are in RAM) MEMMAP EQU 0xE01FC040 ; Memory Mapping Control IF :DEF:REMAP LDR R0, =MEMMAP IF :DEF:RAM_MODE MOV R1, #2 ELSE MOV R1, #1 ENDIF STR R1, [R0] ENDIF
So uVision generated REMAP and RAM_MODE, but not a RAM_INTVEC part... And I guess that this is the reason why vectors are not remapped as in Tamir's case, but have to be copied manually in my case...
that is exactly what I am saying. an application that uses these macros, makes its startup file copy the vectors and set MEMMAP for it (have a look in the startup file - search for 'memmap'). this should be done in the application. however, you can do the mapping manually in the bootloader instead - using memcpy and MEMMAP. about my question: if you have a piece of code (bootloader) than jumps to software that is intended to handle interrupts, that jumps in its turn to an RTX application (no interrupts handling intended here), then the handling will be a little different: the mid section will use the macros to remap the interrupt vectors, but the startup file of the application must do something like this:
LDR R0,=RAM_BASE+0x28 LDR R1, =SWI_Handler STR R1, [R0]
to copy the SWI handler of application to the internal memory - otherwise RTX will not start. this arrangement makes sure all interrupts but the SWI will be handled in the mid section software. just one more comment: too bad you posted and never correct code that is clearly misleading...
Thanks Tamir,
I quite agree that instead of
memcpy((char *)0x00000000, (char *)(0x00002000), 64);
there should be
That was leftover after experimenting a milion times :)....
But this is what I don't understand: You said that I should use either:
or:
But in my case, I do use
but I also have to copy vectors manually. Nothing works if i do not copy IVT manually.
In other words, "RAM_INTVEC REMAP RAM_MODE" does the remapping, but doesn't copy the interupt vector table as I would expect it...
Or are you saying that "RAM_INTVEC REMAP RAM_MODE" should move IVT and there is no need to do this manually?
You don't need the file SWI_Table.s in your project at all. you only need it if you want to implement your own SWIs.
View all questions in Keil forum