Skip to content

Commit a5266c7

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 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 484f1b4 commit a5266c7

File tree

3 files changed

+27
-49
lines changed

3 files changed

+27
-49
lines changed

CI/utils/stm32variant.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,21 +1229,20 @@ def print_variant(generic_list):
12291229
# Define extra HAL modules
12301230
hal_modules_list = []
12311231
if daclist:
1232-
hal_modules_list.append("HAL_DAC_MODULE_ENABLED")
1232+
hal_modules_list.append("DAC")
12331233
if eth_list:
1234-
hal_modules_list.append("HAL_ETH_MODULE_ENABLED")
1234+
hal_modules_list.append("ETH")
12351235
if quadspidata0_list:
12361236
if "OCTOSPI" in quadspidata0_list[0][2]:
1237-
hal_modules_list.append("HAL_OSPI_MODULE_ENABLED")
1237+
hal_modules_list.append("OSPI")
12381238
else:
1239-
hal_modules_list.append("HAL_QSPI_MODULE_ENABLED")
1239+
hal_modules_list.append("QSPI")
12401240
if sd_list:
1241-
hal_modules_list.append("HAL_SD_MODULE_ENABLED")
1241+
hal_modules_list.append("SD")
12421242

12431243
variant_h_file.write(
12441244
variant_h_template.render(
12451245
year=datetime.datetime.now().year,
1246-
generic_list=generic_list,
12471246
pins_number_list=pins_number_list,
12481247
alt_pins_list=alt_pins_list,
12491248
waltpin=max(waltpin),
@@ -1728,8 +1727,8 @@ def manage_repo():
17281727
periph_c_filename = "PeripheralPins.c"
17291728
pinvar_h_filename = "PinNamesVar.h"
17301729
config_filename = Path("variant_config.json")
1731-
variant_h_filename = "variant.h"
1732-
variant_cpp_filename = "variant.cpp"
1730+
variant_h_filename = "variant_generic.h"
1731+
variant_cpp_filename = "variant_generic.cpp"
17331732
boards_entry_filename = "boards_entry.txt"
17341733
generic_clock_filename = "generic_clock.c"
17351734
repo_local_path = cur_dir / "repo"

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
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 %}
@@ -40,8 +36,5 @@ const uint32_t analogInputPin[] = {
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)