Skip to content

Commit 1bd31c2

Browse files
authored
Merge pull request hathach#1374 from kasjer/kasjer/stm32wb55
stm32wb55 support
2 parents 4c6bb16 + 76c8d4d commit 1bd31c2

File tree

13 files changed

+913
-1
lines changed

13 files changed

+913
-1
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
[submodule "hw/mcu/st/stm32l5xx_hal_driver"]
9898
path = hw/mcu/st/stm32l5xx_hal_driver
9999
url = https://github.com/STMicroelectronics/stm32l5xx_hal_driver.git
100+
[submodule "hw/mcu/st/cmsis_device_wb"]
101+
path = hw/mcu/st/cmsis_device_wb
102+
url = https://github.com/STMicroelectronics/cmsis_device_wb.git
103+
[submodule "hw/mcu/st/stm32wbxx_hal_driver"]
104+
path = hw/mcu/st/stm32wbxx_hal_driver
105+
url = https://github.com/STMicroelectronics/stm32wbxx_hal_driver.git
100106
[submodule "lib/sct_neopixel"]
101107
path = lib/sct_neopixel
102108
url = https://github.com/gsteiert/sct_neopixel
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2022, Jerzy Kasenberg
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef BOARD_H_
28+
#define BOARD_H_
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
// LED
35+
#define LED_PORT GPIOB
36+
#define LED_PIN GPIO_PIN_5
37+
#define LED_STATE_ON 1
38+
39+
// Button
40+
#define BUTTON_PORT GPIOC
41+
#define BUTTON_PIN GPIO_PIN_4
42+
#define BUTTON_STATE_ACTIVE 0
43+
44+
// UART Enable for STLink VCOM
45+
#define UART_DEV USART1
46+
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
47+
#define UART_GPIO_PORT GPIOB
48+
#define UART_GPIO_AF GPIO_AF7_USART1
49+
#define UART_TX_PIN GPIO_PIN_6
50+
#define UART_RX_PIN GPIO_PIN_7
51+
52+
53+
//--------------------------------------------------------------------+
54+
// RCC Clock
55+
//--------------------------------------------------------------------+
56+
static inline void board_clock_init(void)
57+
{
58+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
59+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
60+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
61+
62+
// Initializes the CPU, AHB and APB busses clocks
63+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE;
64+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
65+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
66+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
67+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
68+
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
69+
RCC_OscInitStruct.PLL.PLLN = 24;
70+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
71+
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
72+
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV3;
73+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
74+
75+
// Initializes the CPU, AHB and APB busses clocks
76+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
77+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
78+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
79+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
80+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
81+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
82+
83+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
84+
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
85+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) ;
86+
87+
#if 0 // TODO need to check if USB clock is enabled
88+
/* Enable HSI48 */
89+
memset(&RCC_OscInitStruct, 0, sizeof(RCC_OscInitStruct));
90+
91+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
92+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
93+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
94+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
95+
96+
/*Enable CRS Clock*/
97+
RCC_CRSInitTypeDef RCC_CRSInitStruct= {0};
98+
__HAL_RCC_CRS_CLK_ENABLE();
99+
100+
/* Default Synchro Signal division factor (not divided) */
101+
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
102+
103+
/* Set the SYNCSRC[1:0] bits according to CRS_Source value */
104+
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
105+
106+
/* HSI48 is synchronized with USB SOF at 1KHz rate */
107+
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
108+
RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
109+
110+
/* Set the TRIM[5:0] to the default value */
111+
RCC_CRSInitStruct.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT;
112+
113+
/* Start automatic synchronization */
114+
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
115+
#endif
116+
}
117+
118+
#ifdef __cplusplus
119+
}
120+
#endif
121+
122+
#endif /* BOARD_H_ */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CFLAGS += \
2+
-DSTM32WB55xx
3+
4+
LD_FILE = $(BOARD_PATH)/stm32wb55xx_flash_cm4.ld
5+
6+
SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32wb55xx_cm4.s
7+
8+
# For flash-jlink target
9+
JLINK_DEVICE = STM32WB55RG
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/**
2+
*****************************************************************************
3+
**
4+
** File : stm32wb55xx_flash_cm4.ld
5+
**
6+
** Abstract : System Workbench Minimal System calls file
7+
**
8+
** For more information about which c-functions
9+
** need which of these lowlevel functions
10+
** please consult the Newlib libc-manual
11+
**
12+
** Environment : System Workbench for MCU
13+
**
14+
** Distribution: The file is distributed “as is,” without any warranty
15+
** of any kind.
16+
**
17+
*****************************************************************************
18+
** @attention
19+
**
20+
** Copyright (c) 2019 STMicroelectronics.
21+
** All rights reserved.
22+
**
23+
** This software is licensed under terms that can be found in the LICENSE file
24+
** in the root directory of this software component.
25+
** If no LICENSE file comes with this software, it is provided AS-IS.
26+
**
27+
*****************************************************************************
28+
*/
29+
30+
/* Entry Point */
31+
ENTRY(Reset_Handler)
32+
33+
/* Highest address of the user mode stack */
34+
_estack = 0x20030000; /* end of RAM */
35+
/* Generate a link error if heap and stack don't fit into RAM */
36+
_Min_Heap_Size = 0x400; /* required amount of heap */
37+
_Min_Stack_Size = 0x1000; /* required amount of stack */
38+
39+
/* Specify the memory areas */
40+
MEMORY
41+
{
42+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
43+
RAM1 (xrw) : ORIGIN = 0x20000008, LENGTH = 0x2FFF8
44+
RAM_SHARED (xrw) : ORIGIN = 0x20030000, LENGTH = 10K
45+
}
46+
47+
/* Define output sections */
48+
SECTIONS
49+
{
50+
/* The startup code goes first into FLASH */
51+
.isr_vector :
52+
{
53+
. = ALIGN(4);
54+
KEEP(*(.isr_vector)) /* Startup code */
55+
. = ALIGN(4);
56+
} >FLASH
57+
58+
/* The program code and other data goes into FLASH */
59+
.text :
60+
{
61+
. = ALIGN(4);
62+
*(.text) /* .text sections (code) */
63+
*(.text*) /* .text* sections (code) */
64+
*(.glue_7) /* glue arm to thumb code */
65+
*(.glue_7t) /* glue thumb to arm code */
66+
*(.eh_frame)
67+
68+
KEEP (*(.init))
69+
KEEP (*(.fini))
70+
71+
. = ALIGN(4);
72+
_etext = .; /* define a global symbols at end of code */
73+
} >FLASH
74+
75+
/* Constant data goes into FLASH */
76+
.rodata :
77+
{
78+
. = ALIGN(4);
79+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
80+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
81+
. = ALIGN(4);
82+
} >FLASH
83+
84+
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
85+
.ARM : {
86+
__exidx_start = .;
87+
*(.ARM.exidx*)
88+
__exidx_end = .;
89+
} >FLASH
90+
91+
.preinit_array :
92+
{
93+
PROVIDE_HIDDEN (__preinit_array_start = .);
94+
KEEP (*(.preinit_array*))
95+
PROVIDE_HIDDEN (__preinit_array_end = .);
96+
} >FLASH
97+
.init_array :
98+
{
99+
PROVIDE_HIDDEN (__init_array_start = .);
100+
KEEP (*(SORT(.init_array.*)))
101+
KEEP (*(.init_array*))
102+
PROVIDE_HIDDEN (__init_array_end = .);
103+
} >FLASH
104+
.fini_array :
105+
{
106+
PROVIDE_HIDDEN (__fini_array_start = .);
107+
KEEP (*(SORT(.fini_array.*)))
108+
KEEP (*(.fini_array*))
109+
PROVIDE_HIDDEN (__fini_array_end = .);
110+
} >FLASH
111+
112+
/* used by the startup to initialize data */
113+
_sidata = LOADADDR(.data);
114+
115+
/* Initialized data sections goes into RAM, load LMA copy after code */
116+
.data :
117+
{
118+
. = ALIGN(4);
119+
_sdata = .; /* create a global symbol at data start */
120+
*(.data) /* .data sections */
121+
*(.data*) /* .data* sections */
122+
123+
. = ALIGN(4);
124+
_edata = .; /* define a global symbol at data end */
125+
} >RAM1 AT> FLASH
126+
127+
128+
/* Uninitialized data section */
129+
. = ALIGN(4);
130+
.bss :
131+
{
132+
/* This is used by the startup in order to initialize the .bss section */
133+
_sbss = .; /* define a global symbol at bss start */
134+
__bss_start__ = _sbss;
135+
*(.bss)
136+
*(.bss*)
137+
*(COMMON)
138+
139+
. = ALIGN(4);
140+
_ebss = .; /* define a global symbol at bss end */
141+
__bss_end__ = _ebss;
142+
} >RAM1
143+
144+
/* User_heap_stack section, used to check that there is enough RAM left */
145+
._user_heap_stack :
146+
{
147+
. = ALIGN(8);
148+
PROVIDE ( end = . );
149+
PROVIDE ( _end = . );
150+
. = . + _Min_Heap_Size;
151+
. = . + _Min_Stack_Size;
152+
. = ALIGN(8);
153+
} >RAM1
154+
155+
156+
157+
/* Remove information from the standard libraries */
158+
/DISCARD/ :
159+
{
160+
libc.a ( * )
161+
libm.a ( * )
162+
libgcc.a ( * )
163+
}
164+
165+
.ARM.attributes 0 : { *(.ARM.attributes) }
166+
MAPPING_TABLE (NOLOAD) : { *(MAPPING_TABLE) } >RAM_SHARED
167+
MB_MEM1 (NOLOAD) : { *(MB_MEM1) } >RAM_SHARED
168+
MB_MEM2 (NOLOAD) : { _sMB_MEM2 = . ; *(MB_MEM2) ; _eMB_MEM2 = . ; } >RAM_SHARED
169+
}
170+
171+

0 commit comments

Comments
 (0)