Skip to content

Commit 0ab1bff

Browse files
authored
Merge pull request #2315 from kasjer/kasjer/nucleo-g491re
Add BSP for nucleo-g491re
2 parents a6b29ae + c9f09d6 commit 0ab1bff

File tree

4 files changed

+311
-0
lines changed

4 files changed

+311
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
******************************************************************************
3+
**
4+
** @file : LinkerScript.ld
5+
**
6+
** @author : Auto-generated by STM32CubeIDE
7+
**
8+
** Abstract : Linker script for NUCLEO-G491RE Board embedding STM32G491RETx Device from stm32g4 series
9+
** 512KBytes FLASH
10+
** 112KBytes 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+
** Copyright (c) 2023 STMicroelectronics.
26+
** All rights reserved.
27+
**
28+
** This software is licensed under terms that can be found in the LICENSE file
29+
** in the root directory of this software component.
30+
** If no LICENSE file comes with this software, it is provided AS-IS.
31+
**
32+
******************************************************************************
33+
*/
34+
35+
/* Entry Point */
36+
ENTRY(Reset_Handler)
37+
38+
/* Highest address of the user mode stack */
39+
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
40+
41+
_Min_Heap_Size = 0x200; /* required amount of heap */
42+
_Min_Stack_Size = 0x400; /* required amount of stack */
43+
44+
/* Memories definition */
45+
MEMORY
46+
{
47+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112K
48+
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
49+
}
50+
51+
/* Sections */
52+
SECTIONS
53+
{
54+
/* The startup code into "FLASH" Rom type memory */
55+
.isr_vector :
56+
{
57+
. = ALIGN(4);
58+
KEEP(*(.isr_vector)) /* Startup code */
59+
. = ALIGN(4);
60+
} >FLASH
61+
62+
/* The program code and other data into "FLASH" Rom type memory */
63+
.text :
64+
{
65+
. = ALIGN(4);
66+
*(.text) /* .text sections (code) */
67+
*(.text*) /* .text* sections (code) */
68+
*(.glue_7) /* glue arm to thumb code */
69+
*(.glue_7t) /* glue thumb to arm code */
70+
*(.eh_frame)
71+
72+
KEEP (*(.init))
73+
KEEP (*(.fini))
74+
75+
. = ALIGN(4);
76+
_etext = .; /* define a global symbols at end of code */
77+
} >FLASH
78+
79+
/* Constant data into "FLASH" Rom type memory */
80+
.rodata :
81+
{
82+
. = ALIGN(4);
83+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
84+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
85+
. = ALIGN(4);
86+
} >FLASH
87+
88+
.ARM.extab : {
89+
. = ALIGN(4);
90+
*(.ARM.extab* .gnu.linkonce.armextab.*)
91+
. = ALIGN(4);
92+
} >FLASH
93+
94+
.ARM : {
95+
. = ALIGN(4);
96+
__exidx_start = .;
97+
*(.ARM.exidx*)
98+
__exidx_end = .;
99+
. = ALIGN(4);
100+
} >FLASH
101+
102+
.preinit_array :
103+
{
104+
. = ALIGN(4);
105+
PROVIDE_HIDDEN (__preinit_array_start = .);
106+
KEEP (*(.preinit_array*))
107+
PROVIDE_HIDDEN (__preinit_array_end = .);
108+
. = ALIGN(4);
109+
} >FLASH
110+
111+
.init_array :
112+
{
113+
. = ALIGN(4);
114+
PROVIDE_HIDDEN (__init_array_start = .);
115+
KEEP (*(SORT(.init_array.*)))
116+
KEEP (*(.init_array*))
117+
PROVIDE_HIDDEN (__init_array_end = .);
118+
. = ALIGN(4);
119+
} >FLASH
120+
121+
.fini_array :
122+
{
123+
. = ALIGN(4);
124+
PROVIDE_HIDDEN (__fini_array_start = .);
125+
KEEP (*(SORT(.fini_array.*)))
126+
KEEP (*(.fini_array*))
127+
PROVIDE_HIDDEN (__fini_array_end = .);
128+
. = ALIGN(4);
129+
} >FLASH
130+
131+
/* Used by the startup to initialize data */
132+
_sidata = LOADADDR(.data);
133+
134+
/* Initialized data sections into "RAM" Ram type memory */
135+
.data :
136+
{
137+
. = ALIGN(4);
138+
_sdata = .; /* create a global symbol at data start */
139+
*(.data) /* .data sections */
140+
*(.data*) /* .data* sections */
141+
*(.RamFunc) /* .RamFunc sections */
142+
*(.RamFunc*) /* .RamFunc* sections */
143+
144+
. = ALIGN(4);
145+
_edata = .; /* define a global symbol at data end */
146+
147+
} >RAM AT> FLASH
148+
149+
/* Uninitialized data section into "RAM" Ram type memory */
150+
. = ALIGN(4);
151+
.bss :
152+
{
153+
/* This is used by the startup in order to initialize the .bss section */
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" Ram type memory 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+
/* Remove information from the compiler libraries */
177+
/DISCARD/ :
178+
{
179+
libc.a ( * )
180+
libm.a ( * )
181+
libgcc.a ( * )
182+
}
183+
184+
.ARM.attributes 0 : { *(.ARM.attributes) }
185+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(MCU_VARIANT stm32g491xx)
2+
set(JLINK_DEVICE stm32g491re)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32G491RETX_FLASH.ld)
5+
6+
function(update_board TARGET)
7+
target_compile_definitions(${TARGET} PUBLIC
8+
STM32G491xx
9+
HSE_VALUE=24000000
10+
)
11+
endfunction()
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020, Ha Thach (tinyusb.org)
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+
// G474RE Nucleo does not has usb connection. We need to manually connect
35+
// - PA12 for D+, CN10.12
36+
// - PA11 for D-, CN10.14
37+
38+
// LED
39+
#define LED_PORT GPIOA
40+
#define LED_PIN GPIO_PIN_5
41+
#define LED_STATE_ON 0
42+
43+
// Button
44+
#define BUTTON_PORT GPIOC
45+
#define BUTTON_PIN GPIO_PIN_13
46+
#define BUTTON_STATE_ACTIVE 1
47+
48+
// UART Enable for STLink VCOM
49+
#define UART_DEV LPUART1
50+
#define UART_CLK_EN __HAL_RCC_LPUART1_CLK_ENABLE
51+
#define UART_GPIO_PORT GPIOA
52+
#define UART_GPIO_AF GPIO_AF12_LPUART1
53+
#define UART_TX_PIN GPIO_PIN_2
54+
#define UART_RX_PIN GPIO_PIN_3
55+
56+
57+
//--------------------------------------------------------------------+
58+
// RCC Clock
59+
//--------------------------------------------------------------------+
60+
static inline void board_clock_init(void)
61+
{
62+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
63+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
64+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
65+
66+
// Configure the main internal regulator output voltage
67+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
68+
69+
// Initializes the CPU, AHB and APB buses clocks
70+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE;
71+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
72+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
73+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
74+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
75+
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV6;
76+
RCC_OscInitStruct.PLL.PLLN = 85;
77+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
78+
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
79+
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
80+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
81+
82+
// Initializes the CPU, AHB and APB buses clocks
83+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
84+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
85+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
86+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
87+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
88+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
89+
90+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
91+
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
92+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) ;
93+
}
94+
95+
static inline void board_vbus_sense_init(void)
96+
{
97+
// Enable VBUS sense (B device) via pin PA9
98+
}
99+
100+
#ifdef __cplusplus
101+
}
102+
#endif
103+
104+
#endif /* BOARD_H_ */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MCU_VARIANT = stm32g491xx
2+
3+
CFLAGS += \
4+
-DSTM32G491xx \
5+
-DHSE_VALUE=24000000
6+
7+
# Linker
8+
LD_FILE_GCC = $(BOARD_PATH)/STM32G491RETX_FLASH.ld
9+
10+
# For flash-jlink target
11+
JLINK_DEVICE = stm32g491re

0 commit comments

Comments
 (0)