Introduction
This tutorial will show you how to use ChibiOS/RT on a Nios II cpu based on an
Altera DE1 Board.
First some notes from http://www.chibios.org: ChibiOS/RT is designed for deeply
embedded real time applications where execution efficiency and compact code are important
requirements. This RTOS is characterized by its high portability, compact size and, mainly,
by its architecture optimized for extremely efficient context switching.
Feature highlights:
- Efficient and portable preemptive kernel.
- Static architecture, everything is statically allocated at compile time.
- Dynamic extensions, dynamic objects are supported by an optional layer built on top of the static core.
- Rich set of primitives: threads, virtual timers, semaphores, mutexes, condition variables, messages, mailboxes, event flags.
- Extensive test suite with benchmarks.
- Many supported architectures.
- And many more features, take a look at the ChibiOS/RT page.
The static architecture makes the life a little easier. Here you do not need to setup e.g.
a thread or semaphore count of your project. It does not waste your memory, only resources
are used which are really needed.
Note: You must have processed session 1 before
you can follow this session.
Like in the session before I do not want to write every time "Quartus II" or "Nios
II" in this tutorial. Therefore I will use the short form "Quartus" and
"Nios".
Install the ChibiOS port
Assumed you have installed the Quartus II 11.1 software under "C:\ altera"
there will exist the following folder:
After expanding the ZIP file, with the ChibiOS port, from the download
section you will get a folder named "chibios_4_niosii_v227". Copy this folder
into the "C:\altera\11.1\ip" folder. You should now have a new folder structure like:
C:\altera\11.1\ip\chibios_4_niosii_v227
Now you can create applications which are based on ChibiOS/RT v2.2.7.
Program the FPGA
Here we will repeat the last section from the session before and program the FPGA.
I assumed that you have connect the DE1 board still with your computer and the
USB-Blaster driver is still installed.
For programming the FPGA select "Tools > Programmer" from the Quartus menu.
Because of the absent Nios license I got a message about the OpenCore Plus feature:
Press "OK", and the programmer window will be opened:
(Click inside the picture to expand)
Everythink looks ok here. Click the "Start" button to program the FPGA. If you
have problems to program the FPGA, press the "Start" button again. If the LEDR9
is blinking and the "Progress" indicator looks like:
The 7-segment display shows 8888, and the green and red LEDs are off? Then programming the
FPGA was successful. Now we can start the Nios II Software Build Tools for Eclipse.
Nios II Software Build Tools (SBT)
To start the Software Build Tools (SBT) click on the shortcut which was created during the
Quartus installation:
While starting Eclipse you should see the following spash screen:
After a while Eclipse want to know where to store the workspace. Here I have installed the
altera software under "D:\altera", therefore I will use "D:\altera\workspace"
for the workspace:
Enter your directory and press "OK". Now the following "Welcome" window
will appear:
(Click inside the picture to expand)
To get more space, close the "Welcome" tab, the window should now look like:
(Click inside the picture to expand)
Before we can start with the application, a Board Support Package (BSP) is needed. The BSP
will created in the next section.
Creating the BSP
To creating a new BSP use "File > New > Nios II Board Support Package". A new
dialog will be opened. For the "Project name:" type "de1_chibios_bsp".
Browse to the SOPC information file which was created during the first session. Your file
should be stored under: "c:\my_design\de1_chibios", select the "de1_sopc.sopcinfo"
file. It will takes some seconds...
Use the default location, it should be:
"C:\my_design\de1_chibios\software\de1_chibios_bsp"
Select "ChibiOS/RT v2.2.7" for the "BSP type". The dialog should now
look like:
Press "Finish". After some seconds, the BSP was created and the Eclipse
window should look like:
(Click inside the picture to expand)
Let us take a look in the "Projekt Explorer", here the new BSP was created. If
you expand the "de1_chibios_bsp" folder by clicking on the "+" sign,
you will see all the files which was created by the SBT.
Even there are some status information available in the "Console" tab. The BSP
was now created, and we can start to configure it in the next step.
Configure the BSP
To configure the BSP project, select the "de1_chibios_bsp" in the
"Project Explorer" and use "Project > Properties":
This will open a new window, which should look like:
(Click inside the picture to expand)
Select "Nios II BSP Properties" and press the "BSP Editor..." button.
The Nios II BSP Editor will be opened:
(Click inside the picture to expand)
There exist a lot of options which can be changed. For more detailed information, please
take a look in the Altera documentation. Here I will explain only a small subset which we
are using.
Under "Settings > Common > hal" you will find the setting for the UART.
The SOPC from our example contains two UARTs, "jtag_uart" and "uart_0".
You remember? Under the hal you can change e.g. which UART should be used for stderr, stdin
and stdout:
Select "jtag_uart" for stderr, stdin and stdout. Even the sys_clk_timer can be
changed here. Important: For the ChibiOS project timer_0 must be selected for the sys_clk_timer.
The ChibiOS configuration can be changed under "Settings > Advanced >
chibios_v227":
(Click inside the picture to expand)
For more information about the ChibiOS configuration, please take a look in the
documentation and guides of ChibiOS itself.
If you have changed anything, a new BSP must be created. Therefore press the
"Generate" button. To leave the Editor, press the "Exit" button. If
you have forgotten to generate a new BSP, you will be asked before leaving:
Press "Yes, Save" if you have changed something, and you want to use this new
configuration. Now the BSP Editor is closed and the focus is set back to the properties of
"de1_chibios_bsp". Press the "OK" button to close the properties dialog.
Hint: You get the option to generate a new BSP or open the "BSP Editor..."
by right click on the "de1_chibios_bsp" project and selecting "Nios II":
(Click inside the picture to expand)
If you have changed anything from your SOPC design (session 1), make sure you generate a new
BSP too.
Creating the Application
Lets start with the application. Use "File > New > Nios II Application and
BSP from Template". A new dialog will be opened. Important: Select here "Blank
Project" first.
Browse to the SOPC information file which was created during the first session. Your file
should be stored under: "c:\my_design\de1_chibios", select the
"de1_sopc.sopcinfo" file.
Use "de1_chibios" for the "Project name:". The default location should
be "C:\my_design\de1_chibios\software\de1_chibios". The dialog should look like:
(Click inside the picture to expand)
Press "Next >". Now you must select the BSP which was created before. Enable
the option "Select an existing BSP project from your workspace". And select
"de1_chibios_bsp". The dialog should now look like:
(Click inside the picture to expand)
Press the "Finish" button to close the dialog. Now it takes some seconds and an
empty project (de1_chibios) was created by the SBT. The "Project Explorer" should
look like:
Next you must add your source files to the project. For the tutorial here I have prepared
an small example which will play with the LEDs. Therefore copy the main.c file itself into the "C:\my_design\de1_chibios\software\de1_chibios"
folder. Now right click on "de1_chibios" and use "Refresh":
The project will now be refreshed, main.c will be added and the makefile updated. The
"Project Explorer" should now look like:
The project can be build now. Right click on "de1_chibios" and use "Build
Project":
This will start the build process of the application and BSP, the window will look like:
(Click inside the picture to expand)
At the end of the build process, the "Project Explorer" will look like:
Hint: In case you have changed the BSP configuration, but do not generate a new BSP itself
you will get an error. Take a look in the Console tab:
(Click inside the picture to expand)
The BSP must be generated again. Start the build process of the application, the
BSP and application will be build, hopefully without any error.
Now it is time for a break. When you get back, we will start to debug the application.
How to debug?
To start the debugger, right click on the "de1_chibios" project and use
"Debug As > Nios II Hardware":
(Click inside the picture to expand)
This will start the debugger, and after a while it is possible that you will see the
following message box:
Press "Yes" and you will switch to the debug perspective. If you enable the
checkmark "Rember my decision", the switch will be done automatically next time.
The debug perspective will look like:
(Click inside the picture to expand)
You can step through the code with the following button (in the Debug window):
Step Into
|
|
Step Over
|
But we want to run the program, use the "Resume" button:
After pressing the "Resume" button, the green and red LEDs are flashing.
You can "Terminate and Remove" your debug task with the "Terminate" button:
Trouble shooting
Under rare conditions, it could be possible that the debugger will not start. In this
case the "Debug Configurations" will be started (or you must start it manual):
(Click inside the picture to expand)
Select the "Target Connections" tab, it should look like:
(Click inside the picture to expand)
In case the "Cable" does not show "USB-Blaster on localhost [USB-0]",
press the "Refresh Connections" button (sometimes twice or more). If you can see
the correct Cable information, press the "System ID Properties..." button. The
message box should look like:
Here it is important that the "Expected system ID" and the "Conencted system
ID" are equal. Even the "Expected system timestamp" and "Connected system
timestamp" must be equal. If not, close the message box and press the "System ID
Properties..." button again.
If everything is OK, the debugger can be start by pressing the "Debug" button in
the "Debug Configurations" windows.
Download
The zip files do not contain a full ChibiOS/RT version. For an original version of ChibiOS/RT
and the license information take a look at the following page.
main.c example (9 KB)
7-Segment Display example (17 KB)
ChibiOS/RT v2.6.8 (20150710) port for Quartus II 11.1 (114 KB)
ChibiOS/RT v2.4.6 (20140501) port for Quartus II 11.1 (115 KB)
Older versions
ChibiOS/RT v2.6.6 (20150101) port for Quartus II 11.1 (114 KB)
ChibiOS/RT v2.6.3 (20140502) port for Quartus II 11.1 (114 KB)
ChibiOS/RT v2.6.0 (20130714) port for Quartus II 11.1 (114 KB)
ChibiOS/RT v2.4.3 (20130203) port for Quartus II 11.1 (115 KB)
ChibiOS/RT v2.4.1 (20120526) port for Quartus II 11.1 (112 KB)
ChibiOS/RT v2.4.0 (20120212) port for Quartus II 11.1 (112 KB)
ChibiOS/RT v2.2.9 (20120318) port for Quartus II 11.1 (110 KB)
ChibiOS/RT v2.2.8 (20120103) port for Quartus II 11.1 (109 KB)
ChibiOS/RT v2.2.7 (20111120) port for Quartus II 11.1 (109 KB)
|