Skip to content

Commit b73a46b

Browse files
committed
added support for stm32l496nucleo
1 parent 5fb3c09 commit b73a46b

File tree

5 files changed

+390
-1
lines changed

5 files changed

+390
-1
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
2+
******************************************************************************
3+
**
4+
5+
** File : LinkerScript.ld
6+
**
7+
** Author : STM32CubeMX
8+
**
9+
** Abstract : Linker script for STM32L496ZGTxP series
10+
** 1024Kbytes FLASH and 320Kbytes 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+
** Distribution: The file is distributed “as is,” without any warranty
19+
** of any kind.
20+
**
21+
*****************************************************************************
22+
** @attention
23+
**
24+
** <h2><center>&copy; COPYRIGHT(c) 2025 STMicroelectronics</center></h2>
25+
**
26+
** Redistribution and use in source and binary forms, with or without modification,
27+
** are permitted provided that the following conditions are met:
28+
** 1. Redistributions of source code must retain the above copyright notice,
29+
** this list of conditions and the following disclaimer.
30+
** 2. Redistributions in binary form must reproduce the above copyright notice,
31+
** this list of conditions and the following disclaimer in the documentation
32+
** and/or other materials provided with the distribution.
33+
** 3. Neither the name of STMicroelectronics nor the names of its contributors
34+
** may be used to endorse or promote products derived from this software
35+
** without specific prior written permission.
36+
**
37+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38+
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39+
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40+
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
41+
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42+
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
43+
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
44+
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45+
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47+
**
48+
*****************************************************************************
49+
*/
50+
51+
/* Entry Point */
52+
ENTRY(Reset_Handler)
53+
54+
/* Highest address of the user mode stack */
55+
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */
56+
/* Generate a link error if heap and stack don't fit into RAM */
57+
_Min_Heap_Size = 0x500; /* required amount of heap */
58+
_Min_Stack_Size = 0x1000; /* required amount of stack */
59+
60+
/* Specify the memory areas */
61+
MEMORY
62+
{
63+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
64+
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
65+
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
66+
}
67+
68+
/* Define output sections */
69+
SECTIONS
70+
{
71+
/* The startup code goes first into FLASH */
72+
.isr_vector :
73+
{
74+
. = ALIGN(8);
75+
KEEP(*(.isr_vector)) /* Startup code */
76+
. = ALIGN(8);
77+
} >FLASH
78+
79+
/* The program code and other data goes into FLASH */
80+
.text :
81+
{
82+
. = ALIGN(8);
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(8);
93+
_etext = .; /* define a global symbols at end of code */
94+
} >FLASH
95+
96+
/* Constant data goes into FLASH */
97+
.rodata :
98+
{
99+
. = ALIGN(8);
100+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
101+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
102+
. = ALIGN(8);
103+
} >FLASH
104+
105+
.ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
106+
{
107+
. = ALIGN(8);
108+
*(.ARM.extab* .gnu.linkonce.armextab.*)
109+
. = ALIGN(8);
110+
} >FLASH
111+
112+
.ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
113+
{
114+
. = ALIGN(8);
115+
__exidx_start = .;
116+
*(.ARM.exidx*)
117+
__exidx_end = .;
118+
. = ALIGN(8);
119+
} >FLASH
120+
121+
.preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
122+
{
123+
. = ALIGN(8);
124+
PROVIDE_HIDDEN (__preinit_array_start = .);
125+
KEEP (*(.preinit_array*))
126+
PROVIDE_HIDDEN (__preinit_array_end = .);
127+
. = ALIGN(8);
128+
} >FLASH
129+
130+
.init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
131+
{
132+
. = ALIGN(8);
133+
PROVIDE_HIDDEN (__init_array_start = .);
134+
KEEP (*(SORT(.init_array.*)))
135+
KEEP (*(.init_array*))
136+
PROVIDE_HIDDEN (__init_array_end = .);
137+
. = ALIGN(8);
138+
} >FLASH
139+
140+
.fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
141+
142+
{
143+
. = ALIGN(8);
144+
PROVIDE_HIDDEN (__fini_array_start = .);
145+
KEEP (*(SORT(.fini_array.*)))
146+
KEEP (*(.fini_array*))
147+
PROVIDE_HIDDEN (__fini_array_end = .);
148+
. = ALIGN(8);
149+
} >FLASH
150+
151+
/* used by the startup to initialize data */
152+
_sidata = LOADADDR(.data);
153+
154+
/* Initialized data sections goes into RAM, load LMA copy after code */
155+
.data :
156+
{
157+
. = ALIGN(8);
158+
_sdata = .; /* create a global symbol at data start */
159+
*(.data) /* .data sections */
160+
*(.data*) /* .data* sections */
161+
*(.RamFunc) /* .RamFunc sections */
162+
*(.RamFunc*) /* .RamFunc* sections */
163+
164+
. = ALIGN(8);
165+
_edata = .; /* define a global symbol at data end */
166+
} >RAM AT> FLASH
167+
168+
169+
/* Uninitialized data section */
170+
. = ALIGN(4);
171+
.bss :
172+
{
173+
/* This is used by the startup in order to initialize the .bss secion */
174+
_sbss = .; /* define a global symbol at bss start */
175+
__bss_start__ = _sbss;
176+
*(.bss)
177+
*(.bss*)
178+
*(COMMON)
179+
180+
. = ALIGN(4);
181+
_ebss = .; /* define a global symbol at bss end */
182+
__bss_end__ = _ebss;
183+
} >RAM
184+
185+
/* User_heap_stack section, used to check that there is enough RAM left */
186+
._user_heap_stack :
187+
{
188+
. = ALIGN(8);
189+
PROVIDE ( end = . );
190+
PROVIDE ( _end = . );
191+
. = . + _Min_Heap_Size;
192+
. = . + _Min_Stack_Size;
193+
. = ALIGN(8);
194+
} >RAM
195+
196+
197+
198+
/* Remove information from the standard libraries */
199+
/DISCARD/ :
200+
{
201+
libc.a ( * )
202+
libm.a ( * )
203+
libgcc.a ( * )
204+
}
205+
206+
}
207+
208+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(MCU_VARIANT stm32l496xx)
2+
set(JLINK_DEVICE stm32l496kb)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32L496XX_FLASH.ld)
5+
6+
function(update_board TARGET)
7+
target_compile_definitions(${TARGET} PUBLIC
8+
STM32L496xx
9+
)
10+
endfunction()
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
/* metadata:
28+
name: STM32 L496 Nucleo
29+
url: https://www.st.com/en/evaluation-tools/nucleo-l496ZG-P.html
30+
*/
31+
32+
#ifndef BOARD_H_
33+
#define BOARD_H_
34+
35+
#ifdef __cplusplus
36+
extern "C" {
37+
#endif
38+
39+
#define LED_PORT GPIOB
40+
#define LED_PIN GPIO_PIN_7
41+
#define LED_STATE_ON 1
42+
43+
// Not a real button
44+
#define BUTTON_PORT GPIOC
45+
#define BUTTON_PIN GPIO_PIN_13
46+
#define BUTTON_STATE_ACTIVE 1
47+
48+
#define UART_DEV LPUART1
49+
#define UART_CLK_EN __HAL_RCC_LPUART1_CLK_ENABLE
50+
#define UART_GPIO_PORT GPIOG
51+
#define UART_GPIO_AF GPIO_AF8_LPUART1
52+
#define UART_TX_PIN GPIO_PIN_7
53+
#define UART_RX_PIN GPIO_PIN_8
54+
55+
//--------------------------------------------------------------------+
56+
// RCC Clock
57+
//--------------------------------------------------------------------+
58+
59+
/**
60+
* @brief System Clock Configuration
61+
* The system Clock is configured as follow :
62+
* System Clock source = PLL (MSI)
63+
* SYSCLK(Hz) = 80000000
64+
* HCLK(Hz) = 80000000
65+
* AHB Prescaler = 1
66+
* APB1 Prescaler = 1
67+
* APB2 Prescaler = 1
68+
* MSI Frequency(Hz) = 8000000
69+
* PLL_M = 1
70+
* PLL_N = 10
71+
* PLL_Q = 2
72+
* PLL_R = 2
73+
* VDD(V) = 3.3
74+
* @param None
75+
* @retval None
76+
*/
77+
78+
static inline void board_clock_init(void)
79+
{
80+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
81+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
82+
RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};
83+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
84+
85+
/** Configure the main internal regulator output voltage
86+
*/
87+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
88+
89+
/** Configure LSE Drive Capability
90+
*/
91+
HAL_PWR_EnableBkUpAccess();
92+
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
93+
94+
/** Initializes the RCC Oscillators according to the specified parameters
95+
* in the RCC_OscInitTypeDef structure.
96+
*/
97+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI;
98+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
99+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
100+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
101+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
102+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
103+
RCC_OscInitStruct.PLL.PLLM = 1;
104+
RCC_OscInitStruct.PLL.PLLN = 10;
105+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
106+
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
107+
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
108+
109+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
110+
111+
/** Initializes the CPU, AHB and APB buses clocks
112+
*/
113+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
114+
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
115+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
116+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
117+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
118+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
119+
120+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
121+
122+
// /** Enable the SYSCFG APB clock
123+
// */
124+
// __HAL_RCC_CRS_CLK_ENABLE();
125+
//
126+
// /** Configures CRS
127+
// */
128+
// RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
129+
// RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
130+
// RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
131+
// RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,1000);
132+
// RCC_CRSInitStruct.ErrorLimitValue = 34;
133+
// RCC_CRSInitStruct.HSI48CalibrationValue = 32;
134+
//
135+
// HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
136+
137+
/* Select HSI48 output as USB clock source */
138+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
139+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
140+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
141+
142+
/* Select PLL output as UART clock source */
143+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
144+
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
145+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
146+
}
147+
148+
static inline void board_vbus_sense_init(void)
149+
{
150+
// Enable VBUS sense (B device) via pin PA9
151+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
152+
}
153+
154+
#ifdef __cplusplus
155+
}
156+
#endif
157+
158+
#endif /* BOARD_H_ */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CFLAGS += \
2+
-DSTM32L496xx \
3+
4+
# GCC
5+
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32l496xx.s
6+
LD_FILE_GCC = $(BOARD_PATH)/STM32L412KBUx_FLASH.ld
7+
8+
# IAR
9+
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32l496xx.s
10+
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32l496xx_flash.icf
11+
12+
# For flash-jlink target
13+
JLINK_DEVICE = stm32l496xx

0 commit comments

Comments
 (0)