PlatformIO Community

How to properly set the upload port on macOS LPC1768 Board & ULINK-ME

Hey,
I have some trouble finding the necessary upload_port path on macOS in order to try to upload/flash a test program for a start.

The board is the LPC1768 dev board by Keil.
latest macOS
I’m on VS Code

I seem not to be able to properly flash a test program onto that microcontroller.
Drivers installation has been tested, as suggested in another topic, did not help, as those drivers do not explicitly support any of these NPX LPCxxx micro controllers.
Best regards and highly appreciate any answer.

This? http://www.keil.com/mcb1700/

Which platformio.ini do you have and what hardware do you have connected to the board?

Which topic?

  1. exactly that board

[env:lpc1768]
platform = nxplpc
board = lpc1768
framework = mbed

I have the Keil ULINK-ME flash thingy connected(via the jtag port), that is being powered via usb by my macbook. Also I have the board connected via one of those old printer usb cables in order to supply power to the board.

  1. The other topic mentioned is this one(it’s a dead end):
    Esp32 upload port

Setup:
IMG_20190912_181846

Alright so openocd isn’t supported right now for this target but theoretically it’s available. (https://github.com/platformio/platform-nxplpc/blob/develop/boards/lpc1768.json)

Could you open a shell and cd into your <home folder>/.platformio/packages/tool-openocd folder and execute

./bin/openocd -f scripts/interface/ulink.cfg -f scripts/board/mcb1700.cfg

And tell me the output.

I have no such file in ~/.platformio/packages/
But I have

tool-pioplus/              
tool-pyocd/                
tool-scons/                
tool-unity/                
toolchain-gccarmnoneeabi/

Also, where are those two relative paths at?

I can install OpenOCD via brew.

So I installed OpenOCD via brew install open-ocd
I do not know, if platformIO actually uses it, but yeah.

I executed your command and got this:
01

The scripts and bin folder are then in tool-openocd.

Can you temporary change your platfromio.ini to

[env:lpc11u68]
platform = nxplpc
framework = mbed
board = lpc11u68
upload_protocol = cmsis-dap

and execute a compile and upload (pio run -t upload). That will force the tool-openocd package to be installed. Then change it back to the original platformio.ini.

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nxplpc/lpc11u68.html
PLATFORM: NXP LPC 4.4.0 > LPCXpresso11U68
HARDWARE: LPC11U68 50MHz, 36KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51304.190826 (5.13.4), tool-pyocd 0.801.0 (8.1)
Collecting mbed sources...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 4 compatible libraries
Scanning dependencies...
No dependencies
Checking size .pio/build/lpc11u68/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   1.5% (used 568 bytes from 36864 bytes)
PROGRAM: [          ]   4.5% (used 11800 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = cmsis-dap
Uploading .pio/build/lpc11u68/firmware.bin
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1
adapter speed: 10 kHz
adapter_nsrst_delay: 200
cortex_m reset_config sysresetreq
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Error: Failed to write memory at 0x40048004
in procedure 'program' 
in procedure 'reset' called at file "embedded:startup.tcl", line 500
in procedure 'ocd_bouncer' 
in procedure 'ocd_process_reset' 
in procedure 'ocd_process_reset_inner' called at file "embedded:startup.tcl", line 248
in procedure 'lpc11xx.cpu' called at file "embedded:startup.tcl", line 382
in procedure 'ocd_bouncer'

** Programming Started **
auto erase enabled
Warn : Verification will fail since checksum in image (0x00000000) to be written to flash is different from calculated vector checksum (0xefff67fd).
Warn : To remove this warning modify build tools on developer PC to inject correct LPC vector checksum.
Warn : not enough working area available(requested 4096)
Error: no working area specified, can't write LPC2000 internal flash
Error: error writing to flash at address 0x00000000 at offset 0x00000000
embedded:startup.tcl:476: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 532
at file "embedded:startup.tcl", line 476
*** [upload] Error 1

I tried to uninstall the brew openocd version and the extension doesn’t seem to install it, nor the command:

pio run -t upload                                                                                                            ✔  10061  19:11:01
Processing lpc11u68 (platform: nxplpc; framework: mbed; board: lpc11u68)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nxplpc/lpc11u68.html
PLATFORM: NXP LPC 4.4.0 > LPCXpresso11U68
HARDWARE: LPC11U68 50MHz, 36KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) On-board (cmsis-dap) External (blackmagic, jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51304.190826 (5.13.4), tool-pyocd 0.801.0 (8.1)
Collecting mbed sources...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 4 compatible libraries
Scanning dependencies...
No dependencies
Checking size .pio/build/lpc11u68/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   1.5% (used 568 bytes from 36864 bytes)
PROGRAM: [          ]   4.5% (used 11800 bytes from 262144 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = cmsis-dap
Uploading .pio/build/lpc11u68/firmware.bin
sh: openocd: command not found
*** [upload] Error 127

So I reinstalled it via brew.
Also in the previous post, I edited the actual output of the command, you asked to be executed.

~/.platformio/packages ls                                                                                                                                         
contrib-piohome          contrib-pysite           framework-mbed           tool-pioplus             tool-pyocd               tool-scons               tool-unity               toolchain-gccarmnoneeabi

Ok so the upload failures are expected because this is just a different chip, the output doesn’t matter. Did install the tool-openocd package in platformio?

The openocd package in brew could be outdated, because I at least get a different error and it tells me it selected JTAG.

max@XXXX:~/.platformio/packages/tool-openocd$ ./bin/openocd -f scripts/interface/ulink.cfg -f scripts/board/mcb1700.cfg 
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:25)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: Could not open ULINK device

There is no tool-openocd in the ./.platformio/packages folder.

I also tried the old platformio.ini with upload_protocol = cmsis-dap
and got this error:

...
Compiling .pio/build/lpc1768/FrameworkMbed/targets/TARGET_NXP/TARGET_LPC176X/sleep.o
Compiling .pio/build/lpc1768/FrameworkMbed/targets/TARGET_NXP/TARGET_LPC176X/spi_api.o
Compiling .pio/build/lpc1768/FrameworkMbed/targets/TARGET_NXP/TARGET_LPC176X/us_ticker.o
Compiling .pio/build/lpc1768/FrameworkMbed/targets/TARGET_NXP/TARGET_LPC176X/watchdog_api.o
Compiling .pio/build/lpc1768/src/main.o
Generating LD script .pio/build/lpc1768/LPC1768.ld.link_script.ld
Linking .pio/build/lpc1768/firmware.elf
Checking size .pio/build/lpc1768/firmware.elf
Building .pio/build/lpc1768/firmware.bin
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   5.2% (used 3417 bytes from 65536 bytes)
PROGRAM: [=         ]   6.6% (used 34716 bytes from 524288 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed
CURRENT: upload_protocol = cmsis-dap
Uploading .pio/build/lpc1768/firmware.bin
Traceback (most recent call last):
  File "/Users/john/.platformio/packages/tool-pyocd/pyocd-flashtool.py", line 24, in <module>
    from pyOCD.tools.flash_tool import main
  File "/Users/john/.platformio/packages/tool-pyocd/site-packages/pyOCD/__init__.py", line 18, in <module>
    import board
ModuleNotFoundError: No module named 'board'
*** [upload] Error 1

I will try to update the brew openOCD package to a newer development version.

Meh. Could you temporary change your platform to

[env:nucleo_f401re]
platform = ststm32
framework = mbed
board = nucleo_f401re

and again pio run -t upload. Does the folder now appear?

Brew version executing the command openocd share/openocd/scripts/interface/ulink.cfg -f share/openocd/scripts/board/mcb1700.cfg

 john@83adbc14  /usr/local/Cellar/open-ocd/HEAD-09eb941  openocd share/openocd/scripts/interface/ulink.cfg -f share/openocd/scripts/board/mcb1700.cfg                               ✔  10104  19:34:57
Open On-Chip Debugger 0.10.0+dev-00930-g09eb941c (2019-09-12-19:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Unexpected command line argument: share/openocd/scripts/interface/ulink.cfg

The package has been successfully installed now.

PlatformManager: Installing ststm32
ststm32 @ 5.6.0 is already installed
The platform 'ststm32' has been successfully installed!
The rest of packages will be installed automatically depending on your build environment.
PackageManager: Installing tool-stm32duino @ ~1.0.1
tool-stm32duino @ 1.0.1 has been successfully installed!
PackageManager: Installing tool-openocd @ ~2.1000.0
Downloading  [####################################]  100%
tool-openocd @ 2.1000.190707 has been successfully installed!
PackageManager: Installing tool-dfuutil @ ~1.9.190708
tool-dfuutil @ 1.9.190708 has been successfully installed!

Executing the same command with the version that is located in ~/.platformio/packages:

john@83adbc14  ~/.platformio/packages/tool-openocd  ./bin/openocd -f scripts/interface/ulink.cfg -f scripts/board/mcb1700.cfg  
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: Could not open ULINK device

Wrong invocation here, misses initial -f flag after openocd. Does that change the output to anything else than Could not open ULINK device?

Hm then this config might only support older devices. I’ll have another look for what USB devices it searches for…

Ok different strategy. According to https://forum.sparkfun.com/viewtopic.php?t=35435 this might work with CMSIS-DAP device. Could you show the output of

openocd -f scripts/interface/cmsis-dap.cfg -f scripts/board/mcb1700.cfg

(for PIO’s openocd version)

PlatformIO version:

john@83adbc14  ~/.platformio/packages/tool-openocd  ./bin/openocd -f scripts/interface/cmsis-dap.cfg -f scripts/board/mcb1700.cfg                                                  ✔  10124  19:54:26
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 1 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 10 kHz
Info : SWD DPIDR 0x2ba01477
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : lpc17xx.cpu: external reset detected
Info : Listening on port 3333 for gdb connections

Brew version:

john@83adbc14  /usr/local/Cellar/open-ocd/HEAD-09eb941  openocd -f share/openocd/scripts/interface/cmsis-dap.cfg -f share/openocd/scripts/board/mcb1700.cfg                        ✔  10127  19:56:39
Open On-Chip Debugger 0.10.0+dev-00930-g09eb941c (2019-09-12-19:27)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 10 kHz
Info : SWD DPIDR 0x2ba01477
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections

Yes yes this is very good, we have a good connection to the hardware. Actually upload_protocol = cmsis-dap should have worked but apparently pyOCD blows up (probably beacuse it doesn’t know that it’s supposed to use the mcb1700.cfg config…)

Let’s try an upload. Change your platformio.ini back to the original one

[env:lpc1768]
platform = nxplpc
board = lpc1768
framework = mbed

so that you compile for the correct chip. Then just compile again (pio run) to produce the firmware.elf file, cancel all openocd sessions again, go into your firmware folder and try the following

openocd -f share/openocd/scripts/interface/cmsis-dap.cfg -f share/openocd/scripts/board/mcb1700.cfg -c "program {{.pio/build/lpc1768/firmware.elf}} verify reset; shutdown;"

What does that output?

I don’t know why the file cannot be found, even tho it is there and I’m in the project folder.

john@83adbc14  ~/Documents/PlatformIO/Projects/Testing MCB1768  ~/.platformio/packages/tool-openocd/bin/openocd -f ~/.platformio/packages/tool-openocd/scripts/interface/cmsis-dap.cfg -f ~/.platformio/packages/tool-openocd/scripts/board/mcb1700.cfg -c "program {{.pio/build/lpc1768/firmware.elf}} verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 10 kHz
Info : SWD DPIDR 0x2ba01477
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Info : High speed (adapter_khz 12500) may be limited by adapter firmware.
** Programming Started **
Error: couldn't open {.pio/build/lpc1768/firmware.elf}
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 508
at file "embedded:startup.tcl", line 449

Hm could you please remove one set of {} from the program subcommand, the two {{..}} might be wrong. (This comes from a shell script and I might have needed escaping there?)

 john@83adbc14  ~/Documents/PlatformIO/Projects/Testing_MCB1768  ~/.platformio/packages/tool-openocd/bin/openocd -f ~/.platformio/packages/tool-openocd/scripts/interface/cmsis-dap.cfg -f ~/.platformio/packages/tool-openocd/scripts/board/mcb1700.cfg -c "program {.pio/build/lpc1768/firmware.elf} verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 10 kHz
Info : SWD DPIDR 0x2ba01477
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff0080 msp: 0x10001ffc
Info : High speed (adapter_khz 12500) may be limited by adapter firmware.
** Programming Started **
Info : Padding image section 1 at 0x0000879c with 4 bytes
Warn : Verification will fail since checksum in image (0x00000000) to be written to flash is different from calculated vector checksum (0xefff30d2).
Warn : To remove this warning modify build tools on developer PC to inject correct LPC vector checksum.
** Programming Finished **
** Verify Started **
Error: checksum mismatch - attempting binary compare
embedded:startup.tcl:449: Error: ** Verify Failed **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 494
at file "embedded:startup.tcl", line 449

Alright well this is a success in programming an image, but a fail that the binary doesn’t contain the right checksum. We are getting close though. Let me check where platformio computes that checksum (or maybe how to directly teach PIO to use the correct configs).

1 Like

Just for my interest, does the blinky code work? If you e.g. take this code from but replace LED1 with a custom chosen GPIO pin from the pin list to which you have access to on the board and add an external LED. Maybe it’s smart enough to write the correct checksum in to allow the firmware to boot.

Oh apparently you have a few onboard LEDs, but no idea where they are physically on the board

It also seems this issue is known and a custom tool for calculating the checksum exists (https://github.com/platformio/platform-nxplpc/issues/6). This should be easy to be incorporated in a post action or custom upload to make PIO automatically do this (http://docs.platformio.org/en/latest/projectconf/advanced_scripting.html). I’ll try to write a script tomorrow.

1 Like