I recently started thinking about whether I could put Kyu onto a Cortex-M3 ARM board. I am doing a lot of work with the STM32F103 chip, which has 128K of flash (on some versions) and 20K of ram.
So I took a look at a recent build of Kyu for the Orange Pi. The code is 184,248 bytes.
184,248 bytes -- Normal build. 122,072 bytes -- without network 91,554 bytes -- without network, thumb codeSo without the network, it would barely fit. On the other hand the compiler for the Cortex-M3 generates "thumb" instructions, which are more compact, so it would be smaller. The claim is that thumb code is 30 percent smaller or maybe 23.5 percent smaller depending what source you believe. So take 25 percent and this would be 91,554 bytes. So it would fit, but not leave a lot for application code.
Figuring out how to make do with 20K of ram would be another challenge.
21640 board.o 3336 console.o 12732 dlmalloc.o 4316 kyulib.o 32100 lib.o 17284 machine.o 1384 main.o 1284 prf.o 1412 random.o 2924 symbols.o 5472 test_io.o 10896 test_kyu.o 768 test_net.o 2984 tests.o 15968 thread.o 1264 timer.o 668 user.o 688 version.o 29212 tcp_xinu.o 25128 net.oThe last two files are the network code, which are roughly 54K in size.
The dlmalloc allocator is fairly big and could be replaced with something more primitive.
The "lib.o" module is 32K, and much of this is probably an imported fancy printf that could
be replaced with something more basic also.
The test routines could be gotten rid of once Kyu was up and running, making room for application
code.
STM32F205G - 1M flash, 128K ram, Cortex-M3, 120Mhz (Particle Photon board) NXP LPC1768 - 512K flash, 64K ram STM32F401CC - 256K flash, 64K ram STM32F411CE - 512K flash, 128K ram, Cortex-M4, 120MhzI have two of the F205 boards on hand, and a bundle of the F411 on the way. Either of these would seem reasonable candidates for trying to get Kyu running on a Cortex-M3 microcontroller. As near as I can tell, the main thing Cortex-M4 adds are floating point instructions, which are neither here nor there to me.
The STM32F411 boards cost about $5 each, and would take the record for the smallest and least expensive board that is able to run Kyu. Trying to move from there to the STM32F103 might be good for bragging rights, but would really be a waste of time and energy.
Kyu / [email protected]