Skip to content

Commit 64e9770

Browse files
authored
Merge pull request #62 from fpistm/variant_template
Create a board variant template
2 parents f9de648 + be3f347 commit 64e9770

File tree

6 files changed

+437
-0
lines changed

6 files changed

+437
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This file could be generated thanks a python script: genpinmap_arduino.py
3+
*
4+
* This script allows to generate the pins mapping of a STM32 MCU.
5+
*
6+
* It is included with the STM32Tools package install with this core.
7+
* Go to:
8+
* <local Arduino directory>\packages\STM32\tools\STM32Tools\<version>\tools\src\genpinmap\
9+
* Tips: <local Arduino directory> is displayed in the "Preferences" dialog of the Arduino IDE.
10+
*
11+
* This script is able to generate the PeripheralPins.c using STM32
12+
* xml file description in Cube MX.
13+
* After file generation, review it carefully.
14+
* Comment a line if the pin is generated several times for the same IP
15+
* or if the pin should not be used
16+
* (overlaid with some HW on the board, for instance)
17+
*
18+
* USAGE: genpinmap_arduino.py <BOARD_NAME> <product xml file name>
19+
*
20+
* <BOARD_NAME> is the name of the board as it will be named in variant folder
21+
* <product xml file name> is the STM32 file description in Cube MX
22+
*
23+
* !!This xml file contains non alpha characters in its name, you should call it with quotes
24+
*
25+
*/

variants/board_template/ldscript.ld

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
*****************************************************************************
3+
**
4+
** File : ldscript.ld
5+
**
6+
** Abstract : Linker script for STM32 Device
7+
**
8+
** Set heap size, stack size and stack location according
9+
** to application requirements.
10+
**
11+
** Set memory bank area and size if external memory is used.
12+
**
13+
** Target : STMicroelectronics STM32
14+
**
15+
**
16+
*****************************************************************************
17+
*/
18+
/* Copy here linker script for the new STM32 Device
19+
* or
20+
* replace this file by the new one with the same file name
21+
* It could be get thanks STM32CubeMX after code generation for Toolchain/IDE: 'SW4STM32',
22+
* ldscript will be availabe in the root folder (STM32YYxxxxxx_FLASH.ld)
23+
* or
24+
* copied from a STM32CubeYY project examples
25+
* where 'YY' could be F0, F1, F2, F3, F4, F7, L0, L1, L4)
26+
*/

variants/board_template/readme.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
See Wiki:
2+
https://github.com/stm32duino/wiki/wiki/Add-a-new-variant-(board)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copy the STM32 HAL config file from the targeted MCU Series HAL
3+
* from ../../system/Drivers/STM32YYxx_HAL_Driver/Inc/stm32yyxx_hal_conf_template.h
4+
* to
5+
* stm32yyxx_hal_conf.h
6+
* where 'yy' could be f0, f1, f2, f3, f4, f7, l0, l1, l4)
7+
*
8+
* Example for a STM32 F4 based board:
9+
* cp ../../system/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_conf_template.h stm32f4xx_hal_conf.h
10+
*
11+
* Then edit it in order to:
12+
* - Disable undesired HAL modules by commenting line like:
13+
* "#define HAL_XXX_MODULE_ENABLED"
14+
* where "XXX" is the feature (ETH, I2S,...)
15+
* - Adjust HSE/HSI Values adaptation if needed
16+
* - Update any other configurations
17+
*
18+
*/

variants/board_template/variant.cpp

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2017, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*******************************************************************************
29+
*/
30+
31+
#include "variant.h"
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
// Pin number
38+
// This array allows to wrap Arduino pin number(Dx or x)
39+
// to STM32 PinName (PYx)
40+
const PinName digitalPin[] = {
41+
//PYx, //Dx
42+
P, //D0
43+
P, //D1
44+
P, //D2
45+
P, //D3
46+
P, //D4
47+
P, //D5
48+
P, //D6
49+
P, //D7
50+
P, //D8
51+
P, //D9
52+
P, //D10
53+
P, //D11
54+
P, //D12
55+
P, //D13
56+
P, //D14
57+
P, //D15
58+
P, //D16
59+
P, //D17
60+
P, //D18
61+
P, //D19
62+
P, //D20
63+
P, //D21
64+
P, //D22
65+
P, //D23
66+
P, //D24
67+
P, //D25
68+
P, //D26
69+
P, //D27
70+
P, //D28
71+
P, //D29
72+
P, //D30
73+
P, //D31
74+
P, //D32
75+
P, //D33
76+
P, //D34
77+
P, //D35
78+
P, //D36
79+
P, //D37
80+
P, //D38
81+
P, //D39
82+
P, //D40
83+
P, //D41
84+
P, //D42
85+
P, //D43
86+
P, //D44
87+
P, //D45
88+
P, //D46
89+
P, //D47
90+
P, //D48
91+
P, //D49
92+
P, //D50
93+
P, //D51
94+
P, //D52
95+
P, //D53
96+
P, //D54
97+
P, //D55
98+
P, //D56
99+
P, //D57
100+
P, //D58
101+
P, //D59
102+
P, //D60
103+
P, //D61
104+
P, //D62
105+
P, //D63
106+
P, //D64
107+
P, //D65
108+
P, //D66
109+
P, //D67
110+
P, //D68
111+
P, //D69
112+
P, //D70
113+
P, //D71
114+
P, //D72
115+
P, //D73
116+
P, //D74
117+
P, //D75
118+
P, //D76
119+
P, //D77
120+
P, //D78/A0
121+
P, //D79/A1
122+
P, //D80/A2
123+
P, //D81/A3
124+
P, //D82/A4
125+
P, //D83/A5
126+
P, //D84/A6
127+
P, //D85/A7
128+
P, //D86/A8
129+
P, //D87/A9
130+
// Duplicated pins in order to be aligned with PinMap_ADC
131+
P, //D88/A10 = D
132+
P, //D89/A11 = D
133+
P, //D90/A12 = D
134+
P, //D91/A13 = D
135+
P, //D92/A14 = D
136+
P, //D93/A15 = D
137+
P, //D94/A16 = D
138+
P //D95/A17 = D
139+
};
140+
141+
#ifdef __cplusplus
142+
}
143+
#endif
144+
145+
/*
146+
* UART objects
147+
*/
148+
// Replace PYx_Rx and PYx_Tx by UART_RX and UART_TX pin names
149+
HardwareSerial Serial(PYx_Rx, PYx_Tx); // Connected to ST-Link
150+
151+
void serialEvent() __attribute__((weak));
152+
void serialEvent() { }
153+
154+
// Define as many Serial instance as desired
155+
// Replace 'SerialX' by the desired name
156+
//#ifdef ENABLE_SERIALX
157+
//HardwareSerial SerialX(PYx_Rx, PYx_Tx);
158+
//
159+
//void serialEventx() __attribute__((weak));
160+
//void serialEventx() { }
161+
//#endif
162+
163+
void serialEventRun(void)
164+
{
165+
if (Serial.available()) serialEvent();
166+
//#ifdef ENABLE_SERIALX
167+
// if (SerialX.available()) serialEventX();
168+
//#endif
169+
}
170+
171+
// ----------------------------------------------------------------------------
172+
173+
#ifdef __cplusplus
174+
extern "C" {
175+
#endif
176+
177+
/**
178+
* @brief System Clock Configuration
179+
* @param None
180+
* @retval None
181+
*/
182+
WEAK void SystemClock_Config(void)
183+
{
184+
// Here copy the desired System Clock Configuration
185+
// It could be generated thanks STM32CubeMX after code generation for Toolchain/IDE: 'SW4STM32',
186+
// available in src/main.c
187+
// or
188+
// copied from a STM32CubeYY project examples
189+
// where 'YY' could be F0, F1, F2, F3, F4, F7, L0, L1, L4
190+
}
191+
192+
#ifdef __cplusplus
193+
}
194+
#endif

0 commit comments

Comments
 (0)