Skip to content

Commit 31a4b7e

Browse files
authored
Merge pull request #423 from danielinux/mcxa153
Added support for NXP MCXA153
2 parents cf05199 + bc0d909 commit 31a4b7e

File tree

9 files changed

+544
-0
lines changed

9 files changed

+544
-0
lines changed

.github/workflows/test-configs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ jobs:
112112
arch: ppc
113113
config-file: ./config/examples/nxp-t2080.config
114114

115+
# MCXA test disabled until MCXA is available in mcux
116+
# nxp_mcxa_test:
117+
# uses: ./.github/workflows/test-build-mcux-sdk.yml
118+
# with:
119+
# arch: arm
120+
# config-file: ./config/examples/mcxa.config
121+
115122
raspi3_test:
116123
uses: ./.github/workflows/test-build.yml
117124
with:

arch.mk

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,36 @@ ifeq ($(TARGET),kinetis)
335335
endif
336336
endif
337337

338+
ifeq ($(TARGET),mcxa)
339+
CORTEX_M33=1
340+
CFLAGS+=\
341+
-I$(MCUXPRESSO_DRIVERS) \
342+
-I$(MCUXPRESSO_DRIVERS)/drivers \
343+
-I$(MCUXPRESSO)/drivers \
344+
-I$(MCUXPRESSO)/drivers/common \
345+
-I$(MCUXPRESSO_CMSIS)/Include \
346+
-I$(MCUXPRESSO_CMSIS)/Core/Include
347+
CFLAGS+=-DCPU_$(MCUXPRESSO_CPU) -DDEBUG_CONSOLE_ASSERT_DISABLE=1
348+
CFLAGS+=-DWOLFSSL_SP_NO_UMAAL
349+
CFLAGS+=-Wno-old-style-declaration
350+
CFLAGS+=-mcpu=cortex-m33 -DCORTEX_M33 -U__ARM_FEATURE_DSP
351+
LDFLAGS+=-mcpu=cortex-m33
352+
OBJS+=\
353+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o \
354+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_spc.o
355+
356+
ifeq ($(MCUXSDK),1)
357+
CFLAGS+=\
358+
-I$(MCUXPRESSO)/drivers/flash \
359+
-I$(MCUXPRESSO)/drivers/sysmpu \
360+
-I$(MCUXPRESSO)/drivers/ltc \
361+
-I$(MCUXPRESSO)/drivers/port \
362+
-I$(MCUXPRESSO)/drivers/gpio
363+
364+
else
365+
endif
366+
endif
367+
338368
ifeq ($(TARGET),imx_rt)
339369
CFLAGS+=\
340370
-I$(MCUXPRESSO_DRIVERS) \

config/examples/mcxa.config

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ARCH?=ARM
2+
TARGET?=mcxa
3+
SIGN?=ECC256
4+
HASH?=SHA256
5+
MCUXSDK?=0
6+
MCUXPRESSO?=$(PWD)/../NXP/MCXA153
7+
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
8+
MCUXPRESSO_CPU?=MCXA153VLH
9+
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/MCXA153
10+
DEBUG?=0
11+
VTOR?=1
12+
CORTEX_M0?=0
13+
NO_ASM?=0
14+
EXT_FLASH?=0
15+
SPI_FLASH?=0
16+
ALLOW_DOWNGRADE?=0
17+
NVM_FLASH_WRITEONCE?=0
18+
WOLFBOOT_VERSION?=0
19+
V?=0
20+
SPMATH?=1
21+
RAM_CODE?=1
22+
DUALBANK_SWAP?=0
23+
PKA?=1
24+
25+
# 8KB sectors
26+
WOLFBOOT_SECTOR_SIZE?=0x2000
27+
28+
# Default configuration
29+
# 32KB boot, 44KB partitions, 8KB swap
30+
WOLFBOOT_PARTITION_SIZE?=0xB000
31+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8000
32+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x13000
33+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1E000
34+
35+
# Alternate larger configuration for debugging or SP ASM
36+
# 40KB boot, 40KB partitions, 8KB swap
37+
#WOLFBOOT_PARTITION_SIZE?=0xA000
38+
#WOLFBOOT_PARTITION_BOOT_ADDRESS?=0xA000
39+
#WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x14000
40+
#WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1E000

docs/Targets.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This README describes configuration of supported targets.
1414
* [NXP P1021 PPC](#nxp-qoriq-p1021-ppc)
1515
* [NXP T1024 PPC](#nxp-qoriq-t1024-ppc)
1616
* [NXP T2080 PPC](#nxp-qoriq-t2080-ppc)
17+
* [NXP MCXA153](#nxp-mcxa153)
1718
* [SiFive HiFive1 RISC-V](#sifive-hifive1-risc-v)
1819
* [STM32F4](#stm32f4)
1920
* [STM32F7](#stm32f7)
@@ -1710,6 +1711,85 @@ Executing Initialization File: /opt/Freescale/CodeWarrior_PA_10.5.1/PA/PA_Suppor
17101711
thread break: Stopped, 0x0, 0x0, cpuPowerPCBig, Connected (state, tid, pid, cpu, target)
17111712
```
17121713

1714+
## NXP MCXA153
1715+
1716+
NXP MCXA153 is a Cortex-M33 microcontroller running at 96MHz.
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
1721+
1722+
### MCX A: Configuring and compiling
1723+
1724+
Copy the example configuration file and build with make:
1725+
1726+
```sh
1727+
cp config/examples/mcxa.config .config`
1728+
make
1729+
```
1730+
1731+
### MCX A: Loading the firmware
1732+
1733+
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
1734+
1735+
Use JLinkExe tool to upload the initial firmware: `JLinkExe -if swd -Device MCXA153`
1736+
1737+
At the Jlink prompt, type:
1738+
1739+
```
1740+
loadbin factory.bin 0
1741+
Downloading file [factory.bin]...
1742+
J-Link: Flash download: Bank 0 @ 0x00000000: Skipped. Contents already match
1743+
O.K.
1744+
```
1745+
1746+
Reset or power cycle board.
1747+
1748+
Once wolfBoot has performaed validation of the partition and booted the D15 Green LED on P3_13 will illuminate.
1749+
1750+
### MCX A: Testing firmware update
1751+
1752+
1) Sign the test-app with version 2:
1753+
1754+
```sh
1755+
./tools/keytools/sign --ecc256 test-app/image.bin wolfboot_signing_private_key.der 2
1756+
```
1757+
1758+
2) Create a bin footer with wolfBoot trailer "BOOT" and "p" (ASCII for 0x70 == IMG_STATE_UPDATING):
1759+
1760+
```sh
1761+
echo -n "pBOOT" > trigger_magic.bin
1762+
```
1763+
1764+
3) Assembly new factory update.bin:
1765+
1766+
```sh
1767+
./tools/bin-assemble/bin-assemble \
1768+
update.bin \
1769+
0x0 test-app/image_v2_signed.bin \
1770+
0xAFFB trigger_magic.bin
1771+
```
1772+
1773+
4) Flash update.bin to 0x13000 (`loadbin update.bin 0x13000`). The D15 RGB LED Blue P3_0 will show if version is > 1.
1774+
1775+
Note: For alternate larger scheme flash `update.bin` to `0x14000` and place trigger_magic.bin at `0x9FFB`.
1776+
1777+
### MCX A: Debugging
1778+
1779+
Debugging with JLink:
1780+
1781+
Note: We include a `.gdbinit` in the wolfBoot root that loads the wolfboot and test-app elf files.
1782+
1783+
In one terminal: `JLinkGDBServer -if swd -Device MCXA153 -port 3333`
1784+
1785+
In another terminal use `gdb`:
1786+
1787+
```
1788+
b main
1789+
mon reset
1790+
c
1791+
```
1792+
17131793

17141794
## TI Hercules TMS570LC435
17151795

hal/mcxa.c

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/* mcxa.c
2+
*
3+
* Copyright (C) 2021 wolfSSL Inc.
4+
*
5+
* This file is part of wolfBoot.
6+
*
7+
* wolfBoot is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfBoot is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
#include <stdint.h>
23+
#include <target.h>
24+
#include "image.h"
25+
/* FSL includes */
26+
#include "fsl_common.h"
27+
28+
/* Clock + RAM voltage settings */
29+
#include "fsl_clock.h"
30+
#include "fsl_spc.h"
31+
32+
/* Flash driver */
33+
#include "fsl_romapi.h"
34+
35+
/*!< Core clock frequency: 96000000Hz */
36+
#define BOARD_BOOTCLOCKFRO96M_CORE_CLOCK 96000000UL
37+
38+
static flash_config_t pflash;
39+
static int flash_init = 0;
40+
41+
#ifdef __WOLFBOOT
42+
/* Assert hook needed by Kinetis SDK */
43+
void __assert_func(const char *a, int b, const char *c, const char *d)
44+
{
45+
while(1)
46+
;
47+
}
48+
49+
/* The following clock setting function is autogenerated by the MCUXpresso IDE */
50+
void BOARD_BootClockFRO96M(void)
51+
{
52+
uint32_t coreFreq;
53+
spc_active_mode_core_ldo_option_t ldoOption;
54+
spc_sram_voltage_config_t sramOption;
55+
56+
/* Get the CPU Core frequency */
57+
coreFreq = CLOCK_GetCoreSysClkFreq();
58+
59+
/* The flow of increasing voltage and frequency */
60+
if (coreFreq <= BOARD_BOOTCLOCKFRO96M_CORE_CLOCK) {
61+
/* Set the LDO_CORE VDD regulator level */
62+
ldoOption.CoreLDOVoltage = kSPC_CoreLDO_NormalVoltage;
63+
ldoOption.CoreLDODriveStrength = kSPC_CoreLDO_NormalDriveStrength;
64+
(void)SPC_SetActiveModeCoreLDORegulatorConfig(SPC0, &ldoOption);
65+
/* Configure Flash to support different voltage level and frequency */
66+
FMU0->FCTRL = (FMU0->FCTRL & ~((uint32_t)FMU_FCTRL_RWSC_MASK)) | (FMU_FCTRL_RWSC(0x2U));
67+
/* Specifies the operating voltage for the SRAM's read/write timing margin */
68+
sramOption.operateVoltage = kSPC_sramOperateAt1P1V;
69+
sramOption.requestVoltageUpdate = true;
70+
(void)SPC_SetSRAMOperateVoltage(SPC0, &sramOption);
71+
}
72+
73+
CLOCK_SetupFROHFClocking(96000000U); /*!< Enable FRO HF(96MHz) output */
74+
75+
CLOCK_SetupFRO12MClocking(); /*!< Setup FRO12M clock */
76+
77+
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /* !< Switch MAIN_CLK to FRO_HF */
78+
79+
/* The flow of decreasing voltage and frequency */
80+
if (coreFreq > BOARD_BOOTCLOCKFRO96M_CORE_CLOCK) {
81+
/* Configure Flash to support different voltage level and frequency */
82+
FMU0->FCTRL = (FMU0->FCTRL & ~((uint32_t)FMU_FCTRL_RWSC_MASK)) | (FMU_FCTRL_RWSC(0x2U));
83+
/* Specifies the operating voltage for the SRAM's read/write timing margin */
84+
sramOption.operateVoltage = kSPC_sramOperateAt1P1V;
85+
sramOption.requestVoltageUpdate = true;
86+
(void)SPC_SetSRAMOperateVoltage(SPC0, &sramOption);
87+
/* Set the LDO_CORE VDD regulator level */
88+
ldoOption.CoreLDOVoltage = kSPC_CoreLDO_NormalVoltage;
89+
ldoOption.CoreLDODriveStrength = kSPC_CoreLDO_NormalDriveStrength;
90+
(void)SPC_SetActiveModeCoreLDORegulatorConfig(SPC0, &ldoOption);
91+
}
92+
93+
/*!< Set up clock selectors - Attach clocks to the peripheries */
94+
95+
/*!< 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 */
98+
}
99+
100+
void hal_init(void)
101+
{
102+
/* Clock setting */
103+
BOARD_BootClockFRO96M();
104+
105+
/* Clear the FLASH configuration structure */
106+
memset(&pflash, 0, sizeof(pflash));
107+
/* FLASH driver init */
108+
FLASH_Init(&pflash);
109+
}
110+
111+
void hal_prepare_boot(void)
112+
{
113+
}
114+
115+
#endif /* __WOLFBOOT */
116+
117+
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
118+
{
119+
int ret;
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+
};
125+
126+
while (len > 0) {
127+
if ((len < 16) || address & 0x0F) {
128+
uint8_t aligned_qword[16];
129+
uint32_t address_align = address - (address & 0x0F);
130+
uint32_t start_off = address - address_align;
131+
int i;
132+
133+
memcpy(aligned_qword, (void*)address_align, 16);
134+
for (i = start_off; ((i < 16) && (i < len + (int)start_off)); i++) {
135+
aligned_qword[i] = data[w++];
136+
}
137+
if (memcmp(aligned_qword, empty_qword, 16) != 0) {
138+
ret = FLASH_ProgramPhrase(&pflash, address_align, aligned_qword, 16);
139+
if (ret != kStatus_Success)
140+
return -1;
141+
}
142+
address += i;
143+
len -= i;
144+
}
145+
else {
146+
uint32_t len_align = len - (len & 0x0F);
147+
ret = FLASH_ProgramPhrase(&pflash, address, (uint8_t*)data + w, len_align);
148+
if (ret != kStatus_Success)
149+
return -1;
150+
len -= len_align;
151+
address += len_align;
152+
}
153+
}
154+
return 0;
155+
}
156+
157+
void RAMFUNCTION hal_flash_unlock(void)
158+
{
159+
}
160+
161+
void RAMFUNCTION hal_flash_lock(void)
162+
{
163+
}
164+
165+
166+
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
167+
{
168+
while ((address % 4) != 0)
169+
address --;
170+
if (FLASH_EraseSector(&pflash, address, len, kFLASH_ApiEraseKey) != kStatus_Success)
171+
return -1;
172+
return 0;
173+
}

0 commit comments

Comments
 (0)