Skip to content

Commit 0ea2390

Browse files
committed
Add stm32g0b1nucleo BSP.
1 parent 152a22f commit 0ea2390

File tree

6 files changed

+915
-0
lines changed

6 files changed

+915
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
******************************************************************************
3+
**
4+
5+
** File : LinkerScript.ld
6+
**
7+
** Author : STM32CubeMX
8+
**
9+
** Abstract : Linker script for STM32G0B1RETx series
10+
** 512Kbytes FLASH and 144Kbytes RAM
11+
**
12+
** Set heap size, stack size and stack location according
13+
** to application requirements.
14+
**
15+
** Set memory bank area and size if external memory is used.
16+
**
17+
** Target : STMicroelectronics STM32
18+
**
19+
** Distribution: The file is distributed “as is,” without any warranty
20+
** of any kind.
21+
**
22+
*****************************************************************************
23+
** @attention
24+
**
25+
** <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
26+
**
27+
** Redistribution and use in source and binary forms, with or without modification,
28+
** are permitted provided that the following conditions are met:
29+
** 1. Redistributions of source code must retain the above copyright notice,
30+
** this list of conditions and the following disclaimer.
31+
** 2. Redistributions in binary form must reproduce the above copyright notice,
32+
** this list of conditions and the following disclaimer in the documentation
33+
** and/or other materials provided with the distribution.
34+
** 3. Neither the name of STMicroelectronics nor the names of its contributors
35+
** may be used to endorse or promote products derived from this software
36+
** without specific prior written permission.
37+
**
38+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39+
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40+
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41+
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
42+
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43+
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44+
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45+
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46+
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48+
**
49+
*****************************************************************************
50+
*/
51+
52+
/* Entry Point */
53+
ENTRY(Reset_Handler)
54+
55+
/* Highest address of the user mode stack */
56+
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */
57+
/* Generate a link error if heap and stack don't fit into RAM */
58+
_Min_Heap_Size = 0x200; /* required amount of heap */
59+
_Min_Stack_Size = 0x400; /* required amount of stack */
60+
61+
/* Specify the memory areas */
62+
MEMORY
63+
{
64+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 144K
65+
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
66+
}
67+
68+
/* Define output sections */
69+
SECTIONS
70+
{
71+
/* The startup code goes first into FLASH */
72+
.isr_vector :
73+
{
74+
. = ALIGN(4);
75+
KEEP(*(.isr_vector)) /* Startup code */
76+
. = ALIGN(4);
77+
} >FLASH
78+
79+
/* The program code and other data goes into FLASH */
80+
.text :
81+
{
82+
. = ALIGN(4);
83+
*(.text) /* .text sections (code) */
84+
*(.text*) /* .text* sections (code) */
85+
*(.glue_7) /* glue arm to thumb code */
86+
*(.glue_7t) /* glue thumb to arm code */
87+
*(.eh_frame)
88+
89+
KEEP (*(.init))
90+
KEEP (*(.fini))
91+
92+
. = ALIGN(4);
93+
_etext = .; /* define a global symbols at end of code */
94+
} >FLASH
95+
96+
/* Constant data goes into FLASH */
97+
.rodata :
98+
{
99+
. = ALIGN(4);
100+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
101+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
102+
. = ALIGN(4);
103+
} >FLASH
104+
105+
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
106+
.ARM : {
107+
__exidx_start = .;
108+
*(.ARM.exidx*)
109+
__exidx_end = .;
110+
} >FLASH
111+
112+
.preinit_array :
113+
{
114+
PROVIDE_HIDDEN (__preinit_array_start = .);
115+
KEEP (*(.preinit_array*))
116+
PROVIDE_HIDDEN (__preinit_array_end = .);
117+
} >FLASH
118+
.init_array :
119+
{
120+
PROVIDE_HIDDEN (__init_array_start = .);
121+
KEEP (*(SORT(.init_array.*)))
122+
KEEP (*(.init_array*))
123+
PROVIDE_HIDDEN (__init_array_end = .);
124+
} >FLASH
125+
.fini_array :
126+
{
127+
PROVIDE_HIDDEN (__fini_array_start = .);
128+
KEEP (*(SORT(.fini_array.*)))
129+
KEEP (*(.fini_array*))
130+
PROVIDE_HIDDEN (__fini_array_end = .);
131+
} >FLASH
132+
133+
/* used by the startup to initialize data */
134+
_sidata = LOADADDR(.data);
135+
136+
/* Initialized data sections goes into RAM, load LMA copy after code */
137+
.data :
138+
{
139+
. = ALIGN(4);
140+
_sdata = .; /* create a global symbol at data start */
141+
*(.data) /* .data sections */
142+
*(.data*) /* .data* sections */
143+
144+
. = ALIGN(4);
145+
_edata = .; /* define a global symbol at data end */
146+
} >RAM AT> FLASH
147+
148+
149+
/* Uninitialized data section */
150+
. = ALIGN(4);
151+
.bss :
152+
{
153+
/* This is used by the startup in order to initialize the .bss secion */
154+
_sbss = .; /* define a global symbol at bss start */
155+
__bss_start__ = _sbss;
156+
*(.bss)
157+
*(.bss*)
158+
*(COMMON)
159+
160+
. = ALIGN(4);
161+
_ebss = .; /* define a global symbol at bss end */
162+
__bss_end__ = _ebss;
163+
} >RAM
164+
165+
/* User_heap_stack section, used to check that there is enough RAM left */
166+
._user_heap_stack :
167+
{
168+
. = ALIGN(8);
169+
PROVIDE ( end = . );
170+
PROVIDE ( _end = . );
171+
. = . + _Min_Heap_Size;
172+
. = . + _Min_Stack_Size;
173+
. = ALIGN(8);
174+
} >RAM
175+
176+
177+
178+
/* Remove information from the standard libraries */
179+
/DISCARD/ :
180+
{
181+
libc.a ( * )
182+
libm.a ( * )
183+
libgcc.a ( * )
184+
}
185+
186+
.ARM.attributes 0 : { *(.ARM.attributes) }
187+
}
188+
189+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020, Ha Thach (tinyusb.org)
5+
* Copyright (c) 2034, 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+
// G0B1RE Nucleo does not has usb connection. We need to manually connect
36+
// - PA12 for D+, CN10.12
37+
// - PA11 for D-, CN10.14
38+
39+
// LED
40+
#define LED_PORT GPIOA
41+
#define LED_PIN GPIO_PIN_5
42+
#define LED_STATE_ON 0
43+
44+
// Button
45+
#define BUTTON_PORT GPIOC
46+
#define BUTTON_PIN GPIO_PIN_13
47+
#define BUTTON_STATE_ACTIVE 1
48+
49+
// UART Enable for STLink VCOM
50+
#define UART_DEV USART2
51+
#define UART_CLK_EN __HAL_RCC_USART2_CLK_ENABLE
52+
#define UART_GPIO_PORT GPIOA
53+
#define UART_GPIO_AF GPIO_AF1_USART2
54+
#define UART_TX_PIN GPIO_PIN_2
55+
#define UART_RX_PIN GPIO_PIN_3
56+
57+
58+
//--------------------------------------------------------------------+
59+
// RCC Clock
60+
//--------------------------------------------------------------------+
61+
static inline void board_clock_init(void)
62+
{
63+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
64+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
65+
RCC_CRSInitTypeDef pInit = {0};
66+
67+
/** Tick priority is used in HAL_RCC_OscConfig, so we need to enable it now
68+
*/
69+
HAL_InitTick(0);
70+
71+
/** Configure the main internal regulator output voltage
72+
*/
73+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
74+
75+
/** Initializes the RCC Oscillators according to the specified parameters
76+
* in the RCC_OscInitTypeDef structure.
77+
*/
78+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48;
79+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
80+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
81+
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
82+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
83+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
84+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
85+
86+
/** Initializes the CPU, AHB and APB buses clocks
87+
*/
88+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
89+
|RCC_CLOCKTYPE_PCLK1;
90+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
91+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
92+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
93+
94+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
95+
96+
/** Enable the SYSCFG APB clock
97+
*/
98+
__HAL_RCC_CRS_CLK_ENABLE();
99+
100+
/** Configures CRS
101+
*/
102+
pInit.Prescaler = RCC_CRS_SYNC_DIV1;
103+
pInit.Source = RCC_CRS_SYNC_SOURCE_USB;
104+
pInit.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
105+
pInit.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000);
106+
pInit.ErrorLimitValue = 34;
107+
pInit.HSI48CalibrationValue = 32;
108+
109+
HAL_RCCEx_CRSConfig(&pInit);
110+
}
111+
112+
#ifdef __cplusplus
113+
}
114+
#endif
115+
116+
#endif /* BOARD_H_ */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CFLAGS += \
2+
-DSTM32G0B1xx
3+
4+
# GCC
5+
GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32g0b1xx.s
6+
GCC_LD_FILE = $(BOARD_PATH)/STM32G0B1RETx_FLASH.ld
7+
8+
# IAR
9+
IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32g0b1xx.s
10+
IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32g0b1xx_flash.icf
11+
12+
# For flash-jlink target
13+
JLINK_DEVICE = stm32g0b1re

0 commit comments

Comments
 (0)