<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Scalable Simulation Environment of Microcontrollers with Remote Access</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Sergei Bykovskii</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Tatyana Prilutskaya</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Elizaveta Kormilitsyna</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>ITMO University</institution>
          ,
          <addr-line>49 Kronverksky Pr., St. Petersburg, 197101, Russian Federation</addr-line>
        </aff>
      </contrib-group>
      <abstract>
        <p>The article deals with the problem of developing a scalable simulating environment of microcontrollers with remote access. The authors proposed the solution based on Tornado Webserver and SystemC models of hardware that can be executed in parallel. The users can connect to the server remotely, test their microcontroller software and then easily move it to real hardware. Currently, the system supports the programming of STM32F4 series microcontrollers integrated into SDK1.1M educational board. The system has been developed by ITMO University and is available on Open EDU platform based on Open edX. It is used for the teaching of Embedded System course. The average compilation time for one project is 3-7 seconds depending on complexity of the project and the number of users worked in parallel. The proposed system can be scalable on several processors (vertical scaling) and servers (horizontal scaling) to reduce the average access time and to increase the number of parallel users.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Microcontrollers</kwd>
        <kwd>Embedded Systems</kwd>
        <kwd>Internet of Things</kwd>
        <kwd>Cyber-Physical Systems</kwd>
        <kwd>Simulation</kwd>
        <kwd>Softwarein-the-loop</kwd>
        <kwd>Remote access</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>In some cases, it is not able to use a real hardware to test developed software for microcontrollers.
The special simulators are needed for this purpose. There are several tools for simulation
microcontrollers and its environment with peripheral devices.</p>
      <p>Some tools are integrated in IDE for software developers and provide the simulation
environment for local projects. The developers should install the IDE and use it on their own computers.
The simulation process requires a lot of computing resources because it needs to provide a
possibility to test the embedded software in real time. If their own computers is not so powerful
the developers can not use this tools.</p>
      <p>Other tools are fully accurate and simulate low-level details of the system. This kind of tools
can not be used for testing the real-time interaction with control elements such as buttons,
switches, touch-displays etc.</p>
      <p>Other tools can simulate only the part of microcontroller like processor or processor with
such peripheral devices as timers, interrupt controller and can not simulate wide range of
peripherals (displays, keyboards, sensors etc).</p>
      <p>The authors proposed the architecture of the system that can be scalable on several processors
and servers and provide the remote access to the simulation environment. It simulates the
hardware on the intermediate level of abstraction (loosely timed) and can provide a real-time
reaction on user actions like pressing buttons and others.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Related works</title>
      <p>In this section, we observe the existing tools that can be used for microcontrollers simulation
and their environment. We observe such tools as Keil µVision, MATLAB&amp;Simulink, QEMU,
Tinkercad and Jumper Virtual Lab.</p>
      <p>
        Keil [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ] is an MCU software development environment for projects of any complexity.
Among other tools like IDE, project manager, Performance Analyzer and debugger it supports
complete instruction set simulation for ARM cores and simulation of the on-chip peripherals.
      </p>
      <p>
        MATLAB [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ] programming environment with Simulink becomes a powerful tool for
system-level design and multidomain modeling. Simulink computes a state of the system on
each simulation loop phase respective to the current model time step. A model time advances
according to the solver program. Simulink supports code verification without target hardware
by software-in-the-loop simulation (SIL). Some execution-time metrics could be collected while
simulation.
      </p>
      <p>
        QEMU [
        <xref ref-type="bibr" rid="ref5 ref6">5, 6</xref>
        ] is a hardware emulator. QEMU translates instructions of the target system into
operations in C, compiles them and runs on the host system. It supports parallel emulations,
debugging, user and system modes, and much more. A wide list of architectures (see Table 1)
and peripherals is implemented. Here’s a partial list of them: watchdog, EXTI, ADC, AFIO,
SPI, PCI, I2C. Despite its rich functionality, QEMU is unable to provide a suficiently accurate
hardware operation: the program does nothing about the timing of execution, it simply runs
the target system code as fast as it can.
      </p>
      <p>
        Tinkercad [
        <xref ref-type="bibr" rid="ref7 ref8">7, 8</xref>
        ] 3D modeling service‘s Circuits extension for electronic circuits simulation
provides a set of of-the-shelf electronic components, graphics editor, sensor readings
configuration, and collaboration tools. It implements the ability to connect some Tinkercad peripherals
like timers, LCD, LED to a virtual MCU via UART, SPI and I2C pins. Tinkercad has clear virtues
like visibility, intuitive interface, and a large community being useful in the studying process.
But the lack of supported industrial MCUs results in inapplicability for serious projects.
      </p>
      <p>Unlike previous ones, Jumper1 is a dedicated tool for hardware emulation only. It is being
promoted as a solution for CI/CD implementation in embedded systems. Jumper normally
provides real-time hardware emulation, acceleration is available. Jumper SDK has Python
modules for interaction with virtual MCU via UART and GPIO APIs. There is also Peripheral
Modeling Framework providing peripheral pinout and configuration templates for conjugation
via SPI or I2C. However, it is up to the user to implement the desired device’s behavior.</p>
      <p>The comparison of observed tools is presented in table 1.</p>
      <p>QEMU emulator provides a fully accurate simulation. It can not be used for real-time
simulation because model time is several times slower than real-time. Keil and Matlab&amp;Simulink are
local solutions for a simulation. It is hard to scale them and provide remote access for multiple
parallel users. Jumper Virtual Lab is more suitable for our purposes but it seems that is out of
support now by their developers because the main website of this site is closed.</p>
    </sec>
    <sec id="sec-3">
      <title>3. Proposed system</title>
      <sec id="sec-3-1">
        <title>3.1. Architecture</title>
        <p>We propose the architecture of the Embedded Systems Virtual Laboratory that is scalable and
can provide remote access. We also implement SDK-1.1M2 development board model as an
example of using the proposed architecture.</p>
        <p>The architecture of the virtual laboratory is shown in Fig. 1.</p>
        <p>The system has a client-server architecture. Clients interact with the system via a Web
browser. Entering the website creates an individual session for each user. During the work, a
user is assigned a unique identifier (id_1, id_2, . . . id_N). Access control to server resources is
realized with help of such an identifier.</p>
        <p>On the website, users can upload code for a programmable embedded system, compile an
executable file of the System Model and run it for execution. The results of the work will
be displayed on the Browser window. The client-side interacts with the server-side via Web
sockets. Tornado Web server executes user session on server site. It provides the scalability
of the virtual laboratory. Tornado server can dispatch process to the several CPU of servers
and can be executed on several servers. Protocol MQTT provides data transfer between user
sessions and system models, this transfer is organized through the message broker. Eclipse
Mosquitto is used as a message broker.</p>
        <p>The system model is a microcontroller which detailed block diagram is shown in Fig. 2. This
microcontroller contains one CPU and programmable input/output peripherals. The common
bus is used as topology and connects CPU with peripheral devices. As peripheral devices, there
are the following units: timers, GPIO Controller, UART, Interrupt Controller, ADC.</p>
        <p>The model consists of two parts: the system part and the user part. The system part is the
loosely timed TLM model of all system units. The user part is a code that executes on CPU.
The way to get an executable model file is shown in Fig. 3. The model was developed using the
SystemC library of C++ programming language. These types of models provide the possibility
of real-time reactions to user actions.</p>
        <p>All interactions are presented as information messages towards client’s Web browser. System
model communicates with a User session via MQTT broker. A User session is supported by
Tornado server. Further, in a User session, all messages are transmitted to Client’s browser
using Web sockest.</p>
        <p>The behavior of system peripherals is simulated on the client site in a Web browser.
All data between System model, User sessions and Web browser is transferred in JSON format.</p>
        <p>Communication via MQTT broker is provided through two channels for each user in
publisher/subscriber mode according to Table 2.</p>
        <p>The Fig. 4 is shown how components of virtual laboratory interact with each other.</p>
      </sec>
      <sec id="sec-3-2">
        <title>3.2. Evaluation</title>
        <p>The webform of the developed simulation environment of SDK1.1M development board is
presented in figure 5. The user can connect to the system remotely and upload the zip archive
with sources. These sources can be used in the developed system and also in real STM32F4
series microcontrollers with minor modifications. After uploading the archive with source codes
the user should compile the sources and run them on the board. During the program execution,
the user can interact with the model using buttons in real-time. The model time in SystemC
hardware models is equal to real-time.</p>
        <p>The system has been installed on the server with Intel Core i5-4200U CPU with 2.3 GHz.
This CPU consist of 4 logic cores and Tornado Web Server can be scaled on it. The Tornado
Webserver can be scalable on all available CPU logic cores. The dependence of the user project
compilation time on the number of parallel users is presented in figure 6.</p>
        <p>There is a drawback of this solution that one user occupies one logic core of CPU. The
overcoming of this drawback is the aim of further research.</p>
        <p>The developed system is using in the Embedded Systems course on Open EDU platform3
based on Open edX.</p>
        <p>3https://openedu.ru/course/ITMOUniversity/EMBSYS/</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Results</title>
      <p>In this article, we propose a scalable architecture for simulating microcontrollers with remote
access. It can be scaled on logic cores of one server or several cores of several servers. The
scalability is provided by using Tornado Web Server. The hardware model of a microcontroller
is implemented as a loosely timed TLM model using SystemC library. SystemC provides a
possibility to implement the model that can interact with a user in real-time.</p>
      <p>Using the proposed architecture, the simulation environment of SDK1.1M development board
based on STM32F4 microcontroller was developed and integrated into the Embedded System
education course on the Open EDU platform.</p>
      <p>The current drawback of the proposed system is the high processor load. It can be decreased
by finding ways of efective data exchange methods between the server and the client sides. It
is an issue for further research.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>H.</given-names>
            <surname>Zhou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Z.</given-names>
            <surname>Xu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Z.</given-names>
            <surname>Lin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Dong</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Huang</surname>
          </string-name>
          ,
          <article-title>Simulation design of inverter in solar photovoltaic system based on mcu</article-title>
          ,
          <source>Wuhan</source>
          ,
          <year>2009</year>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>4</lpage>
          . doi:
          <volume>10</volume>
          .1109/SOPO.
          <year>2009</year>
          .
          <volume>5230265</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>C.</surname>
          </string-name>
          <article-title>Bing-jie, Y. Li-chao, The construction of virtual lab base on proteus and keil, 3, 2009</article-title>
          . doi:
          <volume>10</volume>
          .1145/1219092.1219093.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>R.</given-names>
            <surname>Grepl</surname>
          </string-name>
          ,
          <article-title>Real-time control prototyping in matlab/simulink: Review of tools for research and education in mechatronics</article-title>
          , IEEE,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Y.-H. L.</given-names>
            <surname>Huang</surname>
          </string-name>
          , Chih-Han,
          <string-name>
            <given-names>H.-L.</given-names>
            <surname>Tsai</surname>
          </string-name>
          ,
          <article-title>Design for microcontroller-based photovoltaic monitoring system using matlab/simulink</article-title>
          , IEEE,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>F.</given-names>
            <surname>Bellard</surname>
          </string-name>
          ,
          <article-title>Qemu, a fast and portable dynamic translator</article-title>
          , volume
          <volume>41</volume>
          ,
          <year>2005</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>D.</given-names>
            <surname>Bartholomew</surname>
          </string-name>
          , Qemu: a multihost,
          <source>multitarget emulator</source>
          ,
          <volume>145</volume>
          ,
          <year>2006</year>
          , pp.
          <fpage>68</fpage>
          -
          <lpage>71</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>B. N.</given-names>
            <surname>Mohapatra</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. K.</given-names>
            <surname>Mohapatra</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Joshi</surname>
          </string-name>
          ,
          <string-name>
            <surname>S. Zagade,</surname>
          </string-name>
          <article-title>Easy performance based learning of arduino and sensors through tinkercad</article-title>
          , volume
          <volume>8</volume>
          ,
          <year>2020</year>
          , pp.
          <fpage>73</fpage>
          -
          <lpage>76</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>B. N.</given-names>
            <surname>Mohapatra</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. K.</given-names>
            <surname>Mohapatra</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Joshi</surname>
          </string-name>
          ,
          <string-name>
            <surname>S. Zagade,</surname>
          </string-name>
          <article-title>Smart performance of virtual simulation experiments through arduino tinkercad circuits</article-title>
          , volume
          <volume>4</volume>
          , New York, NY,
          <year>2020</year>
          , pp.
          <fpage>157</fpage>
          -
          <lpage>160</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>