Skip to content

Commit ab59175

Browse files
dgarskedanielinux
authored andcommitted
Fix for nRF5340 uart_write issue with memchr args, which caused occasional corrupt characters to be printed. Improve core state description in logging. Enabled network core test app GPIO work on LED2 P0.29.
1 parent 29a30a6 commit ab59175

8 files changed

Lines changed: 165 additions & 69 deletions

File tree

config/examples/nrf5340.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ CFLAGS_EXTRA+=-DFLASHBUFFER_SIZE=0x1000
5757
# Use UART0 on P0.22
5858
#CFLAGS_EXTRA+=-DUART_PORT=0 -DUART_PIN=22
5959

60-
CFLAGS_EXTRA+=-DDEBUG_FLASH
61-
CFLAGS_EXTRA+=-DDEBUG_QSPI=1
60+
#CFLAGS_EXTRA+=-DDEBUG_FLASH
61+
#CFLAGS_EXTRA+=-DDEBUG_QSPI=1

config/examples/nrf5340_net.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ DEBUG?=0
5050
DEBUG_UART?=1
5151
USE_GCC=1
5252

53-
CFLAGS_EXTRA+=-DDEBUG_FLASH
53+
#CFLAGS_EXTRA+=-DDEBUG_FLASH

docs/Targets.md

Lines changed: 102 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,73 +2195,129 @@ Application Core:
21952195
21962196
```
21972197
wolfBoot HAL Init (app core)
2198-
QSPI Freq=24MHz (Div Clk=3/Sck=1), Addr=24-bits, PageSz=256
2199-
QSPI Activate
2200-
QSPI Flash ID (ret 0): 0xC2 0x28 0x17
2201-
Status Reg: Ret 0, 0x40 (Quad Enabled: Yes)
2202-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x2000012C
2203-
Update partition: 0x0 (sz 7864, ver 0x2, type 0x201)
2204-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x100000 -> 0x2000012C
2205-
Update partition: 0x100000 (sz 5780, ver 0x2, type 0x202)
2206-
Network Image: Ver 0x2, Size 5780
2207-
Network Core: Holding for update
2208-
Status: App 1 (ver 2), Net 1 (ver 1)
2209-
QSPI Flash ID (ret 0): 0xC2 0x28 0x17
2210-
Status Reg: Ret 0, 0x40 (Quad Enabled: Yes)
2211-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x20000230
2212-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x20000230
2213-
Boot partition: 0xC000 (sz 7864, ver 0x1, type 0x201)
2214-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x2000012C
2215-
Update partition: 0x0 (sz 7864, ver 0x2, type 0x201)
2216-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 4 , 0xEDFFC -> 0x20000230
2217-
Boot partition: 0xC000 (sz 7864, ver 0x1, type 0x201)
2198+
Boot header magic 0x00000000 invalid at 0x20000128
2199+
Update partition: 0x100000 (sz 4120, ver 0x1, type 0x202)
2200+
Network Image: Update not found
2201+
Network Core: Releasing for boot
2202+
Status: App 8 (ver 0), Net 1 (ver 1)
2203+
Boot partition: 0xC000 (sz 4832, ver 0x1, type 0x201)
2204+
Boot header magic 0x00000000 invalid at 0x20000128
2205+
Boot partition: 0xC000 (sz 4832, ver 0x1, type 0x201)
22182206
Booting version: 0x1
2219-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x0 -> 0x2000012C
2220-
Update partition: 0x0 (sz 7864, ver 0x2, type 0x201)
2221-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x100000 -> 0x2000012C
2222-
Update partition: 0x100000 (sz 5780, ver 0x2, type 0x202)
2223-
Network Image: Ver 0x2, Size 5780
2224-
Found Network Core update: Ver 1->2, Size 6036->6036
2225-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 256 , 0x101700 -> 0x2000002C
2207+
Waiting for network core...
2208+
========================
2209+
nRF5340 wolfBoot (app core)
2210+
Copyright 2024 wolfSSL Inc
2211+
GPL v3
2212+
Version : 0x1
2213+
========================
2214+
```
2215+
2216+
Network Core:
2217+
2218+
```
2219+
wolfBoot HAL Init (net core)
2220+
Boot partition: 0x100C000 (sz 4120, ver 0x1, type 0x202)
2221+
Network Image: Ver 0x1, Size 4120
2222+
Waiting for status from app core...
2223+
Status: App 8 (ver 0), Net 1 (ver 2)
2224+
Boot partition: 0x100C000 (sz 4120, ver 0x1, type 0x202)
2225+
Boot header magic 0xF7E99810 invalid at 0x21000128
2226+
Boot partition: 0x100C000 (sz 4120, ver 0x1, type 0x202)
2227+
Booting version: 0x1
2228+
========================
2229+
nRF5340 wolfBoot (net core)
2230+
Copyright 2024 wolfSSL Inc
2231+
GPL v3
2232+
Version : 0x1
2233+
========================
2234+
```
2235+
2236+
Example output when doing an update:
2237+
2238+
Application Core:
2239+
2240+
```
2241+
wolfBoot HAL Init (app core)
2242+
Update partition: 0x0 (sz 4832, ver 0x2, type 0x201)
2243+
Network Image: Ver 0x2, Size 4832
2244+
Found Network Core update: Ver 1->2, Size 4376->5088
22262245
Network image valid, loading into shared mem
2227-
QSPI Flash Read: Ret 0, Cmd 0xEB, Len 6036 , 0x100000 -> 0x20010020
2246+
Waiting for net core update to finish...
22282247
Network core firmware update done
2248+
Status: App 8 (ver 2), Net 4 (ver 2)
2249+
Update partition: 0x0 (sz 4832, ver 0x2, type 0x201)
2250+
Boot partition: 0xC000 (sz 4832, ver 0x1, type 0x201)
2251+
Update partition: 0x0 (sz 4832, ver 0x2, type 0x201)
2252+
Staring Update (fallback allowed 0)
2253+
Update partition: 0x0 (sz 4832, ver 0x2, type 0x201)
2254+
Boot partition: 0xC000 (sz 4832, ver 0x1, type 0x201)
2255+
Versions: Current 0x1, Update 0x2
2256+
Copy sector 0 (part 1->2)
2257+
Copy sector 0 (part 0->1)
2258+
Copy sector 0 (part 2->0)
2259+
Boot partition: 0xC000 (sz 4832, ver 0x2, type 0x201)
2260+
Boot header magic 0x00000000 invalid at 0x20000128
2261+
Copy sector 1 (part 1->2)
2262+
Copy sector 1 (part 0->1)
2263+
Copy sector 1 (part 2->0)
2264+
Erasing remainder of partitions (235 sectors)...
2265+
Boot partition: 0xC000 (sz 4832, ver 0x2, type 0x201)
2266+
Boot header magic 0x00000000 invalid at 0x20000128
2267+
Copy sector 236 (part 0->2)
2268+
Boot partition: 0xC000 (sz 4832, ver 0x2, type 0x201)
2269+
Booting version: 0x2
2270+
Waiting for network core...
22292271
========================
22302272
nRF5340 wolfBoot (app core)
22312273
Copyright 2024 wolfSSL Inc
22322274
GPL v3
2233-
Version : 0x1
2275+
Version : 0x2
22342276
========================
2235-
Internal Flash Write: addr 0xF9FFC, len 4
2236-
Internal Flash Write: addr 0xF9FFB, len 1
22372277
```
22382278
22392279
Network Core:
22402280
22412281
```
22422282
wolfBoot HAL Init (net core)
2243-
Boot partition: 0x100C000 (sz 5780, ver 0x1, type 0x201)
2244-
Network Image: Ver 0x1, Size 5780
2245-
Starting update: Ver 1->2, Size 6036->6036
2246-
Internal Flash Erase: addr 0x100C000, len 6036
2247-
Internal Flash Erase: page 0x100C000
2248-
Internal Flash Erase: page 0x100C800
2249-
Internal Flash Erase: page 0x100D000
2250-
Internal Flash Write: addr 0x100C000, len 6036
2251-
Boot partition: 0x100C000 (sz 5780, ver 0x2, type 0x202)
2252-
Network Image: Ver 0x2, Size 5780
2253-
Network version (after update): 0x2
2254-
Status: App 2 (ver 2), Net 4 (ver 2)
2255-
Boot partition: 0x100C000 (sz 5780, ver 0x2, type 0x202)
2283+
Boot partition: 0x100C000 (sz 4120, ver 0x1, type 0x201)
2284+
Network Image: Ver 0x1, Size 4120
2285+
Waiting for status from app core...
2286+
Starting update: Ver 1->2, Size 4376->4376
2287+
Status: App 2 (ver 2), Net 1 (ver 1)
2288+
Update partition: 0x100000 (sz 4120, ver 0x2, type 0x202)
2289+
Boot partition: 0x100C000 (sz 4120, ver 0x1, type 0x201)
2290+
Update partition: 0x100000 (sz 4120, ver 0x2, type 0x202)
2291+
Staring Update (fallback allowed 0)
2292+
Update partition: 0x100000 (sz 4120, ver 0x2, type 0x202)
2293+
Boot partition: 0x100C000 (sz 4120, ver 0x1, type 0x201)
2294+
Versions: Current 0x1, Update 0x2
2295+
Copy sector 0 (part 1->2)
2296+
Copy sector 0 (part 0->1)
2297+
Copy sector 0 (part 2->0)
2298+
Boot partition: 0x100C000 (sz 4120, ver 0x2, type 0x202)
2299+
Update partition: 0x100000 (sz 4120, ver 0x1, type 0x201)
2300+
Copy sector 1 (part 1->2)
2301+
Copy sector 1 (part 0->1)
2302+
Copy sector 1 (part 2->0)
2303+
Copy sector 2 (part 1->2)
2304+
Copy sector 2 (part 0->1)
2305+
Copy sector 2 (part 2->0)
2306+
Erasing remainder of partitions (88 sectors)...
2307+
Boot partition: 0x100C000 (sz 4120, ver 0x2, type 0x202)
2308+
Update partition: 0x100000 (sz 4120, ver 0x1, type 0x201)
2309+
Copy sector 90 (part 0->2)
2310+
Boot partition: 0x100C000 (sz 4120, ver 0x2, type 0x202)
22562311
Booting version: 0x2
2312+
Boot partition: 0x100C000 (sz 4120, ver 0x2, type 0x202)
2313+
Network Image: Ver 0x2, Size 4120
2314+
Network version (after update): 0x2
22572315
========================
22582316
nRF5340 wolfBoot (net core)
22592317
Copyright 2024 wolfSSL Inc
22602318
GPL v3
22612319
Version : 0x2
22622320
========================
2263-
Internal Flash Write: addr 0x1039FFC, len 4
2264-
Internal Flash Write: addr 0x1039FFB, len 1
22652321
```
22662322
22672323
### Building / Flashing Nordic nRF5340

hal/nrf5340.c

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ static int do_update = 0;
9898
#define UART_SEL 0 /* select UART 0 or 1 */
9999
#endif
100100
#if !defined(UART_PORT) && !defined(UART_PIN)
101-
#if UART_SEL == 0 && !defined(TARGET_nrf5340_net)
101+
#if defined(TARGET_nrf5340_app)
102102
#define UART_PORT 0
103103
#define UART_PIN 20
104+
#define UART_NET_PORT 1
105+
#define UART_NET_PIN 1
104106
#else
105107
#define UART_PORT 1
106108
#define UART_PIN 1
@@ -109,8 +111,9 @@ static int do_update = 0;
109111

110112
void uart_init(void)
111113
{
112-
/* nRF5340-DK:
113-
* App: UART0=P1.01, UART1=P0.20 */
114+
/* nRF5340-DK: (P0.20 or P1.01)
115+
* App: UART0=P0.20
116+
* Net: UART0=P1.01 */
114117
UART_ENABLE(UART_SEL) = 0;
115118
GPIO_PIN_CNF(UART_PORT, UART_PIN) = (GPIO_CNF_OUT
116119
#ifdef TARGET_nrf5340_net
@@ -122,9 +125,11 @@ void uart_init(void)
122125
UART_CONFIG(UART_SEL) = 0; /* Flow=Diabled, Stop=1-bit, Parity exclude */
123126
UART_ENABLE(UART_SEL) = 8;
124127

125-
/* allow network core access to P1.01 - must be set from application core */
126-
#ifdef TARGET_nrf5340_app
127-
GPIO_PIN_CNF(1, 1) = (GPIO_CNF_OUT | GPIO_CNF_MCUSEL(1));
128+
/* allow network core access to UART pin - must be set from app core */
129+
#if defined(TARGET_nrf5340_app) && \
130+
defined(UART_NET_PORT) && defined(UART_NET_PIN)
131+
GPIO_PIN_CNF(UART_NET_PORT, UART_NET_PIN) =
132+
(GPIO_CNF_OUT | GPIO_CNF_MCUSEL(1));
128133
#endif
129134
}
130135

@@ -160,18 +165,20 @@ void uart_write(const char* buf, unsigned int sz)
160165
unsigned int lineSz;
161166
do {
162167
/* find `\n` */
163-
line = memchr(buf, sz, '\n');
168+
line = memchr(buf, '\n', sz);
164169
if (line == NULL) {
165170
uart_write_sz(buf, sz);
166171
break;
167172
}
168173
lineSz = line - buf;
174+
if (lineSz > sz-1)
175+
lineSz = sz-1;
169176

170-
uart_write_sz(line, lineSz);
171-
uart_write_sz("\r", 1); /* handle CRLF */
177+
uart_write_sz(buf, lineSz);
178+
uart_write_sz("\r\n", 2); /* handle CRLF */
172179

173180
buf = line;
174-
sz -= lineSz;
181+
sz -= lineSz + 1; /* skip \n, already sent */
175182
} while ((int)sz > 0);
176183
}
177184
#endif /* DEBUG_UART */
@@ -427,6 +434,23 @@ static int hal_shm_status_wait(ShmInfo_t* info, uint32_t status,
427434
return ret;
428435
}
429436

437+
static const char* hal_shm_status_string(uint32_t status)
438+
{
439+
switch (status) {
440+
case SHARED_STATUS_READY:
441+
return "Ready";
442+
case SHARED_STATUS_UPDATE_START:
443+
return "Update Start";
444+
case SHARED_STATUS_UPDATE_DONE:
445+
return "Update Done";
446+
case SHARED_STATUS_DO_BOOT:
447+
return "Do boot";
448+
default:
449+
break;
450+
}
451+
return "Unknown";
452+
}
453+
430454
/* Handles network core updates */
431455
static void hal_net_check_version(void)
432456
{
@@ -510,8 +534,9 @@ static void hal_net_check_version(void)
510534
}
511535
#endif /* TARGET_nrf5340_* */
512536
exit:
513-
wolfBoot_printf("Status: App %d (ver %d), Net %d (ver %d)\n",
514-
shm->app.status, shm->app.version, shm->net.status, shm->net.version);
537+
wolfBoot_printf("Status: App %s (ver %d), Net %s (ver %d)\n",
538+
hal_shm_status_string(shm->app.status), shm->app.version,
539+
hal_shm_status_string(shm->net.status), shm->net.version);
515540
}
516541

517542
void hal_init(void)

hal/nrf5340.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ void sleep_us(unsigned int us);
236236
#endif
237237
#define UART_TASK_STARTTX(n) *((volatile uint32_t *)(UART_BASE(n) + 0x008))
238238
#define UART_TASK_STOPTX(n) *((volatile uint32_t *)(UART_BASE(n) + 0x00C))
239+
#define UART_EVENT_TXDRDY(n) *((volatile uint32_t *)(UART_BASE(n) + 0x11C))
239240
#define UART_EVENT_ENDTX(n) *((volatile uint32_t *)(UART_BASE(n) + 0x120))
240241
#define UART_ENABLE(n) *((volatile uint32_t *)(UART_BASE(n) + 0x500))
241242
#define UART_PSEL_TXD(n) *((volatile uint32_t *)(UART_BASE(n) + 0x50C))

test-app/app_nrf5340.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ void main(void)
4545
uint32_t pin = 28;
4646
uint32_t app_version;
4747

48-
GPIO_PIN_CNF(port, pin) = 1; /* Output */
48+
GPIO_PIN_CNF(port, pin) = GPIO_CNF_OUT;
49+
/* Allow network core access to P0.29 GPIO */
50+
GPIO_PIN_CNF(0, 29) = (GPIO_CNF_OUT | GPIO_CNF_MCUSEL(1));
4951

5052
app_version = wolfBoot_current_firmware_version();
5153

@@ -55,7 +57,7 @@ void main(void)
5557
wolfBoot_printf("nRF5340 wolfBoot (app core)\n");
5658
wolfBoot_printf("Copyright 2024 wolfSSL Inc\n");
5759
wolfBoot_printf("GPL v3\n");
58-
wolfBoot_printf("Version : 0x%lx\r\n", app_version);
60+
wolfBoot_printf("Version : 0x%lx\n", app_version);
5961
wolfBoot_printf("========================\n");
6062

6163
/* mark boot successful */

test-app/app_nrf5340_net.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ void main(void)
4242
* LED3 P0.30
4343
* LED4 P0.31 */
4444
uint32_t port = 0;
45-
uint32_t pin = 28;
45+
uint32_t pin = 29;
4646
uint32_t app_version;
4747

48-
GPIO_PIN_CNF(port, pin) = 1; /* Output */
48+
GPIO_PIN_CNF(port, pin) = GPIO_CNF_OUT;
4949

5050
app_version = wolfBoot_current_firmware_version();
5151

@@ -55,7 +55,7 @@ void main(void)
5555
wolfBoot_printf("nRF5340 wolfBoot (net core)\n");
5656
wolfBoot_printf("Copyright 2024 wolfSSL Inc\n");
5757
wolfBoot_printf("GPL v3\n");
58-
wolfBoot_printf("Version : 0x%lx\r\n", app_version);
58+
wolfBoot_printf("Version : 0x%lx\n", app_version);
5959
wolfBoot_printf("========================\n");
6060

6161
/* mark boot successful */

tools/scripts/nrf5340/build_flash.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
# run from wolfBoot root
66
# ./tools/scripts/nrf5340/build_flash.sh
7+
# optionally run with "erase" argument to rease both internal and external flash
8+
# or provide make arguments "DEBUG=1"
9+
10+
11+
if [ "$1" == "erase" ]; then
12+
DO_ERASE=1
13+
MAKE_ARGS="$2"
14+
else
15+
DO_ERASE=0
16+
MAKE_ARGS="$1"
17+
fi
718

819
rm -f ./tools/scripts/nrf5340/*.bin
920
rm -f ./tools/scripts/nrf5340/*.hex
@@ -13,7 +24,7 @@ rm -f ./tools/scripts/nrf5340/*.hex
1324
# Build net
1425
cp config/examples/nrf5340_net.config .config
1526
make clean
16-
make DEBUG=1
27+
make $MAKE_ARGS
1728
cp factory.bin tools/scripts/nrf5340/factory_net.bin
1829
# Sign flash update for testing (use partition type 2 for network update)
1930
tools/keytools/sign --ecc256 --id 2 test-app/image.bin wolfboot_signing_private_key.der 2
@@ -22,7 +33,8 @@ cp test-app/image_v2_signed.bin tools/scripts/nrf5340/image_v2_signed_net.bin
2233
# Build app
2334
cp config/examples/nrf5340.config .config
2435
make clean
25-
make DEBUG=1
36+
make $MAKE_ARGS
37+
2638
cp factory.bin tools/scripts/nrf5340/factory_app.bin
2739
# Sign flash update for testing
2840
tools/keytools/sign --ecc256 test-app/image.bin wolfboot_signing_private_key.der 2
@@ -44,7 +56,7 @@ arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10000000 tools/scri
4456
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10100000 tools/scripts/nrf5340/image_v2_signed_net.bin tools/scripts/nrf5340/image_v2_signed_net.hex
4557

4658

47-
if [ "$1" == "erase" ]; then
59+
if [ "$DO_ERASE" == "1" ]; then
4860
nrfjprog -f nrf53 --recover
4961
nrfjprog -f nrf53 --qspieraseall
5062
fi

0 commit comments

Comments
 (0)