Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JS Fest 2018. Володимир Шиманський. Запуск двіжка JS на мікроконтролері

77 views

Published on

JavaScript - усюди! Тільки нещодавно запускав один і той самий JS код в Browser, Node.js, та React Native, як уже новий виклик - Embedded системи… Спокійно, JS справиться! На цій доповіді ви дізнаєтесь, які двіжки JS працюють в дуже обмежених середовищах, хто і як це використовує в продакшні та наскільки весело розробляти софт під всякі залізяки на JS.
[Спойлер] Якщо все вийде, спробуємо відтворити мелодію Mario на звичайному Bluetooth-брелку для ключів :)

Published in: Education
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

JS Fest 2018. Володимир Шиманський. Запуск двіжка JS на мікроконтролері

  1. 1. Running JavaScript on microcontrollers Volodymyr Shymanskyy
  2. 2. What systems are we talking about? System architecture Engines overview Benefits Used on production? Demo!
  3. 3. V8 SpiderMonkey JavaScriptCore Chakra JavaScriptCoreV8 ???
  4. 4. Raspberry Pi Zero W VoCore v2 Intel Joule
  5. 5. Library Processor(s) Memory Devices Kernel Drivers Supervisor Application Hardware Library Lib Library L Program Program Program ProgramNode.js SYSTEM OVERVIEW
  6. 6. ARDUINO UNO CPU 16 MHz [8-bit] Flash 32 Kb RAM 2 Kb Bare metal (no OS)
  7. 7. ESP8266 ~ $1.8 CPU 160 MHz Flash 4 Mb RAM 128 Kb + WiFi ESP32 ~ $4.5 CPU 2x 240 MHz Flash 4 Mb+ RAM 520 Kb + WiFi + Bluetooth 4.2 + crypto engine, etc. nRF52832 ~ $8.5 CPU 64MHz Flash 512 Kb RAM 64 Kb + Bluetooth 5 + 6LoWPAN + NFC + Low Power
  8. 8. HOW MUCH IS ENOUGH? Engine License Binary RAM Google V8 BSD 3-clause >8M >24M JavaScriptCore LGPL 2.0 >4M >8M Duktape MIT 100k 30k V7 GPL v2.0 70k 1k mJS GPL v2.0 50k 1k JerryScript Apache 2 200k 64k Espruino MPL v2.0 128k 8k
  9. 9. JS Library Processor(s) Memory Devices RTOS Drivers Application Hardware JS Lib JS JS Library JS App JS engine Supervisor SYSTEM OVERVIEW
  10. 10. JS Library Processor(s) Memory Devices JS engine Drivers Supervisor Application Hardware JS Lib JS JS Library JS App SYSTEM OVERVIEW
  11. 11. Bluetooth Key Tag ~ $12
  12. 12. DISASSEMBLING
  13. 13. SOC: nRF51822 ● Single chip 2.4 GHz multi-protocol device ● 32-bit ARM Cortex M0 CPU core ● 256k Flash ● 32k RAM ● Bluetooth Low Energy 4.0 ● Thread safe and run-time protected ● Event driven API
  14. 14. +3.3v IO CLK GND
  15. 15. ● Feature-rich JS engine ● Declares nRF51822 support (as well as many other MCUs) ● Supports Bluetooth ● Has an IDE ● Auto-minifies JS ● Provides REPL via bluetooth ● & I had some prev. experience ;)
  16. 16. BUILD IT 1. Get Espruino release from github 2. Install gcc-arm-none-eabi-5_4-2016q3 toolchain 3. Build: BOARD=NUT2 RELEASE=1 make -> hex file is produced 4. Flash it to the board .:[ complete instructions ]:. ST-Link V2 ~ $2
  17. 17. LET’S CODE LED1.write(1); /* Turn led ON */ LED1.write(0); /* Turn led OFF */ function toggle() { state = !state; LED1.write(state); } /* Start timer */ setInterval(toggle, 500) /* Output frequency: 1000 hz square wave */ analogWrite(D30, 0.5, { freq: 1000 } )
  18. 18. function buzz(f, duration) { analogWrite(D30, 0.5, { freq: f } ); setTimeout(function() { pinMode(D30, 'input'); }, duration); } let mario_freq = new Uint16Array([330,330,0,330,0,262,330,0,392,0,0,196,0,0, ...]); let mario_temp = new Uint8Array([80 ,80,80,80,80,80,80,80,80,80,40,80,80,40, ...]); let pos = 0, tmr = -1; function step() { let freq = mario_freq[pos]; if (freq === undefined) return stop(); let temp = 10000/mario_temp[pos]; changeInterval(tmr, temp); buzz(freq, temp); pos++; } function stop() { if (tmr >= 0) { buzz(0); clearInterval(tmr); tmr = -1; } } function play_mario() { stop(); pos = 0; tmr = setInterval(step, 0); } Not too much simplified ;)
  19. 19. DEMO (plays Mario theme)
  20. 20. ● Platform abstraction ● Interactive, dynamic execution ● Event-Driven model ● Semi-automatic Power Management ● Perfect for prototyping ● Security BENEFITS
  21. 21. IN PRODUCTION Python, actually
  22. 22. Puck.js .:[nRF52]:. M5stack .:[ESP32]:. OUT OF THE BOX
  23. 23. .:[ Q & A ]:.
  24. 24. Volodymyr Shymanskyy Entrepreneur, Software & Hardware Developer, Trainer Co-Founder of Blynk, Hackerspace Coordinator ● Lots of projects ● 10+ years in IT, 8 in outsourcing and embedded ● Master’s degree in Cybernetics @ National Taras Shevchenko University of Kyiv > facebook > LinkedIn > vshymanskyi@gmail.com Disclaimer: these brands are not affiliated with current presentation or it’s topic
  25. 25. .:[ additional materials ]:.
  26. 26. TI CC2650 ~ $8.5 CPU 48MHz Flash 128 Kb RAM 28 Kb + Bluetooth 4.2 + 6LoWPAN EZ-BLE™ PSoC® ~ $10 CPU 48MHz Flash 128 Kb RAM 16 Kb + Bluetooth 4.1 TI CC3220 ~ $15.6 CPU 80 MHz Flash 1 Mb RAM 256 Kb + WiFi + secure + low power
  27. 27. OpenOCD: Backup source [find interface/cmsis-dap.cfg] set WORKAREASIZE 0 source [find target/nrf51.cfg] openocd_ble_nano.cfg:
  28. 28. OpenOCD: Backup $ openocd -f openocd_ble_nano.cfg Open On-Chip Debugger 0.9.0 (2015-09-02-10:42) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : only one transport option; autoselect 'swd' cortex_m reset_config sysresetreq adapter speed: 1000 kHz Info : CMSIS-DAP: SWD Supported Info : CMSIS-DAP: Interface Initialised (SWD) Info : CMSIS-DAP: FW Version = 1.0 Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1 Info : CMSIS-DAP: Interface ready Info : clock speed 1000 kHz Info : SWD IDCODE 0x0bb11477 Info : nrf51.cpu: hardware has 4 breakpoints, 2 watchpoints
  29. 29. OpenOCD: Backup $ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger > flash list {name nrf51 base 0 size 0 bus_width 1 chip_width 1} {name nrf51 base 268439552 size 0 bus_width 1 chip_width 1} > flash banks #0 : nrf51.flash (nrf51) at 0x00000000, size 0x00040000, buswidth 1, chipwidth 1 #1 : nrf51.uicr (nrf51) at 0x10001000, size 0x00000100, buswidth 1, chipwidth 1 > flash info 0 nRF51822-QFAA(build code: H0) 256kB Flash … > dump_image backup.bin 0x00000000 0x00040000 dumped 262144 bytes in 16.601297s (15.420 KiB/s) http://openocd.org/doc/html/Flash-Commands.html
  30. 30. OpenOCD: Restore $ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger > reset halt target state: halted target halted due to debug-request, current mode: Thread xPSR: 0xc1000000 pc: 0x000006d0 msp: 0x000007c0 > program backup.bin verify reset exit 0x00000000 ...

×