Skip to content

Commit 3a5f435

Browse files
committed
Board support for STM32F407VETx
1 parent 50e61e0 commit 3a5f435

File tree

7 files changed

+1438
-0
lines changed

7 files changed

+1438
-0
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/**
2+
******************************************************************************
3+
* @file LinkerScript.ld
4+
* @author Auto-generated by STM32CubeIDE
5+
* @brief Linker script for STM32F407VETx Device from STM32F4 series
6+
* 512Kbytes FLASH
7+
* 64Kbytes CCMRAM
8+
* 128Kbytes RAM
9+
*
10+
* Set heap size, stack size and stack location according
11+
* to application requirements.
12+
*
13+
* Set memory bank area and size if external memory is used
14+
******************************************************************************
15+
* @attention
16+
*
17+
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
18+
* All rights reserved.</center></h2>
19+
*
20+
* This software component is licensed by ST under BSD 3-Clause license,
21+
* the "License"; You may not use this file except in compliance with the
22+
* License. You may obtain a copy of the License at:
23+
* opensource.org/licenses/BSD-3-Clause
24+
*
25+
******************************************************************************
26+
*/
27+
28+
/* Entry Point */
29+
ENTRY(Reset_Handler)
30+
31+
/* Highest address of the user mode stack */
32+
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
33+
34+
_Min_Heap_Size = 0x200 ; /* required amount of heap */
35+
_Min_Stack_Size = 0x400 ; /* required amount of stack */
36+
37+
/* Memories definition */
38+
MEMORY
39+
{
40+
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
41+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
42+
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
43+
}
44+
45+
/* Sections */
46+
SECTIONS
47+
{
48+
/* The startup code into "FLASH" Rom type memory */
49+
.isr_vector :
50+
{
51+
. = ALIGN(4);
52+
KEEP(*(.isr_vector)) /* Startup code */
53+
. = ALIGN(4);
54+
} >FLASH
55+
56+
/* The program code and other data into "FLASH" Rom type memory */
57+
.text :
58+
{
59+
. = ALIGN(4);
60+
*(.text) /* .text sections (code) */
61+
*(.text*) /* .text* sections (code) */
62+
*(.glue_7) /* glue arm to thumb code */
63+
*(.glue_7t) /* glue thumb to arm code */
64+
*(.eh_frame)
65+
66+
KEEP (*(.init))
67+
KEEP (*(.fini))
68+
69+
. = ALIGN(4);
70+
_etext = .; /* define a global symbols at end of code */
71+
} >FLASH
72+
73+
/* Constant data into "FLASH" Rom type memory */
74+
.rodata :
75+
{
76+
. = ALIGN(4);
77+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
78+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
79+
. = ALIGN(4);
80+
} >FLASH
81+
82+
.ARM.extab : {
83+
. = ALIGN(4);
84+
*(.ARM.extab* .gnu.linkonce.armextab.*)
85+
. = ALIGN(4);
86+
} >FLASH
87+
88+
.ARM : {
89+
. = ALIGN(4);
90+
__exidx_start = .;
91+
*(.ARM.exidx*)
92+
__exidx_end = .;
93+
. = ALIGN(4);
94+
} >FLASH
95+
96+
.preinit_array :
97+
{
98+
. = ALIGN(4);
99+
PROVIDE_HIDDEN (__preinit_array_start = .);
100+
KEEP (*(.preinit_array*))
101+
PROVIDE_HIDDEN (__preinit_array_end = .);
102+
. = ALIGN(4);
103+
} >FLASH
104+
105+
.init_array :
106+
{
107+
. = ALIGN(4);
108+
PROVIDE_HIDDEN (__init_array_start = .);
109+
KEEP (*(SORT(.init_array.*)))
110+
KEEP (*(.init_array*))
111+
PROVIDE_HIDDEN (__init_array_end = .);
112+
. = ALIGN(4);
113+
} >FLASH
114+
115+
.fini_array :
116+
{
117+
. = ALIGN(4);
118+
PROVIDE_HIDDEN (__fini_array_start = .);
119+
KEEP (*(SORT(.fini_array.*)))
120+
KEEP (*(.fini_array*))
121+
PROVIDE_HIDDEN (__fini_array_end = .);
122+
. = ALIGN(4);
123+
} >FLASH
124+
125+
/* Used by the startup to initialize data */
126+
_sidata = LOADADDR(.data);
127+
128+
/* Initialized data sections into "RAM" Ram type memory */
129+
.data :
130+
{
131+
. = ALIGN(4);
132+
_sdata = .; /* create a global symbol at data start */
133+
*(.data) /* .data sections */
134+
*(.data*) /* .data* sections */
135+
136+
. = ALIGN(4);
137+
_edata = .; /* define a global symbol at data end */
138+
139+
} >RAM AT> FLASH
140+
141+
/* Uninitialized data section into "RAM" Ram type memory */
142+
. = ALIGN(4);
143+
.bss :
144+
{
145+
/* This is used by the startup in order to initialize the .bss section */
146+
_sbss = .; /* define a global symbol at bss start */
147+
__bss_start__ = _sbss;
148+
*(.bss)
149+
*(.bss*)
150+
*(COMMON)
151+
152+
. = ALIGN(4);
153+
_ebss = .; /* define a global symbol at bss end */
154+
__bss_end__ = _ebss;
155+
} >RAM
156+
157+
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
158+
._user_heap_stack :
159+
{
160+
. = ALIGN(8);
161+
PROVIDE ( end = . );
162+
PROVIDE ( _end = . );
163+
. = . + _Min_Heap_Size;
164+
. = . + _Min_Stack_Size;
165+
. = ALIGN(8);
166+
} >RAM
167+
168+
/* Remove information from the compiler libraries */
169+
/DISCARD/ :
170+
{
171+
libc.a ( * )
172+
libm.a ( * )
173+
libgcc.a ( * )
174+
}
175+
176+
.ARM.attributes 0 : { *(.ARM.attributes) }
177+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set(MCU_VARIANT stm32f407xx)
2+
set(JLINK_DEVICE stm32f407ve)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F407VETx_FLASH.ld)
5+
set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)
6+
7+
set(STARTUP_FILE_GNU ${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+
STM32F407xx
13+
HSE_VALUE=8000000
14+
CORE_CM4
15+
BOARD_TUD_RHPORT=0
16+
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
17+
)
18+
endfunction()
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
// LED
35+
#define LED_PORT GPIOA
36+
#define LED_PIN GPIO_PIN_6
37+
#define LED_STATE_ON 1
38+
39+
// Button
40+
#define BUTTON_PORT GPIOE
41+
#define BUTTON_PIN GPIO_PIN_4
42+
#define BUTTON_STATE_ACTIVE 0
43+
44+
// Enable PA2 as the debug log UART
45+
// It is not routed to the ST/Link on the Discovery board.
46+
#define UART_DEV USART2
47+
#define UART_GPIO_PORT GPIOA
48+
#define UART_GPIO_AF GPIO_AF7_USART2
49+
#define UART_TX_PIN GPIO_PIN_2
50+
#define UART_RX_PIN GPIO_PIN_3
51+
52+
//--------------------------------------------------------------------+
53+
// RCC Clock
54+
//--------------------------------------------------------------------+
55+
static inline void board_clock_init(void)
56+
{
57+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
58+
RCC_OscInitTypeDef RCC_OscInitStruct;
59+
60+
/* Enable Power Control clock */
61+
__HAL_RCC_PWR_CLK_ENABLE();
62+
63+
/* The voltage scaling allows optimizing the power consumption when the device is
64+
clocked below the maximum system frequency, to update the voltage scaling value
65+
regarding system frequency refer to product datasheet. */
66+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
67+
68+
/* Enable HSE Oscillator and activate PLL with HSE as source */
69+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
70+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
71+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
72+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
73+
RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/2000000;
74+
RCC_OscInitStruct.PLL.PLLN = 168;
75+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
76+
RCC_OscInitStruct.PLL.PLLQ = 7;
77+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
78+
79+
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
80+
clocks dividers */
81+
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
82+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
83+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
84+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
85+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
86+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
87+
88+
// Enable clocks for LED, Button, Uart
89+
__HAL_RCC_GPIOA_CLK_ENABLE();
90+
__HAL_RCC_GPIOE_CLK_ENABLE();
91+
__HAL_RCC_GPIOH_CLK_ENABLE();
92+
__HAL_RCC_USART2_CLK_ENABLE();
93+
}
94+
95+
static inline void board_vbus_sense_init(void)
96+
{
97+
// Black F407VET6 doesn't use VBUS sense (B device) explicitly disable it
98+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
99+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
100+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
101+
}
102+
103+
#ifdef __cplusplus
104+
}
105+
#endif
106+
107+
#endif /* BOARD_H_ */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CFLAGS += -DSTM32F407xx
2+
3+
# GCC
4+
GCC_SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f407xx.s
5+
GCC_LD_FILE = $(BOARD_PATH)/STM32F407VGTx_FLASH.ld
6+
7+
# IAR
8+
IAR_SRC_S += $(ST_CMSIS)/Source/Templates/iar/startup_stm32f407xx.s
9+
IAR_LD_FILE = $(ST_CMSIS)/Source/Templates/iar/linker/stm32f407xx_flash.icf
10+
11+
12+
# For flash-jlink target
13+
JLINK_DEVICE = stm32f407vg
14+
15+
# flash target using on-board stlink
16+
flash: flash-stlink

0 commit comments

Comments
 (0)