Thursday, July 12, 2018

FreeRTOS on Cortex M3 with QEMU

This is a brief guide on how to get started with ARM development with FreeRTOS running on an Cortex M3 MCU (Stellaris LM3S811) in QEMU.

First get the latest version of ARM GCC and FreeRTOS. Download, extract and install the ARM GCC and then build the FreeRTOS demo.

cd FreeRTOSv10.0.1/FreeRTOS/Demo/CORTEX_LM3S811_GCC
make


if you get:

LD    gcc/RTOSDemo.axf
arm-none-eabi-ld: section .text.startup LMA [0000000000002a2c,0000000000002b97] overlaps section .data LMA [0000000000002a2c,0000000000002a2f]
makedefs:189: recipe for target 'gcc/RTOSDemo.axf' failed
make: *** [gcc/RTOSDemo.axf] Error 1


You will need to patch the standalone.ld file, my modified ld file looks like this:


MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
}

SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text)
*(.rodata*)
_etext = .;
} > FLASH

/* .data : AT (ADDR(.text) + SIZEOF(.text)) */
.ARM.exidx :
{
*(.ARM.exidx*)
*(.gnu.linkonce.armexidx.*)
} > FLASH

_begin_data = .;

.data : AT ( _begin_data )
{
_data = .;
*(vtable)
*(.data)
_edata = .;
} > SRAM

.bss :
{
_bss = .;
*(.bss)
*(COMMON)
_ebss = .;
} > SRAM
}


Now install QEMU

sudo apt install qemu-system-arm

I had an issue with curl versioning, i had curl4 installed but QEMU required curl3.
I got the following error message:

qemu-system-arm: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found (required by qemu-system-arm)

And I resolved it by running:

sudo apt install libcurl3

Now launch the FreeRTOS demo inside QEMU with:

qemu-system-arm -machine lm3s811evb -kernel gcc/RTOSDemo.bin -s -S


Open a new terminal and run:

arm-none-eabi-gdb -ex="target remote localhost:1234"


You should now be connected to the STM3 core running in QEMU, notice that its "stopped"
To start the execution enter "continue" or "c" in GDB.

To learn about ARM assembly take a look here https://azeria-labs.com/writing-arm-assembly-part-1/
and to get better control of GDB check here: https://sourceware.org/gdb/current/onlinedocs/gdb/

1 comment: