As an alternative, you can try free utility from Segger, named bin2c: What is Bin2c
It creates C source file with null-terminated array of unsigned char containing data of the binary file which is specified on command line as an argument: bin2c binary_file.
The only manual correction I had to do was to change the array name because my binary file contained dots as part of its name, and they got carried over to the array name.
After that, you can include this C file in yours, and voila.
I have an issue with this using platform = espressif32@1.11.0
As a conclusion for my analysis: [ COMPONENT_EMBED_TXTFILES ] yes does support binary, but as well it adds “\0” at the end of the string once stored on ESP32. That illegal character was breaking the java scripts that I was uploading to ESP32. The solution was to copy “string length -1” to avoid including the “\0” at the end of the file once it is returned to the user from ESP32
Every time I now build or upload my program it will add another “\0” at the end of the file…
I have to go through the embedded files manually and delete the extra \0\0\0\0\0\0\ depending on how many builds i do.
that was fixed. Is it still not working in the latest espressif32 release? If it is fixed, you would either need to upgrade your platform version or a backport of the fix is needed.
If you take a look at CMakeLists.txt file for a current project, and that one you will notice they are significantly different. Using Esp32 v3.2.0 & PlatformIO v2.3.2.
If you try to add target_add_binary_data(${COMPONENT_TARGET} “src/myfile.txt” TEXT)
you will get an error.
I.E. A current project looks like this:
> # This file was automatically generated for projects
> # without default 'CMakeLists.txt' file.
>
> FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
>
> idf_component_register(SRCS ${app_sources})
It says, you can use board_build.embed_txtfiles = your file.
When I enter this in using my file it gives an error. Not at work so cannot copy it now. Basically I just want to be sure that the docs are still correct and things have not changed. That example does not do it this way, and I want to be able to.
No dependencies
Building in release mode
Compiling .pio\build\esp32dev\src\main.o
Linking .pio\build\esp32dev\firmware.elf
c:/users/jim/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.o:(.literal.app_main+0x0): undefined reference to `_binary_web_favicon_ico_end'
c:/users/jim/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.o:(.literal.app_main+0x4): undefined reference to `_binary_web_favicon_ico_start'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1
The latest core is 5.2.x. 3.2.0 is impossible and core 2.3.2 should be too old to build anything. Can you post the exact versions as they appear in the build log, e.g.
# This file was automatically generated for projects
# without default 'CMakeLists.txt' file.
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources})
fatal: not a git repository (or any of the parent directories): .git
CMake Error at CMakeLists.txt:5 (target_add_binary_data):
target_add_binary_data Function invoked with incorrect arguments for
function named: target_add_binary_data
I have tried this before, this is why I asked if the docs are up to date.
However, this is a big issue here that I discovered. Whenever I add a a new new file, and add the accompanying code for it (like above) it wont compile. I found that if you do a clean all first the recompile it will. This is a repeatable issue.
I can confirm this solution (or workaround) works and what is marked as a solution / what should be done per Platformio documentation doesn’t.
Thank you mikemoy.