Skip to content

Commit 61d24ab

Browse files
committed
Added test-app code to change LED color based on version. Improved documentation. Minor code cleanups.
1 parent 9ea316d commit 61d24ab

File tree

4 files changed

+134
-82
lines changed

4 files changed

+134
-82
lines changed

docs/Targets.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,8 +1714,10 @@ thread break: Stopped, 0x0, 0x0, cpuPowerPCBig, Connected (state, tid, pid, cpu
17141714
## NXP MCXA153
17151715

17161716
NXP MCXA153 is a Cortex-M33 microcontroller running at 96MHz.
1717-
The support has been tested using FRDM-MCXA153 with the onboard MCU-Link
1718-
configured in JLink mode.
1717+
The support has been tested using FRDM-MCXA153 with the onboard MCU-Link configured in JLink mode.
1718+
1719+
This requires the MCXA SDK from the NXP MCUXpresso SDK Builder. We tested using `SDK_2.14.2_MCXA153` and placed into `../NXP/MCXA153` by default (see .config or set with `MCUXPRESSO`).
1720+
MCUXpresso SDK Builder
17191721

17201722
### Configuring and compiling
17211723

@@ -1729,16 +1731,57 @@ Compile via:
17291731

17301732
### Loading the firmware
17311733

1734+
The NXP Freedom MCX A board debugger comes loaded with MCU Link, but it can be updated to JLink. See https://docs.nxp.com/bundle/UM12012/page/topics/Updating_MCU_Link_firmware.html
1735+
17321736
Use JLinkExe tool to upload the initial firmware:
17331737

17341738
`JLinkExe -if swd -Device MCXA153`
17351739

17361740
At the Jlink prompt, type:
17371741

17381742
```
1739-
J-Link>loadbin factory.bin 0
1743+
loadbin factory.bin 0
1744+
'loadbin': Performing implicit reset & halt of MCU.
1745+
ResetTarget() start
1746+
Reset via SYSRESETREQ and reset pin + halt after bootloader
1747+
ResetTarget() end - Took 111ms
1748+
AfterResetTarget() start
1749+
SRAM_XEN set to RWX
1750+
FLASH and IFR set to RWX
1751+
AfterResetTarget() end - Took 7.40ms
1752+
Downloading file [factory.bin]...
1753+
J-Link: Flash download: Bank 0 @ 0x00000000: Skipped. Contents already match
1754+
O.K.
1755+
```
1756+
1757+
Reset or power cycle board.
1758+
1759+
Once wolfBoot has performaed validation of the partition and booted the D15 Green LED on P3_13 will illuminate.
1760+
1761+
### Testing firmware update
1762+
1763+
1) Sign the test-app with version 2:
1764+
1765+
```
1766+
./tools/keytools/sign --ecc256 test-app/image.bin wolfboot_signing_private_key.der 2
1767+
```
1768+
1769+
2) Create a bin footer with wolfBoot trailer "BOOT" and "p" (ASCII for 0x70 == IMG_STATE_UPDATING):
1770+
1771+
```
1772+
echo -n "pBOOT" > trigger_magic.bin
1773+
```
1774+
1775+
3) Assembly new factory update.bin:
1776+
1777+
```sh
1778+
./tools/bin-assemble/bin-assemble \
1779+
update.bin \
1780+
0x0 test-app/image_v2_signed.bin \
1781+
0xAFFB trigger_magic.bin
17401782
```
17411783

1784+
4) Flash update.bin to 0x13000 (`loadbin update.bin 0x13000`). The D15 GDB LED Blue P3_0 will show if version is > 1.
17421785

17431786

17441787
## TI Hercules TMS570LC435

hal/mcxa.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
/* Flash driver */
3333
#include "fsl_romapi.h"
3434

35-
#define BOARD_BOOTCLOCKFRO96M_CORE_CLOCK 96000000U /*!< Core clock frequency: 96000000Hz */
35+
/*!< Core clock frequency: 96000000Hz */
36+
#define BOARD_BOOTCLOCKFRO96M_CORE_CLOCK 96000000UL
3637

3738
static flash_config_t pflash;
38-
//static ftfx_cache_config_t pcache;
3939
static int flash_init = 0;
4040

4141
#ifdef __WOLFBOOT
@@ -70,11 +70,11 @@ void BOARD_BootClockFRO96M(void)
7070
(void)SPC_SetSRAMOperateVoltage(SPC0, &sramOption);
7171
}
7272

73-
CLOCK_SetupFROHFClocking(96000000U); /*!< Enable FRO HF(96MHz) output */
73+
CLOCK_SetupFROHFClocking(96000000U); /*!< Enable FRO HF(96MHz) output */
7474

75-
CLOCK_SetupFRO12MClocking(); /*!< Setup FRO12M clock */
75+
CLOCK_SetupFRO12MClocking(); /*!< Setup FRO12M clock */
7676

77-
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /* !< Switch MAIN_CLK to FRO_HF */
77+
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /* !< Switch MAIN_CLK to FRO_HF */
7878

7979
/* The flow of decreasing voltage and frequency */
8080
if (coreFreq > BOARD_BOOTCLOCKFRO96M_CORE_CLOCK) {
@@ -93,11 +93,10 @@ void BOARD_BootClockFRO96M(void)
9393
/*!< Set up clock selectors - Attach clocks to the peripheries */
9494

9595
/*!< Set up dividers */
96-
CLOCK_SetClockDiv(kCLOCK_DivAHBCLK, 1U); /* !< Set AHBCLKDIV divider to value 1 */
97-
CLOCK_SetClockDiv(kCLOCK_DivFRO_HF_DIV, 1U); /* !< Set FROHFDIV divider to value 1 */
96+
CLOCK_SetClockDiv(kCLOCK_DivAHBCLK, 1U); /* !< Set AHBCLKDIV divider to value 1 */
97+
CLOCK_SetClockDiv(kCLOCK_DivFRO_HF_DIV, 1U); /* !< Set FROHFDIV divider to value 1 */
9898
}
9999

100-
101100
void hal_init(void)
102101
{
103102
/* Clock setting */
@@ -113,33 +112,37 @@ void hal_prepare_boot(void)
113112
{
114113
}
115114

116-
117-
#endif
115+
#endif /* __WOLFBOOT */
118116

119117
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
120118
{
121-
int w = 0;
122119
int ret;
123-
const uint8_t empty_qword[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
124-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
120+
int w = 0;
121+
const uint8_t empty_qword[16] = {
122+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
123+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
124+
};
125125

126126
while (len > 0) {
127127
if ((len < 16) || address & 0x0F) {
128128
uint8_t aligned_qword[16];
129129
uint32_t address_align = address - (address & 0x0F);
130130
uint32_t start_off = address - address_align;
131131
int i;
132+
132133
memcpy(aligned_qword, (void*)address_align, 16);
133-
for (i = start_off; ((i < 16) && (i < len + (int)start_off)); i++)
134+
for (i = start_off; ((i < 16) && (i < len + (int)start_off)); i++) {
134135
aligned_qword[i] = data[w++];
136+
}
135137
if (memcmp(aligned_qword, empty_qword, 16) != 0) {
136-
ret = FLASH_ProgramPhrase(&pflash, address_align, aligned_qword, 16);
138+
ret = FLASH_ProgramPhrase(&pflash, address_align, aligned_qword, 16);
137139
if (ret != kStatus_Success)
138140
return -1;
139141
}
140142
address += i;
141143
len -= i;
142-
} else {
144+
}
145+
else {
143146
uint32_t len_align = len - (len & 0x0F);
144147
ret = FLASH_ProgramPhrase(&pflash, address, (uint8_t*)data + w, len_align);
145148
if (ret != kStatus_Success)
@@ -168,5 +171,3 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
168171
return -1;
169172
return 0;
170173
}
171-
172-

test-app/ARM-mcxa.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MEMORY
22
{
33
FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
4-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 24K
4+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 24K
55
}
66

77
SECTIONS
@@ -17,7 +17,7 @@ SECTIONS
1717
. = ALIGN(4);
1818
_end_text = .;
1919
} > FLASH
20-
20+
2121
.ARM :
2222
{
2323
__exidx_start = .;

test-app/app_mcxa.c

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,88 @@
1+
/* app_mcxa.c
2+
*
3+
* Test bare-metal boot-led-on application
4+
*
5+
* Copyright (C) 2024 wolfSSL Inc.
6+
*
7+
* This file is part of wolfBoot.
8+
*
9+
* wolfBoot is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation; either version 2 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* wolfBoot is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
22+
*/
23+
24+
125
#include <stdlib.h>
226
#include <stdint.h>
327
#include <string.h>
428
#include "fsl_common.h"
529
#include "fsl_port.h"
630
#include "fsl_gpio.h"
731
#include "fsl_clock.h"
8-
#include "wolfboot/wolfboot.h"
9-
10-
11-
#define BOARD_LED_GPIO_PORT PORT3
12-
#define BOARD_LED_GPIO GPIO3
13-
#define BOARD_LED_GPIO_PIN 12U
1432

33+
#include "wolfboot/wolfboot.h"
1534

16-
void gpio_init(void)
35+
/* init gpio for port 3 */
36+
void gpio_port3_init(int pin)
1737
{
18-
/* Write to GPIO3: Peripheral clock is enabled */
19-
CLOCK_EnableClock(kCLOCK_GateGPIO3);
20-
/* Write to PORT3: Peripheral clock is enabled */
21-
CLOCK_EnableClock(kCLOCK_GatePORT3);
22-
/* GPIO3 peripheral is released from reset */
23-
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn);
24-
/* PORT3 peripheral is released from reset */
25-
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn);
26-
27-
gpio_pin_config_t LED_RED_config = {
38+
const port_pin_config_t GPIO_OUT_LED = {
39+
kPORT_PullDisable, /* Internal pull-up/down resistor is disabled */
40+
kPORT_LowPullResistor, /* Low internal pull resistor value is selected. */
41+
kPORT_FastSlewRate, /* Fast slew rate is configured */
42+
kPORT_PassiveFilterDisable, /* Passive input filter is disabled */
43+
kPORT_OpenDrainDisable, /* Open drain output is disabled */
44+
kPORT_LowDriveStrength, /* Low drive strength is configured */
45+
kPORT_NormalDriveStrength, /* Normal drive strength is configured */
46+
kPORT_MuxAlt0, /* Configure as GPIO */
47+
kPORT_InputBufferEnable, /* Digital input enabled */
48+
kPORT_InputNormal, /* Digital input is not inverted */
49+
kPORT_UnlockRegister /* Pin Control Register fields [15:0] are not locked */
50+
};
51+
const gpio_pin_config_t GPIO_OUT_LED_config = {
2852
.pinDirection = kGPIO_DigitalOutput,
2953
.outputLogic = 0U
3054
};
31-
/* Initialize GPIO functionality on pin PIO3_12 (pin 38) */
32-
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &LED_RED_config);
3355

34-
const port_pin_config_t LED_RED = {/* Internal pull-up/down resistor is disabled */
35-
kPORT_PullDisable,
36-
/* Low internal pull resistor value is selected. */
37-
kPORT_LowPullResistor,
38-
/* Fast slew rate is configured */
39-
kPORT_FastSlewRate,
40-
/* Passive input filter is disabled */
41-
kPORT_PassiveFilterDisable,
42-
/* Open drain output is disabled */
43-
kPORT_OpenDrainDisable,
44-
/* Low drive strength is configured */
45-
kPORT_LowDriveStrength,
46-
/* Normal drive strength is configured */
47-
kPORT_NormalDriveStrength,
48-
/* Pin is configured as P3_12 */
49-
kPORT_MuxAlt0,
50-
/* Digital input enabled */
51-
kPORT_InputBufferEnable,
52-
/* Digital input is not inverted */
53-
kPORT_InputNormal,
54-
/* Pin Control Register fields [15:0] are not locked */
55-
kPORT_UnlockRegister};
56-
/* PORT3_12 (pin 38) is configured as P3_12 */
57-
PORT_SetPinConfig(BOARD_LED_GPIO_PORT, BOARD_LED_GPIO_PIN, &LED_RED);
58-
}
56+
/* Enable GPIO port 3 clocks */
57+
CLOCK_EnableClock(kCLOCK_GateGPIO3); /* Write to GPIO3: Peripheral clock is enabled */
58+
CLOCK_EnableClock(kCLOCK_GatePORT3); /* Write to PORT3: Peripheral clock is enabled */
59+
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn); /* GPIO3 peripheral is released from reset */
60+
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn); /* PORT3 peripheral is released from reset */
5961

62+
/* Initialize GPIO functionality on pin */
63+
GPIO_PinInit(GPIO3, pin, &GPIO_OUT_LED_config);
64+
PORT_SetPinConfig(PORT3, pin, &GPIO_OUT_LED);
65+
}
6066

61-
void main(void) {
67+
void main(void)
68+
{
6269
int i = 0;
63-
gpio_pin_config_t led_config = {
64-
kGPIO_DigitalOutput, 0,
65-
};
66-
/* Write to GPIO3: Peripheral clock is enabled */
67-
CLOCK_EnableClock(kCLOCK_GateGPIO3);
68-
/* Write to PORT3: Peripheral clock is enabled */
69-
CLOCK_EnableClock(kCLOCK_GatePORT3);
70-
/* GPIO3 peripheral is released from reset */
71-
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn);
72-
/* PORT3 peripheral is released from reset */
73-
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn);
74-
gpio_init();
70+
uint8_t* bootPart = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS;
71+
uint32_t bootVer = wolfBoot_get_blob_version(bootPart);
7572

76-
GPIO_PinWrite(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, 0);
73+
/* If application version 1 then GREEN, else BLUE */
74+
/* RGB LED D15 (RED=P3_12, GREEN=P3_13, BLUE=P3_0) */
75+
if (bootVer == 1) {
76+
gpio_port3_init(13);
77+
GPIO_PinWrite(GPIO3, 13, 0);
78+
}
79+
else {
80+
gpio_port3_init(0);
81+
GPIO_PinWrite(GPIO3, 0, 0);
82+
}
7783

78-
while(1)
84+
/* busy wait */
85+
while (1) {
7986
__WFI();
87+
}
8088
}

0 commit comments

Comments
 (0)