Skip to content

Commit ed9a5bd

Browse files
authored
Optimise arduino library management in speeduino repo (speeduino#1306)
* Replace bit_shifts.h with avr-fast-shift library * Replace embedded libdivide source with library * Replace embedded FastCRC source with library * Replace udiv_32_16() with avr-fast-div library * Fix non-mega builds * Fix Arduino CLI build * Fix non-mega Arduino CLI build * Reduce flash usage on Arduino CLI compile * Use specific library versions * Use shared lists of core libraries * Add missing library for Arduino build * Performance: replace stock division with fast_div(), percentage() or shifts
1 parent 73b788f commit ed9a5bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+213
-204296
lines changed

.github/workflows/pr-memory-deltas-generate.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ on:
77
env:
88
# It's convenient to set variables for values used multiple times in the workflow.
99
SKETCHES_REPORTS_PATH: sketches-reports
10+
# Libraries shared by all builds
11+
COMMON_LIB_DEPS: |
12+
- name: SimplyAtomic
13+
version: "1.0"
14+
- name: avr-fast-shift
15+
version: "1.1.0"
16+
- name: libdivide
17+
version: "5.2.0"
18+
- name: FastCRC
19+
version: "1.41"
20+
- name: avr-fast-div
21+
version: "1.4.0"
1022
1123
jobs:
1224
compile:
@@ -25,10 +37,10 @@ jobs:
2537
- name: arduino:avr
2638
compile-flags: |
2739
- --build-property
28-
- build.extra_flags=-DPLATFORMIO -DUSE_LIBDIVIDE -O3 -ffast-math -fshort-enums -funroll-loops -Wall -Wextra -std=c++14
40+
- build.extra_flags=-DPLATFORMIO -DUSE_LIBDIVIDE -DCRC_BIGTABLES=0 -DAFD_INLINE=0 -O3 -ffast-math -fshort-enums -funroll-loops -Wall -Wextra -std=c++14
2941
lib_deps: |
3042
- name: Time
31-
- name: SimplyAtomic
43+
3244
- fqbn: teensy:avr:teensy35
3345
artifact-name-suffix: teensy-avr-teensy35
3446
platform: |
@@ -39,9 +51,9 @@ jobs:
3951
- build.extra_flags="-Wall"
4052
lib_deps: |
4153
- name: SDfat
42-
- name: SimplyAtomic
4354
- name: InternalTemperature
4455
- name: elapsedMillis
56+
4557
- fqbn: teensy:avr:teensy41
4658
artifact-name-suffix: teensy-avr-teensy41
4759
platform: |
@@ -52,9 +64,9 @@ jobs:
5264
- build..extra_flags="-Wall"
5365
lib_deps: |
5466
- name: SDfat
55-
- name: SimplyAtomic
5667
- name: InternalTemperature
5768
- name: elapsedMillis
69+
5870
- fqbn: STMicroelectronics:stm32:GenF4
5971
artifact-name-suffix: stm32-avr-stm32f4
6072
platform: |
@@ -68,12 +80,11 @@ jobs:
6880
- name: "STM32duino RTC"
6981
version: 1.2.0
7082
- name: SdFat
71-
- name: SimplyAtomic
7283
- name: elapsedMillis
7384
7485
steps:
7586
- name: Checkout repository
76-
uses: actions/checkout@v4
87+
uses: actions/checkout@v4
7788

7889
- name: Compile platforms
7990
uses: arduino/compile-sketches@v1.1.2
@@ -90,6 +101,7 @@ jobs:
90101
${{ matrix.board.compile-flags }}
91102
libraries: |
92103
${{ matrix.board.lib_deps }}
104+
${{ env.COMMON_LIB_DEPS }}
93105
94106
# This step is needed to pass the size data to the report job.
95107
- name: Upload sketches report to workflow artifact

misra/check_misra.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,8 @@ if [ $output_xml -eq 1 ]; then
9494
cppcheck_parameters+=(--xml)
9595
fi
9696

97-
# There is no way to tell the misra add on to skip certain headers
98-
# libdivide adds 10+ minutes to each file so rename the folder
99-
# before the scan
100-
mv "$source_folder"/src/libdivide "$source_folder"/src/_libdivide
101-
10297
"$cppcheck_bin" ${cppcheck_parameters[@]} 2> $cppcheck_out_file
10398

104-
# Restore libdivide folder name after scan
105-
mv "$source_folder"/src/_libdivide "$source_folder"/src/libdivide
106-
10799
# Count lines for Mandatory or Required rules
108100
error_count=`grep -i "Mandatory - \|Required - " < "$cppcheck_out_file" | wc -l`
109101

platformio.ini

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@
88
; Please visit documentation for the other options and examples
99
; http://docs.platformio.org/page/projectconf.html
1010

11+
[common]
12+
; These libraries are used by all builds.
13+
lib_deps =
14+
wizard97/SimplyAtomic@^1.0
15+
adbancroft/avr-fast-shift@^1.1.0
16+
ridiculousfish/libdivide@^5.2.0
17+
frankboesing/FastCRC@^1.41
18+
adbancroft/avr-fast-div@^1.4.0
19+
1120
[env:megaatmega2560]
1221
platform=atmelavr
1322
board=megaatmega2560
1423
framework=arduino
1524
build_unflags = -Os -std=gnu++11
16-
build_flags = -DUSE_LIBDIVIDE -O3 -ffast-math -fshort-enums -funroll-loops -Wall -Wextra -std=c++14
17-
; Note that fp64lib is only used by unit tests. It isn't referenced by the firmware & will be
18-
; ignored.
19-
lib_deps = EEPROM, Time, fp64lib, simplyatomic
20-
;test_build_project_src = true
25+
build_flags = -DCRC_BIGTABLES=0 -DUSE_LIBDIVIDE -DAFD_INLINE=0U -O3 -ffast-math -fshort-enums -funroll-loops -Wall -Wextra -std=c++14
26+
lib_deps =
27+
EEPROM
28+
Time
29+
${common.lib_deps}
30+
; Note that fp64lib is only used by unit tests. It isn't referenced by the firmware & will be
31+
; ignored.
32+
fp64lib/fp64lib@^1.1.20
2133
debug_tool = simavr
2234
test_ignore = test_table3d_native
2335

@@ -53,7 +65,12 @@ test_testing_command =
5365
platform=https://github.com/platformio/platform-teensy.git
5466
board=teensy35
5567
framework=arduino
56-
lib_deps = EEPROM, FlexCAN_T4, Time, SimplyAtomic, InternalTemperature
68+
lib_deps =
69+
EEPROM
70+
FlexCAN_T4
71+
Time
72+
InternalTemperature
73+
${common.lib_deps}
5774
test_ignore = test_table3d_native
5875
extra_scripts = post:post_extra_script.py
5976

@@ -62,7 +79,12 @@ extra_scripts = post:post_extra_script.py
6279
platform=https://github.com/platformio/platform-teensy.git
6380
board=teensy36
6481
framework=arduino
65-
lib_deps = EEPROM, FlexCAN_T4, Time, SimplyAtomic, InternalTemperature
82+
lib_deps =
83+
EEPROM
84+
FlexCAN_T4
85+
Time
86+
InternalTemperature
87+
${common.lib_deps}
6688
test_ignore = test_table3d_native
6789
extra_scripts = post:post_extra_script.py
6890

@@ -71,7 +93,12 @@ extra_scripts = post:post_extra_script.py
7193
platform=https://github.com/platformio/platform-teensy.git
7294
board=teensy41
7395
framework=arduino
74-
lib_deps = EEPROM, FlexCAN_T4, Time, SimplyAtomic, InternalTemperature
96+
lib_deps =
97+
EEPROM
98+
FlexCAN_T4
99+
Time
100+
InternalTemperature
101+
${common.lib_deps}
75102
test_ignore = test_table3d_native
76103
build_flags = -DTEENSY_INIT_USB_DELAY_AFTER=40
77104
extra_scripts = post:post_extra_script.py
@@ -82,7 +109,11 @@ platform = ststm32
82109
framework = arduino
83110
board = black_f407ve
84111
; RTC library fixed to 1.2.0, because in newer than that the RTC fails to keep up time. At least up to 1.3.7 version
85-
lib_deps = stm32duino/STM32duino RTC @ 1.2.0, greiman/SdFat, SimplyAtomic, elapsedMillis
112+
lib_deps =
113+
stm32duino/STM32duino RTC @ 1.2.0
114+
greiman/SdFat
115+
elapsedMillis
116+
${common.lib_deps}
86117
board_build.core = stm32
87118
build_flags = -DUSE_LIBDIVIDE -std=c++14 -UBOARD_MAX_IO_PINS -DENABLE_HWSERIAL2 -DENABLE_HWSERIAL3 -DUSBCON -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC -DHAL_CAN_MODULE_ENABLED -DSERIAL_TX_BUFFER_SIZE=128 -DSERIAL_RX_BUFFER_SIZE=128
88119
upload_protocol = dfu
@@ -122,7 +153,9 @@ build_flags = ${env:black_F407VE.build_flags} -DFRAM_AS_EEPROM
122153
platform = ststm32
123154
framework = arduino
124155
board = blackpill_f401cc
125-
lib_deps = stm32duino/STM32duino RTC @ 1.2.0, SimplyAtomic
156+
lib_deps =
157+
stm32duino/STM32duino RTC @ 1.2.0
158+
${common.lib_deps}
126159
board_build.core = stm32
127160
build_flags = -DUSE_LIBDIVIDE -std=c++14 -UBOARD_MAX_IO_PINS -DUSBCON -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC -DHAL_DAC_MODULE_DISABLED -DHAL_ETH_MODULE_DISABLED -DHAL_SD_MODULE_DISABLED -DHAL_QSPI_MODULE_DISABLED
128161
upload_protocol = dfu
@@ -134,7 +167,9 @@ monitor_speed = 115200
134167
platform = ststm32
135168
framework = arduino
136169
board = blackpill_f411ce
137-
lib_deps = stm32duino/STM32duino RTC @ 1.2.0, SimplyAtomic
170+
lib_deps =
171+
stm32duino/STM32duino RTC @ 1.2.0
172+
${common.lib_deps}
138173
board_build.core = stm32
139174
build_flags = -DUSE_LIBDIVIDE -O3 -std=c++14 -UBOARD_MAX_IO_PINS
140175
upload_protocol = dfu
@@ -146,13 +181,45 @@ monitor_speed = 115200
146181
platform = ststm32
147182
framework = arduino
148183
board = blackpill_f411ce
149-
lib_deps = stm32duino/STM32duino RTC @ 1.2.0, SimplyAtomic
184+
lib_deps =
185+
stm32duino/STM32duino RTC @ 1.2.0
186+
${common.lib_deps}
150187
board_build.core = stm32
151188
build_flags = -DUSE_LIBDIVIDE -O3 -std=c++14 -UBOARD_MAX_IO_PINS -DUSBCON -DHAL_PCD_MODULE_ENABLED -DUSBD_USE_CDC
152189
upload_protocol = dfu
153190
debug_tool = stlink
154191
monitor_speed = 115200
155192

193+
[env:bluepill_f103c8]
194+
platform = ststm32
195+
framework = arduino
196+
; framework-arduinoststm32
197+
board = bluepill_f103c8_128k
198+
lib_deps =
199+
EEPROM
200+
stm32duino/STM32duino RTC @ 1.2.0
201+
${common.lib_deps}
202+
build_flags = -DUSE_LIBDIVIDE -fpermissive -std=gnu++11 -Os -DCORE_STM32_OFFICIAL -UBOARD_MAX_IO_PINS
203+
204+
;SAMD21
205+
[env:samd21]
206+
platform = atmelsam
207+
framework = arduino
208+
board = zeroUSB
209+
build_flags = -DUSE_LIBDIVIDE -fpermissive -std=gnu++11
210+
upload_protocol = sam-ba
211+
212+
;SAME51
213+
[env:same51]
214+
platform = atmelsam
215+
framework = arduino
216+
board = adafruit_feather_m4_can
217+
build_flags = -DUSE_LIBDIVIDE -fpermissive -std=gnu++11
218+
upload_protocol = sam-ba
219+
220+
[env:custom_monitor_speedrate]
221+
monitor_speed = 115200
222+
156223
[platformio]
157224
src_dir=speeduino
158225
default_envs = megaatmega2560

0 commit comments

Comments
 (0)