Tuesday, November 8, 2016

STM32f429 Discovery on ucLinux: How to run user programs.

The uClinux is able to run on the STMf429 Discovery board.
But...

What should user programs run to do on the boards?


I have two ideas.
  1) User programs write "romfs" on your PC.
  2) User programs transmit via console.

This document explains two methods.

Chapter 1. Writing to "romfs".

The uClinux environment was installed and built successfully, when you see development directory.
pardus@STM32dev:~/src/stm32f429-linux-builder$ ls
busybox-1.22.1  downloads  mk   README.md  stamp-kernel  u-boot
configs         Makefile   out  rootfs     stamp-uboot   uclinux

That "rootfs" is base image of rootfs and user programs write under "rootfs".
Ex. Writung "hello" at /root/

pardus@STM32dev:~/src/stm32f429-linux-builder$ cp ../hello/hello rootfs/root
pardus@STM32dev:~/src/stm32f429-linux-builder$ ls rootfs/root
hello placeholder

Rebuild and reinstallation run on development PC.
pardus@STM32dev:~/src/stm32f429-linux-builder$ make clean-rootfs
pardus@STM32dev:~/src/stm32f429-linux-builder$ make build-rootfs
pardus@STM32dev:~/src/stm32f429-linux-builder$ make install

When rebooted, you can type command on uClinux to see hello program in board file system.
~ # cd root    
/root # ls
hello
/root # ./hello
   Hello World!!    
/root #


Chapter 2. Transmit via Console.

Method Chapter 1 is previously write romfs, but romfs is read-only file system and romfs must rebuild whenever update programs. I want to transmit running on uClinux.

Let see file system by "mount" and "df" command.
~ # mount
rootfs on / type rootfs (rw)
/dev/root on / type romfs (ro,relatime)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
/dev/ram0 on /var type ext2 (rw,relatime,errors=continue,user_xattr,acl)

/root # df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                  364       364         0 100% /
/dev/ram0                 1003        17       986   2% /var
 

This system has two file device, one is romfs other is ramfs.
"romfs" isn't writing read only but "ramfs" is possible read and write.
There are several method of transfer programs, I adopt simplest method by copy-paste and linux commands.
Using commands are "uuencode" and "uudecode" in busybox, but they wasn't built. Using commands edits busybox configuration file.
   [your development environment]/stm32f429-linux-builder/configs
   busybox_config

There are two configuration way, one is editing two line in that file.
  # CONFIG_UUDECODE is not set
  # CONFIG_UUENCODE is not set
    Change to
  CONFIG_UUDECODE=y
  CONFIG_UUENCODE=y

More one is able to change by "make menuconfig".


You need configuration file Load/Save!

If you use "make menuconfig" when you need previously installing ncurses.
   apt-get install ncurses-dev  

Configure file changed completely then rebuild file system and installing.
Rebuilding previously clean busybox development environment.

pardus@STM32dev:~/src/stm32f429-linux-builder$ cd busybox-1.22.1/
pardus@STM32dev:~/src/stm32f429-linux-builder$ make clean
pardus@STM32dev:~/src/stm32f429-linux-builder$ make mrproper
pardus@STM32dev:~/src/stm32f429-linux-builder$ cd ..
pardus@STM32dev:~/src/stm32f429-linux-builder$ make clean-rootfs
pardus@STM32dev:~/src/stm32f429-linux-builder$ make build-rootfs
      :
pardus@STM32dev:~/src/stm32f429-linux-builder$ make install

Sample program "hello2.c"
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {      

    if(argc < 2) {
        printf("I need a arg!\n");
        exit(-1);
    }
    printf("   Hello World!!\n");
    printf("      %s\n", argv[1]);

    exit(0);
}

$ arm-uclinuxeabi-gcc -g -Os -g2 -mthumb -mcpu=cortex-m3 -O2 hello2.c -o hello2 

Binary file "hello2" convert text file use "uuencode" command on development PC.
pardus@STM32dev:~/src/hello2$ uuencode hello2 hello2 > hello2.uu  


if "uuencode" command isn't installed your PC when you install commands.

   apt-get install sharutils  

Created "hello2.uu" show on PC terminal and all slect and copy.
STM32f4 console type command "uudecode" and paste.
~ # cd /var
/var # uudecode
STOP TERMINAL,
AND YOU CAN PASTE "hello2.uu" TEXT FILE.
       :
       :
/var # ./hello2
I need a arg!
/var # ./hello2 hoge
   Hello World!!
      hoge
/var #

However, you want to transfer STM32f4 to PC, when you can use "uuencode" command on STB32f4 and copy text. For example games save data files...


Have a nice computing!


No comments:

Post a Comment