Lua is a powerful, easy to learn, robust scripting language. eLua brings all the features of Lua into several Microcontrollers. In this speech, held on The Developers Conference 2016 in São Paulo, the advantages of using Lua and the main characteristics of eLua project were presented. At the end a quick demonstration of a Lua script running in a microcontroller was show.
1. COPYRIGHT 2016 – Fundação CERTI
eLua – Lua for
Microcontrollers
Vinicius Zein
Bruno Herrera
2. COPYRIGHT 2016 – Fundação CERTI
https://br.linkedin.com/in/viniciuszein
Vinicius Tadeu Zein
www.linkedin.com/in/bherrera
Bruno Herrera
3. COPYRIGHT 2016 – Fundação CERTI
R&D Institute
Founded in 1984 with the mission to
develop technology solutions for products
and processes
500 employees
Private, but results are reinvested in R&D
MCTI and SUFRAMA accredited – projects
with “Lei de Informática”, “Lei do Bem” and
Embrapii
More than 500 clients around the world
4. The information in this presentation was compiled from sources believed to be
reliable for informational purposes only.
Content includes opinions, presentations, articles, hyperlinks or other third
party content (“Third Party Material”) that is not intended to, nor constitutes an
endorsement by CERTI of the author or the Third Party Materials. The content
and views within the Third Party Material are solely those of the third party and
do not reflect the opinions of CERTI.
The opinions expressed in this presentation and on the following slides are
solely those of the
presenter and not necessarily those of CERTI. CERTI does not guarantee the
accuracy or
reliability of the information provided herein.
. Disclaimer
5. COPYRIGHT 2016 – Fundação CERTI
Ag
en
da
CAPÍTULO 1
Introdução
CAPÍTULO 2
Lógica de
negócios
CAPÍTULO 3
Embedded Lua
CAPÍTULO 4
DevKits e build
CAPÍTULO 5
eLua demo
CAPÍTULO 6
Wrap-up
12. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 2 | LÓGICA DE NEGÓCIOS
Business Logic with script > Motivação
Processo de
Desenvolvimento
e.g. em C
1. Alterar código
2. Compilar
3. Deploy
13. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 2 | LÓGICA DE NEGÓCIOS
Business Logic with script > Processo de
desenvolvimento
com script
1. Alterar código
2. Compilar
3. Deploy
14. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 2 | LÓGICA DE NEGÓCIOS
Business Logic with script > Linguagens de script são
simples de se apreender
Menor complexidade
Precisa ser
integrável à
linguagem
compilada
(C, C++)
15. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 2 | LÓGICA DE NEGÓCIOS
Business Logic with script Lua
Por que Lua?
16. COPYRIGHT 2016 – Fundação CERTI
Porque Lua
é leve x86 – 171K
arm – 160K
arm – 124K
liblua.so
17. COPYRIGHT 2016 – Fundação CERTI
Porque Lua é leve
180K
171K
160K
124K
20. COPYRIGHT 2016 – Fundação CERTI
PODEROSA>permite orientação a objetos
>permite estender aplicações em outras
linguagens
>pode ser estendida por bibliotecas
escritas em outras linguagens
e também
21. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 2 | LÓGICA DE NEGÓCIOS
Business Logic with script Lua
Exemplo 1:
User interface do Set-Top Box CERTI
23. COPYRIGHT 2016 – Fundação CERTI
Integração Lua e C
CAPÍTULO 2 | INTEGRAÇÃO LUA E C
Módulo C
Lua
Bind
Módulo C
Bind
Módulo C
Bind
Módulo C
Bind
24. COPYRIGHT 2016 – Fundação CERTI
Integração Lua e C
CAPÍTULO 3 | EMBEDDED LUA
2 flavors:
> Aplicação C inicializa scripts Lua
> Script Lua carrega biblioteca naNva
É possível ter
a combinação
dos dois
25. COPYRIGHT 2016 – Fundação CERTI
Integração Lua e C
Aplicação C inicializa máquina Lua
> lua_State *lua_newstate (lua_Alloc f,
void *ud);
> void luaL_openlibs (lua_State *L);
> int luaL_dofile (lua_State *L, const
char *filename);
> int lua_pcall (lua_State *L, int nargs,
int nresults, int msgh);
> void lua_close (lua_State *L);
CAPÍTULO 2 | INTEGRAÇÃO LUA E C
26. COPYRIGHT 2016 – Fundação CERTI
Integração Lua e C > Inicialização da máquina Lua
CAPÍTULO 2 | INTEGRAÇÃO LUA E C
27. COPYRIGHT 2016 – Fundação CERTI
Integração Lua e C > Bind para ser usado em Lua
CAPÍTULO 2 | INTEGRAÇÃO LUA E C
28. COPYRIGHT 2016 – Fundação CERTI
Integração Lua e C > Bind para ser usado em Lua
CAPÍTULO 2 | INTEGRAÇÃO LUA E C
45. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 3 | EMBEDDED LUA
“Microcontrollers are designed for
embedded applications, in contrast to
the microprocessors used in personal
computers or other general purpose
applications consisting of various
discrete chips.”
-Wikipedia
46. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 3 | EMBEDDED LUA
BSP(board support package) / HAL
(hardware abstraction layer) provided
by the “Chip” vendor
Hardware dependent code, not
portable
No operating system
Hard to port applications
Hard to update on the field
Do not forget: it is all about
registers!!
without
addition; basic
and simple
Bare Metal
47. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 3 | EMBEDDED LUA
eLua www.eluaproject.net
Embedded power, driven by Lua
Quickly prototype and develop embedded
software applications with the power of Lua and
run them on a wide range of microcontroller
architectures
MicroPython micropython.org
MicroPython is a lean and efficient
implementation of the Python 3 programming
language that includes a small subset of the
Python standard library and is optimised to run
on microcontrollers and in constrained
environments.
Netduino www.netduino.com
Netduino, an open-source electronics platform
using the .NET Micro Framework.
Cont: JavaME,
Not so bare
Bare Metal
48. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 3 | EMBEDDED LUA
e-Lua Embedded Lua
On a wide range of
microncontrollers
The power of Lua
Flexibility
Rapid prototyping
Reduced time-to-market
49. COPYRIGHT 2016 – Fundação CERTI
eLua is not an operational system
commercial software
nor GPL
reduced Lua
platform specific
CAPÍTULO 3 | EMBEDDED LUA
61. COPYRIGHT 2016 – Fundação CERTI
>platform.c–platforminterfaceimpl
62. COPYRIGHT 2016 – Fundação CERTI
>stm32f4xx_conf.h–infoabout
platformandbuildconfig
63. COPYRIGHT 2016 – Fundação CERTI
Porting eLua > new CPU
CAPÍTULO 3 | EMBEDDED LUA
1. edit build_data.lua
2. add a new board to eLua
3. customize the list of source file and/or
compilation flags
64. COPYRIGHT 2016 – Fundação CERTI
Porting eLua > new board
CAPÍTULO 3 | EMBEDDED LUA
1. Name your board - stm32f429disco
2. Write a configuration file
3. Change the file list according to the board name
> cp boards/known/stm32-port407z.lua boards/
known/stm32f429disco.lua
> edit stm32f429disco.lua to set up UART and RX/
TX pins
68. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 6 | eLUA DEMO
GPIO
The famous hello world “led blink” at
user space
pio.pin.setdir(pio.OUTPUT, pio.PG_14)
pio.pin.sethigh(pio.PG_14)
pio.pin.setlow(pio.PG_14)
Action
71. Take away
Use a script language for
app development
Lua is lightweight,
portable and easy to use
eLua runs in
microcontrollers
CAPÍTULO 6 | WRAP-UP