how to control physical devices with mruby
DESCRIPTION
RubyConf2013: "How to control physical devices with mruby" by YamanekkoTRANSCRIPT
![Page 1: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/1.jpg)
How to control How to control physical devicesphysical devices
with mrubywith mrubyRubyConf 2013RubyConf 2013
Team YamanekkoTeam YamanekkoYurie Yamane / Masayoshi TakahashiYurie Yamane / Masayoshi Takahashi
![Page 2: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/2.jpg)
Demo
Blinking 4 LEDson STM32F4 Discovery(using Timer)
![Page 3: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/3.jpg)
DEMO (STM32F4 Discovery)● blinking LED
Green on -> Orange on -> Red on -> Blue on -> Green off -> Orange off -> Red off -> Blue off -> ...
![Page 4: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/4.jpg)
Contents● Demo (STM32F4 Discovery)● Introduction● What's mruby● 7 steps to use mruby● Demo (Raspberry Pi)● Another Demo (STM32F4 Discovery)
![Page 5: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/5.jpg)
Who are we?
●やまね ゆりえ (Yurie Yamane)●高橋征義 (Masayoshi Takahashi)
![Page 6: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/6.jpg)
Who are we?
Team Yamanekko
![Page 7: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/7.jpg)
Independent E-Book Publisher
http://tatsu-zine.com/
Tatsu-zine Publishing Inc.
![Page 8: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/8.jpg)
This session is supported by
http://ruby-no-kai.org/
![Page 9: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/9.jpg)
members of asakusa.rb
![Page 10: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/10.jpg)
Who are we?
●Not professional Embedded programmers– it's our hobby project
●not made e-book reader yet
![Page 11: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/11.jpg)
Our goals
“embedded programming for everyone without hassle”
![Page 12: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/12.jpg)
Our talks
RubyConf2012
![Page 13: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/13.jpg)
Our talks
RubyConf.tw 2012
![Page 14: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/14.jpg)
Our talks
OSDC.tw 2013
![Page 15: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/15.jpg)
Our talks
http://www.flickr.com/photos/igaiga/8564676738/
Ôedo RubyKaigi 03
![Page 16: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/16.jpg)
Embedded is hard??
●small memory●RTOS or no OS●no STDIO●cross compile C/C++/Asm●cross debugger with ICE
![Page 17: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/17.jpg)
Embedded is hard??
●small memory●RTOS or no OS●no STDIO●cross compile C/C++/Asm●cross debugger with ICE
![Page 18: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/18.jpg)
http://mrb.h2so5.net/
![Page 19: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/19.jpg)
What's mruby?
● “yet another implementation of Ruby”–not a new language nor variant
![Page 20: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/20.jpg)
CRuby vs mruby
●mruby is not “an application”●mruby is “a part”
–embedded into other application●webserver, editor, game, ...
–embedded into other systems●robot, router, vending machine, ...
![Page 21: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/21.jpg)
mruby's feature
(1) embeddable(2) configurable(3) pluggable
![Page 22: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/22.jpg)
(1) embeddable
*.rb
C/C++ app
CRuby app mruby app
*.rb(bytecode)
/usr/bin/ruby
libmruby.a
![Page 23: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/23.jpg)
CRuby
/usr/bin/ruby
*.rb (your code)
*.rb (stdlib) Gems
![Page 24: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/24.jpg)
mruby
mruby core
*.rb (stdlib)
*.rb (your code)
C/C++libmruby.a
Bytecode(C String)
mrbgems
Bytecode(C String)
![Page 25: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/25.jpg)
(2) configurable● mruby has many #define macros to configure
– float or double as Float object– using NaN boxing or not– default size of heap, pool, khash, ...
● You can change them at compile time
![Page 26: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/26.jpg)
#define in mrbconf.h● MRB_USE_FLOAT● MRB_INT64● MRB_NAN_BOXING● MRB_ENDIAN_BIG● MRB_FUNCALL_ARGC_MAX● MRB_HEAP_PAGE_SIZE● MRB_USE_IV_SEGLIST● MRB_IVHASH_INIT_SIZE
● MRB_IREP_ARRAY_INIT_SIZE● KHASH_DEFAULT_SIZE● POOL_ALIGNMENT● POOL_PAGE_SIZE● MRB_STR_BUF_MIN_SIZE● MRB_PARSER_BUF_SIZE● ENABLE_DEBUG
![Page 27: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/27.jpg)
(3) pluggable● mruby has mrbgems like RubyGems● mrbgems in C are linked statically● some functions in CRuby are provided as gem– you can choose which is added / removed
![Page 28: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/28.jpg)
standard mrbgems● mrbgems/mruby-array-ext● mrbgems/mruby-enum-ext● mrbgems/mruby-eval● mrbgems/mruby-exit● mrbgems/mruby-fiber● mrbgems/mruby-hash-ext● mrbgems/mruby-math● mrbgems/mruby-numeric-ext● mrbgems/mruby-object-ext● mrbgems/mruby-objectspace
● mrbgems/mruby-print● mrbgems/mruby-proc-ext● mrbgems/mruby-random● mrbgems/mruby-range-ext● mrbgems/mruby-sprintf● mrbgems/mruby-string-ext● mrbgems/mruby-struct● mrbgems/mruby-symbol-ext● mrbgems/mruby-time● mrbgems/mruby-toplevel-ext
you can remove them all
![Page 29: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/29.jpg)
7 steps to use mruby ● choose your target board● setup development environments● write application● cross build● transfer binary to the board● cross debugging● it works!
![Page 30: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/30.jpg)
7 steps to use mruby ● choose your target board● setup development environments● write application● cross build● transfer binary to the board● cross debugging● it works!
![Page 31: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/31.jpg)
Our targets crieteria● easy to buy around the world
– some are hard outside Japan :(● don't use apps depending on OSs or environments
– FLOSS tools are better● a bit large memory that mruby can run on
– > 64KB is MUST, > 1MB is BETTER
![Page 32: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/32.jpg)
(1) STM32F4 Discovery● ARM (Cortex M4)● 1MB Flash, 192KB RAM● 8LEDs, 2Buttons, MEMS Accelerometer etc.
● on board STLINK
http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252419
![Page 33: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/33.jpg)
(2) Raspberry Pi● ARM (arm1176jzf-s)● 256/512MB RAM● SD card● 700mA (3.5W)● JTAG
![Page 34: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/34.jpg)
ARM11 & Cortex-M4
Raspberry Pi
STM32F4
http://www.emcu.it/CortexFamily/CortexFamily.html
![Page 35: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/35.jpg)
**NOTICE**
● We do not use OS on Raspberry Pi– no raspbian nor other Linux/Unix
![Page 36: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/36.jpg)
Why no OS (bare metal)?● same as STM32F4 Discovery
–STM32F4 Discovery is used without OS● We want to use Raspberry Pi like MCU, not PC
– just as MCU with HUGE memory–If using Linux, even CRuby can work on Raspberry Pi :-/
● Bare metal programming is fun :-)
![Page 37: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/37.jpg)
bare metal RasPi Programming
● dwelch67's github repos is incredibly useful– https://github.com/dwelch67/raspberrypi– everything we need is here
![Page 38: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/38.jpg)
STM32F4d architecture
CortexMCU
Systicktimer
NVICinterrupt controller
otherperipheralsM
CU
Peripheral Register & Interrupt Vector Definitions
Core PeripheralFunctions
Device PeripheralFunctions
mruby core (in c)
mrbgems for STM32F4 Discovery
Ruby code (*.rb → bytecode)
CMSI
Sap
ps
libc (newlib), syscalls
libmruby.amain(c)
![Page 39: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/39.jpg)
Raspberry Pi architecture
ARM11MCU
Timer Other BCM2385peripheralsSo
C
mruby core
mrbgems for Raspberry Pi
Ruby code (*.rb → bytecode)
apps
libc (newlib), syscalls
vectors.s
libmruby.a
![Page 40: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/40.jpg)
7 steps to use mruby ● choose your target board● setup development environments● write application● cross build● transfer binary to the board● cross debugging● it works!
![Page 41: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/41.jpg)
Our Development Environment
● Cross Compiler: GNU tool chain● IDE: Eclipse CDT + our original plugin● Debugging :
– STLINK (for STM32F4d)– JTAG (for RasPi)
![Page 42: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/42.jpg)
cross compiler for STM32F4GNU Tools for ARM Embedded Processors (https://launchpad.net/gcc-arm-embedded)
![Page 43: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/43.jpg)
cross compiler for RasPi● 'GNU Tools for ARM Embedded Processors' is...
– “1. ARM11 is not our primary targets, so those tools are not tested on such targets.”
– “Thus I don't recommend this tool chain for Raspberry Pi.”https://answers.launchpad.net/gcc-arm-embedded/+question/227876
● So we use GNU Tools built by our own.https://github.com/dwelch67/build_gcc/blob/master/build_arm
![Page 44: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/44.jpg)
PC
How to debug with STM32F4d
STM32F4d
EclipseSTLINK stlink
USB cable
stlink: https://github.com/texane/stlink
gdbfor arm
arm-none-eabi-gdb
![Page 45: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/45.jpg)
PC
How to debug with RasPi
RasPi
USB and JTAG cable
OpenOCD: http://openocd.sf.net/armjtag: https://github.com/dwelch67/raspberrypi/tree/master/armjtag
Eclipsearmjtag OpenOCD gdbfor arm
arm-none-eabi-gdb
![Page 46: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/46.jpg)
JTAG debugger (hardware)
● connect ARM via USB
https://www.olimex.com/Products/ARM/JTAG/ARM-USB-TINY-H/
ARM-USB-TINY-H
![Page 47: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/47.jpg)
JTAG debugger (hardware)
● connect JTAG cable
and RasPi● Use 6pins only (and GND)
https://www.olimex.com/Products/ARM/_resources/arm-jtag-layout.gif
![Page 48: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/48.jpg)
JTAG debugger (software)
● You can do fash programming and GDB debugging with OpenOCD.
http://openocd.sourceforge.net/
![Page 49: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/49.jpg)
armjtag
https://github.com/dwelch67/raspberrypi/tree/master/armjtag
“an alternate bootloader”“The ARM11 on the Raspberry Pi has a jtag based debug port for software development.”
![Page 50: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/50.jpg)
are you tired?
![Page 51: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/51.jpg)
7 steps to use mruby ● choose your target board● setup development environments● write application● cross build● transfer binary to the board● cross debugging● it works!
![Page 52: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/52.jpg)
write application
● write Ruby code● write mrbgems● write C code
![Page 53: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/53.jpg)
Including Ruby code in mruby
● As source code of Ruby– Human readable
● As Byte code– Machine readable
![Page 54: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/54.jpg)
Including Ruby code in mruby
● As source code of Ruby– Human readable
● As Byte code– Machine readable
![Page 55: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/55.jpg)
hello world in mruby (1)#include <stdlib.h>#include <stdio.h>#include <mruby.h>#include <mruby/compile.h>
int main(void){ mrb_state *mrb = mrb_open(); char code[] = "p 'hello world!'"; mrb_load_string(mrb, code); mrb_close(mrb); return 0;}
![Page 56: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/56.jpg)
hello world in mruby (1)
mrb_state *mrb = mrb_open(); char code[] = "p 'hello world!'"; mrb_load_string(mrb, code); mrb_close(mrb);
![Page 57: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/57.jpg)
Including Ruby code in mruby
● As source code of Ruby– Human readable
● As Byte code– Machine readable
![Page 58: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/58.jpg)
hello world in mruby (2) mrb_state *mrb = mrb_open();
const uint8_t bcode[] = { 0x52,0x49,0x54,0x45,0x30,0x30,0x30, (… byte byte byte …) 0x00,0x00,0x00,0x00,0x08, };
mrb_load_irep(mrb, bcode); mrb_close(mrb);
![Page 59: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/59.jpg)
hello world in mruby (2)$ cat hello.rbp 'hello world!'$ ./bin/mrbc -Bbcode hello.rb$ cat hello.c#include <stdint.h>const uint8_t foo[] = {0x52,0x49,0x54,0x45,0x30,0x30,0x30,0x31,0xb9,0x71,0x00,0x00,0x00,0x65,0x4d,0x41,(…)0x00,0x00,0x00,0x00,0x08,};$
![Page 60: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/60.jpg)
mrb_open
Create and initialize new mruby VM
Usage:
mrb_state *mrb = mrb_open();
![Page 61: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/61.jpg)
mrb_close
release mruby VM
Usage:
mrb_close(mrb);
![Page 62: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/62.jpg)
mrb_load_irep
load mruby bytecode and execute.
Usage:
mrb_load_irep(mrb, bcode);
![Page 63: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/63.jpg)
mruby API
In include/mruby.hand include/mruby/*.h
※all API has mrb_state at 1st arg.
ex. mrb_load_string(mrb, code);
![Page 64: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/64.jpg)
mrbgems
● “mruby gems” by bovi● library packaging system like RubyGems
● static linked with compile time
![Page 65: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/65.jpg)
mrbgem.rake
MRuby::Gem::Specification.new(
'mruby-rs-led') do |spec|
spec.license = 'MIT'
spec.authors = 'yamanekko'
end
![Page 66: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/66.jpg)
minirake
mruby has minirake full source– minimal rake clone by masuidrive– you do not have to install rake even if using Ruby 1.8
● mrbgems and mruby itself are built by minirake
![Page 67: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/67.jpg)
Why (mini)rake● old mruby used CMake● but mruby build system became complex
– build mrbgems (Ruby and C)– get source code from github– support gem bundle (gembox)
● we want to write them in Ruby
![Page 68: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/68.jpg)
build_config.rb
● Ruby (not mruby) script– Execute in host machine at building time
● DSL to build mruby● Load from Rakefile
![Page 69: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/69.jpg)
Default (minimal) build_config.rb
MRuby::Build.new do |conf|
toolchain :gcc
conf.gembox 'default'
end
![Page 70: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/70.jpg)
DEMO (Raspberry Pi)● blinking LED (like STM32F4 Discovery)
Green on -> Orange on -> Red on -> Blue on ->Green off -> Orange off -> Red off -> Blue off
![Page 71: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/71.jpg)
Ruby Code (init)
![Page 72: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/72.jpg)
Ruby Code (blink)
![Page 73: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/73.jpg)
7 steps to use mruby ● choose your target board● setup development environments● write application● cross build● transfer binary to the board● cross debugging● it works!
demousing Eclipse
![Page 74: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/74.jpg)
Install MrubyTools plugins
![Page 75: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/75.jpg)
Install MrubyTools plugins
![Page 76: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/76.jpg)
create mruby project● cloned from https://github.com/mruby/mruby
![Page 77: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/77.jpg)
CREATE CUSTOM mrbgems● create new mrbgem to control STM32F4-Discovery's LED
from ruby
![Page 78: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/78.jpg)
generated mrbgem filesmrbgem wizard can create necessary files, directory structure and template files
![Page 79: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/79.jpg)
generated mrbgem template
![Page 80: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/80.jpg)
add code for Led class
← class
← constants
↑ methods
![Page 81: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/81.jpg)
build_config.rb for RasPi
![Page 82: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/82.jpg)
libmruby.a generated
![Page 83: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/83.jpg)
CREATE RasPi'S PROJECT● Create new C project● Create new files
– demo.c– syscalls.c– vectors.s– memmap– makefile–
![Page 84: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/84.jpg)
create app project
![Page 85: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/85.jpg)
Write ruby code● Insert “beginning tag” and “ending tag”● write ruby code between beginning tag and ending tag● Two ways to embed ruby code1.Use menu bar
2.Use tool bar
Insert ruby code in .c file
Insert .rb file name in .c file
/* <ruby->
... <-ruby> */
/* <rubyfile->
aaa.rb <-rubyfile> */
![Page 86: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/86.jpg)
before conversion
![Page 87: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/87.jpg)
execute mrbc wrapper
![Page 88: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/88.jpg)
after conversion
![Page 89: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/89.jpg)
OpenOCD uses gdb and telnet
openocd
telnet
gdbEclipse
RasPi
port 3333
port 4444
command Interface
![Page 90: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/90.jpg)
openocd as external tool
![Page 91: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/91.jpg)
call openocd
![Page 92: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/92.jpg)
OpenOCD log in Eclipse
![Page 93: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/93.jpg)
connect OpenOCD via telnet
![Page 94: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/94.jpg)
setting gdb command
![Page 95: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/95.jpg)
Another Demo: blinking LED & MEMS Accelerometer
using STM32F4d
Push Button
Push Button
Power ON
blinkingmode
tilt sensormode
switching 2 modes by pushing button
![Page 96: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/96.jpg)
Tilt sensor in STM32F4d
● using 3-axis MEMS accelerometer in STM32F4 Discovery– only use 2 axis (X and Y)– LED show which side is downward
![Page 97: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/97.jpg)
Another Demo: blinking LED & MEMS Accelerometer
using STM32F4d
Push Button
Push Button
Power ON
blinkingmode
tilt sensormode
switching 2 modes by pushing button
![Page 98: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/98.jpg)
future issues● Ruby source level debugger
● support bytecodes generated by mrbc● more mrbgem samples
![Page 99: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/99.jpg)
Our Links● source code
● http://github.com/yamanekko/mruby/tree/rubyconf● Eclipse Plugin download site (for Eclipse)
– http://yamanekko.github.io/mruby-tools-EclipsePlugin● This slide
● http://slideshare.net/yamanekko/rubyconf2013
![Page 100: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/100.jpg)
Useful mruby linksmruby repos: https://github.com/mruby/mrubymruby.sh: http://blog.mruby.sh/Introduction to Lightweight Ruby "mruby" (by Toshiba): http://www.tjsys.co.jp/page.jsp?id=3059
mruby code search: http://mruby-code-search.ongaeshi.me/ngx_mruby: http://matsumoto-r.github.io/ngx_mruby/webruby: https://github.com/xxuejie/webrubymobiruby: http://mobiruby.org/
![Page 101: How to control physical devices with mruby](https://reader034.vdocuments.net/reader034/viewer/2022042513/554f938bb4c905435d8b51e4/html5/thumbnails/101.jpg)
Thanks!Happy mruby Hacking!
special thanks to: @tenderlove and @_zzak