Getting TI-RTOS running on the BeagleBone Black

Why An RTOS when the BeagleBone has Linux?

This is an excellent question. For most things, Linux is great and works well. For my purposes, Linux isn’t fast enough and I enjoy working close to the metal and figuring out what makes pieces of silicon tick. Also, I hope to make the BeagleBone Black into a long term development platform that I won’t outgrow for some time. Normally I do my development with no operating system at all, but the real time operating system will make upgrading platforms in the future somewhat less painful. Just a fair warning, I’m writing out every detail I can think of for getting the environment up, which can be a bit cumbersome for experience users, but I’m an idiot and can’t figure out what to do when a guide leaves out details.

Why The BeagleBone Black?

The reasons for the BeagleBone Black are many, but the biggest two are it’s low price and ample documentation. It is a shockingly powerful platform and is all open source, with a 4500+ pdf describing its innards. Also, it comes in at $56, although for bare metal and RTOS programming it will be a bit more expensive than that as you will need to buy a JTAG debugger. I use the XDS110 from TI, and have very few problems with it. You will also need to get your hands dirty with a soldering iron and some surface mount soldering with this adapter to allow JTAG debugging. I have found a good video describing what needs to be done here

Why Another Stupid HowTo Guide?

This is meant as a documentation page for myself and for my team mates on projects. Also, I’ve had a heck of time tracking down the necessary documentation for the different pieces necessary to get this up and running.

Getting the Environment Set Up

I’m going to be using Code Composer Studio, TI’s IDE and glorified version of Eclipse, because it makes my life easier for embedded development, even though I normally use vim+make/cmake. So the first step is to go and download Code Composer Studio, which has been made free by the fine folks down at TI. In the bad old days, it wasn’t this way.

You can get CCS here. Follow the instructions for whatever operating system you use, although from here on out I’ll be assuming you are using Linux, because there are no other operating systems. I will highly suggest that you install all of the compilers, although the only one’s we’ll need here are the Sitara and PRU compilers. I have found it exceedingly difficult to install new compilers after the fact, so much so that its just easier to run the installer again.

Now that you have CCS as well as the drivers installed (on Linux, you had to run a script to do so), you are ready to install the processor SDK for the AM355x, which is the processor that our friend the BeagleBone Black features.

You can get the Processor SDK here. You may have to change the file download to executable with our old friend chmod +x $FILE_NAME.

As you go through the wizard, just leave everything checked and standard. I would advise that you put the install in the same place that you put your CCS install. I put mine under the default ~/ti/. I know, I’m a monster.

Wait a few seconds for everything to finish up. Also, install doxygen to make your life easier. I’m running ubuntu-gnome so the magic spell is

sudo apt-get install doxygen

Once that’s installed, open up a terminal and type in the incantations below. From here on out I’m assuming the install directory is ~/ti. If you put it somewhere else, I’m assuming you are adept enough to figure out what to change. Also, some of the version numbers may change depending on when you access this post.

cd ~/ti/processor_sdk_rtos_am335x_4_00_00_04/
export CG_XML_BIN_INSTALL_PATH="~/ti/CG_XML/bin"
export DOXYGEN_INSTALL_PATH="/usr/bin/doxygen"
source setupenv.sh
make

Now get up, get some coffee and come back, its building quite a few files. It took a couple of minutes on my machine, although your mileage may vary. If good is good and right is right, you should have a fully built processor sdk. If you got some errors, I would guess that you ran setupenv.sh instead of sourcing it, which is a problem that I ran into for a few hours.

Making Our First Project

Wipe the sweat off your forehead, its time to get down close to the metal. Open up your copy of Code Composer Studio. If you installed the processor SDK in the same parent directory as Code Composer, it should auto recognize the software that we just installed.

Go to File->New Project. In the “Target” box, type in BeagleBone_Black.

Select the Cortex A as the processor target and scroll down in the templates box until you see SYS/BIOS, expand that option and click “Typical.” Let’s give our project a snappy, original name like “HelloWorld”. Also if you have your JTAG debugger hooked up, you can test that connection here. Go to the dropdown box labeled “Connection” and select your JTAG debugger. For me, it was the XDS110. You can click the “verify” button and you’ll see some text about scans and then this line.

The JTAG DR Integrity scan-test has succeeded.

If you didn’t get something like this, something probably went wrong, although I can’t speak for all debuggers. Also, choose a compiler, I go with GCC 4.9.x since it’s what I use for some other libraries that I link against, although I assume GCC 6 will work fine as well.

Click Next and you’ll be presented with installable software. Select am355x PDK, NDK, EDMA3 Low Level Driver, and SYS/BIOS and Sitara. For the platform, select ti.platforms.beaglebone. Click Finish.

Now you should have a project template with a task setup. Note that it uses System_printf (), instead of printf. Not a problem, just remember to flush the buffer with System_flush when you want to receive output. Don’t do this too often, as it is supposedly a somewhat costly operation. Take the task  defined in taskFxn and delete the body of it. Insert the following incantations:

System_printf ("Hello, world!\n");
System_flush ();

Also, get rid of the System_printf () in the main function, just to be true to style.

Before we build, we need to add a library which will let us use the System_printf properly. Right Click on the project we made and click on properties. Go to Build->GNU Linker. On the Libraries window, click the button with the page with little green plus, to add a library. Put the following text into the box:

"rdimon"

While you are there, remove “nosys” from the libraries.

Next open up the *.cfg (mine’s called app.cfg) file in your project. Add the following line, which will allow us to view text in CCS:

var semihostsupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');

Click the little bug on the toolbar on top, and load the program into memory and start debugging. It will ask you what processor you want to load this onto, select the Cortex A8. I have not tried the little M3 wakeup MCU that is there yet, but I suppose it could work.

If your BBB is off in Linux land, you’ll get an error that the JTAG debugger wasn’t able to grab the processor with it’s pesky MMU. There are a couple fixes to this, the best one seems to be to hold down the boot button with no SD card while power is applied, to stop the loading process. This works better when we get to the PRU’s down the road. For now, if you are lazy like me, you can just hit the reset button on the BBB and quickly hit retry on the error window.

You should be greeted by a few windows that show up detailing registers and cores and etc. Its fun to look around, there’s quite a bit in this little processor, although not all of it will be available with the MMU on. We will get to that problem a little later on.

Finally hit run, it should be the little “go” arrow. You should see the following output below:

[CortxA8] Hello, World!

Tada! Its probably not the most complicated way to do it, but it sure is a bit tougher than on a native processor.  In the next post we will be going over how to utilize the Ne10 library made by ARM to use the all powerful NEON vector operator without having to get down and dirty with assembly quite yet. After that we’ll look at debugging the programmable real time units and how we can communicate with them in the RTOS and the hell that ensues with the MMU.

Until next time,

Marc