-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test-app code to change LED color based on version. Improved do…
…cumentation. Minor code cleanups.
- Loading branch information
Showing
4 changed files
with
134 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,88 @@ | ||
/* app_mcxa.c | ||
* | ||
* Test bare-metal boot-led-on application | ||
* | ||
* Copyright (C) 2024 wolfSSL Inc. | ||
* | ||
* This file is part of wolfBoot. | ||
* | ||
* wolfBoot is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* wolfBoot is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA | ||
*/ | ||
|
||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include "fsl_common.h" | ||
#include "fsl_port.h" | ||
#include "fsl_gpio.h" | ||
#include "fsl_clock.h" | ||
#include "wolfboot/wolfboot.h" | ||
|
||
|
||
#define BOARD_LED_GPIO_PORT PORT3 | ||
#define BOARD_LED_GPIO GPIO3 | ||
#define BOARD_LED_GPIO_PIN 12U | ||
|
||
#include "wolfboot/wolfboot.h" | ||
|
||
void gpio_init(void) | ||
/* init gpio for port 3 */ | ||
void gpio_port3_init(int pin) | ||
{ | ||
/* Write to GPIO3: Peripheral clock is enabled */ | ||
CLOCK_EnableClock(kCLOCK_GateGPIO3); | ||
/* Write to PORT3: Peripheral clock is enabled */ | ||
CLOCK_EnableClock(kCLOCK_GatePORT3); | ||
/* GPIO3 peripheral is released from reset */ | ||
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn); | ||
/* PORT3 peripheral is released from reset */ | ||
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn); | ||
|
||
gpio_pin_config_t LED_RED_config = { | ||
const port_pin_config_t GPIO_OUT_LED = { | ||
kPORT_PullDisable, /* Internal pull-up/down resistor is disabled */ | ||
kPORT_LowPullResistor, /* Low internal pull resistor value is selected. */ | ||
kPORT_FastSlewRate, /* Fast slew rate is configured */ | ||
kPORT_PassiveFilterDisable, /* Passive input filter is disabled */ | ||
kPORT_OpenDrainDisable, /* Open drain output is disabled */ | ||
kPORT_LowDriveStrength, /* Low drive strength is configured */ | ||
kPORT_NormalDriveStrength, /* Normal drive strength is configured */ | ||
kPORT_MuxAlt0, /* Configure as GPIO */ | ||
kPORT_InputBufferEnable, /* Digital input enabled */ | ||
kPORT_InputNormal, /* Digital input is not inverted */ | ||
kPORT_UnlockRegister /* Pin Control Register fields [15:0] are not locked */ | ||
}; | ||
const gpio_pin_config_t GPIO_OUT_LED_config = { | ||
.pinDirection = kGPIO_DigitalOutput, | ||
.outputLogic = 0U | ||
}; | ||
/* Initialize GPIO functionality on pin PIO3_12 (pin 38) */ | ||
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &LED_RED_config); | ||
|
||
const port_pin_config_t LED_RED = {/* Internal pull-up/down resistor is disabled */ | ||
kPORT_PullDisable, | ||
/* Low internal pull resistor value is selected. */ | ||
kPORT_LowPullResistor, | ||
/* Fast slew rate is configured */ | ||
kPORT_FastSlewRate, | ||
/* Passive input filter is disabled */ | ||
kPORT_PassiveFilterDisable, | ||
/* Open drain output is disabled */ | ||
kPORT_OpenDrainDisable, | ||
/* Low drive strength is configured */ | ||
kPORT_LowDriveStrength, | ||
/* Normal drive strength is configured */ | ||
kPORT_NormalDriveStrength, | ||
/* Pin is configured as P3_12 */ | ||
kPORT_MuxAlt0, | ||
/* Digital input enabled */ | ||
kPORT_InputBufferEnable, | ||
/* Digital input is not inverted */ | ||
kPORT_InputNormal, | ||
/* Pin Control Register fields [15:0] are not locked */ | ||
kPORT_UnlockRegister}; | ||
/* PORT3_12 (pin 38) is configured as P3_12 */ | ||
PORT_SetPinConfig(BOARD_LED_GPIO_PORT, BOARD_LED_GPIO_PIN, &LED_RED); | ||
} | ||
/* Enable GPIO port 3 clocks */ | ||
CLOCK_EnableClock(kCLOCK_GateGPIO3); /* Write to GPIO3: Peripheral clock is enabled */ | ||
CLOCK_EnableClock(kCLOCK_GatePORT3); /* Write to PORT3: Peripheral clock is enabled */ | ||
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn); /* GPIO3 peripheral is released from reset */ | ||
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn); /* PORT3 peripheral is released from reset */ | ||
|
||
/* Initialize GPIO functionality on pin */ | ||
GPIO_PinInit(GPIO3, pin, &GPIO_OUT_LED_config); | ||
PORT_SetPinConfig(PORT3, pin, &GPIO_OUT_LED); | ||
} | ||
|
||
void main(void) { | ||
void main(void) | ||
{ | ||
int i = 0; | ||
gpio_pin_config_t led_config = { | ||
kGPIO_DigitalOutput, 0, | ||
}; | ||
/* Write to GPIO3: Peripheral clock is enabled */ | ||
CLOCK_EnableClock(kCLOCK_GateGPIO3); | ||
/* Write to PORT3: Peripheral clock is enabled */ | ||
CLOCK_EnableClock(kCLOCK_GatePORT3); | ||
/* GPIO3 peripheral is released from reset */ | ||
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn); | ||
/* PORT3 peripheral is released from reset */ | ||
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn); | ||
gpio_init(); | ||
uint8_t* bootPart = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS; | ||
uint32_t bootVer = wolfBoot_get_blob_version(bootPart); | ||
|
||
GPIO_PinWrite(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, 0); | ||
/* If application version 1 then GREEN, else BLUE */ | ||
/* RGB LED D15 (RED=P3_12, GREEN=P3_13, BLUE=P3_0) */ | ||
if (bootVer == 1) { | ||
gpio_port3_init(13); | ||
GPIO_PinWrite(GPIO3, 13, 0); | ||
} | ||
else { | ||
gpio_port3_init(0); | ||
GPIO_PinWrite(GPIO3, 0, 0); | ||
} | ||
|
||
while(1) | ||
/* busy wait */ | ||
while (1) { | ||
__WFI(); | ||
} | ||
} |