Skip to content

Commit d046589

Browse files
committed
[stm32variant] Change generic variant generation
- variant.* files are renamed variant_generic.* Generic variant header file will be included thanks a single variant.h using a variable defined in boards.txt - Clean template to remove useless extern "C" - Include guards replaced by #pragma once directive - Use PIN_Ax instead of Ax - Add Dx and Ax info to the digitalPin array Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent abf08af commit d046589

File tree

3 files changed

+39
-58
lines changed

3 files changed

+39
-58
lines changed

CI/utils/stm32variant.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,34 +1188,37 @@ def print_variant(generic_list):
11881188
pyn = io[0].replace("_", "", 1)
11891189
if [item for item in adclist if item[0] == io[0]]:
11901190
ax = "A{}".format(analog_index)
1191-
pins_number_list.append({"name": pyn, "val": ax})
1191+
pins_number_list.append({"name": pyn, "val": "PIN_" + ax})
1192+
pinnames_list.append({"name": io[0], "ax": analog_index})
11921193
analog_pins_list.append({"val": idx, "ax": ax, "pyn": pyn})
11931194
analog_index += 1
11941195
else:
11951196
pins_number_list.append({"name": pyn, "val": idx})
1196-
pinnames_list.append(io[0])
1197+
pinnames_list.append({"name": io[0], "ax": -1})
11971198

11981199
for idx, io in enumerate(dualpad_list):
11991200
pyn = io[0].replace("_", "", 1)
12001201
if [item for item in adclist if item[0] == io[0]]:
12011202
ax = "A{}".format(analog_index)
1202-
pins_number_list.append({"name": pyn, "val": ax})
1203+
pins_number_list.append({"name": pyn, "val": "PIN_" + ax})
1204+
pinnames_list.append({"name": io[0], "ax": analog_index})
12031205
analog_pins_list.append({"val": idx + idx_sum, "ax": ax, "pyn": pyn})
12041206
analog_index += 1
12051207
else:
12061208
pins_number_list.append({"name": pyn, "val": idx + idx_sum})
1207-
pinnames_list.append(io[0])
1209+
pinnames_list.append({"name": io[0], "ax": -1})
12081210
idx_sum += len(dualpad_list)
12091211
for idx, io in enumerate(remap_list):
12101212
pyn = io[0].replace("_", "", 1)
12111213
if [item for item in adclist if item[0] == io[0]]:
12121214
ax = "A{}".format(analog_index)
1213-
pins_number_list.append({"name": pyn, "val": ax})
1215+
pins_number_list.append({"name": pyn, "val": "PIN_" + ax})
1216+
pinnames_list.append({"name": io[0], "ax": analog_index})
12141217
analog_pins_list.append({"val": idx + idx_sum, "ax": ax, "pyn": pyn})
12151218
analog_index += 1
12161219
else:
12171220
pins_number_list.append({"name": pyn, "val": idx + idx_sum})
1218-
pinnames_list.append(io[0])
1221+
pinnames_list.append({"name": io[0], "ax": -1})
12191222
alt_pins_list = []
12201223
waltpin = [0]
12211224
for p in alt_list:
@@ -1229,21 +1232,20 @@ def print_variant(generic_list):
12291232
# Define extra HAL modules
12301233
hal_modules_list = []
12311234
if daclist:
1232-
hal_modules_list.append("HAL_DAC_MODULE_ENABLED")
1235+
hal_modules_list.append("DAC")
12331236
if eth_list:
1234-
hal_modules_list.append("HAL_ETH_MODULE_ENABLED")
1237+
hal_modules_list.append("ETH")
12351238
if quadspidata0_list:
12361239
if "OCTOSPI" in quadspidata0_list[0][2]:
1237-
hal_modules_list.append("HAL_OSPI_MODULE_ENABLED")
1240+
hal_modules_list.append("OSPI")
12381241
else:
1239-
hal_modules_list.append("HAL_QSPI_MODULE_ENABLED")
1242+
hal_modules_list.append("QSPI")
12401243
if sd_list:
1241-
hal_modules_list.append("HAL_SD_MODULE_ENABLED")
1244+
hal_modules_list.append("SD")
12421245

12431246
variant_h_file.write(
12441247
variant_h_template.render(
12451248
year=datetime.datetime.now().year,
1246-
generic_list=generic_list,
12471249
pins_number_list=pins_number_list,
12481250
alt_pins_list=alt_pins_list,
12491251
waltpin=max(waltpin),
@@ -1728,8 +1730,8 @@ def manage_repo():
17281730
periph_c_filename = "PeripheralPins.c"
17291731
pinvar_h_filename = "PinNamesVar.h"
17301732
config_filename = Path("variant_config.json")
1731-
variant_h_filename = "variant.h"
1732-
variant_cpp_filename = "variant.cpp"
1733+
variant_h_filename = "variant_generic.h"
1734+
variant_cpp_filename = "variant_generic.cpp"
17331735
boards_entry_filename = "boards_entry.txt"
17341736
generic_clock_filename = "generic_clock.c"
17351737
repo_local_path = cur_dir / "repo"

CI/utils/templates/variant.cpp renamed to CI/utils/templates/variant_generic.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@
1414

1515
#include "pins_arduino.h"
1616

17-
#ifdef __cplusplus
18-
extern "C" {
19-
#endif
20-
2117
// Digital PinName array
2218
const PinName digitalPin[] = {
2319
{% for pinname in pinnames_list %}
2420
{% if not loop.last %}
25-
{{pinname}},
21+
{{"%-7s // %s"|format("{},".format(pinname.name), "D{}{}".format(loop.index, "" if pinname.ax == -1 else "/A{}".format(pinname.ax)))}}
2622
{% else %}
27-
{{pinname}}
23+
{{"%-7s // %s"|format(pinname.name, "D{}{}".format(loop.index, "" if pinname.ax == -1 else "/A{}".format(pinname.ax)))}}
2824
{% endif %}
2925
{% endfor %}
3026
};
@@ -35,13 +31,10 @@ const uint32_t analogInputPin[] = {
3531
{% if not loop.last %}
3632
{{"%-3s // %-4s %s"|format("{},".format(analog_pin.val), "{},".format(analog_pin.ax), analog_pin.pyn)}}
3733
{% else %}
38-
{{"%-2s // %-4s %s"|format(analog_pin.val, "{},".format(analog_pin.ax), analog_pin.pyn)}}
34+
{{"%-3s // %-4s %s"|format(analog_pin.val, "{},".format(analog_pin.ax), analog_pin.pyn)}}
3935
{% endif %}
4036
{% endfor %}
4137
};
4238

43-
#ifdef __cplusplus
44-
} // extern "C"
45-
#endif
4639
#endif /* ARDUINO_GENERIC_* */
4740

CI/utils/templates/variant.h renamed to CI/utils/templates/variant_generic.h

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@
1010
*
1111
*******************************************************************************
1212
*/
13-
14-
#if !defined(ARDUINO_GENERIC_{{generic_list[0].board}}){% for name in generic_list[1:] %} && !defined(ARDUINO_GENERIC_{{name.board}}){% endfor %}
15-
16-
#include VARIANT_BOARD_H
17-
#else
18-
#ifndef _VARIANT_ARDUINO_STM32_
19-
#define _VARIANT_ARDUINO_STM32_
20-
#ifdef __cplusplus
21-
extern "C" {
22-
#endif // __cplusplus
13+
#pragma once
2314

2415
/*----------------------------------------------------------------------------
2516
* STM32 pins number
@@ -46,79 +37,77 @@ extern "C" {
4637

4738
// On-board LED pin number
4839
#ifndef LED_BUILTIN
49-
#define LED_BUILTIN ND
40+
#define LED_BUILTIN ND
5041
#endif
5142

5243
// On-board user button
5344
#ifndef USER_BTN
54-
#define USER_BTN ND
45+
#define USER_BTN ND
5546
#endif
5647

5748
// SPI definitions
5849
#ifndef PIN_SPI_SS
59-
#define PIN_SPI_SS {{spi_pins.ss}}
50+
#define PIN_SPI_SS {{spi_pins.ss}}
6051
#endif
6152
#ifndef PIN_SPI_SS1
62-
#define PIN_SPI_SS1 {{spi_pins.ss1}}
53+
#define PIN_SPI_SS1 {{spi_pins.ss1}}
6354
#endif
6455
#ifndef PIN_SPI_SS2
65-
#define PIN_SPI_SS2 {{spi_pins.ss2}}
56+
#define PIN_SPI_SS2 {{spi_pins.ss2}}
6657
#endif
6758
#ifndef PIN_SPI_SS3
68-
#define PIN_SPI_SS3 {{spi_pins.ss3}}
59+
#define PIN_SPI_SS3 {{spi_pins.ss3}}
6960
#endif
7061
#ifndef PIN_SPI_MOSI
71-
#define PIN_SPI_MOSI {{spi_pins.mosi}}
62+
#define PIN_SPI_MOSI {{spi_pins.mosi}}
7263
#endif
7364
#ifndef PIN_SPI_MISO
74-
#define PIN_SPI_MISO {{spi_pins.miso}}
65+
#define PIN_SPI_MISO {{spi_pins.miso}}
7566
#endif
7667
#ifndef PIN_SPI_SCK
77-
#define PIN_SPI_SCK {{spi_pins.sck}}
68+
#define PIN_SPI_SCK {{spi_pins.sck}}
7869
#endif
7970

8071
// I2C definitions
8172
#ifndef PIN_WIRE_SDA
82-
#define PIN_WIRE_SDA {{i2c_pins.sda}}
73+
#define PIN_WIRE_SDA {{i2c_pins.sda}}
8374
#endif
8475
#ifndef PIN_WIRE_SCL
85-
#define PIN_WIRE_SCL {{i2c_pins.scl}}
76+
#define PIN_WIRE_SCL {{i2c_pins.scl}}
8677
#endif
8778

8879
// Timer Definitions
8980
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
9081
#ifndef TIMER_TONE
91-
#define TIMER_TONE {{timer.tone}}
82+
#define TIMER_TONE {{timer.tone}}
9283
#endif
9384
#ifndef TIMER_SERVO
94-
#define TIMER_SERVO {{timer.servo}}
85+
#define TIMER_SERVO {{timer.servo}}
9586
#endif
9687

9788
// UART Definitions
9889
#ifndef SERIAL_UART_INSTANCE
99-
#define SERIAL_UART_INSTANCE {{serial.instance}}
90+
#define SERIAL_UART_INSTANCE {{serial.instance}}
10091
#endif
10192

10293
// Default pin used for generic 'Serial' instance
10394
// Mandatory for Firmata
10495
#ifndef PIN_SERIAL_RX
105-
#define PIN_SERIAL_RX {{serial.rx}}
96+
#define PIN_SERIAL_RX {{serial.rx}}
10697
#endif
10798
#ifndef PIN_SERIAL_TX
108-
#define PIN_SERIAL_TX {{serial.tx}}
99+
#define PIN_SERIAL_TX {{serial.tx}}
109100
#endif
110101

111102
{% if hal_modules_list %}
112103
// Extra HAL modules
113104
{% for hal_module in hal_modules_list %}
114-
#define {{hal_module}}
105+
#if !defined(HAL_{{hal_module}}_MODULE_DISABLED)
106+
#define HAL_{{hal_module}}_MODULE_ENABLED
107+
#endif
115108
{% endfor %}
116109

117110
{% endif %}
118-
#ifdef __cplusplus
119-
} // extern "C"
120-
#endif
121-
122111
/*----------------------------------------------------------------------------
123112
* Arduino objects - C++ only
124113
*----------------------------------------------------------------------------*/
@@ -147,6 +136,3 @@ extern "C" {
147136
#endif
148137
#endif
149138

150-
#endif /* _VARIANT_ARDUINO_STM32_ */
151-
#endif /* !ARDUINO_GENERIC_* */
152-

0 commit comments

Comments
 (0)