The purpose of this tutorial is to build our first “hello world” program for the MB997D evaluation kit. In this tutorial, we are going to set up a simplest demonstration program. We download a simple “hello.c” program based on Hyperpanel OS. We will compile this simple app and make a binary of hyperpanel OS including this app.
- A STMicroelectronics discovery kit with STM32F407VG MCU, order code STM32F407-DISC1 (replaces STM32F4DISCOVERY).
- USB 2.0 male to micro B cable (supplied with evaluation kit).
- A full installation of an Hyperpanel OS release on a linux based PC including tools for flashing and debugging. This tutorial requires release V10.03.02 for MB997D or higher. Hyperpanel OS releases are available for free in the Download section of the website.
- A Lunix PC with ARM gcc compiler, ARM gdb debugger and minicom installed.
- A text editor to edit or modify source codes (We are using vi in our demo).
- Added wires for trace access on USB port: The ST evaluation kit is USB-powered. You need to plug the ST-LINK kit’s USB socket into a USB socket on the Linux computer. This also enables you to view the application standard output. To do this, you also need to add the 2 wires (cf. picture) that send seria port 1 (ASY 1) to the MCU (STM32103CBT6) dedicated to ST-LINK output management.
hypv100302 and higher
Binary file
Hardware rework
The evaluation kit uses a USB port for power and debugger access. This connector is managed by a ST-LINK part, controlled by a STM32F103CBT6 (U2 on the board). The ST-LINK supports a virtual COM port on U2 pin 12 (ST-LINK_TX) and U2 pin 13 (ST-LINK_RX) but these pins are not connected to the USART of the STM32F407. To access to serial port for traces and messages, the solution is to use two flying wires to connect ST-LINK virtual COM port to the ASY1 HyperPanelOS serial port :
U2 (STM32F103CBT6) P2 (CONNECTOR)
PIN 12 (ST-LINK_TX) <---------------------> PC11 (ASY1_RX)
PIN 13 (ST-LINK_RX) <---------------------> PC10 (ASY1_TX)
- On www.tutorial.hyperpanel.com, select Download from the main menu.
- Download “Hyperpanel OS v10.03.02 for MB997D” or higher release for the MB997D kit.
- On your PC Linux, copy and unzip the zip file in your root directory, for example:
cp hypv100302.zip /home/hyperpanel cd /home/hyperpanel unzip hypv100302.zip
4. With a text editor, update hhome environment variable in the stm32m4 file:
cd ~/hypv100302/shells vi stm32m4
Update the first line, according to your root directory:
export hhome=/home/hyperpanel/hypv100302
5. Save this file and an execute the command:
source stm32m4
6. From this tutorial, use the button “Binary file” to download the zip file containing the binary. Unzip this file:
unzip hpos-tuto310-bin.zip
7. Copy this binary file in HyperPanelOS release:
cp hello.bin ~/hypv100302/boards/stm32m4/exe
8. Connect the MB997D board to a USB port on your Linux PC using the USB cable supplied with the board. Wait for a window to appear, then close it.
9. Open a Terminal window and run minicom to get access to application menu:
minicom -D /dev/ttyACM0 -b 115200
10. Open another Terminal window on your computer and enter the following commands:
cd ~/hypv100302/shells source stm32m4 exe
11. Upload software to the board:
hgdb romload stm32m4 hello
You should see messages similar to these:
Open On-Chip Debugger 0.10.0+dev-00001-g0ecee83-dirty (2017-02-10-06:53) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html 0x00002ec2 in ?? () target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00003138 msp: 0x10002000 auto erase enabled target halted due to breakpoint, current mode: Thread xPSR: 0x61000000 pc: 0x20000046 msp: 0x10002000 wrote 393216 bytes from file hello.bin in 11.147055s (34.449 KiB/s) hello.elf: No such file or directory.
Wait until the flashing operation is complete (approx. 30 seconds). The last message (hello.elf: No such file or directory) is normal.
12. You can now press on the reset button (black button) of the MB997D. Hyperpanel OS will start, and a “Hello World” message sent every second on the serial output.
To go further
If you want to edit the source code, write modifications, compile, link, etc., here’s how to do it:
- From this tutorial, use the button “Source code” to download the zip file containing the source file. Unzip this file:
unzip hpos-tuto310-source.zip
- Copy this source code in HyperPanelOS release:
cp hello.c ~/hypv100302/user/stm32app
- Copy the link file in Hyperpanel release:
cp hello.lst ~/hypv100302/boards/stm32m4/exe
- You can edit and make any modifications you want in the source file. For example, you can modify the time between two successive displays of “Hello World”. To do this, simply modify the value (in milliseconds) of the second parameter of the “set_uto()” procedure.
cd ~/hypv100302/user/stm32app vi hello.c
- Save the source file.
- Compile the source file:
cd ~/hypv100302/user/stm32app cmm hello
- Call the linker to create the new binary file:
exe lhypos hello
- You can now upload this new binary to the board, in the same way as in the previous Installation chapter.
Links
Serial output on console
/* ** Myapp_hello.c - Sample code for HyperpanelOS ========================== ** ** ** ** This simple code is located into the Application Container, it is run ** ** by the VMK sub-operating system. On the other hand, the I/O container ** ** runs all the drivers that are VMIO Finite State machines. ** ** ** ** The goal of this small aplication is to write a single message ** ** "Hello World" each second to serial port ASY0 ** ** ** ** ======================================================================= ** */ /* Includes files and external references ...................................*/ #include <hypos.h> // Hyperpanel OS basic interfaces #include <drv_asy.h> // Prototype of "asy_write" #include <mytsk.h> // Interface of "mytsk.c" /* Internal defines of this module ------------------------------------------*/ #define TICK 10000 // Code for tick event /* Internal global variables of this module ---------------------------------*/ unsigned int idto ; // Timer identifier /* Beginning of the code ---------------------------------------------------- loop_app_tsk Entry point for create_task - Main event loop */ /* Procedure loop_app_tsk ---------------------------------------------------- Purpose : This is our task main loop. */ int loop_app_tsk (void *param) { int ev ; // Our event int cpt = 0 ; // Counter of messages char mess[80] ; // Message to be sent /***************************************************************************** * Step 1 : We start a timer that will send us an event every 1 second so * * ------ that we can update the time. * *****************************************************************************/ set_uto(CLOCK , // Timer mode: clock 1000 , // Duration in milliseconds TICK , // Event code 0 , // Event reserve field &idto ) ; // Timer identifier /***************************************************************************** * Step 2 : Here is our main event loop. For each loop, we do as follows : * * ------- - First we wait for an event. * * - Then if the event code is TICK we print "Hello World" * *****************************************************************************/ wait_ev : // Beginning of loop label ev = wait_allevent() ; // Unschedule until an event is // received if ( ev == TICK ) // If the event is the tick event { // hsprintf(mess , // We build in "mess" the message "%6d Hello World\r\n", // to be sent cpt ++ ) ; // asy_write(0 , // We send on ASY0 (unsigned char*)mess , // the "mess" message strlen(mess) ) ; // Count of bytes to be sent } goto wait_ev ; // Wait for the next event return 0 ; }