Skip to content

Commit 031d274

Browse files
author
Jamie Smith
authored
Fix some upload and test issues, especially for LPC1768 (ARMmbed#231)
* Fix USB instructions for Ubuntu, fix greentea compile failure for devices without TRNG * Don't compile device key without COMPONENT_FLASHIAP * Fix some upload issues for LPC1768 * Oops don't commit cmake variants * Don't build connectivity-netsocket-tls without TRNG support
1 parent 033058a commit 031d274

File tree

14 files changed

+250
-34
lines changed

14 files changed

+250
-34
lines changed

connectivity/mbedtls/tests/TESTS/mbedtls/selftest/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright (c) 2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
if(NOT "DEVICE_TRNG=1" IN_LIST MBED_TARGET_DEFINITIONS)
5+
set(TEST_SKIPPED "This test requires TRNG support!")
6+
endif()
7+
48
if(MBED_GREENTEA_TEST_BAREMETAL)
59
set(TEST_SKIPPED "This test requires an RTOS!")
610
endif()

connectivity/netsocket/tests/TESTS/netsocket/tls/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if(MBED_GREENTEA_TEST_BAREMETAL)
2727
set(TEST_SKIPPED "This test requires an RTOS!")
2828
endif()
2929

30+
if(NOT "DEVICE_TRNG=1" IN_LIST MBED_TARGET_DEFINITIONS)
31+
set(TEST_SKIPPED "This test requires TRNG support!")
32+
endif()
33+
3034
mbed_greentea_add_test(
3135
TEST_NAME
3236
mbed-connectivity-netsocket-tls

drivers/device_key/tests/TESTS/device_key/functionality/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if(NOT "DEVICE_TRNG=1" IN_LIST MBED_TARGET_DEFINITIONS)
55
set(TEST_SKIPPED "True RNG is not supported for this target so device key cannot be used")
66
endif()
77

8-
if(NOT "DEVICE_FLASH=1" IN_LIST MBED_TARGET_DEFINITIONS)
8+
if(NOT ("DEVICE_FLASH=1" IN_LIST MBED_TARGET_DEFINITIONS AND "COMPONENT_FLASHIAP=1" IN_LIST MBED_TARGET_DEFINITIONS))
99
set(TEST_SKIPPED "Flash IAP is not supported for this target so device key cannot be used")
1010
endif()
1111

drivers/usb/tests/TESTS/usb_device/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,11 @@ See also [Known issues](#known-issues).
2929
1. Plug both USB interfaces (*DAPLink* and *USB device*).
3030

3131
### Linux
32-
1. Install the `hidapi` Python module, otherwise some USB HID test cases will
33-
be skipped. This module is not installed during the initial setup due to
34-
external dependencies for Linux.
35-
36-
For Debian-based Linux distros, the dependencies can be installed as follows
37-
(based on module's [README][LN-hidapi_readme]):
38-
39-
```bash
40-
apt-get install python-dev libusb-1.0-0-dev libudev-dev
41-
pip install --upgrade setuptools
42-
```
43-
44-
To install the `hidapi` module itself, please use the attached
45-
[requirements.txt][LN-hid_requirements] file:
46-
47-
```bash
48-
pip install -r TESTS/usb_device/hid/requirements.txt
49-
```
50-
2. Add your user to the `plugdev` group with `sudo usermod -G plugdev <your username>`
32+
1. Install the `hidapi` and `usb` (aka pyusb) Python modules. It's recommended to install these via a package manager because they have some binary dependencies:
33+
```
34+
sudo apt-get install python3-hidapi python3-usb
35+
```
36+
2. Add your user to the `plugdev` group with `sudo usermod -a -G plugdev <your username>`
5137
3. Update the `udev` rules for the USB VIDs/PIDs used in the test as follows:
5238

5339
```bash
@@ -67,6 +53,22 @@ See also [Known issues](#known-issues).
6753
port and sending the `AT commands`, which it does for every new
6854
`/dev/ttyACM` device registered in system.
6955
4. Install the `udisks2` package, which the test script uses to mount USB disks. Additionally, you may need to disable any automounting of disks provided by your file manager / distro.
56+
5. Last but not least, at least on Ubuntu, you may need to change permission settings such that udisks2 actually allows ordinary users to mount disks. You are supposed to do this with a [polkit rule](https://askubuntu.com/a/1457819/1612342), but I had absolutely no luck getting this to work. So instead I had to edit `/usr/share/polkit-1/actions/org.freedesktop.UDisks2.policy1` and change the first
57+
```
58+
<defaults>
59+
<allow_any>auth_admin</allow_any>
60+
<allow_inactive>auth_admin</allow_inactive>
61+
<allow_active>yes</allow_active>
62+
</defaults>
63+
```
64+
block to
65+
```
66+
<defaults>
67+
<allow_any>yes</allow_any>
68+
<allow_inactive>yes</allow_inactive>
69+
<allow_active>yes</allow_active>
70+
</defaults>
71+
```
7072
7173
### Mac
7274
No setup method has been verified for this platform.

targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_GCC_ARM/LPC1768.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SECTIONS
135135
} > RAM
136136

137137

138-
.bss :
138+
.bss (NOLOAD):
139139
{
140140
__bss_start__ = .;
141141
*(.bss*)
@@ -145,7 +145,7 @@ SECTIONS
145145
} > RAM
146146

147147

148-
.heap :
148+
.heap (NOLOAD):
149149
{
150150
__end__ = .;
151151
end = __end__;
@@ -157,7 +157,7 @@ SECTIONS
157157
/* .stack_dummy section doesn't contains any symbols. It is only
158158
* used for linker to calculate size of stack sections, and assign
159159
* values to stack symbols later */
160-
.stack_dummy :
160+
.stack_dummy (NOLOAD):
161161
{
162162
*(.stack)
163163
} > RAM

targets/upload_method_cfg/LPC1768.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,4 @@ set(MBED_RESET_BAUDRATE 115200)
3232

3333
set(OPENOCD_UPLOAD_ENABLED TRUE)
3434
set(OPENOCD_CHIP_CONFIG_COMMANDS
35-
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/lpc1768.cfg
36-
-c "gdb_memory_map disable" # prevents OpenOCD crash on GDB connect
37-
-c "gdb_breakpoint_override hard" # Make sure GDB uses HW breakpoints
38-
)
35+
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/lpc1768.cfg)

targets/upload_method_cfg/openocd_cfgs/lpc1768.cfg

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,197 @@
11
source [find interface/cmsis-dap.cfg]
2-
source [find target/lpc17xx.cfg]
2+
3+
# The below contents are is copied from the OpenOCD scripts for the lpc1768 with only *one* change:
4+
# the "flash bank" line has been commented out so that we can configure the bank manually.
5+
# I wasn't able to find a way to use the lpc17xx.cfg include file and not have it run this line.
6+
# Original sources:
7+
# - https://github.com/openocd-org/openocd/blob/master/tcl/target/lpc17xx.cfg
8+
# - https://github.com/openocd-org/openocd/blob/master/tcl/target/lpc1xxx.cfg
9+
10+
# SPDX-License-Identifier: GPL-2.0-or-later
11+
12+
# NXP LPC17xx Cortex-M3 with at least 8kB SRAM
13+
set CHIPNAME lpc17xx
14+
set CHIPSERIES lpc1700
15+
if { ![info exists WORKAREASIZE] } {
16+
set WORKAREASIZE 0x2000
17+
}
18+
19+
# Main file for NXP LPC1xxx/LPC40xx series Cortex-M0/0+/3/4F parts
20+
#
21+
# !!!!!!
22+
#
23+
# This file should not be included directly, rather by the lpc11xx.cfg,
24+
# lpc13xx.cfg, lpc17xx.cfg, etc. which set the needed variables to the
25+
# appropriate values.
26+
#
27+
# !!!!!!
28+
29+
# LPC8xx chips support only SWD transport.
30+
# LPC11xx chips support only SWD transport.
31+
# LPC12xx chips support only SWD transport.
32+
# LPC11Uxx chips support only SWD transports.
33+
# LPC13xx chips support only SWD transports.
34+
# LPC17xx chips support both JTAG and SWD transports.
35+
# LPC40xx chips support both JTAG and SWD transports.
36+
# Adapt based on what transport is active.
37+
source [find target/swj-dp.tcl]
38+
39+
if { [info exists CHIPNAME] } {
40+
set _CHIPNAME $CHIPNAME
41+
} else {
42+
error "CHIPNAME not set. Please do not include lpc1xxx.cfg directly, but the specific chip configuration file (lpc11xx.cfg, lpc13xx.cfg, lpc17xx.cfg, etc)."
43+
}
44+
45+
if { [info exists CHIPSERIES] } {
46+
# Validate chip series is supported
47+
if { $CHIPSERIES != "lpc800" && $CHIPSERIES != "lpc1100" && $CHIPSERIES != "lpc1200" && $CHIPSERIES != "lpc1300" && $CHIPSERIES != "lpc1700" && $CHIPSERIES != "lpc4000" } {
48+
error "Unsupported LPC1xxx chip series specified."
49+
}
50+
set _CHIPSERIES $CHIPSERIES
51+
} else {
52+
error "CHIPSERIES not set. Please do not include lpc1xxx.cfg directly, but the specific chip configuration file (lpc11xx.cfg, lpc13xx.cfg, lpc17xx.cfg, etc)."
53+
}
54+
55+
# After reset, the chip is clocked by an internal RC oscillator.
56+
# When board-specific code (reset-init handler or device firmware)
57+
# configures another oscillator and/or PLL0, set CCLK to match; if
58+
# you don't, then flash erase and write operations may misbehave.
59+
# (The ROM code doing those updates cares about core clock speed...)
60+
# CCLK is the core clock frequency in KHz
61+
if { [info exists CCLK] } {
62+
# Allow user override
63+
set _CCLK $CCLK
64+
} else {
65+
# LPC8xx/LPC11xx/LPC12xx/LPC13xx use a 12MHz one, LPC17xx uses a 4MHz one(except for LPC177x/8x,LPC407x/8x)
66+
if { $_CHIPSERIES == "lpc800" || $_CHIPSERIES == "lpc1100" || $_CHIPSERIES == "lpc1200" || $_CHIPSERIES == "lpc1300" } {
67+
set _CCLK 12000
68+
} elseif { $_CHIPSERIES == "lpc1700" || $_CHIPSERIES == "lpc4000" } {
69+
set _CCLK 4000
70+
}
71+
}
72+
73+
if { [info exists CPUTAPID] } {
74+
# Allow user override
75+
set _CPUTAPID $CPUTAPID
76+
} else {
77+
# LPC8xx/LPC11xx/LPC12xx use a Cortex-M0/M0+ core, LPC13xx/LPC17xx use a Cortex-M3 core, LPC40xx use a Cortex-M4F core.
78+
if { $_CHIPSERIES == "lpc800" || $_CHIPSERIES == "lpc1100" || $_CHIPSERIES == "lpc1200" } {
79+
set _CPUTAPID 0x0bb11477
80+
} elseif { $_CHIPSERIES == "lpc1300" || $_CHIPSERIES == "lpc1700" || $_CHIPSERIES == "lpc4000" } {
81+
if { [using_jtag] } {
82+
set _CPUTAPID 0x4ba00477
83+
} {
84+
set _CPUTAPID 0x2ba01477
85+
}
86+
}
87+
}
88+
89+
if { [info exists WORKAREASIZE] } {
90+
set _WORKAREASIZE $WORKAREASIZE
91+
} else {
92+
error "WORKAREASIZE is not set. The $CHIPNAME part is available in several Flash and RAM size configurations. Please set WORKAREASIZE."
93+
}
94+
95+
swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
96+
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
97+
98+
set _TARGETNAME $_CHIPNAME.cpu
99+
target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap
100+
101+
# The LPC11xx devices have 2/4/8kB of SRAM in the ARMv7-M "Code" area (at 0x10000000)
102+
# The LPC12xx devices have 4/8kB of SRAM in the ARMv7-M "Code" area (at 0x10000000)
103+
# The LPC11Uxx devices have 4/6/8kB of SRAM in the ARMv7-M "Code" area (at 0x10000000)
104+
# The LPC13xx devices have 4/8kB of SRAM in the ARMv7-M "Code" area (at 0x10000000)
105+
# The LPC17xx devices have 8/16/32/64kB of SRAM in the ARMv7-M "Code" area (at 0x10000000)
106+
# The LPC40xx devices have 16/32/64kB of SRAM in the ARMv7-ME "Code" area (at 0x10000000)
107+
$_TARGETNAME configure -work-area-phys 0x10000000 -work-area-size $_WORKAREASIZE
108+
109+
# The LPC11xx devies have 8/16/24/32/48/56/64kB of flash memory (at 0x00000000)
110+
# The LPC12xx devies have 32/48/64/80/96/128kB of flash memory (at 0x00000000)
111+
# The LPC11Uxx devies have 16/24/32/40/48/64/96/128kB of flash memory (at 0x00000000)
112+
# The LPC13xx devies have 8/16/32kB of flash memory (at 0x00000000)
113+
# The LPC17xx devies have 32/64/128/256/512kB of flash memory (at 0x00000000)
114+
# The LPC40xx devies have 64/128/256/512kB of flash memory (at 0x00000000)
115+
#
116+
# All are compatible with the "lpc1700" variant of the LPC2000 flash driver
117+
# (same cmd51 destination boundary alignment, and all three support 256 byte
118+
# transfers).
119+
#
120+
# flash bank <name> lpc2000 <base> <size> 0 0 <target#> <variant> <clock> [calc checksum] [iap entry]
121+
set _IAP_ENTRY 0
122+
if { [info exists IAP_ENTRY] } {
123+
set _IAP_ENTRY $IAP_ENTRY
124+
}
125+
set _FLASHNAME $_CHIPNAME.flash
126+
#flash bank $_FLASHNAME lpc2000 0x0 0 0 0 $_TARGETNAME \
127+
# lpc1700 $_CCLK calc_checksum $_IAP_ENTRY
128+
129+
if { $_CHIPSERIES == "lpc800" || $_CHIPSERIES == "lpc1100" || $_CHIPSERIES == "lpc1200" || $_CHIPSERIES == "lpc1300" } {
130+
# Do not remap 0x0000-0x0200 to anything but the flash (i.e. select
131+
# "User Flash Mode" where interrupt vectors are _not_ remapped,
132+
# and reside in flash instead).
133+
#
134+
# Table 8. System memory remap register (SYSMEMREMAP, address 0x4004 8000) bit description
135+
# Bit Symbol Value Description
136+
# 1:0 MAP System memory remap
137+
# 0x0 Boot Loader Mode. Interrupt vectors are re-mapped to Boot ROM.
138+
# 0x1 User RAM Mode. Interrupt vectors are re-mapped to Static RAM.
139+
# 0x2 User Flash Mode. Interrupt vectors are not re-mapped and reside in Flash.
140+
# 31:2 - - Reserved.
141+
$_TARGETNAME configure -event reset-init {
142+
mww 0x40048000 0x02
143+
}
144+
} elseif { $_CHIPSERIES == "lpc1700" || $_CHIPSERIES == "lpc4000" } {
145+
# Do not remap 0x0000-0x0020 to anything but the flash (i.e. select
146+
# "User Flash Mode" where interrupt vectors are _not_ remapped,
147+
# and reside in flash instead).
148+
#
149+
# See Table 612. Memory Mapping Control register (MEMMAP - 0x400F C040) bit description
150+
# Bit Symbol Value Description Reset
151+
# value
152+
# 0 MAP Memory map control. 0
153+
# 0 Boot mode. A portion of the Boot ROM is mapped to address 0.
154+
# 1 User mode. The on-chip Flash memory is mapped to address 0.
155+
# 31:1 - Reserved. The value read from a reserved bit is not defined. NA
156+
#
157+
# http://ics.nxp.com/support/documents/microcontrollers/?scope=LPC1768&type=user
158+
$_TARGETNAME configure -event reset-init {
159+
mww 0x400FC040 0x01
160+
}
161+
}
162+
163+
# Run with *real slow* clock by default since the
164+
# boot rom could have been playing with the PLL, so
165+
# we have no idea what clock the target is running at.
166+
adapter speed 10
167+
168+
# delays on reset lines
169+
adapter srst delay 200
170+
if {[using_jtag]} {
171+
jtag_ntrst_delay 200
172+
}
173+
174+
# LPC8xx (Cortex-M0+ core) support SYSRESETREQ
175+
# LPC11xx/LPC12xx (Cortex-M0 core) support SYSRESETREQ
176+
# LPC13xx/LPC17xx (Cortex-M3 core) support SYSRESETREQ
177+
# LPC40xx (Cortex-M4F core) support SYSRESETREQ
178+
if {![using_hla]} {
179+
# if srst is not fitted use SYSRESETREQ to
180+
# perform a soft reset
181+
cortex_m reset_config sysresetreq
182+
}
183+
184+
185+
# It seems like there's some sort of issue with the OpenOCD memory auto-probing for this part.
186+
# When connecting, you often (though not always) get:
187+
#
188+
# Debug: 265 9395 lpc2000.c:850 lpc2000_iap_call(): IAP command = 54 (0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000) completed with result = 0737212c
189+
# Debug: 266 9395 target.c:2143 target_free_working_area_restore(): freed 260 bytes of working area at address 0x10000000
190+
# Debug: 267 9395 target.c:1940 print_wa_layout(): 0x10000000-0x10001fff (8192 bytes)
191+
# Error: 268 9395 lpc2000.c:1513 lpc2000_auto_probe_flash(): BUG: unknown Part ID encountered: 0xaaa0
192+
#
193+
# We can avoid this by manually configuring the flash driver instead of using autoprobing.
194+
flash bank $_FLASHNAME lpc2000 0x0 0x00080000 0 0 $_TARGETNAME lpc1700 $_CCLK calc_checksum $_IAP_ENTRY
3195

4196
# For some reason, the bundled OpenOCD LPC1768 scripts set a _very_ slow default speed that makes programming
5197
# take several minutes. Increasing it seems to work OK.

tools/cmake/mbed_greentea.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ function(mbed_greentea_add_test)
113113

114114
# All of the upload methods already reset the chip after uploading so we don't need to reset via
115115
# the serial port. Doing that type of reset also seems to give the Pitaya-Link probe trouble.
116-
list(APPEND MBED_HTRUN_ARGUMENTS --skip-reset)
116+
# However, for targets which support semihosting (currently just LPC1768), we do need the reset as otherwise
117+
# semihosting stuff like localfilesystem won't work.
118+
if(NOT "DEVICE_SEMIHOST=1" IN_LIST MBED_TARGET_DEFINITIONS)
119+
list(APPEND MBED_HTRUN_ARGUMENTS --skip-reset)
120+
endif()
117121

118122
if(DEFINED MBED_GREENTEA_EXTRA_HTRUN_ARGUMENTS)
119123
list(APPEND MBED_HTRUN_ARGUMENTS ${MBED_GREENTEA_EXTRA_HTRUN_ARGUMENTS})

tools/cmake/upload_methods/UploadMethodJLINK.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ set(UPLOAD_LAUNCH_COMMANDS
9898
"monitor halt"
9999
"monitor reset"
100100
"load"
101-
"break main"
101+
"tbreak main"
102102
"monitor reset"
103103
)
104104
set(UPLOAD_RESTART_COMMANDS

tools/cmake/upload_methods/UploadMethodOPENOCD.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function(gen_upload_target TARGET_NAME BIN_FILE)
4747
COMMAND ${OpenOCD}
4848
${OPENOCD_CHIP_CONFIG_COMMANDS}
4949
${OPENOCD_ADAPTER_SERIAL_COMMAND}
50+
-c "gdb_port disabled" # Don't start a GDB server when just programming
5051
-c "program $<TARGET_FILE:${TARGET_NAME}> reset exit"
5152
VERBATIM)
5253

@@ -69,8 +70,17 @@ set(UPLOAD_WANTS_EXTENDED_REMOTE TRUE)
6970
# Reference: https://github.com/Marus/cortex-debug/blob/056c03f01e008828e6527c571ef5c9adaf64083f/src/openocd.ts#L100
7071
set(UPLOAD_LAUNCH_COMMANDS
7172
"monitor reset halt"
73+
74+
# For targets which support semihosting, prevent GDB from stopping when a semihosting event happens.
75+
# AFAIK, semihosting is only used to communicate between the interface chip and the CPU; we never
76+
# want to process semihosting data on the host
77+
"handle SIGTRAP nostop noprint"
78+
79+
# Increase remote timeout to 30 sec in case programming takes a long time
80+
"set remotetimeout 30"
81+
7282
"load"
73-
"break main"
83+
"tbreak main"
7484
"monitor reset halt"
7585
)
7686
set(UPLOAD_RESTART_COMMANDS

tools/cmake/upload_methods/UploadMethodPYOCD.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ set(UPLOAD_GDBSERVER_DEBUG_COMMAND
5656
set(UPLOAD_LAUNCH_COMMANDS
5757
"monitor reset halt"
5858
"load"
59-
"break main"
59+
"tbreak main"
6060
)
6161
set(UPLOAD_RESTART_COMMANDS
6262
"monitor reset"

tools/cmake/upload_methods/UploadMethodSTLINK.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ set(UPLOAD_LAUNCH_COMMANDS
5050
"monitor halt"
5151
"monitor reset"
5252
"load"
53-
"break main"
53+
"tbreak main"
5454
"monitor reset"
5555
)
5656
set(UPLOAD_RESTART_COMMANDS

tools/cmake/upload_methods/UploadMethodSTM32CUBE.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ set(UPLOAD_GDBSERVER_DEBUG_COMMAND
6161
set(UPLOAD_LAUNCH_COMMANDS
6262
"monitor reset"
6363
"load"
64-
"break main"
64+
"tbreak main"
6565
"monitor reset"
6666
)
6767
set(UPLOAD_RESTART_COMMANDS

tools/requirements-ci-build.apt.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
python3-usb
2+
python3-hidapi
3+
udisks2

0 commit comments

Comments
 (0)