Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
For a full reference visit the Markdown syntax.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Currently Espruino (and Javascipt) is based on 64bit float arithmetic which is not implemented in hardware on most devices. However nrf52 platform has Cortex M4F CPU which has native 32bit floats implemented. Looks like with relatively simple changes it can be used in existing Espruino build without any additional invasive changes as part of inline C code https://www.espruino.com/InlineC
Here is the example:
The mandel method is from compiled js example https://www.espruino.com/Compilation and can be then called as
This works as is because mandel method has integer parameters. Next trick is 32bit float parameters. There is no direct support for 32 bit float basic type however Javascript (and Espruino too!) supports Float32Array type which is enough for us thanks to Espruino shared arrays and softfp compiler calling convention :-) See definition of fadd and fmul inline C methods above and then this usage
Cool? What can you do with it?
Well currently it is in not so rosy as this is not supported by Espruino compiler service called from Web IDE. Fortunately Gordon hosts the compiler source here https://github.com/gfwilliams/EspruinoCompiler and supporting cortex M4F with native floats is single line change in compile.js, so you can host it yourself and replace line
with
Another catch is power drain caused by FPU exceptions described in Nordic nrf52 errata. The suggested fix is not currently part of Espruino codebase but it is easy to add there and it can be even done right now in inline C code. See my full example with links to more info and workaround code here
Simple fadd fmul calls do not trigger it with the example above but with the mandel example you can see that after running it
c.getFPUPendingIRQ()
return 1 and fpu flagsc.getFPSCR().toString(16)
has some exception bits set. It can be fixed by callingc.clearFPU()
and power draw in sleep should be back to normal :-)