forked from wolfSSL/wolfBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_stm32u5.c
More file actions
153 lines (135 loc) · 4.24 KB
/
app_stm32u5.c
File metadata and controls
153 lines (135 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* app_stm32u5.c
*
* Test bare-metal application.
*
* Copyright (C) 2026 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 3 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "system.h"
#include "hal.h"
#include "wolfboot/wolfboot.h"
#include "target.h"
#ifdef STM32_DISCOVERY
#define LED_BOOT_PIN (7) /* PH7 - Discovery - Green Led */
#define LED_USR_PIN (6) /* PH6 - Discovery - Red Led */
#else
#define LED_BOOT_PIN (7) /* PC7 - Nucleo-U575ZI-Q - Green Led */
#define LED_USR_PIN (2) /* PG2 - Nucleo-U575ZI-Q - Red Led */
#endif
/*Non-Secure */
#define RCC_BASE (0x46020C00) /* RM0456 - Table 4 */
#define PWR_BASE (0x46020800) /* RM0456 - Table 4 */
#define GPIOC_BASE 0x42020800
#define GPIOG_BASE 0x42021800
#define GPIOH_BASE 0x42021C00
#define GPIOC_MODER (*(volatile uint32_t *)(GPIOC_BASE + 0x00))
#define GPIOC_PUPDR (*(volatile uint32_t *)(GPIOC_BASE + 0x0C))
#define GPIOC_BSRR (*(volatile uint32_t *)(GPIOC_BASE + 0x18))
#define GPIOG_MODER (*(volatile uint32_t *)(GPIOG_BASE + 0x00))
#define GPIOG_PUPDR (*(volatile uint32_t *)(GPIOG_BASE + 0x0C))
#define GPIOG_BSRR (*(volatile uint32_t *)(GPIOG_BASE + 0x18))
#define GPIOH_MODER (*(volatile uint32_t *)(GPIOH_BASE + 0x00))
#define GPIOH_PUPDR (*(volatile uint32_t *)(GPIOH_BASE + 0x0C))
#define GPIOH_BSRR (*(volatile uint32_t *)(GPIOH_BASE + 0x18))
#define RCC_AHB2ENR1_CLOCK_ER (*(volatile uint32_t *)(RCC_BASE + 0x8C ))
#define GPIOC_AHB2ENR1_CLOCK_ER (1 << 2)
#define GPIOG_AHB2ENR1_CLOCK_ER (1 << 6)
#define GPIOH_AHB2ENR1_CLOCK_ER (1 << 7)
#define PWR_CR2 (*(volatile uint32_t *)(PWR_BASE + 0x04))
#define PWR_CR2_IOSV (1 << 9)
static void boot_led_on(void)
{
uint32_t reg;
uint32_t pin = LED_BOOT_PIN;
#ifdef STM32_DISCOVERY
RCC_AHB2ENR1_CLOCK_ER|= GPIOH_AHB2ENR1_CLOCK_ER;
#else
RCC_AHB2ENR1_CLOCK_ER|= GPIOC_AHB2ENR1_CLOCK_ER;
#endif
/* Delay after an RCC peripheral clock enabling */
reg = RCC_AHB2ENR1_CLOCK_ER;
#if 0
/* Disabled, may not need it */
PWR_CR2 |= PWR_CR2_IOSV;
#endif
#ifdef STM32_DISCOVERY
reg = GPIOH_MODER & ~(0x03 << (pin * 2));
GPIOH_MODER = reg | (1 << (pin * 2));
GPIOH_PUPDR &= ~(0x03 << (pin * 2));
GPIOH_BSRR |= (1 << (pin + 16));
#else
reg = GPIOC_MODER & ~(0x03 << (pin * 2));
GPIOC_MODER = reg | (1 << (pin * 2));
GPIOC_PUPDR &= ~(0x03 << (pin * 2));
GPIOC_BSRR |= (1 << pin);
#endif
}
static void boot_led_off(void)
{
#ifdef STM32_DISCOVERY
GPIOH_BSRR |= (1 << (LED_BOOT_PIN));
#else
GPIOC_BSRR |= (1 << (LED_BOOT_PIN + 16));
#endif
}
void usr_led_on(void)
{
uint32_t reg;
uint32_t pin = LED_USR_PIN;
#ifdef STM32_DISCOVERY
RCC_AHB2ENR1_CLOCK_ER|= GPIOH_AHB2ENR1_CLOCK_ER;
#else
RCC_AHB2ENR1_CLOCK_ER|= GPIOG_AHB2ENR1_CLOCK_ER;
#endif
/* Delay after an RCC peripheral clock enabling */
reg = RCC_AHB2ENR1_CLOCK_ER;
#ifdef STM32_DISCOVERY
reg = GPIOH_MODER & ~(0x03 << (pin * 2));
GPIOH_MODER = reg | (1 << (pin * 2));
GPIOH_PUPDR &= ~(0x03 << (pin * 2));
GPIOH_BSRR |= (1 << (pin + 16));
#else
reg = GPIOG_MODER & ~(0x03 << (pin * 2));
GPIOG_MODER = reg | (1 << (pin * 2));
GPIOG_PUPDR &= ~(0x03 << (pin * 2));
GPIOG_BSRR |= (1 << pin);
#endif
}
void usr_led_off(void)
{
#ifdef STM32_DISCOVERY
GPIOH_BSRR |= (1 << (LED_USR_PIN));
#else
GPIOG_BSRR |= (1 << (LED_USR_PIN + 16));
#endif
}
void main(void)
{
hal_init();
boot_led_on();
usr_led_on();
boot_led_off();
if (wolfBoot_current_firmware_version() > 1)
boot_led_on();
while(1)
;
}