ChibiOS on tiva launchpad

Posted at 2014-10-29.

Another little test session with a Tiva Launchpad.

(Previous at 2014-10-28)

I decided to try building and booting ChibiOS. I've seen it used on STM32 and it looks like a promising project.

Build

I cloned a ChibiOS-Tiva port repo. (edit: New developments might be in this chibios contrib repo)

$ git clone https://github.com/marcoveeneman/ChibiOS-Tiva.git
Cloning into 'ChibiOS-Tiva'...
remote: Counting objects: 2295, done.
remote: Total 2295 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2295/2295), 3.64 MiB | 119.00 KiB/s, done.
Resolving deltas: 100% (1389/1389), done.
Checking connectivity... done.

Build out of the box, almost.

$ cd https://github.com/marcoveeneman/ChibiOS-Tiva
$ make
...
Linking build/ch.elf
main.c: In function 'main':
main.c:51:5: internal compiler error: Segmentation fault
 int main(void)
     ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: arm-none-eabi-gcc returned 1 exit status
/usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/bin/ld:
lto-wrapper failed
collect2: error: ld returned 1 exit status
../../../os/common/ports/ARMCMx/compilers/GCC/rules.mk:230: recipe for
target 'build/ch.elf' failed
make: *** [build/ch.elf] Error 1

This apparently is a conflict with some options as well as a genuine compiler bug since segfault is never appropriate behaviour. Dropping optimization makes the linking work:

$ make USE_LTO=0
Linking build/ch.elf
Creating build/ch.hex
Creating build/ch.bin
Creating build/ch.dmp

   text    data     bss     dec     hex filename
  27176     824    5448   33448    82a8 build/ch.elf

Done

Run

Our friendly debuggers again:

$ openocd -f interface/ti-icdi.cfg -f target/stellaris_icdi.cfg
Open On-Chip Debugger 0.7.0 (2013-08-04-09:35)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : This adapter doesn't support configurable speed
Info : ICDI Firmware version: 9270
Info : lm3s.cpu: hardware has 6 breakpoints, 4 watchpoints

$ arm-none-eabi-gdb build/ch.elf 
GNU gdb (7.7.1+dfsg-1+6) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/ch.elf...done.
(gdb) target remote :3333
Remote debugging using :3333
0x00000000 in _vectors ()
(gdb) monitor reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000002e0 msp: 0x20000100
(gdb) load
Loading section startup, size 0x280 lma 0x0
Loading section .text, size 0x6a28 lma 0x280
Loading section .data, size 0xb8 lma 0x6ca8
Start address 0x380, load size 28000
Transfer rate: 20 KB/sec, 7000 bytes/write.
(gdb) monitor reset init
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000380 msp: 0x20000400
(gdb) cont
Continuing.

And there's a lightshow. :)

Modify

For a little more interesting rgb shuffle, try some changes like this:

$ git diff
diff --git a/demos/TIVA/RT-TM4C123G-LAUNCHPAD/main.c
b/demos/TIVA/RT-TM4C123G-LAUNCHPAD/main.c
index bb6e963..8b796f0 100644
--- a/demos/TIVA/RT-TM4C123G-LAUNCHPAD/main.c
+++ b/demos/TIVA/RT-TM4C123G-LAUNCHPAD/main.c
@@ -31,6 +31,7 @@ typedef struct led_config
 static THD_WORKING_AREA(waBlinkLedRed, 128);
 static THD_WORKING_AREA(waBlinkLedGreen, 128);
 static THD_WORKING_AREA(waBlinkLedBlue, 128);
+
 static msg_t blinkLed(void *arg)
 {
   led_config_t *ledConfig = (led_config_t*) arg;
@@ -64,15 +65,15 @@ int main(void)

   ledRed.port    = GPIOF;
   ledRed.pin     = GPIOF_LED_RED;
-  ledRed.sleep   = 100;
+  ledRed.sleep   = 250;

   ledGreen.port  = GPIOF;
   ledGreen.pin   = GPIOF_LED_GREEN;
-  ledGreen.sleep = 101;
+  ledGreen.sleep = 500;

   ledBlue.port   = GPIOF;
   ledBlue.pin    = GPIOF_LED_BLUE;
-  ledBlue.sleep  = 102;
+  ledBlue.sleep  = 1000;

   /*
    * Creating the blinker threads.

Since it's a git repo, git diff is a nice way to see what you've been up to.

Test thread (edit)

Apparently there's also a test thread that can be triggered with SW2. Output comes over serial port. After a bit of grepping, I found the bitrate define as 38400 for TIVA.

$ picocom /dev/ttyACM0  -b 38400
picocom v1.7

port is        : /dev/ttyACM0
flowcontrol    : none
baudrate is    : 38400
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,

Terminal ready

*** ChibiOS/RT test suite
***
*** Kernel:       3.0.0dev
*** Compiled:     Oct 29 2014 - 23:06:04
*** Compiler:     GCC 4.8.3 20140820 (release)
*** Architecture: ARMv7-ME
*** Core Variant: Cortex-M4F
*** Port Info:    Advanced kernel mode
*** Platform:     Tiva C Series TM4C123x
*** Test Board:   Texas Instruments TM4C123G Launchpad

----------------------------------------------------------------------------
--- Test Case 1.1 (Threads, enqueuing test #1)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 1.2 (Threads, enqueuing test #2)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 1.3 (Threads, priority change)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 1.4 (Threads, delays)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.1 (Semaphores, enqueuing)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.2 (Semaphores, timeout)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.3 (Semaphores, atomic signal-wait)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.4 (Binary Semaphores, functionality)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.1 (Mutexes, priority enqueuing test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.2 (Mutexes, priority return)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.3 (Mutexes, status)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.4 (CondVar, signal test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.5 (CondVar, broadcast test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.6 (CondVar, boost test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.1 (Messages, loop)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 5.1 (Mailboxes, queuing and timeouts)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 6.1 (Events, registration and dispatch)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 6.2 (Events, wait and broadcast)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 6.3 (Events, timeouts)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 7.1 (Heap, allocation and fragmentation test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 8.1 (Memory Pools, queue/dequeue)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 9.1 (Dynamic APIs, threads creation from heap)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 9.2 (Dynamic APIs, threads creation from memory pool)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 9.3 (Dynamic APIs, registry and references)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 10.1 (Queues, input queues)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 10.2 (Queues, output queues)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.1 (Benchmark, messages #1)
--- Score : 244476 msgs/S, 488952 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.2 (Benchmark, messages #2)
--- Score : 203513 msgs/S, 407026 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.3 (Benchmark, messages #3)
--- Score : 203513 msgs/S, 407026 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.4 (Benchmark, context switch)
--- Score : 730128 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.5 (Benchmark, threads, full cycle)
--- Score : 163330 threads/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.6 (Benchmark, threads, create only)
--- Score : 224756 threads/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.7 (Benchmark, mass reschedule, 5 threads)
--- Score : 63934 reschedules/S, 383604 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.8 (Benchmark, round robin context switching)
--- Score : 445520 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.9 (Benchmark, I/O Queues throughput)
--- Score : 661028 bytes/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.10 (Benchmark, virtual timers set/reset)
--- Score : 749472 timers/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.11 (Benchmark, semaphores wait/signal)
--- Score : 1079996 wait+signal/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.12 (Benchmark, mutexes lock/unlock)
--- Score : 762260 lock+unlock/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.13 (Benchmark, RAM footprint)
--- System: 732 bytes
--- Thread: 68 bytes
--- Timer : 20 bytes
--- Semaph: 12 bytes
--- EventS: 4 bytes
--- EventL: 20 bytes
--- Mutex : 16 bytes
--- CondV.: 8 bytes
--- Queue : 36 bytes
--- MailB.: 40 bytes
--- Result: SUCCESS
----------------------------------------------------------------------------

Final result: SUCCESS

Conclusion

Things work, but the incompatibility of GCC link time optimization and -ggdb was news. In fact both options are new to me at this point.

Links