Building and Running a Sample Program
Written by: Chan Siew Kiat (CHiPES, NTU)
Edited by: Mohit Sindhwani (TE@Onghu)
In a , we looked at the procedure to set up the T-Engine Development Kit under Linux. In this article, we present the steps that are needed to build and run a sample program under Linux. We tried with Red Hat 9.0 and also under Ubuntu Linux. The steps are fairly generic, and will work for any Linux distribution. The information presented in this article is derived from a similar article on TRONWeb. This article mentions some of those items, and also adds a few steps that we carried out in addition to the steps presented in that article.
Equipment and Tools Used
We set up the system on the following environment:
- Red Hat Linux 9.0 and Ubuntu Linux 5.04 (Intel x86 versions)
- T-Engine Development Kit Release 1.11E
- SH7727 T-Engine (with 128MB Compact Flash)
Procedure - Building a Sample Program
On the T-Engine Development Kit CD, sample programs can be found in the directory /home/USERNAME/te/kappl/ In this article, we will use the sample program from the location /home/USERNAME/te/kappl/sample
The typical directory structure includes one sub-directory for source code (called src) and one for files needed for and produced by the build process. This sub-directory includes the makefile for the application and all the object, executable, hex files, etc. are created here. All samples are built in the build directory. In the case of the SH7727 kit, the build directory is called sh7727, so we will work in the directory /home/USERNAME/te/kappl/sample/sh7727
1. Move to the build directory
We need to move to the build directory to do the build. If you have a different T-Engine development kit, the build directory may be different.
%cd /home/USERNAME/te/kappl/sample/sh7727
2. Run make
The makefile is already present in this directory. You need to use gmake for doing the build.
%gmake
You should see a number of messages as the build process takes place. If the program compilation and linking ends without error, a file called sample will be created within the directory. This is the executable file that will be downloaded to the T-Engine and run. If there are errors, make sure that the kit is .
3. Connect the T-Engine to the PC
Connect the T-Engine to the PC using the serial cable and to the power using the power supply cable.
4. Start the terminal on the PC
The T-Engine development kit comes with a terminal software that can communicate with the T-Engine using the serial port. This software is called gterm and is used to send commands and files to the T-Engine and vice versa. Start up the gterm on the Linux PC.
%/home/USERNAME/te/etc/etc/gterm –l /dev/ttyS0 –3
Notes:
- In the command above, the ‘-l’ is “minus L” and NOT “minus one”.
- The above command starts communication at a baud rate of 38400. If the jumper on the T-Engine is set to communicate at 115,200 baud, you will need to start gterm as follows:
%/home/USERNAME/te/etc/etc/gterm –l /dev/ttyS0 –b
%/home/USERNAME/te/etc/etc/gterm –l /dev/ttyUSB0 –3
5. Switch on the T-Engine
Slot the CF Card into the T-Engine’s PCMCIA slot and start up the T-Engine by holding the button located on the upper left of the board (on the side) for about 1 second. Upon successful startup, “[/SYS]%” prompt can be seen in the gterm window on the PC.
6. Format & Prepare the CF Card
The CF Card needs to be formatted before it can be used by the T-Engine as a working disk. Type these commands into the gterm window.
[/SYS]% hdpart pca
pca [C:977 H:8 S:32 B:250368 (122 MB)]
No System Boot StartCHS End CHS SecNo SecCnt MB
1 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
2 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
3 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
4 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
** Create/Delete/Boot/Edit/Quit ? c
Create PartNo (1-4) ? 1
Size [MB] (<123MB) ?
No System Boot StartCHS End CHS SecNo SecCnt MB
1 13 BTRON 00 0: 1: 1 977: 7:32 32 250336 122
2 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
3 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
4 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
** Create/Delete/Boot/Edit/Update/Quit ? b
Boot PartNo (1-4) ? 1
No System Boot StartCHS End CHS SecNo SecCnt MB
1 13 BTRON 80 0: 1: 1 977: 7:32 32 250336 122
2 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
3 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
4 00 ------ 00 0: 0: 0 0: 0: 0 0 0 0
** Create/Delete/Boot/Edit/Update/Quit ? u
** pca: Updated Master Boot Block
[/SYS]%
Next, we format the disk and call it WORK:
[/SYS]% format -b pca0 WORK
Format pca0 [STD] WORK
Logical Formatting...
Writing BootCode...
Disk Format Success.
[/SYS]%
7. Attaching the Disk
Similar to mounting a disk in Linux, it is necessary to attach the partition before it can be accessed by the T-Engine software. In the example below, the connection name is A. Type these commands into the gterm window.
[/SYS]% att pca0 A
pca0 -> A
[/SYS]% cd /A
[/A]%
8. Downloading the Executable
Next, we download the file sample from where we compiled it to the T-Engine CF Card. Type this command into the gterm window.
[/A]% recv -d sample
9. Executing the Program
Finally, we start the program sample using the lodspg command. Type this command into the gterm window.
[/A]% lodspg sample
hello (ac=1)
av[0] = 'sample'
SYSPRG sample [6] 40229000 - 4022f000
[/A]%
10. Downloading the Executable
The program can be terminated using the unlspg command. If the program terminates by itself, then you do not need to do this. Type this command into the gterm window. The number in the command must correspond to the number that was displayed when the program was loaded in the previous step.
[/A]% unlspg 6
hello (ac=-1)
[/A]%
That’s all there is! You should now be able to do the same for other samples, or for other programs that you write.
Notes:
(1) This article has been contributed to TE@Onghu by the Centre for High Performance Embedded Systems, and has been used by permission.
(2) As always, I have made an effort to ensure that the content available on this site is correct and is up to date. If you find any information to be incorrect, please inform me by emailing mohits@onghu.com
© Centre for High Performance Embedded Systems, Nanyang Technological University, Singapore & Mohit Sindhwani, 2005.