Skip to content

Commit d0f7293

Browse files
authored
optionally move float emulation code into iram (#8958)
* optionally move float emulation code into iram allows doing float operation in iram suitable for libraries like AccelStepper when called from ISR * proposed changes for pio from @mcspr
1 parent 74c04c8 commit d0f7293

7 files changed

+201
-9
lines changed

boards.txt

+153
Large diffs are not rendered by default.

doc/ideoptions.rst

+6
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ See our issue tracker in regards to default version selection.
263263

264264
Notice that 3.x.x is provided **as-is** and remains **experimental**.
265265

266+
Floating Point operations
267+
~~~~~~~~~~~~~~~~~~~~~~~~~
268+
269+
- ``in IROM``: This provides more free space in IRAM but disallows using floating operations inside ISRs.
270+
- ``allowed in ISR``: Floats can be used in ISRs, cost is ~1KB IRAM when floats are used.
271+
266272
SSL Support
267273
~~~~~~~~~~~
268274

package/package_esp8266com_index.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,4 @@
383383
]
384384
}
385385
]
386-
}
386+
}

platform.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ build.spiffs_start=
6262
build.spiffs_end=
6363
build.spiffs_blocksize=
6464

65+
# soft float location
66+
build.iramfloat=-DFP_IN_IROM
67+
6568
# Fully qualified file names for processing sketch global options
6669
globals.h.source.fqfn={build.source.path}/{build.project_name}.globals.h
6770
commonhfile.fqfn={build.core.path}/CommonHFile.h
@@ -79,7 +82,7 @@ compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_S
7982
compiler.libraries.ldflags=
8083

8184
compiler.c.cmd=xtensa-lx106-elf-gcc
82-
compiler.c.flags=-c "{compiler.warning_flags}-cflags" -std=gnu17 {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
85+
compiler.c.flags=-c "{compiler.warning_flags}-cflags" -std=gnu17 {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags} {build.iramfloat}
8386

8487
compiler.S.cmd=xtensa-lx106-elf-gcc
8588
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls "-I{runtime.tools.xtensa-lx106-elf-gcc.path}/include/"
@@ -90,7 +93,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc
9093
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc
9194

9295
compiler.cpp.cmd=xtensa-lx106-elf-g++
93-
compiler.cpp.flags=-c "{compiler.warning_flags}-cppflags" {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
96+
compiler.cpp.flags=-c "{compiler.warning_flags}-cppflags" {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags} {build.iramfloat}
9497

9598
compiler.as.cmd=xtensa-lx106-elf-as
9699

@@ -128,7 +131,7 @@ recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" -I "{runt
128131
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.mkdir}" -p "{build.path}/ld_h/"
129132
recipe.hooks.linking.prelink.2.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.cp}" "{runtime.platform.path}/tools/sdk/ld/{build.flash_ld}" "{build.path}/ld_h/local.eagle.flash.ld.h"
130133
recipe.hooks.linking.prelink.3.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} {build.mmuflags} "{build.path}/ld_h/local.eagle.flash.ld.h" -o "{build.path}/local.eagle.flash.ld"
131-
recipe.hooks.linking.prelink.4.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} {build.mmuflags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
134+
recipe.hooks.linking.prelink.4.pattern="{compiler.path}{compiler.c.cmd}" {build.iramfloat} -CC -E -P {build.vtable_flags} {build.mmuflags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
132135

133136
## Compile c files
134137
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" -DARDUINO_BOARD_ID="{_id}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

tools/boards.txt.py

+14
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,17 @@ def sdk ():
16821682

16831683
################################################################
16841684

1685+
def float_in_iram ():
1686+
return { 'iramfloat': collections.OrderedDict([
1687+
('.menu.iramfloat.no', 'in IROM'),
1688+
('.menu.iramfloat.no.build.iramfloat', '-DFP_IN_IROM'),
1689+
('.menu.iramfloat.yes', 'allowed in ISR'),
1690+
('.menu.iramfloat.yes.build.iramfloat', '-DFP_IN_IRAM'),
1691+
])
1692+
}
1693+
1694+
################################################################
1695+
16851696
def all_boards ():
16861697

16871698
if boardsgen or boardslocalgen:
@@ -1709,6 +1720,7 @@ def all_boards ():
17091720
macros.update(led('led', led_default, range(0,led_max+1)))
17101721
macros.update(led('led216', 2, { 16 }))
17111722
macros.update(sdk())
1723+
macros.update(float_in_iram())
17121724

17131725
if boardfilteropt or excludeboards:
17141726
print('#')
@@ -1754,6 +1766,7 @@ def all_boards ():
17541766
print('menu.stacksmash=Stack Protection')
17551767
print('menu.wipe=Erase Flash')
17561768
print('menu.sdk=NONOS SDK Version')
1769+
print('menu.iramfloat=Floating Point operations')
17571770
print('menu.ssl=SSL Support')
17581771
print('menu.mmu=MMU')
17591772
print('menu.non32xfer=Non-32-Bit Access')
@@ -1791,6 +1804,7 @@ def all_boards ():
17911804
macrolist += speeds[default_speed]
17921805

17931806
macrolist += [ 'autoflash' ]
1807+
macrolist += [ 'iramfloat' ]
17941808

17951809
for block in macrolist:
17961810
for optname in macros[block]:

tools/platformio-build.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,23 @@ def scons_patched_match_splitext(path, suffixes=None):
275275
#
276276

277277
current_vtables = None
278-
fp_in_irom = ""
278+
current_fp = None
279279
for d in flatten_cppdefines:
280280
if str(d).startswith("VTABLES_IN_"):
281281
current_vtables = d
282-
if str(d) == "FP_IN_IROM":
283-
fp_in_irom = "-DFP_IN_IROM"
282+
if str(d).startswith("FP_IN_"):
283+
current_fp = d
284+
284285
if not current_vtables:
285286
current_vtables = "VTABLES_IN_FLASH"
286287
env.Append(CPPDEFINES=[current_vtables])
287288
assert current_vtables
288289

290+
if not current_fp:
291+
current_fp = "FP_IN_IROM"
292+
env.Append(CPPDEFINES=[current_fp])
293+
assert current_fp
294+
289295
#
290296
# MMU
291297
#
@@ -363,17 +369,17 @@ def scons_patched_match_splitext(path, suffixes=None):
363369
join("$BUILD_DIR", "ld", "local.eagle.app.v6.common.ld"),
364370
join(FRAMEWORK_DIR, "tools", "sdk", "ld", "eagle.app.v6.common.ld.h"),
365371
env.VerboseAction(
366-
"$CC -CC -E -P -D%s %s %s $SOURCE -o $TARGET"
372+
"$CC -CC -E -P -D%s -D%s %s $SOURCE -o $TARGET"
367373
% (
368374
current_vtables,
375+
current_fp,
369376
# String representation of MMU flags
370377
" ".join(
371378
[
372379
"-D%s=%s" % f if isinstance(f, (tuple, list)) else "-D" + f
373380
for f in mmu_flags
374381
]
375382
),
376-
fp_in_irom,
377383
),
378384
"Generating LD script $TARGET",
379385
),

tools/sdk/ld/eagle.app.v6.common.ld.h

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ SECTIONS
142142

143143
/* all functional callers are placed in IRAM (including SPI/IRQ callbacks/etc) here */
144144
*(.text._ZNKSt8functionIF*EE*) /* std::function<any(...)>::operator()() const */
145+
146+
#ifdef FP_IN_IRAM
147+
*libgcc.a:*f2.o(.literal .text)
148+
*libgcc.a:*f3.o(.literal .text)
149+
*libgcc.a:*fsi.o(.literal .text)
150+
*libgcc.a:*fdi.o(.literal .text)
151+
*libgcc.a:*ifs.o(.literal .text)
152+
*libgcc.a:*idf.o(.literal .text)
153+
#endif
154+
145155
} >iram1_0_seg :iram1_0_phdr
146156

147157
.irom0.text : ALIGN(4)

0 commit comments

Comments
 (0)