Skip to content

Commit 97741a5

Browse files
authored
Merge pull request #3220 from adam-embedded/with-stm32l496nucleo
Added stm32l496nucleo board support
2 parents 2e29d1c + 10e86b0 commit 97741a5

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+
** @file : LinkerScript.ld
5+
**
6+
** @author : Auto-generated by STM32CubeIDE
7+
**
8+
** Abstract : Linker script for NUCLEO-L496ZG Board embedding STM32L496ZGTx Device from stm32l4 series
9+
** 1024Kbytes ROM
10+
** 256Kbytes RAM
11+
** 64Kbytes SRAM2
12+
**
13+
** Set heap size, stack size and stack location according
14+
** to application requirements.
15+
**
16+
** Set memory bank area and size if external memory is used
17+
**
18+
** Target : STMicroelectronics STM32
19+
**
20+
** Distribution: The file is distributed as is, without any warranty
21+
** of any kind.
22+
**
23+
******************************************************************************
24+
** @attention
25+
**
26+
** Copyright (c) 2022 STMicroelectronics.
27+
** All rights reserved.
28+
**
29+
** This software is licensed under terms that can be found in the LICENSE file
30+
** in the root directory of this software component.
31+
** If no LICENSE file comes with this software, it is provided AS-IS.
32+
**
33+
******************************************************************************
34+
*/
35+
36+
/* Entry Point */
37+
ENTRY(Reset_Handler)
38+
39+
_Min_Heap_Size = 0x200; /* required amount of heap */
40+
_Min_Stack_Size = 0x400; /* required amount of stack */
41+
42+
/* Memories definition */
43+
MEMORY
44+
{
45+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
46+
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
47+
ROM (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
48+
}
49+
50+
/* Highest address of the user mode stack */
51+
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
52+
53+
/* Sections */
54+
SECTIONS
55+
{
56+
/* The startup code into "ROM" Rom type memory */
57+
.isr_vector :
58+
{
59+
. = ALIGN(4);
60+
KEEP(*(.isr_vector)) /* Startup code */
61+
. = ALIGN(4);
62+
} >ROM
63+
64+
/* The program code and other data into "ROM" Rom type memory */
65+
.text :
66+
{
67+
. = ALIGN(4);
68+
*(.text) /* .text sections (code) */
69+
*(.text*) /* .text* sections (code) */
70+
*(.glue_7) /* glue arm to thumb code */
71+
*(.glue_7t) /* glue thumb to arm code */
72+
*(.eh_frame)
73+
74+
KEEP (*(.init))
75+
KEEP (*(.fini))
76+
77+
. = ALIGN(4);
78+
_etext = .; /* define a global symbols at end of code */
79+
} >ROM
80+
81+
/* Constant data into "ROM" Rom type memory */
82+
.rodata :
83+
{
84+
. = ALIGN(4);
85+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
86+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
87+
. = ALIGN(4);
88+
} >ROM
89+
90+
.ARM.extab :
91+
{
92+
. = ALIGN(4);
93+
*(.ARM.extab* .gnu.linkonce.armextab.*)
94+
. = ALIGN(4);
95+
} >ROM
96+
97+
.ARM :
98+
{
99+
. = ALIGN(4);
100+
__exidx_start = .;
101+
*(.ARM.exidx*)
102+
__exidx_end = .;
103+
. = ALIGN(4);
104+
} >ROM
105+
106+
.preinit_array :
107+
{
108+
. = ALIGN(4);
109+
PROVIDE_HIDDEN (__preinit_array_start = .);
110+
KEEP (*(.preinit_array*))
111+
PROVIDE_HIDDEN (__preinit_array_end = .);
112+
. = ALIGN(4);
113+
} >ROM
114+
115+
.init_array :
116+
{
117+
. = ALIGN(4);
118+
PROVIDE_HIDDEN (__init_array_start = .);
119+
KEEP (*(SORT(.init_array.*)))
120+
KEEP (*(.init_array*))
121+
PROVIDE_HIDDEN (__init_array_end = .);
122+
. = ALIGN(4);
123+
} >ROM
124+
125+
.fini_array :
126+
{
127+
. = ALIGN(4);
128+
PROVIDE_HIDDEN (__fini_array_start = .);
129+
KEEP (*(SORT(.fini_array.*)))
130+
KEEP (*(.fini_array*))
131+
PROVIDE_HIDDEN (__fini_array_end = .);
132+
. = ALIGN(4);
133+
} >ROM
134+
135+
/* Used by the startup to initialize data */
136+
_sidata = LOADADDR(.data);
137+
138+
/* Initialized data sections into "RAM" Ram type memory */
139+
.data :
140+
{
141+
. = ALIGN(4);
142+
_sdata = .; /* create a global symbol at data start */
143+
*(.data) /* .data sections */
144+
*(.data*) /* .data* sections */
145+
*(.RamFunc) /* .RamFunc sections */
146+
*(.RamFunc*) /* .RamFunc* sections */
147+
148+
. = ALIGN(4);
149+
_edata = .; /* define a global symbol at data end */
150+
151+
} >RAM AT> ROM
152+
153+
_sisram2 = LOADADDR(.sram2);
154+
155+
/* SRAM2 section
156+
*
157+
* IMPORTANT NOTE!
158+
* If initialized variables will be placed in this section,
159+
* the startup code needs to be modified to copy the init-values.
160+
*/
161+
.sram2 :
162+
{
163+
. = ALIGN(4);
164+
_ssram2 = .; /* create a global symbol at sram2 start */
165+
*(.sram2)
166+
*(.sram2*)
167+
168+
. = ALIGN(4);
169+
_esram2 = .; /* create a global symbol at sram2 end */
170+
} >SRAM2 AT> ROM
171+
172+
/* Uninitialized data section into "RAM" Ram type memory */
173+
. = ALIGN(4);
174+
.bss :
175+
{
176+
/* This is used by the startup in order to initialize the .bss section */
177+
_sbss = .; /* define a global symbol at bss start */
178+
__bss_start__ = _sbss;
179+
*(.bss)
180+
*(.bss*)
181+
*(COMMON)
182+
183+
. = ALIGN(4);
184+
_ebss = .; /* define a global symbol at bss end */
185+
__bss_end__ = _ebss;
186+
} >RAM
187+
188+
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
189+
._user_heap_stack :
190+
{
191+
. = ALIGN(8);
192+
PROVIDE ( end = . );
193+
PROVIDE ( _end = . );
194+
. = . + _Min_Heap_Size;
195+
. = . + _Min_Stack_Size;
196+
. = ALIGN(8);
197+
} >RAM
198+
199+
/* Remove information from the compiler libraries */
200+
/DISCARD/ :
201+
{
202+
libc.a ( * )
203+
libm.a ( * )
204+
libgcc.a ( * )
205+
}
206+
207+
.ARM.attributes 0 : { *(.ARM.attributes) }
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 stm32l496zg)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32L496ZGTX_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_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
83+
84+
/** Configure the main internal regulator output voltage
85+
*/
86+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
87+
88+
/** Configure LSE Drive Capability
89+
*/
90+
HAL_PWR_EnableBkUpAccess();
91+
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
92+
93+
/** Initializes the RCC Oscillators according to the specified parameters
94+
* in the RCC_OscInitTypeDef structure.
95+
*/
96+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI;
97+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
98+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
99+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
100+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
101+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
102+
RCC_OscInitStruct.PLL.PLLM = 1;
103+
RCC_OscInitStruct.PLL.PLLN = 10;
104+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
105+
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
106+
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
107+
108+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
109+
110+
/** Initializes the CPU, AHB and APB buses clocks
111+
*/
112+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
113+
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
114+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
115+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
116+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
117+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
118+
119+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
120+
121+
// /** Enable the SYSCFG APB clock
122+
// */
123+
// __HAL_RCC_CRS_CLK_ENABLE();
124+
//
125+
// /** Configures CRS
126+
// */
127+
// RCC_CRSInitTypeDef RCC_CRSInitStruct = {0};
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)/STM32L496ZGTX_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 = stm32l496zg

0 commit comments

Comments
 (0)