Sunday, December 22, 2013

Olimex Micro and PWM Pin outs

Here are some of the issues of moving the Serial port to AUART

- During boot the RX AUART needs to be tied to VCC to prevent it from floating and having junk appear and cause u-boot to suspend booting.
- The debug UART does output a message if the SDCARD is not valid.


Added a couple of boot scripts to control the LED on the Micro. The idea is to let the user know the status of the boot process.

- solid green: u-boot is running.
- slow blink rate: Linux kernel us running
- flash blink rate: Wifi is connected to AP

During the Linux boot process /etc/init.d boot scripts are executed.  The lower the number the file will be started before others:

S10Led:

cd /sys/class/leds/green
cat trigger
echo none > trigger
cat trigger
echo 1 > brightness
echo 0 > brightness
echo timer > trigger
echo 500 > delay_on
echo 500 > delay_off

Sets up the LED to blink at 500ms off and 500ms on.



Micro and u-boot

One of the issues of using buildroot with imx233-OLinuxino Micro is any time the Linux image requires to be updated (adding drivers, or features for some user app needs from the kernel) the sdcard needed to be removed and re-imaged.

One way to fix this is to use a bootloader (u-boot).  u-boot is a simple boot loader able to read EXT4/EXT3/EXT2/FAT file systems and load Linux, device trees, and boot files.  It is a very powerful boot loader.

With u-boot, the linux binary zImage is in the EXT4 file system at /boot.  So, using simple ssh commands from Linux, the zImage can be updated like a normal file.

The project the Micro is going to be used for is to control a Multi-Chassis via WIFI using a web browser from an iPAD or Phone.   The reason of using a Web Browser, is it is cross platform; no code to be written for each OS.  To keep things simple, it does not support control from the desktop; will get into that more later.

Controlling the chassis is done via a motor controller via PWM.  The Micro has 3 PWM controllers.
For this project one of the biggest hurdle was the PWM pins are also used for the serial pins for u-boot and Linux.  PWM0 (RX) PWM1(TX) are on the debug serial port.  So, needed to reconfigure u-boot to use AUART APP0 serial port.

To move u-boot and Linux serial ports does take some doing.  Here are the basic steps:

1. edit build/uboot-2013.10/include/configs/mx23_olinuxino.h
Basic changes are the ENV to boot a zImage and use AUART

/* Extra Environment */
#define CONFIG_EXTRA_ENV_SETTINGS \
"update_sd_firmware_filename=u-boot.sd\0" \
"update_sd_firmware=" /* Update the SD firmware partition */ \
"if mmc rescan ; then " \
"if tftp ${update_sd_firmware_filename} ; then " \
"setexpr fw_sz ${filesize} / 0x200 ; " /* SD block size */ \
"setexpr fw_sz ${fw_sz} + 1 ; " \
"mmc write ${loadaddr} 0x800 ${fw_sz} ; " \
"fi ; " \
"fi\0" \
"script=boot.scr\0" \
"uimage=zImage\0" \
"console=ttyAMA0\0" \
"fdt_file=imx23-olinuxino.dtb\0" \
"fdt_addr=0x41000000\0" \
"boot_fdt=try\0" \
"ip_dyn=yes\0" \
"mmcdev=0\0" \
"mmcpart=2\0" \
"mmcroot=/dev/mmcblk0p3 rw rootwait\0" \
"mmcargs=setenv bootargs console=${console},${baudrate} " \
"root=${mmcroot}\0" \
"loadbootscript="  \
"ext4load mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};\0" \
"bootscript=echo Running bootscript from mmc ...; " \
"source\0" \
"loaduimage=ext4load mmc ${mmcdev}:${mmcpart} ${loadaddr} /boot/${uimage}\0" \
"loadfdt=ext4load mmc ${mmcdev}:${mmcpart} ${fdt_addr} /boot/${fdt_file}\0" \
"mmcboot=echo Booting from mmc ...; " \
"run mmcargs; " \
"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
"if run loadfdt; then " \
"bootz ${loadaddr} - ${fdt_addr}; " \
"else " \
"if test ${boot_fdt} = try; then " \
"bootz; " \
"else " \
"echo WARN: Cannot load the DT; " \
"fi; " \
"fi; " \
"else " \
"bootz; " \
"fi;\0" \
"netargs=setenv bootargs console=${console},${baudrate} " \
"root=/dev/nfs " \
"ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
"netboot=echo Booting from net ...; " \
"usb start; " \
"run netargs; " \
"if test ${ip_dyn} = yes; then " \
"setenv get_cmd dhcp; " \
"else " \
"setenv get_cmd tftp; " \
"fi; " \
"${get_cmd} ${uimage}; " \
"if test ${boot_fdt} = yes; then " \
"if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
"bootz ${loadaddr} - ${fdt_addr}; " \
"else " \
"if test ${boot_fdt} = try; then " \
"bootz; " \
"else " \
"echo WARN: Cannot load the DT; " \
"fi;" \
"fi; " \
"else " \
"bootz; " \
"fi;\0"

#define CONFIG_BOOTCOMMAND \
"mmc dev ${mmcdev}; if mmc rescan; then " \
"if run loadbootscript; then " \
"run bootscript; " \
"else " \
"if run loaduimage; then " \
"run mmcboot; " \
"else run netboot; " \
"fi; " \
"fi; " \
"else run netboot; fi"

#define CONFIG_MXS_AUART
#define CONFIG_MXS_AUART_BASE  MXS_UARTAPP0_BASE
/* The rest of the configuration is shared */
#include <configs/mxs.h>


  • Change spl_boot.c in uboot-2013.10/board/olimex/mx23_olinuxino/spl_boot.c

/* DUART */
// MX23_PAD_PWM0__DUART_RX,
// MX23_PAD_PWM1__DUART_TX,
MX23_PAD_I2C_SDA__AUART1_RX,
MX23_PAD_I2C_SCL__AUART1_TX,


For Linux, it is a little easier, need to change the (2) device tree files and one driver file
  • Device tree files imx23.dtsi
pwm0_pins_a: pwm0@0 {
reg = <0>;
fsl,pinmux-ids = <
0x11a0 /* MX23_PAD_PWM0__DUART_RX */
>;
fsl,drive-strength = <0>;
fsl,voltage = <1>;
fsl,pull-up = <0>;
};

pwm1_pins_a: pwm1@0 {
reg = <0>;
fsl,pinmux-ids = <
0x11b0 /* MX23_PAD_PWM1__DUART_TX */
>;
fsl,drive-strength = <0>;
fsl,voltage = <1>;
fsl,pull-up = <0>;
};

pwm2_pins_a: pwm2@0 {
reg = <0>;
fsl,pinmux-ids = <
0x11c0 /* MX23_PAD_PWM2__PWM2 */
>;
fsl,drive-strength = <0>;
fsl,voltage = <1>;
fsl,pull-up = <0>;
};

  • imx23-olinuxino.dts
lradc@80050000 {
status = "okay";
};


  pwm: pwm@80064000 {
pinctrl-names = "default";
pinctrl-0 = <&pwm0_pins_a &pwm1_pins_a &pwm2_pins_a>;
status = "okay";
}; 


auart0: serial@8006c000 {
pinctrl-names = "default";
pinctrl-0 = <&auart0_2pins_a>;
status = "okay";
};

What this does is move the UART and enable the PWM on the proper pins.  One issue is now the PWM clocks are not enabled.  So, need to and the pwm to the clocks when enabled.

  • the clock driver at clk-imx23.c 
Now add pwm to:

static enum imx23_clk clks_init_on[] __initdata = {
cpu, hbus, xbus, emi, uart,pwm,
};

See the last entry is pwm.  Now.. U-boot and the kernel are done.

busybox must also know which tty interface to use along with the boot messages when Linux boots up.

  • CONFIG_CMDLINE="root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyAPP0,115200"
  • And tty is ttyAPP0
If there are questions please post.  The goal is to provide background information on how to do this and it is possible.

The next couple of blogs is how to setup WIFI, use PWM and web page to control ..






Using buildroot

IMHO buildroot is the one of the smallest footprint Linux distribution in WWW for embedded devices. Having a small memory foot print is very useful when only 64MB of RAM is available; the amount on the Micro.

Here is a step by step to create a simple Linux distrubution for the Micro using buildroot on Linux.


  1. Create a directory in your home directory ie mkdir micro; cd micro; mkdir bld
  2. The idea is to have buildroot in one directory and your build directory bld as another directory,  This keeps things clean and able to know what is what. 
  3. Use git to retrieve buildroot git clone git://git.buildroot.net/buildroot
  4. Now there should be two directories under micro; bld and build
  5. cd into bld
  6. make -C ../buildroot/ O=$PWD olimex_imx233_olinuxino_defconfig
  7. The above step creates the proper make files to start the compile process of tools (compilers, tools, Linux, rootfs)
  8. Once this completes do a make
  9. This will take some time to complete. Once this a image directory is created with a sdcard image ready to program.
  10. There is directions to program a SD card image in the buildroot/board/olimex/imx233_olinuxino/readme.txt  Buildroot creates a boot-able Linux image.
In the next post how to create a u-boot image for the Micro... 


Saturday, October 5, 2013

How to pass command line arguments via the device tree



Need to append kernel boot arguments that are provided within the kernel image

Why would this be needed?

u-boot can pass device tree, boot arguments for the Linux kernel, load the Linux image from a sdcard or flash chip via the boot script.  Very flexible and powerful idea.  But, if changes need to be done of enhancing the kernel arguments due to some new feature, then u-boot environment needs change.  

To simplify this process, the kernel can provide a default boot arguments, so, if a kernel feature or some feature then the can be added.  But here is the issue, if the device tree is appended image then the boot arguments need to come from the device tree not the compiled in aurgments. 

For example:

chosen {
  bootargs = "console=ttyS0,115200 loglevel=8";
  
 }
Status of Beaglebone (White) and Micro
- The Micro has support in buildroot
- Buildroot is getting support The BeagleBone (white) and black.  It is in process; in the mean time, here is a simple way to get it working

  1. create a directory bealgebone
  2. git clone git://git.buildroot.net/buildroot
    This will create a directory buildroot
  3. For the kernel use https://github.com/beagleboard/kernel/tree/3.8 I download load via the zip link on the far right of the web page
  4. unzip the file
  5. run the ./patch.sh
  6. Create a tar file: tar zvcf kernel linux-3.8.tar.gz 
  7. copy the linux-3.8.tar.gz into the buildroot/dl directory.  This "stuffs" the kernel into the buildroot download tree
  8. mkdir bld
  9. cd bld
  10. make -C ../buildroot/ O=$PWD beaglebone_defconfig
  11. make
  12. wait few hours
On of the issues when copying the image the most of the sdcard is not used.  To fix that do the following:
sudo resize2fs /dev/xxxx

the xxxx is the partition of the sdcard   this will expand the image until to space is filledd

Wednesday, December 26, 2012

Using wpa_supplicate with buildroot

Using wpa_supplicant with buidlroot 
  • Buildroot does not provide scripts ifup/ifdown integrated with wpa_supplicant
    • Ubuntu/OpenWrt and others have scripts that parse interfaces file to start tools 
    • So doing this by hand
      • wpa_supplicant start -iwlan0 -c/etc/wpa_supplicant.conf &
        • Configures wifi and makes a connection then the connection is made need to start a ifup.
      • ifup wlan0 (This kicks off the dhcp client)
  • Will publish more on this issue again.. Might just use openwrt for this..

Monday, December 24, 2012

Working with Micro and buildroot

Have made progress on several projects
  1. imx28-evk (http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MCIMX28EVKJ)  HW updated the board to have a SPI 8MB chip.
    1. Have a working u-boot boot from SPI flash
      • Customized u-boot imx28-evk 
      • Customized mxsboot to format the image to be loaded by SPI
    2. Have a working linux 3.7 kernel image boot from SPI flash
      • Using squashfs for ROM file system
      • Using mtdparts to segment flash 
      • Using JFFS2 for write flash area
    • Currently testing a method to program production boards from JTAG or USB.  HAve tried using JTAG Here is the issue https://community.freescale.com/thread/302010
    • So, now u-boot is loading but SPI flash access is not correct.  So, looking at the issues why  boot cannot access SPI flash
  2. Micro board (https://www.olimex.com/Products/OLinuXino/iMX233/iMX233-OLinuXino-MICRO/)
    1. Have buildroot creating a linux 3.7.1 image able to
      1. Connect wifi dongle connect to internet
        1. There is a kernel issue in the driver that dumps time out .  This is due to i2c DMA not timing out.  Have a custom driver to add DMA clear to fix time outs.
      2. Connect to Wii numchuck via i2c 
        1. Will change to use a classic controller
        2. Next need to add a case and power supply.  This will serve as controller to quad copter.
        3. Here is the power supply: https://www.sparkfun.com/products/11496
  3. Teensy3 (http://www.pjrc.com/store/teensy3.html) and Android 
    1. This little board is an ARM Cortex M4 (floating point) with USB (host/device)
    2. I've modified the USB descriptors  to support a bulk endpoint In/OUT
    3. Created an Android App to talk to the board via USB client.  Most cell phones support USB OTG, so all what is need is a simple converter cable:
      1. http://www.amazon.com/eForCity-Micro-USB-OTG-Adapter/dp/B005QX7KYU
      2. Connected the cable to my Samsung III loaded the Teensy USB Android app. now they are connected.
      3. My goal is to port some of IOIO and connect a WII classic or WII numchuck and use it the same was the above Micro board.  The phone has an internal wifi antenna the range is not good, but for close range good enough.  The micro has an external Wifi board using a Alfa which supports one watt of power.  So, should get about 1km of range. Also, now can use a better radio ie http://www.rctimer.com/index.php?gOo=goods_details.dwt&goodsid=817&productname=  One rado connected to teensy 3.0 the other on the beaglebone
      4. The android app uses simple USBHost mode and bulk API to communicate. 

  4. BeagleBone
    1. Restarted this project using Buildroot
      1. Fast boot time, 10 seconds or less
      2. Common startup ie Micro and imx28-evk
    2. Using buildroot to make:
      1. MLO
      2. u-boot
      3. Linux