Issues flashing LPC-Link2 with labtool-based code

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

Issues flashing LPC-Link2 with labtool-based code

1,465 Views
ksahin
Contributor II

Hi,

We've created a project for the LPC-Link2/LPC4370 based on the Embedded Artist's labtool codebase. We started there in order to leverage their implementation of HSADC using DMA.

 

Now we are trying to deploy this firmware by flashing it on our LPC-Link2, but whenever we configure the flash memory, the code crashes. The code will not successfully run from flash, nor will it work from the debugger. If the flash is configured as below, the code will not run. If we remove the flash configuration line, the code runs fine.

ksahin_0-1691173272650.png

 

The original labtool code goes straight to HardFault_Handler() upon running from the debugger. Our heavily modified code fails upon executing this simple assignment operator in HAL_Reset () (line 81 in Endpoint_LPC18xx.c:

USB_REG(USBPortNum)->ENDPTCTRL1 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);

 

Do you have any insights as to why this may be? How can we get our code to run from flash?

 

Thanks,

Koray Sahin

 

Labels (1)
Tags (2)
0 Kudos
Reply
7 Replies

1,393 Views
ksahin
Contributor II

Hi XiangJun,

Thanks for looking into this. When I comment that line out, it just fails on the following line, which is very similar:

USB_REG(USBPortNum)->ENDPTCTRL2 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);

If I comment out all assignments to USB_REG, including the call to USB_Device_SetDeviceAddress() which also assigns to that memory location, the code just fails somewhere else.

It feels like we're writing to a memory location that we shouldn't be writing to. Perhaps adding the flash to the memory configuration is changing a memory address offset somewhere? I'm no expert in MCUs and FW, so I'm just guessing here.

0 Kudos
Reply

1,390 Views
ksahin
Contributor II

And by the way, USBPortNum is 0 at the time the code crashes, and USB_REG(USBPortNum) resolves to a memory address of 0x40006000.

0 Kudos
Reply

1,365 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I suppose that you know the LPCOpen package for LPC4370, you can try to run USB example in the package and check if there is any error.

https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/lpcopen-libr...

BR

XiangJun Rong

0 Kudos
Reply

1,307 Views
ksahin
Contributor II

The LPCOpen usbd_rom_hid_generic project behaves exactly the same way as the original labtool project - if flash is configured, it goes straight to HardFault_Handler() after I start debugging.

If I remove the flash from the memory configuration, the code runs fine from RAM.

0 Kudos
Reply

1,175 Views
ksahin
Contributor II

Any further thoughts on this? Can you reproduce the bug on your end using the labtool code?

Thanks,

Koray

0 Kudos
Reply

1,461 Views
ksahin
Contributor II

Also, we are able to flash some basic blinky code with the memory configured as shown in the screenshot in my first post. We used the MCUXpresso GUI flash tool. The blinky code runs fine no matter how we run it. We can debug running from RAM, debug running from flash, and also run from flash as a stand-alone device.

 

So it looks to us like our toolchain and hardware work fine, but the labtool code simply won't run from flash without crashing.

0 Kudos
Reply

1,405 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

From your description, you run the led blinky example, no problem.

I suppose that the line USB_REG(USBPortNum)->ENDPTCTRL1 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable); has problem.

If you comment the above line, does the hardfault error happen or not?

BR

XiangJun Rong

0 Kudos
Reply