Ciocirlan Stefan-Dan - SRIC
The goal of the project is to emulate some target machines for Nuttx over Qemu. It will make the development of Nuttx and the testing of the machines more easy. It also offer templates for adding other machines and debuging them.
”“The Stellaris family of microcontrollers—the first ARM® CortexTM-M3 based controllers—brings high-performance 32-bit computing to cost-sensitive embedded microcontroller applications. These pioneering parts deliver customers 32-bit performance at a cost equivalent to legacy 8- and 16-bit devices, all in a package with a small footprint. The Stellaris family offers efficient performance and extensive integration, favorably positioning the device into cost-conscious applications requiring significant control-processing and connectivity capabilities. The Stellaris LM3S6000 series combines both a 10/100 Ethernet Media Access Control (MAC) and Physical (PHY) layer, marking the first time that integrated connectivity is available with an ARM Cortex-M3 MCU and the only integrated 10/100 Ethernet MAC and PHY available in an ARM architecture MCU. The LM3S6965 microcontroller is targeted for industrial applications, including remote monitoring, electronic point-of-sale machines, test and measurement equipment, network appliances and switches, factory automation, HVAC and building control, gaming equipment, motion control, medical instrumentation, and fire and security. For applications requiring extreme conservation of power, the LM3S6965 microcontroller features a battery-backed Hibernation module to efficiently power down the LM3S6965 to a low-power state during extended periods of inactivity. With a power-up/power-down sequencer, a continuous time counter (RTC), a pair of match registers, an APB interface to the system bus, and dedicated non-volatile memory, the Hibernation module positions the LM3S6965 microcontroller perfectly for battery applications. In addition, the LM3S6965 microcontroller offers the advantages of ARM's widely available development tools, System-on-Chip (SoC) infrastructure IP applications, and a large user community. Additionally, the microcontroller uses ARM's Thumb®-compatible Thumb-2 instruction set to reduce memory requirements and, thereby, cost. Finally, the LM3S6965 microcontroller is code-compatible to all members of the extensive Stellaris family; providing flexibility to fit our customers' precise needs.”” This info and more can be found in the datasheet at lm3s6965.pdf
”“STM32-P103 board is development board which allows you to explore thee features of the ARM Cortex M3 STM32F103RBT6 microcontroller produced by ST Microelectronics Inc. The board has SD/MMC card connector and allows USB Mass storage device demo to be evaluated. The RS232 driver and connector allows USB to Virtual COM port demo to be evaluated. The CAN port and driver allows CAN applications to be developed. The UEXT connector allows access to all other UEXT modules produced by OLIMEX (like MOD-MP3, MOD-NRF24LR, MOD-NOKIA6610, etc) to be connected easily. In the prototype area the customer can solder his own custom circuits and interface them to USB, CAN, RS232 etc.”” This info and more can be found in the datasheet at stm32-p103.pdf
”“The STM32F4DISCOVERY Discovery kit allows users to easily develop applications with the STM32F407VG high performance microcontroller with the ARM ® Cortex ® -M4 32-bit core. It includes everything required either for beginners or for experienced users to get quickly started. Based on STM32F407VG, it includes an ST-LINK/V2 or ST-LINK/V2-A embedded debug tool, two ST-MEMS digital accelerometers, a digital microphone, one audio DAC with integrated class D speaker driver, LEDs, push buttons and a USB OTG micro-AB connector.”” This info and more can be found in the datasheet at stm32-f407.pdf
A device that runs at least Ubuntu 10.04 LTS and can build the qemu source code. I used a Lenovo Thinkpad x250 (Ubuntu 16.04 LTS) and a PC with intel cpu i3-2100 and 4GB DDR3 (Ubuntu 14.04 LTS).
NuttX is a real-time operating system (RTOS) with an emphasis on standards compliance and small footprint. Scalable from 8-bit to 32-bit microcontroller environments, the primary governing standards in NuttX are Posix and ANSI standards. Additional standard APIs from Unix and other common RTOS's (such as VxWorks) are adopted for functionality not available under these standards, or for functionality that is not appropriate for deeply-embedded environments (such as fork()).
NuttX was first released in 2007 by Gregory Nutt under the permissive BSD license.
NuttX is a real timed embedded operating system (RTOS). Its goals are:
QEMU (short for Quick Emulator) is a free and open-source emulator that performs hardware virtualization.
QEMU is a hosted virtual machine monitor: it emulates the machine's processor through dynamic binary translation and provides a set of different hardware and device models for the machine, enabling it to run a variety of guest operating systems. It also can be used with KVM to run virtual machines at near-native speed (by taking advantage of hardware extensions such as IntelVT). QEMU can also do emulation for user-level processes, allowing applications compiled for one architecture to run on another.
QEMU has multiple operating modes:
We used the System emulation operating mode. For Cortex-M4 I used a fork from qemu https://gnu-mcu-eclipse.github.io/qemu/
1. git
sudo apt-get install git
2. qemu
sudo apt-get --no-install-recommends -y build-dep qemu
If is not working!
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list sudo apt-get update sudo apt-get --no-install-recommends -y build-dep qemu
3. nuttx
sudo apt-get install automake bison build-essential flex gcc-arm-none-eabi gperf libncurses5-dev libtool libusb-dev libusb-1.0.0-dev sudo apt-get install libgmp-dev libgmp3-dev libmpfr-dev libmpc-dev texinfo sudo apt-get install opencd
4. qemu gnu muc eclipse
sudo apt-get install automake bison build-essential flex gcc-arm-none-eabi gperf libncurses5-dev libtool libusb-dev libusb-1.0.0-dev sudo apt-get install libgmp-dev libgmp3-dev libmpfr-dev libmpc-dev texinfo sudo apt-get install opencd sudo apt-get install docker rm -rf ~/Downloads/qemu-build.git git clone --recurse-submodules https://github.com/gnu-mcu-eclipse/qemu-build.git ~/Downloads/qemu-build.git bash ~/Downloads/qemu-build.git/scripts/build.sh preload-images
To debug and create the entire functionalities for our machines you need the source code for Qemu. I used a version of Qemu which is targeting the arm devices and stm32 boards.
git clone https://github.com/beckus/qemu_stm32.git qemu-arm
The site for more demos and tutorials is at Link For Qemu_stm32 For making the stm32-p103 works we need to make a little change in Qemu source code.
cd qemu-arm gedit hw/arm/stm32_p103.c
At the line 129 I had to change the following:
/* Connect RS232 to UART */ stm32_uart_connect( (Stm32Uart *)uart2, serial_hds[0], STM32_USART2_NO_REMAP); /* These additional UARTs have not been tested yet... */ stm32_uart_connect( (Stm32Uart *)uart1, serial_hds[1], STM32_USART1_NO_REMAP);
in:
/* Connect RS232 to UART */ stm32_uart_connect( (Stm32Uart *)uart1, serial_hds[0], STM32_USART1_NO_REMAP); /* These additional UARTs have not been tested yet... */ stm32_uart_connect( (Stm32Uart *)uart2, serial_hds[1], STM32_USART2_NO_REMAP);
After you need to configure the qemu with debuging features:
./configure --enable-debug --target-list="arm-softmmu" --disable-werror --extra-cflags=-DDEBUG_CLKTREE --extra-cflags=-DDEBUG_STM32_RCC --extra-cflags=-DDEBUG_STM32_UART --extra-cflags=-DDEBUG_STM32_TIMER
Add –extra-cflags=-DDEBUG_GIC only if you want to see the interupts from the cpu and its state.
Build Qemu
make
For Nuttx we also need the source code. And some auxiliary modules if we want to use them later.
mkdir nuttx_env cd nuttx_env git clone https://bitbucket.org/nuttx/nuttx.git nuttx git clone https://bitbucket.org/nuttx/buildroot.git buildroot git clone https://bitbucket.org/nuttx/nonbsd.git nonbsd git clone https://bitbucket.org/nuttx/pascal.git Pascal git clone https://bitbucket.org/nuttx/tools.git tools git clone https://bitbucket.org/nuttx/uclibc.git uClibc++ git clone https://bitbucket.org/nuttx/apps.git apps
Nx module was moved in the apps repository. If you want an older version, you can find it at The nx module.
cd nuttx/ cd tools/
for STM32-p103:
./configure.sh stm32f103-minimum/nsh
for lm3s6965:
./configure.sh lm3s6965-ek/nsh
for stm32-f4discovery:
./configure.sh stm32f4discovery/nsh
Use the menuconfig to select buildtool and applications.
cd .. make menuconfig
In menuconfig enable (minimum):
Build Setup/Build Host Platform/Linux Build Setup/Debug Options/Generate Debug Symbols System type/Toolchain Selection/Generic GNU EABI toolchain under Linux (or other POSIX enviroment)
You can enable other features but be ready to implement some functions. Build:
make
First you need to build for the first time
bash ~/Downloads/qemu-build.git/scripts/build.sh --linux64 --develop --debug
Now in your home directory you have an directory called Work and in inside a folder called qemu-REALEASE_VERSION. It depends on your release version. The executable is located at ~/Work/qemu-REALEASE_VERSION/install/centos64/qemu/bin/qemu-system-gnuarmeclipse. The code that is being build is located at ~/Work/qemu-REALEASE_VERSION/qemu.git. You can modify as you want this code and after you can reuse the command shown before for building the new code. I made a fork with some USART implementation for the devices at https://github.com/sdcioc/qemu.
for running the machine(stm32-p103/lm3s6965) on Qemu with gdb debuging(-s)
./qemu-arm/arm-softmmu/qemu-system-arm -M stm32-p103 -kernel ./nuttx_env/nuttx/nuttx.bin -s
for running the machine(stm32-f407) on Qemu with gdb debuging(-s)
~/Work/qemu-REALEASE_VERSION/install/centos64/qemu/bin/qemu-system-gnuarmeclipse -M STM42F4-Discovery -kernel ./nuttx_env/nuttx/nuttx.bin --cpu cortex-m4 -s --serial pty --serial pty --serial pty --serial pty --serial pty --serial pty --serial pty --serial pty --serial pty --serial pty -S
After you can use the elf file from directory to use gdb
arm-none-eabi-gdb ./nuttx_env/nuttx/nuttx
In gdb use:
target remote localhost:1234
For Qemu MCU Eclipse for the stm32 type machine you can find a template in gnu-mcu-eclpise/develop/template
if you want to add a new machine to nuttx the next tutorial it can help you http://www.nuttx.org/Documentation/NuttxPortingGuide.html
Use the template for app nuttx_env/apps/examples/hello and after use the menuconfig to add the app from Aplication configuration/Examples/YOUR_APP
http://ieiointhecomputerland.blogspot.com/2015/02/nuttx-is-real-time-operating-system.html https://cristovaorufino.wordpress.com/2014/01/14/compiling-nuttx-for-stm32f4discovery/
If you want to implement the stelaris ethernet follow http://www.zilogic.com/blog/building-nuttx.html
If you want to test different functionalitties for stm32-f4 discovery follow http://jeremyherbert.net/get/stm32f4_getting_started