Skip to content

Commit c3bde52

Browse files
committed
add new b_g474e_dpow1 board
1 parent cbbd858 commit c3bde52

File tree

10 files changed

+560
-30
lines changed

10 files changed

+560
-30
lines changed

.idea/cmake.xml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/rp2040.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
******************************************************************************
3+
**
4+
** File : LinkerScript.ld
5+
**
6+
** Author : Auto-generated by STM32CubeIDE
7+
**
8+
** Abstract : Linker script for STM32G474RETx Device from stm32g4 series
9+
** 512Kbytes FLASH
10+
** 128Kbytes 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) 2020 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" Ram type memory */
57+
58+
_Min_Heap_Size = 0x1000 ; /* required amount of heap */
59+
_Min_Stack_Size = 0x1000 ; /* required amount of stack */
60+
61+
/* Memories definition */
62+
MEMORY
63+
{
64+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
65+
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
66+
}
67+
68+
/* Sections */
69+
SECTIONS
70+
{
71+
/* The startup code into "FLASH" Rom type memory */
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 into "FLASH" Rom type memory */
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 into "FLASH" Rom type memory */
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 : {
106+
. = ALIGN(4);
107+
*(.ARM.extab* .gnu.linkonce.armextab.*)
108+
. = ALIGN(4);
109+
} >FLASH
110+
111+
.ARM : {
112+
. = ALIGN(4);
113+
__exidx_start = .;
114+
*(.ARM.exidx*)
115+
__exidx_end = .;
116+
. = ALIGN(4);
117+
} >FLASH
118+
119+
.preinit_array :
120+
{
121+
. = ALIGN(4);
122+
PROVIDE_HIDDEN (__preinit_array_start = .);
123+
KEEP (*(.preinit_array*))
124+
PROVIDE_HIDDEN (__preinit_array_end = .);
125+
. = ALIGN(4);
126+
} >FLASH
127+
128+
.init_array :
129+
{
130+
. = ALIGN(4);
131+
PROVIDE_HIDDEN (__init_array_start = .);
132+
KEEP (*(SORT(.init_array.*)))
133+
KEEP (*(.init_array*))
134+
PROVIDE_HIDDEN (__init_array_end = .);
135+
. = ALIGN(4);
136+
} >FLASH
137+
138+
.fini_array :
139+
{
140+
. = ALIGN(4);
141+
PROVIDE_HIDDEN (__fini_array_start = .);
142+
KEEP (*(SORT(.fini_array.*)))
143+
KEEP (*(.fini_array*))
144+
PROVIDE_HIDDEN (__fini_array_end = .);
145+
. = ALIGN(4);
146+
} >FLASH
147+
148+
/* Used by the startup to initialize data */
149+
_sidata = LOADADDR(.data);
150+
151+
/* Initialized data sections into "RAM" Ram type memory */
152+
.data :
153+
{
154+
. = ALIGN(4);
155+
_sdata = .; /* create a global symbol at data start */
156+
*(.data) /* .data sections */
157+
*(.data*) /* .data* sections */
158+
159+
. = ALIGN(4);
160+
_edata = .; /* define a global symbol at data end */
161+
162+
} >RAM AT> FLASH
163+
164+
/* Uninitialized data section into "RAM" Ram type memory */
165+
. = ALIGN(4);
166+
.bss :
167+
{
168+
/* This is used by the startup in order to initialize the .bss section */
169+
_sbss = .; /* define a global symbol at bss start */
170+
__bss_start__ = _sbss;
171+
*(.bss)
172+
*(.bss*)
173+
*(COMMON)
174+
175+
. = ALIGN(4);
176+
_ebss = .; /* define a global symbol at bss end */
177+
__bss_end__ = _ebss;
178+
} >RAM
179+
180+
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
181+
._user_heap_stack :
182+
{
183+
. = ALIGN(8);
184+
PROVIDE ( end = . );
185+
PROVIDE ( _end = . );
186+
. = . + _Min_Heap_Size;
187+
. = . + _Min_Stack_Size;
188+
. = ALIGN(8);
189+
} >RAM
190+
191+
/* Remove information from the compiler libraries */
192+
/DISCARD/ :
193+
{
194+
libc.a ( * )
195+
libm.a ( * )
196+
libgcc.a ( * )
197+
}
198+
199+
.ARM.attributes 0 : { *(.ARM.attributes) }
200+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(MCU_VARIANT stm32g474xx)
2+
set(JLINK_DEVICE stm32g474re)
3+
4+
set(LD_FILE_gcc ${CMAKE_CURRENT_LIST_DIR}/STM32G474RETx_FLASH.ld)
5+
set(LD_FILE_iar ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)
6+
7+
set(STARTUP_FILE_gcc ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s)
8+
set(STARTUP_FILE_iar ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
9+
10+
function(update_board TARGET)
11+
target_compile_definitions(${TARGET} PUBLIC
12+
STM32G474xx
13+
)
14+
endfunction()
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 GPIOB
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 0
47+
48+
// UART Enable for STLink VCOM
49+
#define UART_DEV USART3
50+
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
51+
#define UART_GPIO_PORT GPIOC
52+
#define UART_GPIO_AF GPIO_AF7_USART3
53+
#define UART_TX_PIN GPIO_PIN_10
54+
#define UART_RX_PIN GPIO_PIN_11
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_DIV4;
76+
RCC_OscInitStruct.PLL.PLLN = 50;
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_DIV1;
87+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
88+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8);
89+
90+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
91+
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
92+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) ;
93+
94+
#if 0 // TODO need to check if USB clock is enabled
95+
/* Enable HSI48 */
96+
memset(&RCC_OscInitStruct, 0, sizeof(RCC_OscInitStruct));
97+
98+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
99+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
100+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
101+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
102+
103+
/*Enable CRS Clock*/
104+
RCC_CRSInitTypeDef RCC_CRSInitStruct= {0};
105+
__HAL_RCC_CRS_CLK_ENABLE();
106+
107+
/* Default Synchro Signal division factor (not divided) */
108+
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
109+
110+
/* Set the SYNCSRC[1:0] bits according to CRS_Source value */
111+
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
112+
113+
/* HSI48 is synchronized with USB SOF at 1KHz rate */
114+
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
115+
RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
116+
117+
/* Set the TRIM[5:0] to the default value */
118+
RCC_CRSInitStruct.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT;
119+
120+
/* Start automatic synchronization */
121+
HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
122+
#endif
123+
}
124+
125+
static inline void board_vbus_sense_init(void)
126+
{
127+
// Enable VBUS sense (B device) via pin PA9
128+
}
129+
130+
#ifdef __cplusplus
131+
}
132+
#endif
133+
134+
#endif /* BOARD_H_ */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CFLAGS += \
2+
-DSTM32G474xx \
3+
4+
# GCC
5+
GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32g474xx.s
6+
GCC_LD_FILE = $(BOARD_PATH)/STM32G474RETx_FLASH.ld
7+
8+
# IAR
9+
IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32g474xx.s
10+
IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32g474xx_flash.icf
11+
12+
# For flash-jlink target
13+
JLINK_DEVICE = stm32g474re

0 commit comments

Comments
 (0)