Pure assembler code for the LPC1114

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pure assembler code for the LPC1114

2,955 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ronikeshet on Sat Mar 12 13:10:44 MST 2011
Hi, :o
My name is Roni Daffan.
I just started to get to know the LPC1114.
I try to write an assembler code from scratch.
Using the LPCxpresso, I try to write a small program that will convert the pull up resistor of P0.7 (led2) to a pull down resistor, just for a start.
Please see the little code below.
When I try to use the debug build mode, is seems to compile it correctly, since I can see the number of bytes is correct.
However, when I use the release build mode, it does not seems to work ok, the number of bytes is always 20, no matter what the code is.
I tried to download the code into the LPC1114.
Downloading the debug *.axf results with an error of "attempt to load into missing flash area".
Downloading the release *.axf file do nothing.

Can anybody help me out with this ?
Is there any assembler freak around here that can help me with this ?
I'm willing provide support as well.
Thank you,
Roni

See code below.
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT].syntax unified[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055].global[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] _start[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]_start:[/LEFT]
[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
.org 0x00000000 [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE]Stack pointer initial value[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055].word[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0x10002000
.org 0x00000004

b main

.org 0x00000100[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]main:[/LEFT]
[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]ldr R0,port_0_config_data
ldr R1,port_0_config_addr
str R1,[R0][/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]endloop:[/LEFT]
[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]b endloop

 [/LEFT]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][LEFT]//*******************************************************[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT].align
port_0_config_data:[/LEFT]
[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055].word[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0b00000000000000000000000011001000[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]port_0_config_addr:[/LEFT]
[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055].word[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0x40044050

 
.end[/LEFT]
[/SIZE]
0 Kudos
Reply
17 Replies

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by affonpign on Fri Jun 17 01:15:35 MST 2011
Hi,

I tried the assembler code disabling the main breakpoint and using the RAMAHB32 but I still have a problem because the debugger tells me:

symbol is not available; 0x00000028

I also use the LPCExpresso IDE Chen is using. Can anybody help? Thanks.

Regards,
affonpign
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cktham on Tue Jun 07 02:52:38 MST 2011
Thanks to CodeRed Support (Rob) for your prompt response.
This problem has stumped me for 2 days.:mad:

StkErr sometimes does not happen, but ImpreciseErr always does.

The problem only occurs with the .word obtained address, e.g. 0x00000060 (which really contains the var1 value).

If I use another memory location, e.g. 0x10004000, everything is fine, e.g.
LDR R3, =0x10004000
STR R2, [R3]
LDR R5, [R3]
:
i.e. R2 content correctly written into 0x10004000 and correct value read back into R5.

Chen
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Sat Jun 04 22:51:10 MST 2011
There must be something else going on.

The Arm v7-M Architecture Reference manual (downloadable via arm.com) tells me:


Quote:

Derived exceptions on exception entry
Where an exception entry sequence itself causes a fault, the exception that caused the exception entry
sequence is known as the original exception. The fault that is caused by the exception entry sequence is
known as the derived exception. The code stream running at the time of the original exception is known as
the preempted code, and the execution priority of that code is the preempted priority.
The following derived exceptions can occur during exception entry:
• A MemManage fault on a write to the stack memory performed as part of the exception entry. This
is described as a MSTKERR class of MemManage fault.
• A BusFault on a write to the stack memory performed as part of the exception entry. This is described
as a STKERR class of BusFault.



So this is a derived bus fault during exception entry.
Meaning the error is not happening where you think it might be, the processor was somehow not able to properly enter the exception.
Are you using interrupts? Or are you simply stuck in one of the exception handlers in the startup code?

ImpreciseErr means that the processor does not show you where the exact bus fault occured. If it was a PreciseErr you would have been able to read the address of the load or store in the Bus Fault Address Register, now you have to trace this back in your code.

It looks like you have a problem elsewhere in your code that appears to happen at this point. Do you see any strange things in your registers? What is the content of R3 when you execute the STR? What ...

Hopefully you will be able to get a bit further with this.
Debugging error exception is a difficult task (I've spend more than a few days tracking down errors like this in my own code). It is (almost) impossible to do this without having the complete environment set up.

Rob
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cktham on Fri Jun 03 21:32:12 MST 2011
[SIZE=2]After the help from CodeRed Support below in early May, I managed to do some fun things with pure assembly language, the LPC1769 registers and stack. :)[/SIZE]

[SIZE=2]However, I am not able to write into memory reserved using .word in the GNU assembler, e.g.[/SIZE]

[SIZE=2]var1:[/SIZE]
[SIZE=2]    . word 0[/SIZE]

[SIZE=2]:[/SIZE]
[SIZE=2]LDR R3, =var1[/SIZE]
[SIZE=2]    STR R0, [R3][/SIZE]
[SIZE=2]:[/SIZE]
[SIZE=2]causes ImpreciseErr and StkErr at the next instruction (contents of R0 also not written into var1 location - I monitored these in the IDE)![/SIZE]

[SIZE=2]Another question is: does it matter where the var1: .word is done? [/SIZE]
[SIZE=2]I did it before vectors: .word definitions and it complained immediately, so I now I do it between vectors: .word definitions and .global _start[/SIZE]

[SIZE=2]Please help.[/SIZE]
[SIZE=2]Thanks.[/SIZE]

[SIZE=2]Chen[/SIZE]
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Mon May 09 08:57:07 MST 2011

Quote: cktham
lpc17_pureasm works :) from within IDE for LPC1769.
Thanks, Andy!

Chen



Hi Chen,

Andy is only one of the nice people that answer under the username CodeRedSupport.  The only reason I had assumed it was Andy was his name in the files in the .zip above and that I knew he was going to ESC. Sorry to cause this confusion.  In the future use CodeRedSupport and not an individuals name when replying to posts.

Thank You,
Larry
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cktham on Mon May 09 02:17:52 MST 2011
lpc17_pureasm works :) from within IDE for LPC1769.
Thanks, Andy!

Chen
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Mon May 02 10:49:34 MST 2011
Thank you both for your quick replies.

Andy are you now in San Jose for ESC?
0 Kudos
Reply

2,905 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon May 02 10:41:46 MST 2011

Quote: larryvc
I spent some time last night trying to figure this out and didn't come up with a solution for building and downloading from the the IDE either.

CodeRedSupport, Can you describe how to do this?



There are a number of issues here. The primary one is that the assembler file is not compatible with the default managed linker script generated by the IDE. This can be overcome by providing a linker script template that matches how the assembler file was written.

Linker templates covered in the FAQ at:
http://support.code-red-tech.com/CodeRedWiki/EnhancedManagedLinkScripts

A secondary issue is that the debugger tries to set on breakpoint on the symbol main. Thus the launch configuration needs editing to instead set the breakpoint on the symbol used by the assembler file : _start, as per the FAQ:
http://support.code-red-tech.com/CodeRedWiki/InitialBP

I've also modified the assembler file itself to reduce the length of the delay loop and also to make the _start symbol accessible by the linker script.

Regards,
CodeRedSupport.
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Mon May 02 10:25:10 MST 2011

Quote: larryvc
Could you tell me how you used the command line tools to accomplish this?



Here's a quick and dirty example using windows batch files. It would be better to write it as one Makefile.

There's a readme.txt file explaining how to set it up.
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Mon May 02 09:17:49 MST 2011
I spent some time last night trying to figure this out and didn't come up with a solution for building and downloading from the the IDE either.

CodeRedSupport, Can you describe how to do this?

jharwood, Could you tell me how you used the command line tools to accomplish this?

Regards,
Larry
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Mon May 02 08:47:48 MST 2011

Quote: cktham

Please advise how best to launch the pure assembler code you gave, using LPCXpresso IDE. I'm using LPCXpresso with LPC 1769.




Hi Chen,
I'm not too sure how to build and run it with the IDE. I just used the command line tools.
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cktham on Sun May 01 18:44:51 MST 2011
Dear jharwood,

Please advise how best to launch the pure assembler code you gave, using LPCXpresso IDE. I'm using LPCXpresso with LPC 1769.

I managed to build it. Running the .axf file doesn't work, but running the .o file seems OK, but I'm not sure whether I'm doing the right thing.

Thanks.

Chen
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Sun Mar 13 00:41:48 MST 2011
Here's a simple assembler app that blinks a LED on an LPC1769 Cortex-M3. The register addresses and operations will differ slightly to the M0.



@ Directives
        .thumb                  @ (same as saying '.code 16')
        .syntax unified

@ Equates
    .equ PINSEL1,      0x4002C004
    .equ FIO0DIR,      0x2009C000
    .equ FIO0SET,     0x2009C018
    .equ FIO0CLR,      0x2009C01c
    .equ LEDPIN,      0x400000
        .equ STACKINIT,   0x10080000
        
        .equ LEDDELAY,    8000000
        
.section .text
        .org 0

@ Vectors
vectors:        
        .word STACKINIT         @ stack pointer value when stack is empty
        .word _start + 1        @ reset vector (manually adjust to odd for thumb)
        .word _nmi_handler + 1  @ 
        .word _hard_fault  + 1  @ 
        .word _memory_fault + 1 @
        .word _bus_fault + 1    @ 
        .word _usage_fault + 1  @
    .word 0            @ checksum 

_start:
    @ disable interrupts left on by bootloader
    cpsid i

    @ set the pinselect
    ldr r6, = PINSEL1
    ldr r0, [r6]
    and r0, 0xffffcfff
    str r0, [r6]
 
    @ and port direction
    ldr r6, = FIO0DIR
    mov r0, LEDPIN
    str r0, [r6]

        @ Load R2 with the led pin number
        mov r2, LEDPIN             @ value to turn on/off LED
        
loop:
    ldr r6, = FIO0SET
        str r2, [r6]           @ set Port 0, pin 22, turning on LED
        ldr r1, = LEDDELAY
delay1:
        subs r1, 1
        bne delay1
        
    ldr r6, = FIO0CLR
        str r2, [r6]           @ clear Port 0, pin 22, turning off LED
        ldr r1, = LEDDELAY
delay2:
        subs r1, 1
        bne delay2

        b loop                 @ continue forever

_dummy:                        @ if any int gets triggered, just hang in a loop
_nmi_handler:
_hard_fault:
_memory_fault:
_bus_fault:
_usage_fault:
        add r0, 1
        add r1, 1
        b _dummy  


0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Sat Mar 12 22:49:38 MST 2011
It's written for ARM7, but this book is a very good (and rare) introduction to ARM assembly and if you can wrap your head around this it will be easy to adopt the changes on the M0 or M3 parts.

http://www.amazon.com/ARM-Assembly-Language-Fundamentals-Techniques/dp/1439806101

It's not cheap, but still the cheapest education you're likely to find, and it's accessible if you have a bit of experience with embedded devices.  It assumes no experience with assembly.
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sat Mar 12 14:33:45 MST 2011
Roni have you seen this [B][COLOR=darkorange]post[/COLOR][/B]. I don't know if it will help address your problem or not.
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ronikeshet on Sat Mar 12 14:28:53 MST 2011
Thank you,
I have corrected this, but still not working.
I think there is some kind of an offset value for the assembler, since when I display the disassembly (right clik the *.axf file and select binary unilitiy) I can see the code is placed at address 0x8000 and on.
If fact I did not start this from scrach, I was unsing a project example of another memer here. Maybe there is a difinition that I need to change, like the assembler start address, of offset ?
Thanks a lot,
Roni
0 Kudos
Reply

2,906 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Sat Mar 12 14:16:37 MST 2011
I haven't ventured into assembly with the cortex-mX chips yet, but I do see one thing:

In the second word of flash memory you have

b main

which I think is the instruction 'branch to main'?  whereas that second word should be the vector to (or address of ) main, not an instruction.
0 Kudos
Reply