Programming NXP uC - Page 1
Forum section: electronics / general

author: vlad777
author_rank: Frequent Contributor
timestamp: November 05, 2019, 11:07:03 pm
content: 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->editarm-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 filebecause 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.

author: vlad777
author_rank: Frequent Contributor
timestamp: November 11, 2019, 07:38:03 pm
content: 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:as -mcpu=cortex-m0 led02.s -o led.oobjcopy -O ihex led.o led.hexThis is the code , it is suppose to turn off gpio pins (they are 1 by default) :Code:PINENABLE0 = 0x4000C1C0value = 0xffffffbfSYSAHBCLKCTRL = 0x40048080GPIO_DIRP0 = 0xA0002000GPIO_CLRP0 = 0xA0002280.text.align 2.global _start_start:balResetHandler@bal.@;handlerUndefbal.@;SWI interrupt handlerbal.@;handlerPrefetchAbortbal.@;handlerDataAbortbal.@;handlerReservedbal.@;handlerIRQbal.@; Remake to save FIQ access time......ResetHandler:ldr r1,=SYSAHBCLKCTRLldr r2, mov r0, #1lsl r0, #6orr r2, r0mov r0, #1lsl r0, #18orr r2, r0str r2, ldr r1,=PINENABLE0ldr r2,=valuestr r2,ldr r1,=GPIO_DIRP0mov r2,#0xFFstr r2,ldr r1,=GPIO_CLRP0mov r2,#0xFFstr r2,loop:bal loop.align 2.bss

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: November 11, 2019, 08:14:58 pm
content: 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.TheLPC-Link2allows debugging for 20-30€. For ~50-60€ you can even buy a Segger EDU which opens the world of debugging with Ozone.

author: vlad777
author_rank: Frequent Contributor
timestamp: November 11, 2019, 08:39:13 pm
content: Quote from: 0xdeadbeef on November 11, 2019, 08:14:58 pmSo 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?

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: November 11, 2019, 08:57:51 pm
content: 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.

author: vlad777
author_rank: Frequent Contributor
timestamp: November 11, 2019, 09:30:40 pm
content: Quote from: 0xdeadbeef on November 11, 2019, 08:57:51 pmI am just learning about ARM assembly, and the uC I have at hand...(somehow programming raspberry pi is not as rewarding...)

author: laneboysrc
author_rank: Contributor
timestamp: November 12, 2019, 02:23:32 am
content: 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:Quotecheers, Werner

author: nctnico
author_rank: Super Contributor
timestamp: November 12, 2019, 09:08:32 am
content: The flash magic tool takes care of calculating the signature/checksum during programming. You don't need to worry about that.

author: vlad777
author_rank: Frequent Contributor
timestamp: November 13, 2019, 10:34:35 am
content: Here is a working example:Code:@ connect led at pin 4PINENABLE0 = 0x4000C1C0value = 0xffffffbbSYSAHBCLKCTRL = 0x40048080GPIO_DIRP0 = 0xA0002000GPIO_CLRP0 = 0xA0002280GPIO_SETP0 = 0xA0002200nval =1000000led =4.text.align 2.global _start_start:.word 0x10000200.wordResetHandler + 1.wordloop + 1.wordloop + 1.wordloop + 1.wordloop + 1.wordloop + 1.wordloop + 1.wordloop + 1ResetHandler:ldr r1,=SYSAHBCLKCTRLldr r2, mov r0, #1lsl r0, #6orr r2, r0mov r0, #1lsl r0, #18orr r2, r0str r2, ldr r1,=PINENABLE0ldr r2,=valuestr r2,ldr r1,=GPIO_DIRP0ldr r2,=ledstr r2,ldr r1,=GPIO_CLRP0ldr r2,=GPIO_SETP0ldr r4,=ledblink3:ldr r3,=nvalblink1:sub r3,#1cmp r3,#0bne blink1ldr r2,=GPIO_SETP0str r4, @turn the LED onldr r3,=nvalblink2:sub r3,#1cmp r3,#0bne blink2ldr r1,=GPIO_CLRP0str r4, @turn the LED offb blink3loop:b loop.align 2.bssCompile like this:Code:as -mcpu=cortex-m0 led06.s -o led.oobjcopy -O ihex led.o led.hexobjdump -D led.o >disasm.txt

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: November 13, 2019, 05:24:27 pm
content: 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:.thumb_funcResetHandler:ldr ...I think you can also place directives to set the CPU etc. instead of stating it on the command line. E.g.Code:.cpu cortex-m0More information can be found e.g.here