Hi All, I am not an expert on ARM yet but an average guy for uC.
I am trying to get hands on with LPC2148 and plan to use it in next project.
One wonderful thing that I came across (I come form a background where we use 8051/mega16 uC) is USB IAP. So without any UART/Serial cable, I can flash program just by using USB cable.
Did some changes like 1. generating bin file (using fromelf --bin ....) and 2. changing IROM1 from 0x0 to 0x2000
to make program work with IAP.
I tasted some program and those worked very well.
But the issue is arising when I try to use Timer0 interrupt. I see controller getting stuck somewhere just after 1st int.
I checked with "Use Memory Layout with Target Dialog" selected and de-selected both. Nothing worked.
This has something to do with vector table but I am not able to make out what?
Any help on this would be appreciated.
Remember, I just made 3 above mentioned changes after creating new project. If there is anything else, please let me know.
Thanks John for that wonderful and easy explanation. While I did get what Per said, but didn't know how to do it.
Right now I do not have access to the board. Will post here the my observation as soon as I get it(Hope to keep some smileys than).
Hi John, I just tried adding "RAM_INTVEC REMAP RAM_MODE" but it didn't worked.
Here is what I tried. 1. I just wrote a prog in keil which toggles 2 port pins. 1st by a while loop, 2nd by timer. 2. Without adding anything I simulated it in keil. (IROM1 still from 0x0, No remapping) 3. This works well and I see both of the port pins toggling.
Now I made a simple change of Adding "RAM_INTVEC REMAP RAM_MODE". I recompiled the code and simulated. Here, I saw that, as soon as int is occurred, LPC jumps to "LDR PC, [PC, #-0x0FF0]", but does not move from that point.
Moreover, I see words REMAP and RAM_MODE in Startup.s but not the RAM_INTVEC. I am using Startup.s provided by keil only.
KEIL has quite a lot startup.s/LPCooxx.s You need another startup.s like this: rtime.felk.cvut.cz/.../lpc21xx-boot
+# Memory Mapping (when Interrupt Vectors are in RAM) + .equ MEMMAP, 0xE01FC040 /* Memory Mapping Control */ +.ifdef RAM_INTVEC + LDR R0, =MEMMAP + MOV R1, #2 + STR R1, [R0] +.endif
I think what I have is exactly this only.
; Memory Mapping (when Interrupt Vectors are in RAM) MEMMAP EQU 0xE01FC040 ; Memory Mapping Control IF :DEF:REMAP LDR R0, =MEMMAP IF :DEF:EXTMEM_MODE MOV R1, #3 ELIF :DEF:RAM_MODE MOV R1, #2 ELSE MOV R1, #1 ENDIF STR R1, [R0] ENDIF
By defining REMAP and RAM_MODE, this will do exactly what your code snippets does with RAM_INTVEC.
In the Startup.s that I am using, what shown above is the only place where REMAP and RAM_MODE is used. There are no other defines.
I guess your startup.s is very like this one:
forum.sparkfun.com/viewtopic.php
If so, you need to figure out how it accomplishes what Per told you.
And, I don't think you can easily simulate USB_IAP.hex + my_prog.bin, it would be easier to run them on the real hardware.
Are you using this: ics.nxp.com/.../ ==> Boot Loader V2.12 for LPC213x and LPC214x (Apr 12, 2007) And it does not provide source code for bootloader (USB_IAP.hex)?
Take a look at this: it is for LPC23xx. http://www.keil.com/forum/13707/
See if you can debug your my_prog.bin like the below. After all of that, I start my Debug Session. The Disassembly Window shows the Machine Code/ASM Code of the Bootloader (without the Source Code). Then, the Bootloader jumps to my application. So that, I get the state while the Bootloader just finishes its work, and pass the control to my application. I can observe the CPSR and the R13/SP of Supervisor Mode etc, to see if the solutions works properly.
John, I did try the changes on hardware also. Yes, you are correct that simulation cannot be always correct.
BTW, I didn't find this connected to this issue. "Are you using this:
USB_IAP.hex is going to be the secondary bootloader which resides in 128k flash. And, as far as I understand, the link you gave is for primary bootloader which is by default by NXP.
Here is what I am using "">www.nxp.com/search
BTW, Right now I am looking at "http://www.keil.com/forum/13707/" which you gave. Though this tread is for different uC and App Not is also different (AN10759), I think the idea should be same.
Thanks for the pointer. Will have a look at it and post the conclusion here.
Meanwhile, if there is something new, I would be glad to take it.
www.nxp.com/.../LPC2000_Series_Secondary_Bootloader.zip
The above link is not for USB_IAP either. I am sorry.
www.sparkfun.com/.../94
LPC2148 USB Bootloader Tutorial by zagGrad | August 04, 2008 | 17 comments
This link should provide everything you need, except it may not be designed for your hardware, and it is not for KEIL toolchain.
.if (RAM_MODE==0) /* Relocate .data section (Copy from ROM to RAM) */ LDR R1, =_etext LDR R2, =_data LDR R3, =_edata CMP R2, R3 BEQ DataIsEmpty LoopRel: CMP R2, R3 LDRLO R0, [R1], #4 STRLO R0, [R2], #4 BLO LoopRel DataIsEmpty: .endif
www.embeddedrelated.com/.../39585.php
Copying Interrupt vector table to RAM
It is for IAR toolchain.
(9) LDMIA r8!,{r0-r7} ; Load Vectors (10) STMIA r9!,{r0-r7} ; Store Vectors (11) LDMIA r8!,{r0-r7} ; Load secondary vector table (12) STMIA r9!,{r0-r7} ; Store secondary vector table ; Setup Memory Mapping Control to remap the RAM vector area (13) LDR r0,=LPC231X_MEMMAP (14) MOV r1,#2 ; MEMMAP to User RAM mode (15) STRNE r1,[r0,#0] ; Remap Memory, if not remapped already
John, From the other link you gave me (http://www.keil.com/forum/13707/) I found this.
; Copy Exception Vectors to Internal RAM --------------------------------------- RAM_BASE EQU 0x40000000 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 think this was missing from my Startup.s This also supports your defines "RAM_INTVEC REMAP RAM_MODE".
Giving it a try now.
Hi John, Something good, something bad... I told you about the link from where I got USB_IAP.hex. (originally Memory.hex) which is USB based secondary bootloader.
Link : www.nxp.com/search
Here, with the code of USB bootloader, there is a sample code as well for user program. I used it and copied it over the board (with some modification for my board) (project name : blinky)
And VOILA, It worked.
Now, I am trying to figure out the changes between two.