Skip to content

Commit a7fe956

Browse files
committed
rename dk board and more update
1 parent 8633a26 commit a7fe956

File tree

7 files changed

+153
-56
lines changed

7 files changed

+153
-56
lines changed

.idea/cmake.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hw/bsp/stm32h5/FreeRTOSConfig/FreeRTOSConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
// skip if included from IAR assembler
4646
#ifndef __IASMARM__
47-
#include "stm32g0xx.h"
47+
#include "stm32h5xx.h"
4848
#endif
4949

5050
/* Cortex M23/M33 port configuration. */
@@ -143,7 +143,7 @@
143143
//--------------------------------------------------------------------+
144144

145145
// For Cortex-M specific: __NVIC_PRIO_BITS is defined in mcu header
146-
#define configPRIO_BITS 2
146+
#define configPRIO_BITS 4
147147

148148
/* The lowest interrupt priority that can be used in a call to a "set priority" function. */
149149
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1<<configPRIO_BITS) - 1)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020, Ha Thach (tinyusb.org)
5+
* Copyright (c) 2023, HiFiPhile
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
* This file is part of the TinyUSB stack.
26+
*/
27+
28+
#ifndef BOARD_H_
29+
#define BOARD_H_
30+
31+
#ifdef __cplusplus
32+
extern "C" {
33+
#endif
34+
35+
// LED
36+
#define LED_PORT GPIOG
37+
#define LED_PIN GPIO_PIN_4
38+
#define LED_STATE_ON 1
39+
40+
// Button
41+
#define BUTTON_PORT GPIOA
42+
#define BUTTON_PIN GPIO_PIN_0
43+
#define BUTTON_STATE_ACTIVE 0
44+
45+
// UART Enable for STLink VCOM
46+
#define UART_DEV USART1
47+
#define UART_CLK_EN __USART1_CLK_ENABLE
48+
#define UART_GPIO_PORT GPIOA
49+
#define UART_GPIO_AF GPIO_AF7_USART1
50+
51+
#define UART_TX_PIN GPIO_PIN_9
52+
#define UART_RX_PIN GPIO_PIN_10
53+
54+
//--------------------------------------------------------------------+
55+
// RCC Clock
56+
//--------------------------------------------------------------------+
57+
static inline void SystemClock_Config(void) {
58+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
59+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
60+
61+
/** Configure the main internal regulator output voltage */
62+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
63+
64+
/** Initializes the RCC Oscillators according to the specified parameters
65+
* in the RCC_OscInitTypeDef structure.
66+
Freq 250MHZ */
67+
68+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE;
69+
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS_DIGITAL;
70+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
71+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
72+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLL1_SOURCE_HSE;
73+
RCC_OscInitStruct.PLL.PLLM = 5;
74+
RCC_OscInitStruct.PLL.PLLN = 100;
75+
RCC_OscInitStruct.PLL.PLLP = 2;
76+
RCC_OscInitStruct.PLL.PLLQ = 10;
77+
RCC_OscInitStruct.PLL.PLLR = 2;
78+
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_2;
79+
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
80+
RCC_OscInitStruct.PLL.PLLFRACN = 0;
81+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
82+
83+
/** Initializes the CPU, AHB and APB buses clocks */
84+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1;
85+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
86+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
87+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
88+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
89+
90+
// Configure CRS clock source
91+
__HAL_RCC_CRS_CLK_ENABLE();
92+
RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};
93+
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
94+
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
95+
RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
96+
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
97+
RCC_CRSInitStruct.ErrorLimitValue = 34;
98+
RCC_CRSInitStruct.HSI48CalibrationValue = 32;
99+
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
100+
101+
/* Select HSI48 as USB clock source */
102+
RCC_PeriphCLKInitTypeDef usb_clk = {0 };
103+
usb_clk.PeriphClockSelection = RCC_PERIPHCLK_USB;
104+
usb_clk.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
105+
HAL_RCCEx_PeriphCLKConfig(&usb_clk);
106+
107+
/* Peripheral clock enable */
108+
__HAL_RCC_USB_CLK_ENABLE();
109+
}
110+
111+
#ifdef __cplusplus
112+
}
113+
#endif
114+
115+
#endif /* BOARD_H_ */

hw/bsp/stm32h5/boards/stm32h573i-dk/board.h renamed to hw/bsp/stm32h5/boards/stm32h573i_dk/board.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,10 @@ extern "C" {
5151
#define UART_TX_PIN GPIO_PIN_9
5252
#define UART_RX_PIN GPIO_PIN_10
5353

54-
55-
56-
5754
//--------------------------------------------------------------------+
5855
// RCC Clock
5956
//--------------------------------------------------------------------+
60-
// Clock configure for STM32stm32h573i-dk
61-
static inline void board_clock_init(void)
62-
{
57+
static inline void SystemClock_Config(void) {
6358
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
6459
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
6560

@@ -103,7 +98,6 @@ static inline void board_clock_init(void)
10398
RCC_CRSInitStruct.HSI48CalibrationValue = 32;
10499
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
105100

106-
107101
/* Select HSI48 as USB clock source */
108102
RCC_PeriphCLKInitTypeDef usb_clk = {0 };
109103
usb_clk.PeriphClockSelection = RCC_PERIPHCLK_USB;
@@ -112,10 +106,6 @@ static inline void board_clock_init(void)
112106

113107
/* Peripheral clock enable */
114108
__HAL_RCC_USB_CLK_ENABLE();
115-
116-
SystemCoreClockUpdate();
117-
118-
119109
}
120110

121111
#ifdef __cplusplus

hw/bsp/stm32h5/family.c

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
//--------------------------------------------------------------------+
4545
// Forward USB interrupt events to TinyUSB IRQ Handler
4646
//--------------------------------------------------------------------+
47-
void USB_DRD_FS_IRQHandler(void)
48-
{
47+
void USB_DRD_FS_IRQHandler(void) {
4948
tud_int_handler(0);
5049
}
5150

@@ -54,23 +53,25 @@ void USB_DRD_FS_IRQHandler(void)
5453
//--------------------------------------------------------------------+
5554
UART_HandleTypeDef UartHandle;
5655

57-
void board_init(void)
58-
{
56+
void board_init(void) {
5957
HAL_Init(); // required for HAL_RCC_Osc TODO check with freeRTOS
60-
board_clock_init();
58+
SystemClock_Config(); // implemented in board.h
59+
SystemCoreClockUpdate();
6160

6261
// Enable All GPIOs clocks
6362
__HAL_RCC_GPIOA_CLK_ENABLE();
6463
__HAL_RCC_GPIOB_CLK_ENABLE();
6564
__HAL_RCC_GPIOC_CLK_ENABLE();
6665
__HAL_RCC_GPIOD_CLK_ENABLE();
6766
__HAL_RCC_GPIOE_CLK_ENABLE();
67+
__HAL_RCC_GPIOG_CLK_ENABLE();
68+
__HAL_RCC_GPIOH_CLK_ENABLE();
6869
__HAL_RCC_GPIOI_CLK_ENABLE();
6970

7071
//__HAL_RCC_SYSCFG_CLK_ENABLE();
7172
//__HAL_RCC_PWR_CLK_ENABLE();
7273

73-
UART_CLK_EN();
74+
UART_CLK_EN();
7475

7576
#if CFG_TUSB_OS == OPT_OS_NONE
7677
// 1ms tick timer
@@ -103,24 +104,23 @@ void board_init(void)
103104

104105
#ifdef UART_DEV
105106
// UART
106-
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
107-
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
108-
GPIO_InitStruct.Pull = GPIO_PULLUP;
109-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
107+
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
108+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
109+
GPIO_InitStruct.Pull = GPIO_PULLUP;
110+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
110111
GPIO_InitStruct.Alternate = UART_GPIO_AF;
111112
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
112113

113-
UartHandle = (UART_HandleTypeDef)
114-
{
115-
.Instance = UART_DEV,
116-
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
117-
.Init.WordLength = UART_WORDLENGTH_8B,
118-
.Init.StopBits = UART_STOPBITS_1,
119-
.Init.Parity = UART_PARITY_NONE,
120-
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
121-
.Init.Mode = UART_MODE_TX_RX,
122-
.Init.OverSampling = UART_OVERSAMPLING_16,
123-
.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT
114+
UartHandle = (UART_HandleTypeDef) {
115+
.Instance = UART_DEV,
116+
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
117+
.Init.WordLength = UART_WORDLENGTH_8B,
118+
.Init.StopBits = UART_STOPBITS_1,
119+
.Init.Parity = UART_PARITY_NONE,
120+
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
121+
.Init.Mode = UART_MODE_TX_RX,
122+
.Init.OverSampling = UART_OVERSAMPLING_16,
123+
.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT
124124
};
125125
HAL_UART_Init(&UartHandle);
126126
#endif
@@ -144,22 +144,19 @@ void board_init(void)
144144
// Board porting API
145145
//--------------------------------------------------------------------+
146146

147-
void board_led_write(bool state)
148-
{
149-
GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
147+
void board_led_write(bool state) {
148+
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
150149
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
151150
}
152151

153-
uint32_t board_button_read(void)
154-
{
152+
uint32_t board_button_read(void) {
155153
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
156154
}
157155

158-
size_t board_get_unique_id(uint8_t id[], size_t max_len)
159-
{
156+
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
160157
(void) max_len;
161-
volatile uint32_t *stm32_uuid = (volatile uint32_t *) UID_BASE;
162-
uint32_t *id32 = (uint32_t *)(uintptr_t) id;
158+
volatile uint32_t* stm32_uuid = (volatile uint32_t*) UID_BASE;
159+
uint32_t* id32 = (uint32_t*) (uintptr_t) id;
163160
uint8_t const len = 12;
164161

165162
id32[0] = stm32_uuid[0];
@@ -169,17 +166,15 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len)
169166
return len;
170167
}
171168

172-
int board_uart_read(uint8_t *buf, int len)
173-
{
169+
int board_uart_read(uint8_t* buf, int len) {
174170
(void) buf;
175171
(void) len;
176172
return 0;
177173
}
178174

179-
int board_uart_write(void const *buf, int len)
180-
{
175+
int board_uart_write(void const* buf, int len) {
181176
#ifdef UART_DEV
182-
HAL_UART_Transmit(&UartHandle, (uint8_t *)(uintptr_t) buf, len, 0xffff);
177+
HAL_UART_Transmit(&UartHandle, (uint8_t*) (uintptr_t) buf, len, 0xffff);
183178
return len;
184179
#else
185180
(void) buf;
@@ -192,27 +187,23 @@ int board_uart_write(void const *buf, int len)
192187
#if CFG_TUSB_OS == OPT_OS_NONE
193188
volatile uint32_t system_ticks = 0;
194189

195-
void SysTick_Handler(void)
196-
{
190+
void SysTick_Handler(void) {
197191
system_ticks++;
198192
HAL_IncTick();
199193
}
200194

201-
uint32_t board_millis(void)
202-
{
195+
uint32_t board_millis(void) {
203196
return system_ticks;
204197
}
205198

206199
#endif
207200

208-
void HardFault_Handler(void)
209-
{
201+
void HardFault_Handler(void) {
210202
__asm("BKPT #0\n");
211203
}
212204

213205
// Required by __libc_init_array in startup code if we are compiling using
214206
// -nostdlib/-nostartfiles.
215-
void _init(void)
216-
{
207+
void _init(void) {
217208

218209
}

0 commit comments

Comments
 (0)