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.
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
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.
And by the way, USBPortNum is 0 at the time the code crashes, and USB_REG(USBPortNum) resolves to a memory address of 0x40006000.
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.
BR
XiangJun Rong
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.
Any further thoughts on this? Can you reproduce the bug on your end using the labtool code?
Thanks,
Koray
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.
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