Skip to content

Catethysis/stm32js

Repository files navigation

Build Status Code Climate

stm32js

stm32js is a framework which gives you a way to write scripts for STM32 in JavaScript.

About it

stm32js provides a hardware abstraction layer (HAL) to common STM32F4 peripheral in a set of two-way C++ ↔ JS bindings.

In other words, now you can program your STM32F4Discovery using JS, and ready-to-use libraries is also available.

What's underneath

stm32js is lying in between web technologies and embedded development, and trying to get the best from two worlds.

It consists of several parts:

  1. Duktape, the light-weight JS engine with small runtime/context memory footprint
  2. Babel, an ES6 → ES5 transpiler
  3. Browserify, a RequireJS resolving tool
  4. Uglify to produce compact JS code
  5. Gulp to rule all the JS code processing
  6. GCC/Make that builds the Core
  7. CMSIS proudly provided by ARM and STM32, that gives all peripheral descriptions
  8. Custom HAL libraries to access the STM32 hardware, such as init functions and common calls.

Build

Currently you cannot build the framework through gcc, but I'm working on it. I provide binary image built on IAR now.

Examples

stm32js is very easy to use for those who have an experience with JS, so I'll show you some particular framework use cases.

SysTick

For example, let's ask the system timer to tick every 500 milliseconds. Didn't you forget about ES6 support? You can use arrow functions in here.

const SysTick = require('../peripheral/systick');

var sysTick = new SysTick(500);

sysTick.on('tick', () => {
	print('tick');
});

print() function will output its argument to SWO so you can see it in "Terminal I/O" window in IAR or appropriate tool in other IDE or ST-Link Utility.