SlideShare a Scribd company logo
Embedded JavaScript
Mikrocontroller programmieren… mit JavaScript?!
Jens Siebert (@jens_siebert)
WebMontag Kassel, 11. Juni 2018
https://www.slideshare.net/JensSiebert1
Mikrocontroller
Embedded Programmierung bisher…
Embedded Programmierung bisher…
Embedded Programmierung bisher…
#define XTAL (12000000UL) /* Oscillator frequency */
#define OSC_CLK ( XTAL) /* Main oscillator frequency */
#define RTC_CLK ( 32000UL) /* RTC oscillator frequency */
#define IRC_OSC ( 4000000UL) /* Internal RC oscillator
frequency */
/* F_cco0 = (2 * M * F_in) / N */
#define __M (((PLL0CFG_Val ) & 0x7FFF) + 1)
#define __N (((PLL0CFG_Val >> 16) & 0x00FF) + 1)
#define __FCCO(__F_IN) ((2ULL * __M * __F_IN) / __N)
#define __CCLK_DIV (((CCLKCFG_Val ) & 0x00FF) + 1)
/* Determine core clock frequency according to settings */
#if (PLL0_SETUP)
#if ((CLKSRCSEL_Val & 0x03) == 1)
#define __CORE_CLK (__FCCO(OSC_CLK) / __CCLK_DIV)
#elif ((CLKSRCSEL_Val & 0x03) == 2)
#define __CORE_CLK (__FCCO(RTC_CLK) / __CCLK_DIV)
#else
#define __CORE_CLK (__FCCO(IRC_OSC) / __CCLK_DIV)
#endif
#else
#if ((CLKSRCSEL_Val & 0x03) == 1)
#define __CORE_CLK (OSC_CLK / __CCLK_DIV)
#elif ((CLKSRCSEL_Val & 0x03) == 2)
#define __CORE_CLK (RTC_CLK / __CCLK_DIV)
#else
#define __CORE_CLK (IRC_OSC / __CCLK_DIV)
#endif
#endif
uint32_t SystemCoreClock = __CORE_CLK;/*!< System Clock Frequency (Core Clock)*/
void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */
{
/* Determine clock frequency according to clock register values */
if (((LPC_SC->PLL0STAT >> 24) & 3) == 3) { /* If PLL0 enabled and connected */
switch (LPC_SC->CLKSRCSEL & 0x03) {
case 0: /* Int. RC oscillator => PLL0 */
case 3: /* Reserved, default to Int. RC */
SystemCoreClock = (IRC_OSC *
((2ULL * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));
break;
case 1: /* Main oscillator => PLL0 */
SystemCoreClock = (OSC_CLK *
((2ULL * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));
break;
case 2: /* RTC oscillator => PLL0 */
SystemCoreClock = (RTC_CLK *
((2ULL * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));
break;
}
}
else {
switch (LPC_SC->CLKSRCSEL & 0x03) {
case 0: /* Int. RC oscillator => PLL0 */
case 3: /* Reserved, default to Int. RC */
SystemCoreClock = IRC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
break;
case 1: /* Main oscillator => PLL0 */
SystemCoreClock = OSC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
break;
case 2: /* RTC oscillator => PLL0 */
SystemCoreClock = RTC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1);
break;
}
}
}
Embedded Programmierung bisher…
#include <stdint.h>
#include "LPC17xx.h“
#define CLOCK_SETUP 1
#define SCS_Val 0x00000020
#define CLKSRCSEL_Val 0x00000001
#define PLL0_SETUP 1
#ifdef MCB1700
# define PLL0CFG_Val 0x00050063
# define PLL1_SETUP 1
# define PLL1CFG_Val 0x00000023
# define CCLKCFG_Val 0x00000003
# define USBCLKCFG_Val 0x00000000
#else
# define PLL0CFG_Val 0x0000000B
# define PLL1_SETUP 0
# define PLL1CFG_Val 0x00000000
# define CCLKCFG_Val 0x00000002
# define USBCLKCFG_Val 0x00000005
#endif
#define PCLKSEL0_Val 0x00000000
#define PCLKSEL1_Val 0x00000000
#define PCONP_Val 0x042887DE
#define CLKOUTCFG_Val 0x00000000
#define FLASH_SETUP 1
#define FLASHCFG_Val 0x0000303A
#define CHECK_RANGE(val, min, max) ((val < min) || (val > max))
#define CHECK_RSVD(val, mask) (val & mask)
if (CHECK_RSVD((SCS_Val), ~0x00000030))
#error "SCS: Invalid values of reserved bits!"
#endif
#if (CHECK_RANGE((CLKSRCSEL_Val), 0, 2))
#error "CLKSRCSEL: Value out of range!"
#endif
#if (CHECK_RSVD((PLL0CFG_Val), ~0x00FF7FFF))
#error "PLL0CFG: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((PLL1CFG_Val), ~0x0000007F))
#error "PLL1CFG: Invalid values of reserved bits!"
#endif
#if (PLL0_SETUP) /* if PLL0 is used */
#if (CCLKCFG_Val < 2) /* CCLKSEL must be greater then 1 */
#error "CCLKCFG: CCLKSEL must be greater then 1 if PLL0 is used!"
#endif
#endif
#if (CHECK_RANGE((CCLKCFG_Val), 2, 255))
#error "CCLKCFG: Value out of range!"
#endif
#if (CHECK_RSVD((USBCLKCFG_Val), ~0x0000000F))
#error "USBCLKCFG: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((PCLKSEL0_Val), 0x000C0C00))
#error "PCLKSEL0: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((PCLKSEL1_Val), 0x03000300))
#error "PCLKSEL1: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((PCONP_Val), 0x10100821))
#error "PCONP: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((CLKOUTCFG_Val), ~0x000001FF))
#error "CLKOUTCFG: Invalid values of reserved bits!"
#endif
/* Flash Accelerator Configuration ------------------------*/
#if (CHECK_RSVD((FLASHCFG_Val), ~0x0000F07F))
#error "FLASHCFG: Invalid values of reserved bits!"
#endif
Embedded Programmierung bisher…
void SystemInit (void)
{
#if (CLOCK_SETUP) /* Clock Setup */
LPC_SC->SCS = SCS_Val;
if (LPC_SC->SCS & (1 << 5)) { /* If Main Oscillator is enabled */
while ((LPC_SC->SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready */
}
LPC_SC->CCLKCFG = CCLKCFG_Val; /* Setup Clock Divider */
/* Periphral clock must be selected before PLL0 enabling and connecting
* - according errata.lpc1768-16.March.2010 -
*/
LPC_SC->PCLKSEL0 = PCLKSEL0_Val; /* Peripheral Clock Selection */
LPC_SC->PCLKSEL1 = PCLKSEL1_Val;
#if (PLL0_SETUP)
LPC_SC->CLKSRCSEL = CLKSRCSEL_Val; /* Select Clock Source for PLL0 */
LPC_SC->PLL0CFG = PLL0CFG_Val; /* configure PLL0 */
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
LPC_SC->PLL0CON = 0x01; /* PLL0 Enable */
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */
LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */
#endif
#if (PLL1_SETUP)
LPC_SC->PLL1CFG = PLL1CFG_Val;
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
LPC_SC->PLL1CON = 0x01; /* PLL1 Enable */
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
while (!(LPC_SC->PLL1STAT & (1<<10)));/* Wait for PLOCK1 */
LPC_SC->PLL1CON = 0x03; /* PLL1 Enable & Connect */
LPC_SC->PLL1FEED = 0xAA;
LPC_SC->PLL1FEED = 0x55;
while (!(LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */
#else
LPC_SC->USBCLKCFG = USBCLKCFG_Val; /* Setup USB Clock Divider */
#endif
LPC_SC->PCONP = PCONP_Val; /* Power Control for Peripherals */
LPC_SC->CLKOUTCFG = CLKOUTCFG_Val; /* Clock Output Configuration */
#endif
#if (FLASH_SETUP == 1) /* Flash Accelerator Setup */
LPC_SC->FLASHCFG = (LPC_SC->FLASHCFG & ~0x0000F000) | FLASHCFG_Val;
#endif
}
Embedded Programmierung bisher…
- Volle Kontrolle über Hardware
- Teure (Entwicklungs-)Hardware
- Spezialwissen
- Für Hobbyanwender kaum geeignet
Die Revolution: Arduino!
Die Revolution: Arduino!
- Preiswerte Hardware
- Viel (preiswerte) Peripherie inkl. Bibliotheken verfügbar
- Für Hobbyanwender/Quereinsteiger/Rapid Prototyping gut geeignet
- Kein Debugger 
Und JavaScript?
Espruino
Espruino
- Preiswerte Hardware
- Viel (preiswerte) Peripherie inkl.
Bibliotheken verfügbar
- Für Hobbyanwender/Quereinsteiger/Rapid
Prototyping gut geeignet
- Debugger verfügbar 
Demo Time!
Beispiel: Temperatur
function onTimer() {
// Messwert vom Temperatursensor auslesen
var t = E.getTemperature().toFixed(1);
// Backbuffer loeschen
g.clear();
// Kleine Schriftart für die Titelzeile auswaehlen
g.setFontBitmap();
// Titelzeile zeichnen
g.drawString("Temperature:");
// Grosse Schriftart für den Messwert auswaehlen
g.setFontVector(40);
// Messwert zentriert zeichnen, 10px Abstand vom oberen Rand
g.drawString(t, (g.getWidth() - g.stringWidth(t))/2, 10);
// Backbuffer auf Display darstellen
g.flip();
}
// Messwert und Display-Inhalt alle zwei Sekunden aktualisieren
setInterval(onTimer,2000);
// Initiale Darstellung des Messwertes
onTimer();
Beispiel: Luftfeuchtigkeit
// I2C-Schnittstelle konfigurieren
I2C1.setup( {scl: A5, sda: A4 } );
// HTU21D-Modul laden und über I2C-Schnittstelle verbinden
var htu = require('HTU21D').connect( I2C1 );
function onTimer() {
// Messwert vom Luftfeuchtesensor auslesen
var t = htu.readHumidity().toFixed(1);
// Backbuffer loeschen
g.clear();
// Kleine Schriftart für die Titelzeile auswaehlen
g.setFontBitmap();
// Titelzeile zeichnen
g.drawString("Humidity:");
// Grosse Schriftart für den Messwert auswaehlen
g.setFontVector(40);
// Messwert zentriert zeichnen, 10px Abstand vom oberen Rand
g.drawString(t, (g.getWidth() - g.stringWidth(t))/2, 10);
// Backbuffer auf Display darstellen
g.flip();
}
// Messwert und Display-Inhalt alle zwei Sekunden aktualisieren
setInterval(onTimer,2000);
// Initiale Darstellung des Messwertes
onTimer();
Beispiel: Bluetooth LE
// I2C-Schnittstelle konfigurieren
I2C1.setup( {scl: A5, sda: A4 } );
// HTU21D-Modul laden und über I2C-Schnittstelle verbinden
var htu = require('HTU21D').connect( I2C1 );
// Verfuegbare BLE Services und Charakteristiken bekannt machen
NRF.setServices({
// Envrionmental Sensing Service konfigurieren
0x181A: {
// Temperatur Charakteristik konfigurieren
0x2A6E: {
readable: true,
notify: true,
writeable: false,
value: new Int16Array([E.getTemperature() * 100]).buffer
},
// Luftfeuchte Charakteristik konfigurieren
0x2A6F: {
readable: true,
notify: true,
writeable: false,
value: new Uint16Array([htu.readHumidity() * 100]).buffer
}
}
// Envrionmental Sensing Service bekannt machen
}, {advertise: ['0x181A']});
// Messwerte erfassen und Benachrichtigungen versenden
function onTimer() {
NRF.updateServices({
// Envrionmental Sensing Service aktualisieren
0x181A: {
// Temperatur Charakteristik aktualisieren
0x2A6E: {
value: new Int16Array([E.getTemperature() * 100]).buffer,
notify: true
},
// Luftfeuchte Charakteristik aktualisieren
0x2A6F: {
value: new Uint16Array([htu.readHumidity() * 100]).buffer,
notify: true
}
}
});
}
NRF.on('connect', function(addr) {
// Messwert aktualisieren und uebermitteln
setInterval(onTimer, 2000);
// Initiale Uebermittlung des Messwertes
onTimer();
});
Beispiel: Bluetooth LE
Literatur
Vielen Dank!
https://www.espruino.com
https://www.espruino.com/Pixl.js
Tessel: https://www.tessel.io
Neonious: https://www.neonious.com
Slides: https://www.slideshare.net/JensSiebert1
Twitter: @jens_siebert

More Related Content

PDF
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
PDF
Advanced cfg bypass on adobe flash player 18 defcon russia 23
PDF
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
PDF
Zn task - defcon russia 20
PDF
Bare metal performance in Elixir
PPT
W8_2: Inside the UoS Educational Processor
PDF
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
DOCX
(381877808) 102054282 5-listing-program
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
Advanced cfg bypass on adobe flash player 18 defcon russia 23
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
Zn task - defcon russia 20
Bare metal performance in Elixir
W8_2: Inside the UoS Educational Processor
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
(381877808) 102054282 5-listing-program

What's hot (20)

PDF
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
ODP
FPGA Tutorial - LCD Interface
DOCX
Uart
PDF
Implementing Lightweight Networking
PDF
Devirtualizing FinSpy
PDF
Implementation of the ZigBee ZCL Reporting Configuration Features
PDF
UART MCU
PPT
Troubleshooting Linux Kernel Modules And Device Drivers
PDF
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
ODP
Sysprog 12
ODP
Sysprog 12
PDF
Handling Asynchronous Events in MCUs
DOCX
CODING IN ARDUINO
PDF
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
DOCX
Assembly language
PDF
망고100 보드로 놀아보자 15
DOC
Network security Lab manual
PPTX
Exception handling in Pipelining in COA
PDF
Verifikation - Metoder og Libraries
DOC
FINISHED_CODE
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
FPGA Tutorial - LCD Interface
Uart
Implementing Lightweight Networking
Devirtualizing FinSpy
Implementation of the ZigBee ZCL Reporting Configuration Features
UART MCU
Troubleshooting Linux Kernel Modules And Device Drivers
No instrumentation Golang Logging with eBPF (GoSF talk 11/11/20)
Sysprog 12
Sysprog 12
Handling Asynchronous Events in MCUs
CODING IN ARDUINO
SFO15-202: Towards Multi-Threaded Tiny Code Generator (TCG) in QEMU
Assembly language
망고100 보드로 놀아보자 15
Network security Lab manual
Exception handling in Pipelining in COA
Verifikation - Metoder og Libraries
FINISHED_CODE
Ad

Similar to Embedded JavaScript (20)

DOCX
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
DOCX
Lampiran 1.programdocx
DOCX
PDF
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
PDF
PWM wave generator using microcontroller
PDF
Pwm wave
DOCX
DOCX
codings related to avr micro controller
PDF
PLEASE HELP!Modify the source code to implement the followingCh.pdf
PDF
Arduino Workshop 2011.05.31
PPTX
How to use peripherals on MCB1700
DOCX
Lab #5_Revised  (Due 121315)This is a revision on the previous.docx
PDF
JS Fest 2018. Володимир Шиманський. Запуск двіжка JS на мікроконтролері
PDF
From Arduino to LinnStrument
ODP
Interfacing to lcd with arduino
TXT
PIC and LCD
DOCX
eece237lab2EECE237Lab2.uvproj 1.1 ### uVision .docx
PDF
2 unit-es-printed
PDF
Design and build a wireless transceiver using nrf24l01p single chip 2.4g hz
PDF
Itsp documentation quadcopter flight controller based on kalman filters
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
Lampiran 1.programdocx
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
PWM wave generator using microcontroller
Pwm wave
codings related to avr micro controller
PLEASE HELP!Modify the source code to implement the followingCh.pdf
Arduino Workshop 2011.05.31
How to use peripherals on MCB1700
Lab #5_Revised  (Due 121315)This is a revision on the previous.docx
JS Fest 2018. Володимир Шиманський. Запуск двіжка JS на мікроконтролері
From Arduino to LinnStrument
Interfacing to lcd with arduino
PIC and LCD
eece237lab2EECE237Lab2.uvproj 1.1 ### uVision .docx
2 unit-es-printed
Design and build a wireless transceiver using nrf24l01p single chip 2.4g hz
Itsp documentation quadcopter flight controller based on kalman filters
Ad

More from Jens Siebert (19)

PDF
WebAssembly
PDF
Embedded Rust
PDF
Embedded Rust
PPTX
Microservices mit Rust
PPTX
Backend-Services mit Rust
PPTX
TinyML – Machine Learning für eingebettete Systeme
PPTX
Deep Learning mit TensorFlow.js
PPTX
Chatbots bauen mit dem Microsoft Bot Framework
PPTX
Integrating The Things Network Applications with Azure IoT Services
PPTX
GraphQL
PPTX
Windows 10 IoT Core
PPTX
Microsoft Bot Framework (Node.js Edition)
PPTX
Microsoft Bot Framework (.NET Edition)
PPTX
Electron
PPTX
Windows 10 IoT Core
PPTX
Physical Web
PPTX
Windows 10 IoT Core
PPTX
TypeScript
PPTX
TypeScript
WebAssembly
Embedded Rust
Embedded Rust
Microservices mit Rust
Backend-Services mit Rust
TinyML – Machine Learning für eingebettete Systeme
Deep Learning mit TensorFlow.js
Chatbots bauen mit dem Microsoft Bot Framework
Integrating The Things Network Applications with Azure IoT Services
GraphQL
Windows 10 IoT Core
Microsoft Bot Framework (Node.js Edition)
Microsoft Bot Framework (.NET Edition)
Electron
Windows 10 IoT Core
Physical Web
Windows 10 IoT Core
TypeScript
TypeScript

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Introduction to Artificial Intelligence
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms II-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How to Migrate SBCGlobal Email to Yahoo Easily
2025 Textile ERP Trends: SAP, Odoo & Oracle
Introduction to Artificial Intelligence
CHAPTER 2 - PM Management and IT Context
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Navsoft: AI-Powered Business Solutions & Custom Software Development
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Softaken Excel to vCard Converter Software.pdf
Online Work Permit System for Fast Permit Processing
How Creative Agencies Leverage Project Management Software.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Odoo POS Development Services by CandidRoot Solutions
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms II-SECS-1021-03

Embedded JavaScript

  • 1. Embedded JavaScript Mikrocontroller programmieren… mit JavaScript?! Jens Siebert (@jens_siebert) WebMontag Kassel, 11. Juni 2018 https://www.slideshare.net/JensSiebert1
  • 5. Embedded Programmierung bisher… #define XTAL (12000000UL) /* Oscillator frequency */ #define OSC_CLK ( XTAL) /* Main oscillator frequency */ #define RTC_CLK ( 32000UL) /* RTC oscillator frequency */ #define IRC_OSC ( 4000000UL) /* Internal RC oscillator frequency */ /* F_cco0 = (2 * M * F_in) / N */ #define __M (((PLL0CFG_Val ) & 0x7FFF) + 1) #define __N (((PLL0CFG_Val >> 16) & 0x00FF) + 1) #define __FCCO(__F_IN) ((2ULL * __M * __F_IN) / __N) #define __CCLK_DIV (((CCLKCFG_Val ) & 0x00FF) + 1) /* Determine core clock frequency according to settings */ #if (PLL0_SETUP) #if ((CLKSRCSEL_Val & 0x03) == 1) #define __CORE_CLK (__FCCO(OSC_CLK) / __CCLK_DIV) #elif ((CLKSRCSEL_Val & 0x03) == 2) #define __CORE_CLK (__FCCO(RTC_CLK) / __CCLK_DIV) #else #define __CORE_CLK (__FCCO(IRC_OSC) / __CCLK_DIV) #endif #else #if ((CLKSRCSEL_Val & 0x03) == 1) #define __CORE_CLK (OSC_CLK / __CCLK_DIV) #elif ((CLKSRCSEL_Val & 0x03) == 2) #define __CORE_CLK (RTC_CLK / __CCLK_DIV) #else #define __CORE_CLK (IRC_OSC / __CCLK_DIV) #endif #endif uint32_t SystemCoreClock = __CORE_CLK;/*!< System Clock Frequency (Core Clock)*/ void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */ { /* Determine clock frequency according to clock register values */ if (((LPC_SC->PLL0STAT >> 24) & 3) == 3) { /* If PLL0 enabled and connected */ switch (LPC_SC->CLKSRCSEL & 0x03) { case 0: /* Int. RC oscillator => PLL0 */ case 3: /* Reserved, default to Int. RC */ SystemCoreClock = (IRC_OSC * ((2ULL * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) / (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) / ((LPC_SC->CCLKCFG & 0xFF)+ 1)); break; case 1: /* Main oscillator => PLL0 */ SystemCoreClock = (OSC_CLK * ((2ULL * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) / (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) / ((LPC_SC->CCLKCFG & 0xFF)+ 1)); break; case 2: /* RTC oscillator => PLL0 */ SystemCoreClock = (RTC_CLK * ((2ULL * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) / (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) / ((LPC_SC->CCLKCFG & 0xFF)+ 1)); break; } } else { switch (LPC_SC->CLKSRCSEL & 0x03) { case 0: /* Int. RC oscillator => PLL0 */ case 3: /* Reserved, default to Int. RC */ SystemCoreClock = IRC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1); break; case 1: /* Main oscillator => PLL0 */ SystemCoreClock = OSC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1); break; case 2: /* RTC oscillator => PLL0 */ SystemCoreClock = RTC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1); break; } } }
  • 6. Embedded Programmierung bisher… #include <stdint.h> #include "LPC17xx.h“ #define CLOCK_SETUP 1 #define SCS_Val 0x00000020 #define CLKSRCSEL_Val 0x00000001 #define PLL0_SETUP 1 #ifdef MCB1700 # define PLL0CFG_Val 0x00050063 # define PLL1_SETUP 1 # define PLL1CFG_Val 0x00000023 # define CCLKCFG_Val 0x00000003 # define USBCLKCFG_Val 0x00000000 #else # define PLL0CFG_Val 0x0000000B # define PLL1_SETUP 0 # define PLL1CFG_Val 0x00000000 # define CCLKCFG_Val 0x00000002 # define USBCLKCFG_Val 0x00000005 #endif #define PCLKSEL0_Val 0x00000000 #define PCLKSEL1_Val 0x00000000 #define PCONP_Val 0x042887DE #define CLKOUTCFG_Val 0x00000000 #define FLASH_SETUP 1 #define FLASHCFG_Val 0x0000303A #define CHECK_RANGE(val, min, max) ((val < min) || (val > max)) #define CHECK_RSVD(val, mask) (val & mask) if (CHECK_RSVD((SCS_Val), ~0x00000030)) #error "SCS: Invalid values of reserved bits!" #endif #if (CHECK_RANGE((CLKSRCSEL_Val), 0, 2)) #error "CLKSRCSEL: Value out of range!" #endif #if (CHECK_RSVD((PLL0CFG_Val), ~0x00FF7FFF)) #error "PLL0CFG: Invalid values of reserved bits!" #endif #if (CHECK_RSVD((PLL1CFG_Val), ~0x0000007F)) #error "PLL1CFG: Invalid values of reserved bits!" #endif #if (PLL0_SETUP) /* if PLL0 is used */ #if (CCLKCFG_Val < 2) /* CCLKSEL must be greater then 1 */ #error "CCLKCFG: CCLKSEL must be greater then 1 if PLL0 is used!" #endif #endif #if (CHECK_RANGE((CCLKCFG_Val), 2, 255)) #error "CCLKCFG: Value out of range!" #endif #if (CHECK_RSVD((USBCLKCFG_Val), ~0x0000000F)) #error "USBCLKCFG: Invalid values of reserved bits!" #endif #if (CHECK_RSVD((PCLKSEL0_Val), 0x000C0C00)) #error "PCLKSEL0: Invalid values of reserved bits!" #endif #if (CHECK_RSVD((PCLKSEL1_Val), 0x03000300)) #error "PCLKSEL1: Invalid values of reserved bits!" #endif #if (CHECK_RSVD((PCONP_Val), 0x10100821)) #error "PCONP: Invalid values of reserved bits!" #endif #if (CHECK_RSVD((CLKOUTCFG_Val), ~0x000001FF)) #error "CLKOUTCFG: Invalid values of reserved bits!" #endif /* Flash Accelerator Configuration ------------------------*/ #if (CHECK_RSVD((FLASHCFG_Val), ~0x0000F07F)) #error "FLASHCFG: Invalid values of reserved bits!" #endif
  • 7. Embedded Programmierung bisher… void SystemInit (void) { #if (CLOCK_SETUP) /* Clock Setup */ LPC_SC->SCS = SCS_Val; if (LPC_SC->SCS & (1 << 5)) { /* If Main Oscillator is enabled */ while ((LPC_SC->SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready */ } LPC_SC->CCLKCFG = CCLKCFG_Val; /* Setup Clock Divider */ /* Periphral clock must be selected before PLL0 enabling and connecting * - according errata.lpc1768-16.March.2010 - */ LPC_SC->PCLKSEL0 = PCLKSEL0_Val; /* Peripheral Clock Selection */ LPC_SC->PCLKSEL1 = PCLKSEL1_Val; #if (PLL0_SETUP) LPC_SC->CLKSRCSEL = CLKSRCSEL_Val; /* Select Clock Source for PLL0 */ LPC_SC->PLL0CFG = PLL0CFG_Val; /* configure PLL0 */ LPC_SC->PLL0FEED = 0xAA; LPC_SC->PLL0FEED = 0x55; LPC_SC->PLL0CON = 0x01; /* PLL0 Enable */ LPC_SC->PLL0FEED = 0xAA; LPC_SC->PLL0FEED = 0x55; while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */ LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */ LPC_SC->PLL0FEED = 0xAA; LPC_SC->PLL0FEED = 0x55; while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */ #endif #if (PLL1_SETUP) LPC_SC->PLL1CFG = PLL1CFG_Val; LPC_SC->PLL1FEED = 0xAA; LPC_SC->PLL1FEED = 0x55; LPC_SC->PLL1CON = 0x01; /* PLL1 Enable */ LPC_SC->PLL1FEED = 0xAA; LPC_SC->PLL1FEED = 0x55; while (!(LPC_SC->PLL1STAT & (1<<10)));/* Wait for PLOCK1 */ LPC_SC->PLL1CON = 0x03; /* PLL1 Enable & Connect */ LPC_SC->PLL1FEED = 0xAA; LPC_SC->PLL1FEED = 0x55; while (!(LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */ #else LPC_SC->USBCLKCFG = USBCLKCFG_Val; /* Setup USB Clock Divider */ #endif LPC_SC->PCONP = PCONP_Val; /* Power Control for Peripherals */ LPC_SC->CLKOUTCFG = CLKOUTCFG_Val; /* Clock Output Configuration */ #endif #if (FLASH_SETUP == 1) /* Flash Accelerator Setup */ LPC_SC->FLASHCFG = (LPC_SC->FLASHCFG & ~0x0000F000) | FLASHCFG_Val; #endif }
  • 8. Embedded Programmierung bisher… - Volle Kontrolle über Hardware - Teure (Entwicklungs-)Hardware - Spezialwissen - Für Hobbyanwender kaum geeignet
  • 10. Die Revolution: Arduino! - Preiswerte Hardware - Viel (preiswerte) Peripherie inkl. Bibliotheken verfügbar - Für Hobbyanwender/Quereinsteiger/Rapid Prototyping gut geeignet - Kein Debugger 
  • 13. Espruino - Preiswerte Hardware - Viel (preiswerte) Peripherie inkl. Bibliotheken verfügbar - Für Hobbyanwender/Quereinsteiger/Rapid Prototyping gut geeignet - Debugger verfügbar 
  • 15. Beispiel: Temperatur function onTimer() { // Messwert vom Temperatursensor auslesen var t = E.getTemperature().toFixed(1); // Backbuffer loeschen g.clear(); // Kleine Schriftart für die Titelzeile auswaehlen g.setFontBitmap(); // Titelzeile zeichnen g.drawString("Temperature:"); // Grosse Schriftart für den Messwert auswaehlen g.setFontVector(40); // Messwert zentriert zeichnen, 10px Abstand vom oberen Rand g.drawString(t, (g.getWidth() - g.stringWidth(t))/2, 10); // Backbuffer auf Display darstellen g.flip(); } // Messwert und Display-Inhalt alle zwei Sekunden aktualisieren setInterval(onTimer,2000); // Initiale Darstellung des Messwertes onTimer();
  • 16. Beispiel: Luftfeuchtigkeit // I2C-Schnittstelle konfigurieren I2C1.setup( {scl: A5, sda: A4 } ); // HTU21D-Modul laden und über I2C-Schnittstelle verbinden var htu = require('HTU21D').connect( I2C1 ); function onTimer() { // Messwert vom Luftfeuchtesensor auslesen var t = htu.readHumidity().toFixed(1); // Backbuffer loeschen g.clear(); // Kleine Schriftart für die Titelzeile auswaehlen g.setFontBitmap(); // Titelzeile zeichnen g.drawString("Humidity:"); // Grosse Schriftart für den Messwert auswaehlen g.setFontVector(40); // Messwert zentriert zeichnen, 10px Abstand vom oberen Rand g.drawString(t, (g.getWidth() - g.stringWidth(t))/2, 10); // Backbuffer auf Display darstellen g.flip(); } // Messwert und Display-Inhalt alle zwei Sekunden aktualisieren setInterval(onTimer,2000); // Initiale Darstellung des Messwertes onTimer();
  • 17. Beispiel: Bluetooth LE // I2C-Schnittstelle konfigurieren I2C1.setup( {scl: A5, sda: A4 } ); // HTU21D-Modul laden und über I2C-Schnittstelle verbinden var htu = require('HTU21D').connect( I2C1 ); // Verfuegbare BLE Services und Charakteristiken bekannt machen NRF.setServices({ // Envrionmental Sensing Service konfigurieren 0x181A: { // Temperatur Charakteristik konfigurieren 0x2A6E: { readable: true, notify: true, writeable: false, value: new Int16Array([E.getTemperature() * 100]).buffer }, // Luftfeuchte Charakteristik konfigurieren 0x2A6F: { readable: true, notify: true, writeable: false, value: new Uint16Array([htu.readHumidity() * 100]).buffer } } // Envrionmental Sensing Service bekannt machen }, {advertise: ['0x181A']}); // Messwerte erfassen und Benachrichtigungen versenden function onTimer() { NRF.updateServices({ // Envrionmental Sensing Service aktualisieren 0x181A: { // Temperatur Charakteristik aktualisieren 0x2A6E: { value: new Int16Array([E.getTemperature() * 100]).buffer, notify: true }, // Luftfeuchte Charakteristik aktualisieren 0x2A6F: { value: new Uint16Array([htu.readHumidity() * 100]).buffer, notify: true } } }); } NRF.on('connect', function(addr) { // Messwert aktualisieren und uebermitteln setInterval(onTimer, 2000); // Initiale Uebermittlung des Messwertes onTimer(); });
  • 20. Vielen Dank! https://www.espruino.com https://www.espruino.com/Pixl.js Tessel: https://www.tessel.io Neonious: https://www.neonious.com Slides: https://www.slideshare.net/JensSiebert1 Twitter: @jens_siebert

Editor's Notes

  • #3: ARM 32-bit Cortex-M4 CPU with FPU, up to 84 MHz, up to 512 Kbytes of Flash memory, up to 96 Kbytes of SRAM, 146 μA/MHz (Run), 2.4 μA (Standby)