Hi, I just noticed your mail about getting TCC to run on an STM32. This will require ARM Thumb-2 support, since the regular ARM instruction set is not supported on Cortex-M.
You may be interested in some work I did previously, located here: https://git.erlendjs.no/erlendjs/tinycc It adds support for generating Thumb-2 instructions, and is almost feature complete. However, I had used it as a regular application running on my own OS, not as a library. I was not using the linker embedded in TCC. I was using the GNU linker, ported to the STM32 to do the final linking steps also on the microcontroller. Some additional work is probably required to use it like you describe (a library). I cannot recall exactly how much memory TCC required, but I did have 8 MiB of external DRAM connected to the microcontroller, and at least the GNU linker was using several megabytes. TCC itself probably used about 1 MiB, but that is as a regular terminal application. If used as a library, maybe it will fit in your 256K. Required memory will of course also vary with what you intend to compile, and I was using it for compiling programs in the order of ~10k LOC which probably explains some of the memory usage. Please let me know if you make progress, I would love to know! I have written about my project earlier on this mailing list, however there is not much interest for the STM32 (or Cortex-M) and TCC combo. Maybe if more people show interest, it could be merged upstream eventually. Regards, Erlend ________________________________ Fra: tinycc-devel-bounces+erlend.sveen=hotmail....@nongnu.org <tinycc-devel-bounces+erlend.sveen=hotmail....@nongnu.org> på vegne av Lilian Besson <lilian.bes...@crans.org> Sendt: onsdag 28. mai 2025 10:06 Til: tinycc-devel@nongnu.org <tinycc-devel@nongnu.org> Emne: Re: [Tinycc-devel] Questions: how to use libtcc on an embedded ARM 32bits micro-controller? Hello, Just to let you know, I've worked on this on my own last Saturday, and I've almost managed to port TCC to the NumWorks: https://github.com/Naereen/A-C-Compiler-for-the-NumWorks-calculator I've had to modify a bit the source code of tinycc.git/ to build a arm-eabihf-libtcc.a static library. I wasn't able to build it without modifying the main Makefile, so I did that (on my fork, see https://github.com/Naereen/tinycc/commit/9802ebdebe7c7a8018083517225e8b3d1d193682#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R18-R295 if someone is curious about the changes). My embedded version of TCC starts by working well, until it calls on tcc_compile_string(tcc_state, code_to_execute) See https://github.com/Naereen/A-C-Compiler-for-the-NumWorks-calculator/issues/2#issuecomment-2908695111 The error is almost certainly an error on the memory allocation process. I've tried to use the newlib's realloc() function, or a manually written malloc/realloc/free (handling the heap manually, on a static array, just to try). Both approaches fail when tcc_compile_string(...) starts to ask for some larger chunks of heap memory. It might be because of RAM fragmentation, or simply (sadly) because the embedded system of the NumWorks calculator, which has no more than 256K of Static RAM. If anyone is interested into a discussion about this project, and mainly on how to pinpoint and try to fix this error cause by memory allocation, I would gladly discuss over email in English and/or French. Many thanks in advance, Kind regards, -- Lilian Besson, Professor of Computer Science at Lycée Kléber, in Strasbourg (France) web : https://Besson.link/ ; phone : +33628412257 email. : lil...@besson.link or lilian.bes...@crans.org Le 24/05/2025 à 11:29, Lilian Besson a écrit : > Hello dear developers and maintainers of TCC, > > I've started to be interested into trying to port the TCC compiler on a > graphical calculator, the ones manufactured by NumWorks (a French startup). > > NumWorks calculators use ARM micro-controllers (specifically, STM32 > micro-controllers). > As stated by the manufacturer: This chip combines an ARMv7-M Cortex-M7 core, > clocked at 216 MHz and 256K of Static RAM. > (see > https://www.numworks.com/engineering/hardware/electrical/parts/#stm32f730v8t6 > if needed) > > I'm trying to understand on my own how I need to use TCC's `configure` and > `make` commands, in order to produce a few files like libtcc.c/libtcc.h. > I would like to embed the awesome TCC's "load, compile & run" features, in a > C application for this NumWorks calculator. > > I have an app that reads a file locally edited on the calculator, and runs it > on a Lua interpreter (or JavaScript), and the calculator ships with > MicroPython already working well. > My goal is to offer the same kind of features but for a C program, which > could be edited on the calculator, read and ran by the "TCC interpreter" > application. > > # Here are a few questions: > > > 1. how to use libtcc on an embedded ARM 32bits micro-controller? > > If I follow the ideas of the libtcc_test.c file > (https://github.com/Tiny-C-Compiler/tinycc-mirror-repository/blob/mob/tests/libtcc_test.c), > will it work directly if I cross-compile the resulting C program to my > ARMv7-M CPU > architecture for my NumWorks calculator? > > I see in the libtcc.c file that there is an option TCC_TARGET_ARM, so I > should enable it, include libtcc.h and "that's it" ? > (https://github.com/Tiny-C-Compiler/tinycc-mirror-repository/blob/b6a16e3be4aff2d6b6e4870a1fde5e83707e9be4/libtcc.c#L36C22-L36C22) > > > 2. Is there any documentation I can follow, by any chance? Regarding any of > these questions. > > > 3. Does anybody already tried such a thing, for instance for Texas Instrument > or Casio calculators? > > I saw that someone did port the GTC C compiler about 13 years ago, for Texas > Instrument calculators, but I don't find any other mentions. > (here https://tiplanet.org/forum/archives_voir.php?id=1000) > > > Kind regards, and thanks in advance; _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel