Paper 5-Microcontrollers Programming Framework
Paper 5-Microcontrollers Programming Framework
Abstract—This paper describes the design of a programming [10], which is based on C language in addition to an API
framework for microcontrollers specially the ones with low which makes the programming process easier. That API works
program and data memory, using as a base a programming on a predefined hardware setup to reduce the setup process
language with modern features. The proposed programming by the programmer. Another popular programming framework
framework is named Aixt Project and took inspiration from for microcontrollers is Micropython which implements on
other similar projects such as Arduino, Micropython and TinyGo
several devices a subset of Python language. Micropython has
among others. The project’s name is inspired on the weasel pet
of the V programming language and at the same time it is a specific relatively high memory requirements which makes
tribute to Ticuna people who live in the Amazon rain-forest, just it impossible to run on small microcontrollers, but it has
between Colombia, Perú and Brasil. Aixt comes from Aixtü or been ported to a large number of different architectures [11]
Aitü rü which means otter in Ticuna language. The proposed mainly in internet of things IoT implementations. Arduino
programming framework has three main components: the Aixt is compiled but its C syntax lacks modern features, on the
language based on the V syntax, a transpiler that turns the other hand Micropython is interpreted and therefore non time
defined V-like source code into C, and a generic cross-platform optimized as compiled language, but there is an intermediate
Application Programming Interface (API). The target of this framework named Tinygo which implements Go language on
project is obtaining a cross-platform programming framework Microcontrollers, offering modern features like Python and the
over the same language modern language an the same API, for
advantage of being compiled [12] like Arduino (C). However,
programming different microcontrollers especially the ones with
low memory resources. Aixt language is based on the syntax most of the microcontroller with limited memory features does
of V programming language but it uses mutable variables by not fit to the memory requirements of the projects previously
default. V language was selected to be used as base of this described, so for those ones it is necessary to use their native
project due to it is a new compiled programming language with C compiler.
interesting modern features. In order to turn the Aixt source
code into C, a transpiler is implemented using Python and the In order to obtain the best execution times and the best code
some specialized libraries to design each part of its translation optimization level [13], [3] it is necessary to use the native C
process. The transpiled code is compiled by the native C compiler compiler of each architecture. Then, if there is a programming
of each microcontroller to obtain the final binary file, that is framework with an upper modern language layer, a transpiler
why the API has to be adapted for each native C compiler. to C and the native C compiler as a part of the framework, this
The complete project is released as a free and open source
project. Finally, different application test were done over the XC8
could have high level language features along with optimiza-
and XC16 compilers for the PIC16, PIC18, PIC24 and dsPIC33 tion levels similar to the ones reached with only the native
microcontrollers families, demonstrating the correct working of compilers. The described programming framework needs to
the overall framework. Those tests show that the use modern have a transpiler [14], which is a translator from the upper layer
language framework to program any microcontrollers is perfectly language to the native C [15]. Transpilers are highly utilized
feasible using the proposed programming framework. nowadays [16], [17], in several languages both compiled and
interpreted [18], [19], [20], and even in languages based on
Keywords—Microcontroller; transpiler; API; programming lan-
guage; V; V-lang; Aixt project
virtual machines [21]. Those transpilers are mainly used in
order to reuse source code that comes from another different
language [18], or improve the execution times or another
I. I NTRODUCTION performance feature of the program [22], [23] changing the
platform or language (for instance turn Python (interpreted)
The different processor architectures used by the com- into Rust (compiled) [19]), even translating source code to
mercial microcontrollers, make the programming process de- gate-based hardware [24] like FPGAs or other processor-less
pendent on those architectures and thus not universal. Even, devices.
when the microcontrollers are programmed on high level
languages, tasks such as peripherals, timers, setup registers, Several new programming languages have emerged nowa-
and others, keep depending on the programmer’s knowledge of days, mainly to solve some of the issues of the traditional ones
the processor’s architecture [1], [2]. There are some different such as safety, memory management among others. Among
projects which pretends to generate cross-platform program- these new languages are Go, Swift, Dart, F# and Rust, being
ming frameworks [3], using different programming languages this last is one of the most preferred ones[25], having even
like JavaScript [4], and other implementations using virtual implementations on microcontrollers [26], [27], [28]. There are
machines [5], [6], [7]. An example of those programming some other other languages such as Peregrine which is based
frameworks (and one of the most popular) is Arduino[8], [9], on the Python’s syntax and the V programming language [29]
www.ijacsa.thesai.org 32 | P a g e
(IJACSA) International Journal of Advanced Computer Science and Applications,
Vol. 13, No. 12, 2022
Once the Lexer analyzer reduced the character flux of the Description Function name
source code to an token flux, the parser analyzes the syntactic ADC setting up adc()
ADC reading value adc_read()
rules of language in order to find possible syntactic error and
transpile it to C. The most of the syntactic rules of V are
implemented in Aixt using the SLY module as shown in the TABLE III. U NIVERSAL A SYNCHRONOUS R ECEIVER T RANSMITTER
extract source code of Listing 5, which matches with the BNF (UART)
definition shown in Listing 6.
Description Function name
UART setting up uartx()
Listing 5: Aixt Parser implementation (extract) single byte transmitting uartx_put()
single byte receiving uartx_get()
...
@ ( ’ i d e n t L i s t DECL ASGN e x p r L i s t ’ ,
) TABLE IV. T IMING F EATURES
def varDecl ( s e l f , p ) : Description Function name
... delays in microseconds sleep_us()
return r e t v a l u e delays in millisecond sleep_ms()
delays in second sleep()
@ ( ’ IDENTIFIER ’ ,
’ i d e n t L i s t ” , ” IDENTIFIER ’ Table I shows the pin and GPIO functions like setup,
) input capture and output set. Some devices even could support
def i d e n t L i s t ( s e l f , p ) : exchange state functions (pin_toggle). The rest of API
... functions follow the same rules:
return p [ 0 ] • The setup function has the same name of the module.
...
• The rest of name functions of the same module follow
the syntax: module_function(). For instance:
Listing 6: Aixt BNF rules (extract) adc_read() function of machine { adc }
module (Table II).
v a r D e c l : : = i d e n t L i s t DECL ASGN e x p r L i s t
• Devices with more than one peripheral of the
i d e n t L i s t : = IDENTIFIER same time follow this name function syntax:
| i d e n t L i s t ” , ” IDENTIFIER modulex_function() where the x refers to the
number that identify each peripheral. For instance:
SLY library uses Python’s function decorators to implement uart2_get() as shown in Table III.
the syntactic rules of the language to be compiled or transpiled, • Some API modules refers to a inner features of the
applying them to each syntactic production, for example the device different to hardware peripherals, for instance
production varDecl is the implementation of variable declara- software delays (Table IV).
tions in Aixt language.
The Fig. 3 shows the folder structure designed for the
As previously said, the transpiler reads the source code overall API, this structure has to be followed for each of the
written in Aixt, which for compatibility with standard source supported microcontrollers and boards to maintain the com-
code editors, the .v file extension. patibility across all the hardware devices. Following strictly
this folder structure allow the transpiler to correctly redirect
C. Application Programming Interface the module including tasks when it is necessary to include to
the project isolated components of a module.
One of the main goals of the proposed framework is
designing a cross-platform API, which includes the basic As previously mentioned, the module including
features and peripherals of most microcontrollers. In order follows the next syntax in Aixt: import module
www.ijacsa.thesai.org 35 | P a g e
(IJACSA) International Journal of Advanced Computer Science and Applications,
Vol. 13, No. 12, 2022
for complete modules, which will be transpiled as are shown. The only difference with C is the octal literals
#include \./module.h". Likewise, the sub-modules beginning with the sequence "0o" (zero + o), instead of only
or module components including follows the syntax: 0 as in C.
import module { sub1, sub2, ...}, which will
be transpiled to #include \./module/sub1.h" etc. Listing 7: Aixt variable declaring and assignment example.
That is very important to optimize the resultant binary file.
On the other hand, when a complete module is included, the var2 := i8 (129)
./module.h header file has to include all of the .h files in var3 := i 6 4 ( −6 835 292 )
the correspondent folder on the folder’s API structure. var4 := u8 ( 0 b0011 0101 )
var5 := u16 ( 0 o073452 )
var7 := u64 ( 0 xAAFF 7625 )
var8 := f 3 2 ( 1 342 . 5 6 )
var9 := f 6 4 ( − 3 4 . 0 3 5 440 )
i n t 8 t var2 = 129;
i n t 6 4 t v a r 3 = −6835292;
u i n t 8 t v a r 4 = 0 b00110101 ;
u i n t 1 6 t var5 = 0073452;
u i n t 6 4 t v a r 7 = 0xAAFF7625 ;
f l o a t var8 = 1342.56;
long double var9 = −34.035440;
the V programming language were implemented. That means [7] R. Gurdeep Singh and C. Scholliers, “Warduino: a dynamic webassem-
this project can highly improve implementing more features bly virtual machine for programming microcontrollers,” in Proceedings
and adapting it to other microcontrollers and boards. It is of the 16th ACM SIGPLAN International Conference on Managed
Programming Languages and Runtimes, 2019, pp. 27–36.
perfectly able to use Aixt language and this framework in the
[8] D. E. Bolanakis, “A survey of research in microcontroller education,”
classroom in Basic courses of microcontroller and embedded IEEE Revista Iberoamericana de Tecnologias del Aprendizaje, vol. 14,
systems, due to currently this project is highly functional. no. 2, pp. 50–57, 2019.
In spite of the short learning curve of V and therefore Aixt [9] S.-M. Kim, Y. Choi, and J. Suh, “Applications of the open-source
hardware arduino platform in the mining industry: A review,” Applied
languages, it is possible to explore another simple languages Sciences, vol. 10, no. 14, p. 5018, 2020.
to improve the proposed programming scheme, or even giving [10] H. K. Kondaveeti, N. K. Kumaravelu, S. D. Vanambathina, S. E.
support to another main languages maintaining the same API. Mathe, and S. Vappangi, “A systematic literature review on prototyping
One of the candidates is the Peregrine Language who is based with arduino: Applications, challenges, advantages, and limitations,”
on the Python syntax. Computer Science Review, vol. 40, p. 100364, 2021.
[11] V. M. Ionescu and F. M. Enescu, “Investigating the performance of
As future work, the development of other useful features micropython and c on esp32 and stm32 microcontrollers,” in 2020 IEEE
of V language are proposed. For example, the array definition, 26th International Symposium for Design and Technology in Electronic
direct array indexing using the array for loop, array inter- Packaging (SIITME), 2020, pp. 234–237.
polation, matching statements among others. Likewise, it is [12] A. Suarez Ruiz, “Diseño de hardware y firmware para un sistema
inalámbrico de adquisición de datos daq de bajo costo,” Departamento
important to keep giving support to other MCUs and board de Ingenierı́a Eléctrica, Electrónica y Computación, 2019.
especially those with low program and data memories, which [13] H. Wu, C. Chen, and K. Weng, “An energy-efficient strategy for
are the motivation for this project. For instance Atmel ® AT microcontrollers,” Applied Sciences, vol. 11, no. 6, p. 2581, 2021.
mega and AT tiny will be included to the project soon due [14] M.-A. Lachaux, B. Roziere, L. Chanussot, and G. Lample, “Un-
to they use also the XC8 compiler. Finally, it is possible supervised translation of programming languages,” arXiv preprint
to combine PC graphical application developed in V with arXiv:2006.03511, 2020.
embedded application developed in Aixt, taking the advantage [15] A. M. Karpiński, “Automatic translation of programs source codes
of learning only one programming basis to develop a complete from python to c# programming language,” Ph.D. dissertation, Zakład
embedded-based graphical application. Sztucznej Inteligencji i Metod Obliczeniowych, 2022.
[16] M. Szafraniec, B. Roziere, H. Leather, F. Charton, P. Labatut, and
G. Synnaeve, “Code translation with compiler representations,” 2022.
ACKNOWLEDGMENT [Online]. Available: https://arxiv.org/abs/2207.03578
This work was supported by Universidad Distrital Fran- [17] F. A. Bastidas and M. Pérez, “A systematic review on transpiler usage
for transaction-oriented applications,” in 2018 IEEE Third Ecuador
cisco José de Caldas and Corporación Unificada Nacional de Technical Chapters Meeting (ETCM), 2018, pp. 1–6.
Educación Superior CUN. The views expressed in this docu- [18] M. Ling, Y. Yu, H. Wu, Y. Wang, J. R. Cordy, and A. E. Hassan, “In rust
ment are not necessarily endorsed by Universidad Distrital or we trust – a transpiler from unsafe c to safer rust,” in 2022 IEEE/ACM
CUN. The authors thank the ARMOS and IDECUN research 44th International Conference on Software Engineering: Companion
groups for the simulations and tests. Proceedings (ICSE-Companion), 2022, pp. 354–355.
[19] H. Lunnikivi, K. Jylkkä, and T. Hämäläinen, “Transpiling python to
rust for optimized performance,” in Embedded Computer Systems:
R EFERENCES Architectures, Modeling, and Simulation, A. Orailoglu, M. Jung, and
[1] A. Radovici and I. Culic, Embedded Systems Software Development. M. Reichenbach, Eds. Cham: Springer International Publishing, 2020,
Berkeley, CA: Apress, 2022, pp. 27–47. pp. 127–138.
[2] E. Kusmenko, B. Rumpe, S. Schneiders, and M. von Wenckstern, [20] M. Marcelino and A. M. Leitão, “Extending PyJL - Transpiling Python
“Highly-optimizing and multi-target compiler for embedded system Libraries to Julia,” in 11th Symposium on Languages, Applications and
models: C++ compiler toolchain for the component and connector Technologies (SLATE 2022), ser. Open Access Series in Informatics
language embeddedmontiarc,” in Proceedings of the 21th ACM/IEEE (OASIcs), J. a. Cordeiro, M. J. a. Pereira, N. F. Rodrigues, and
International Conference on Model Driven Engineering Languages S. a. Pais, Eds., vol. 104. Dagstuhl, Germany: Schloss Dagstuhl
and Systems, ser. MODELS ’18. New York, NY, USA: Association – Leibniz-Zentrum für Informatik, 2022, pp. 6:1–6:14. [Online].
for Computing Machinery, 2018, p. 447–457. [Online]. Available: Available: https://drops.dagstuhl.de/opus/volltexte/2022/16752
https://doi.org/10.1145/3239372.3239388 [21] B. F. Andrés and M. Pérez, “Transpiler-based architecture for multi-
[3] A. K. Rachioti, D. E. Bolanakis, and E. Glavas, “Teaching strategies for platform web applications,” in 2017 IEEE Second Ecuador Technical
the development of adaptable (compiler, vendor/processor independent) Chapters Meeting (ETCM), 2017, pp. 1–6.
embedded c code,” in 2016 15th International Conference on Informa- [22] T. Würthinger, C. Wimmer, C. Humer, A. Wöß, L. Stadler, C. Seaton,
tion Technology Based Higher Education and Training (ITHET), 2016, G. Duboscq, D. Simon, and M. Grimmer, “Practical partial evaluation
pp. 1–7. for high-performance dynamic language runtimes,” in Proceedings
[4] K. Grunert, “Overview of javascript engines for resource-constrained of the 38th ACM SIGPLAN Conference on Programming Language
microcontrollers,” in 2020 5th International Conference on Smart and Design and Implementation, ser. PLDI 2017. New York, NY, USA:
Sustainable Technologies (SpliTech), 2020, pp. 1–7. Association for Computing Machinery, 2017, p. 662–676. [Online].
Available: https://doi.org/10.1145/3062341.3062381
[5] K. Zandberg and E. Baccelli, “Minimal virtual machines on iot mi-
crocontrollers: The case of berkeley packet filters with rbpf,” in 2020 [23] R. Pereira, M. Couto, F. Ribeiro, R. Rua, J. Cunha, J. P. Fernandes,
9th IFIP International Conference on Performance Evaluation and and J. Saraiva, “Ranking programming languages by energy efficiency,”
Modeling in Wireless Networks (PEMWN). IEEE, 2020, pp. 1–6. Science of Computer Programming, vol. 205, p. 102609, 2021.
[6] S. Varoumas, B. Pesin, B. Vaugon, and E. Chailloux, “Programming [24] K. Takano, T. Oda, and M. Kohata, “Approach of a coding conventions
microcontrollers through high-level abstractions,” in Proceedings of the for warning and suggestion in transpiler for rust convert to rtl,” in 2020
12th ACM SIGPLAN International Workshop on Virtual Machines and IEEE 9th Global Conference on Consumer Electronics (GCCE), 2020,
Intermediate Languages, 2020, pp. 5–14. pp. 789–790.
[25] W. Bugden and A. Alahmar, “Rust: The programming language for
safety and performance,” arXiv preprint arXiv:2206.05503, 2022.
www.ijacsa.thesai.org 38 | P a g e
(IJACSA) International Journal of Advanced Computer Science and Applications,
Vol. 13, No. 12, 2022
[26] T. Uzlu and E. Şaykol, “On utilizing rust programming language for Master’s thesis, Luleå University of Technology, Computer Science,
internet of things,” in 2017 9th International Conference on Compu- 2020.
tational Intelligence and Communication Networks (CICN), 2017, pp. [29] N. P. Kumar Rao, Getting Started with
93–96. V Programming. Packt Publishing, 2021. [Online].
[27] K. I. Vishnunaryan and G. Banda, “Harsark multi rs: A hard real- Available: https://www.packtpub.com/product/getting-started-with-v-
time kernel for multi-core microcontrollers in rust language,” in Smart programming/9781839213434
Intelligent Computing and Applications, Volume 2, S. C. Satapathy, [30] F. Martı́nez Santa, S. Orjuela Rivera, and F. H. Martı́nez Sarmiento,
V. Bhateja, M. N. Favorskaya, and T. Adilakshmi, Eds. Singapore: “Rust-like programming language for low-resource microcontrollers,”
Springer Nature Singapore, 2022, pp. 21–32. Advances in Dynamical Systems and Applications, 2022.
[28] J. Aparicio Rivera, “Real time rust on multi-core microcontrollers,”
www.ijacsa.thesai.org 39 | P a g e