Author Topic: Programming NXP uC  (Read 6489 times)

0 Members and 2 Guests are viewing this topic.

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Programming NXP uC
« on: November 05, 2019, 11:07:03 pm »
I want to program NXP uC LPC810M021FN8FP using FlashMagic software.
I have USB to UART TTL converter.
I have successfully read the signature of the uC in FlashMagic.

I am surprised that LPCXpresso doesn't compile to .hex by default,
but I added a post build step:

rclick_on_project->c/c++build->settings->post_build_steps->edit

arm-none-eabi-objcopy -v -O ihex "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.hex"

from here:

https://mcuoneclipse.com/2017/03/29/mcuxpresso-ide-s-record-intel-hex-and-binary-files/


LPCXpresso compiles to .axf file but I don't know how to burn that file
because LPCXpresso doesn't have burner.exe file anywhere.
 (MCUXpresso should have this burner probably:
   https://mcuoneclipse.com/2012/09/27/s-record-intel-hex-and-binary-files/
 )

What is the best way to burn LPC810 uC ?

Many thanks.
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming NXP uC
« Reply #1 on: November 11, 2019, 07:38:03 pm »
Hi,

I am trying to program lpc810 in assembly.

It doesn't work. Can you please help me?

I don't even know if the address 0x0 is suppose to be address or jump?

I compile like this:

Code: [Select]
as -mcpu=cortex-m0  led02.s -o led.o
objcopy -O ihex led.o led.hex


This is the code , it is suppose to turn off gpio pins (they are 1 by default) :

Code: [Select]
PINENABLE0      = 0x4000C1C0
value           = 0xffffffbf
SYSAHBCLKCTRL   = 0x40048080
GPIO_DIRP0      = 0xA0002000
GPIO_CLRP0      = 0xA0002280   

.text
        .align  2
        .global _start
_start:

bal ResetHandler @
bal . @;handlerUndef
bal . @;SWI interrupt handler
bal . @;handlerPrefetchAbort
bal . @;handlerDataAbort
bal . @;handlerReserved
bal . @;handlerIRQ
bal . @; Remake to save FIQ access time......

ResetHandler:
        ldr     r1,=SYSAHBCLKCTRL
        ldr     r2, [r1]
        mov     r0, #1
        lsl     r0, #6
        orr     r2, r0
        mov     r0, #1
        lsl     r0, #18
        orr     r2, r0
        str     r2, [r1]

        ldr     r1,=PINENABLE0
        ldr     r2,=value
        str     r2,[r1]

        ldr     r1,=GPIO_DIRP0
        mov     r2,#0xFF
        str     r2,[r1]

        ldr     r1,=GPIO_CLRP0
        mov     r2,#0xFF
        str     r2,[r1]

loop:
 
        bal     loop

        .align  2

.bss

« Last Edit: November 11, 2019, 07:40:10 pm by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1912
  • Country: de
Re: Programming NXP uC
« Reply #2 on: November 11, 2019, 08:14:58 pm »
The entry at 0x0 is the main stack pointer MSP (initial stack pointer), the 2nd 32bit value is the address of the reset handler (0x4), followed by all the trap and interrupt handlers.
Note that the lowermost bit of all vectors including the reset vector must be set to indicate Thumb mode. So all the addresses "look" odd, even though the lowermost bit is actually not part of the address.

Anyway, I would advise you to use a slightly bigger part like LPC812 or LPC824 where you can use the SWD interface and still have some pins left. The SO20 or even TSSOP20 parts are easy to handle and can be e.g. soldered to a DIP adapter PCB to use them on breadboards.
The LPC-Link2 allows debugging for 20-30€. For ~50-60€ you can even buy a Segger EDU which opens the world of debugging with Ozone.


Trying is the first step towards failure - Homer J. Simpson
 
The following users thanked this post: vlad777

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming NXP uC
« Reply #3 on: November 11, 2019, 08:39:13 pm »
The entry at 0x0 is the main stack pointer MSP (initial stack pointer), the 2nd 32bit value is the address of the reset handler (0x4), followed by all the trap and interrupt handlers.
Note that the lowermost bit of all vectors including the reset vector must be set to indicate Thumb mode. So all the addresses "look" odd, even though the lowermost bit is actually not part of the address.

So it should be:

_start:

        .word       0x10000200
        .word       ResetHandler+1   @


Is that right?

Looking at the disassembly of a c code that works, i gather that only flash (instructions) addresses have lowermost bit set.

edit: Or is it just in vector table?
« Last Edit: November 11, 2019, 08:43:19 pm by vlad777 »
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1912
  • Country: de
Re: Programming NXP uC
« Reply #4 on: November 11, 2019, 08:57:51 pm »
The lowermost bit must be set for any address that is loaded into the program counter (PC) as it indicates the instruction set, and the Cortex-M0+ only supports Thumb instructions.
This affects also instructions like BX, BLX and POP. When the link register LR is updated by BL or BLX, the lowermost bit is automatically set.

Honestly I'm not sure if the assembler somehow handles this lowermost bit automatically or not. I'd suggest to dump a binary and have a look.
Again, if you had a SWD debugger, you could single step through your code and looks what it's doing. After all, this is the 21st century.

Anyway, is there any specific reason you want to program the LPC810 in assembler? As someone who just wrote a few hundred assembler lines at work I can only say I (would) do this only if absolutely necessary.
Apart from some inline assembly here and there to use some commands not directly accessible in C and very specific functions like certain trap handlers, there is no real reason to use ASM on a Cortex-M CPU.
Trying is the first step towards failure - Homer J. Simpson
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming NXP uC
« Reply #5 on: November 11, 2019, 09:30:40 pm »

Anyway, is there any specific reason you want to program the LPC810 in assembler? As someone who just wrote a few hundred assembler lines at work I can only say I (would) do this only if absolutely necessary.
Apart from some inline assembly here and there to use some commands not directly accessible in C and very specific functions like certain trap handlers, there is no real reason to use ASM on a Cortex-M CPU.


I am just learning about ARM assembly, and the uC I have at hand...
(somehow programming raspberry pi is not as rewarding...)
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline laneboysrc

  • Contributor
  • Posts: 28
  • Country: sg
    • LANE Boys RC - radio control related electronics
Re: Programming NXP uC
« Reply #6 on: November 12, 2019, 02:23:32 am »
Note that you also must have a checksum correctly programmed in vector location 7 to get the chip running:

Citation from LPC81X user manual, Chapter21 LPC81x Boot ROM, 21.6.2 Boot process:
Quote
During the boot process, the boot loader checks if there is valid user code in flash. The
criterion for valid user code is as follows:

The reserved Cortex-M0+ exception vector location 7 (offset 0x0000 001C in the vector
table) should contain the 2’s complement of the check-sum of table entries 0 through 6.
This causes the checksum of the first 8 table entries to be 0. The bootloader code
checksums the first 8 locations in sector 0 of the flash. If the result is 0, then execution
control is transferred to the user code.

If the signature is not valid, the auto-baud routine synchronizes with the host via serial port
USART0. ...

cheers, Werner
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30380
  • Country: nl
    • NCT Developments
Re: Programming NXP uC
« Reply #7 on: November 12, 2019, 09:08:32 am »
The flash magic tool takes care of calculating the signature/checksum during programming. You don't need to worry about that.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline vlad777Topic starter

  • Frequent Contributor
  • **
  • Posts: 350
  • Country: 00
Re: Programming NXP uC
« Reply #8 on: November 13, 2019, 10:34:35 am »

Here is a working example:

Code: [Select]

@ connect led at pin 4

PINENABLE0      = 0x4000C1C0
value           = 0xffffffbb
SYSAHBCLKCTRL   = 0x40048080
GPIO_DIRP0      = 0xA0002000
GPIO_CLRP0      = 0xA0002280   
GPIO_SETP0      = 0xA0002200 
                 

nval            =1000000
led             =4

.text
        .align  2
        .global _start
_start:

        .word   0x10000200
.word ResetHandler + 1
.word loop + 1
.word loop + 1
.word loop + 1
.word loop + 1
.word loop + 1
.word loop + 1
.word loop + 1

ResetHandler:
        ldr     r1,=SYSAHBCLKCTRL
        ldr     r2, [r1]
        mov     r0, #1
        lsl     r0, #6
        orr     r2, r0
        mov     r0, #1
        lsl     r0, #18
        orr     r2, r0
        str     r2, [r1]

        ldr     r1,=PINENABLE0
        ldr     r2,=value
        str     r2,[r1]

        ldr     r1,=GPIO_DIRP0
        ldr     r2,=led
        str     r2,[r1]



        ldr     r1,=GPIO_CLRP0
        ldr     r2,=GPIO_SETP0
        ldr     r4,=led



blink3:

        ldr     r3,=nval
blink1:
        sub     r3,#1
        cmp     r3,#0
bne     blink1       
        ldr     r2,=GPIO_SETP0
        str     r4,[r2]            @turn the LED on



        ldr     r3,=nval
blink2:
        sub     r3,#1
        cmp     r3,#0
bne     blink2     
        ldr     r1,=GPIO_CLRP0
        str     r4,[r1]           @turn the LED off



b blink3

loop:
 
        b     loop

        .align  2

.bss


Compile like this:

Code: [Select]
as -mcpu=cortex-m0  led06.s -o led.o
objcopy -O ihex led.o led.hex
objdump -D led.o >disasm.txt
Mind over matter. Pain over mind. Boss over pain.
-------------------------
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1912
  • Country: de
Re: Programming NXP uC
« Reply #9 on: November 13, 2019, 05:24:27 pm »
I haven't tried it myself, but some quick'n'dirty googling indicated that there's an assembler directive ".thumb_func" that tells the assembler to set the lowermost bit for the following function(s):

Code: [Select]
.thumb_func

ResetHandler:
    ldr ...

I think you can also place directives to set the CPU etc. instead of stating it on the command line. E.g.

Code: [Select]
.cpu cortex-m0

More information can be found e.g. here
Trying is the first step towards failure - Homer J. Simpson
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->