6

I would like to know if it would be possible to cross-compile application written in Ocaml on processor like STM32F407 (1MB Flash, 196kB RAM) ? (without OS).

I have read Cross-compiling ocaml apps for ARM ; the experiment seems to have been done on beaglebone; so more powerfull than STM32, and with Linux as OS.

There is also OcaPIC (http://www.algo-prog.info/ocaml_for_pic/web/index.php?id=ocapic) - which is meant for PIC processors. Is there any similar port for ARM Cortex M4 ?

Community
  • 1
  • 1
Pierre G.
  • 4,346
  • 1
  • 12
  • 25

1 Answers1

3

I'm not aware of a port, but see the related mailing list thread 1,2.

To get started you could use the same toolchain that you use for building a C or Arduino code to cross-compile the OCaml bytecode interpreter (ocamlrun), and then run 32-bit OCaml bytecode. The tricky part would be to port the runtime to work without an OS (allocating memory, etc.). Projects like Mirage have done that for Xen based partially on Xen's miniOS. Perhaps you could use FreeRTOS, ChibiOS, etc. to get started.

Once that works you can look at native code with ocamlopt, it supports armv4 to armv7, but I don't know if ARMv7E-M is a superset of that or not.

Or you could write a DSL embedded in OCaml that generates C code which you would finally run on your MCU, like Haskell does with Ivory3 and Atom4.

Török Edwin
  • 561
  • 2
  • 5