This document provides an overview of controlling physical devices with the mruby embedded Ruby implementation. It describes a demo of blinking 4 LEDs on an STM32F4 Discovery board using timers. It then discusses what mruby is, outlines a 7 step process for using mruby, and describes demos on the STM32F4 Discovery and Raspberry Pi boards without an operating system. Development environments and debugging methods are also covered.
20. 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, ...
25. (2) configurable
●
mruby has many #define macros to configure
–
–
using NaN boxing or not
–
●
float or double as Float object
default size of heap, pool, khash, ...
You can change them at compile time
27. (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
29. 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!
30. 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!
31. Our targets crieteria
●
easy to buy around the world
–
●
don't use apps depending on OSs or environments
–
●
some are hard outside Japan :(
FLOSS tools are better
a bit large memory that mruby can run on
–
> 64KB is MUST, > 1MB is BETTER
32. (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
36. Why no OS (bare metal)?
●
same as STM32F4 Discovery
–
●
We want to use Raspberry Pi like MCU, not PC
–
–
●
STM32F4 Discovery is used without OS
just as MCU with HUGE memory
If using Linux, even CRuby can work on
Raspberry Pi :-/
Bare metal programming is fun :-)
37. bare metal RasPi Programming
●
dwelch67's github repos is incredibly useful
–
–
https:/
/github.com/dwelch67/raspberrypi
everything we need is here
38. apps
STM32F4d architecture
main
(c)
Ruby code (*.rb → bytecode)
mruby core (in c)
mrbgems for STM32F4 Discovery
libmruby.a
CMSIS
Core Peripheral
Device Peripheral
Functions
Functions
Peripheral Register & Interrupt Vector Definitions
MCU
libc (newlib), syscalls
Cortex
MCU
Systick
timer
NVIC
interrupt controller
other
peripherals
39. Raspberry Pi architecture
Ruby code (*.rb → bytecode)
apps
mruby core
mrbgems for Raspberry Pi
libmruby.a
libc (newlib), syscalls
SoC
vectors.s
ARM11
MCU
Timer
Other BCM2385
peripherals
40. 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!
41. Our Development Environment
●
Cross Compiler: GNU tool chain
●
IDE: Eclipse CDT + our original plugin
●
Debugging :
–
STLINK (for STM32F4d)
–
JTAG (for RasPi)
42. cross compiler for STM32F4
GNU Tools for ARM Embedded Processors
(https:/
/launchpad.net/gcc-arm-embedded)
43. 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
44. How to debug with STM32F4d
PC
STM32F4d
stlink
STLINK
USB cable
gdb
for arm
Eclipse
arm-none-eabi-gdb
stlink: https:/
/github.com/texane/stlink
45. How to debug with RasPi
PC
RasPi
armjtag
OpenOCD
USB and
JTAG cable
gdb
for arm
Eclipse
arm-none-eabi-gdb
OpenOCD: http:/
/openocd.sf.net/
armjtag:
https:/
/github.com/dwelch67/raspberrypi/tree/master/armjtag
51. 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!
66. 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
–
●
67. Why (mini)rake
●
old mruby used CMake
●
but mruby build system became complex
–
–
get source code from github
–
●
build mrbgems (Ruby and C)
support gem bundle (gembox)
we want to write them in Ruby
70. DEMO (Raspberry Pi)
●
blinking LED (like STM32F4 Discovery)
Green on -> Orange on -> Red on -> Blue on ->
Green off -> Orange off -> Red off -> Blue off
73. 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!
demo
using Eclipse
85. Write ruby code
●
Insert “beginning tag” and “ending tag”
●
write ruby code between beginning tag and ending tag
●
Two ways to embed ruby code
1. se
U
menu bar
Insert ruby code in .c file
2. se
U
tool bar
/* <ruby->
...
<-ruby> */
Insert .rb file name in .c file
/* <rubyfile->
aaa.rb
<-rubyfile> */
95. Another Demo: blinking LED &
MEMS Accelerometer
using STM32F4d
Power ON
blinking
mode
Push Button
Push Button
tilt sensor
mode
switching 2 modes by pushing button
96. 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
–
97. Another Demo: blinking LED &
MEMS Accelerometer
using STM32F4d
Power ON
blinking
mode
Push Button
Push Button
tilt sensor
mode
switching 2 modes by pushing button