|
| 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 | + |
1 | 25 | #include <stdlib.h> |
2 | 26 | #include <stdint.h> |
3 | 27 | #include <string.h> |
4 | 28 | #include "fsl_common.h" |
5 | 29 | #include "fsl_port.h" |
6 | 30 | #include "fsl_gpio.h" |
7 | 31 | #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 |
14 | 32 |
|
| 33 | +#include "wolfboot/wolfboot.h" |
15 | 34 |
|
16 | | -void gpio_init(void) |
| 35 | +/* init gpio for port 3 */ |
| 36 | +void gpio_port3_init(int pin) |
17 | 37 | { |
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 = { |
28 | 52 | .pinDirection = kGPIO_DigitalOutput, |
29 | 53 | .outputLogic = 0U |
30 | 54 | }; |
31 | | - /* Initialize GPIO functionality on pin PIO3_12 (pin 38) */ |
32 | | - GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &LED_RED_config); |
33 | 55 |
|
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 */ |
59 | 61 |
|
| 62 | + /* Initialize GPIO functionality on pin */ |
| 63 | + GPIO_PinInit(GPIO3, pin, &GPIO_OUT_LED_config); |
| 64 | + PORT_SetPinConfig(PORT3, pin, &GPIO_OUT_LED); |
| 65 | +} |
60 | 66 |
|
61 | | -void main(void) { |
| 67 | +void main(void) |
| 68 | +{ |
62 | 69 | 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); |
75 | 72 |
|
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 | + } |
77 | 83 |
|
78 | | - while(1) |
| 84 | + /* busy wait */ |
| 85 | + while (1) { |
79 | 86 | __WFI(); |
| 87 | + } |
80 | 88 | } |
0 commit comments