openOCD Configuration

###OpenOCD Device Scan Install and view the OpenOCD:

	$ pacman -S openocd
	[Trusty@XXXyyy debian_octopress]$ openocd -v
	Open On-Chip Debugger 0.7.0 (2013-11-02-01:53)
	Licensed under GNU GPL v2
	For bug reports, read
		http://openocd.sourceforge.net/doc/doxygen/bugs.html

Insert your openJTAG debug board, and view its connection:

	[Trusty@XXXyyy debian_octopress]$ lsusb
	Bus 001 Device 016: ID 1457:5118 First International Computer, Inc. OpenMoko Neo1973 Debug board (V2+)

From the dmesg information:

	[15767.673553] usb 1-1: new full-speed USB device number 11 using xhci_hcd
	[15767.695990] usb 1-1: Device not responding to set address.
	[15767.938262] usb 1-1: Device not responding to set address.
	[15768.140725] usb 1-1: device not accepting address 11, error -71
	[15768.421057] usb 1-1: new full-speed USB device number 13 using xhci_hcd
	[15769.015800] usbcore: registered new interface driver usbserial
	[15769.016012] usbcore: registered new interface driver usbserial_generic
	[15769.016075] usbserial: USB Serial support registered for generic
	[15769.020028] usbcore: registered new interface driver ftdi_sio
	[15769.020050] usbserial: USB Serial support registered for FTDI USB Serial Device
	[15769.020458] usb 1-1: Ignoring serial port reserved for JTAG
	[15769.020499] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected
	[15769.020544] usb 1-1: Detected FT2232C
	[15769.020548] usb 1-1: Number of endpoints 2
	[15769.020550] usb 1-1: Endpoint 1 MaxPacketSize 64
	[15769.020553] usb 1-1: Endpoint 2 MaxPacketSize 64
	[15769.020555] usb 1-1: Setting MaxPacketSize 64
	[15769.026647] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
	[15975.012193] usb 1-1: USB disconnect, device number 13
	[15975.012449] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
	[15975.012465] ftdi_sio 1-1:1.1: device disconnected
	[15975.270658] usb 1-1: new full-speed USB device number 14 using xhci_hcd
	[15975.355869] usb 1-1: Ignoring serial port reserved for JTAG
	[15975.366867] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected
	[15975.366902] usb 1-1: Detected FT2232C
	[15975.366904] usb 1-1: Number of endpoints 2
	[15975.366906] usb 1-1: Endpoint 1 MaxPacketSize 64
	[15975.366908] usb 1-1: Endpoint 2 MaxPacketSize 64
	[15975.366909] usb 1-1: Setting MaxPacketSize 64
	[15975.371933] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
	[16608.914153] usb 1-1: USB disconnect, device number 14
	[16608.914371] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
	[16608.914402] ftdi_sio 1-1:1.1: device disconnected
	[16609.394763] usb 1-1: new full-speed USB device number 15 using xhci_hcd
	[16609.395097] usb 1-1: Device not responding to set address.
	[16609.598734] usb 1-1: Device not responding to set address.
	[16609.801899] usb 1-1: device not accepting address 15, error -71
	[16609.962045] usb 1-1: new full-speed USB device number 16 using xhci_hcd
	[16609.962371] usb 1-1: Device not responding to set address.
	[16610.250376] usb 1-1: Ignoring serial port reserved for JTAG
	[16610.261380] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected
	[16610.261428] usb 1-1: Detected FT2232C
	[16610.261431] usb 1-1: Number of endpoints 2
	[16610.261433] usb 1-1: Endpoint 1 MaxPacketSize 64
	[16610.261435] usb 1-1: Endpoint 2 MaxPacketSize 64
	[16610.261437] usb 1-1: Setting MaxPacketSize 64
	[16610.266397] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

From the above information we could know, Now we have a new Serial port named ttyUSB0, and also a FT2232C debug port. Currently we don’t use Serial Port, FT2232 is all we want to configure. ###OpenOCD Configuration We have to make a cfg file for OpenOCD to use. There are some pre-defined configuration files for us to refer under the directory of “/usr/share/openocd/scripts/", since we know the debug board information and we know exactly the development board info, we can easily write our own OpenOCD startup scripts.
Get the interface definition via:

	[Trusty@XXXyyy interface]$ pwd
	/usr/share/openocd/scripts/interface
	[Trusty@XXXyyy interface]$ grep "1457" ./ -r
	./neodb.cfg:ft2232_vid_pid 0x1457 0x5118
	./ftdi/neodb.cfg:ftdi_vid_pid 0x1457 0x5118

So we directly copy the neodb.cfg to our openocd.cfg under our home directory. But the usb name of our OpenOCD is changed,

	ft2232_device_desc "USB<=>JTAG&RS232

The definition is taken from the output of “lsusb -v -d 1457:5118”

We also want to define the port for telnet and gdb connection

	#########daemon configuration####
	telnet_port 4444
	gdb_port 3333


The Target configuration is taken from the /usr/share/openocd/scripts/target/stm32f1x.cfg, which is the definition of the stm32f1x. Copy them directly to your own config file.

Finally your configuration file should be listed as:


#########daemon configuration####
telnet_port 4444
gdb_port 3333

########Interface Info###########
################################################
# Since our board takes the same vid_pid
# We directly use openmoko's definition.
################################################
#
# Openmoko USB JTAG/RS232 adapter
#
# http://wiki.openmoko.org/wiki/Debug_Board_v3
#
interface ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_vid_pid 0x1457 0x5118

########Board Info###########
# Adjust Work-area size (RAM size) according to MCU in use:
#STM32F103VC --> 48KB
#STM32F103RB --> 20KB
#set WORKAREASIZE 0x5000
# STM32F103RE --> 64KB
# set WORKAREASIZE 0x10000

# reset_config parameter (see OpenOCD manual):
# none --> srst and trst of MCU not connected to JTAG device
# srst_only --> only srst of MCU connected to JTAG device
# trst_only --> only trst of MCU connected to JTAG device
# srst_and_trst --> srst and trst of MCU connected to JTAG device
# default setting: "reset_config none" will produce a single reset via SYSRESETREQ (JTAG commands) at reset pin of MCU
#reset_config none


#script for stm32f1x family

if { [info exists CHIPNAME] } {
   set _CHIPNAME $CHIPNAME
} else {
   set _CHIPNAME stm32f1x
}

if { [info exists ENDIAN] } {
   set _ENDIAN $ENDIAN
} else {
   set _ENDIAN little
}

# Work-area is a space in RAM used for flash programming
# By default use 16kB
if { [info exists WORKAREASIZE] } {
   set _WORKAREASIZE $WORKAREASIZE
} else {
   set _WORKAREASIZE 0x4000
}

# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
adapter_khz 1000

adapter_nsrst_delay 100
jtag_ntrst_delay 100

#jtag scan chain
if { [info exists CPUTAPID] } {
   set _CPUTAPID $CPUTAPID
} else {
  # See STM Document RM0008
  # Section 26.6.3
   set _CPUTAPID 0x3ba00477
}
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

if { [info exists BSTAPID] } {
   # FIXME this never gets used to override defaults...
   set _BSTAPID $BSTAPID
} else {
  # See STM Document RM0008
  # Section 29.6.2
  # Low density devices, Rev A
  set _BSTAPID1 0x06412041
  # Medium density devices, Rev A
  set _BSTAPID2 0x06410041
  # Medium density devices, Rev B and Rev Z
  set _BSTAPID3 0x16410041
  set _BSTAPID4 0x06420041
  # High density devices, Rev A
  set _BSTAPID5 0x06414041
  # Connectivity line devices, Rev A and Rev Z
  set _BSTAPID6 0x06418041
  # XL line devices, Rev A
  set _BSTAPID7 0x06430041
  # VL line devices, Rev A and Z In medium-density and high-density value line devices
  set _BSTAPID8 0x06420041
  # VL line devices, Rev A
  set _BSTAPID9 0x06428041

}
jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 \
	-expected-id $_BSTAPID2 -expected-id $_BSTAPID3 \
	-expected-id $_BSTAPID4 -expected-id $_BSTAPID5 \
	-expected-id $_BSTAPID6 -expected-id $_BSTAPID7 \
	-expected-id $_BSTAPID8 -expected-id $_BSTAPID9

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME

$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

# flash size will be probed
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME

# if srst is not fitted use SYSRESETREQ to
# perform a soft reset
cortex_m reset_config sysresetreq


[root@XXXyyy target]# openocd -f /media/y/embedded/stm32/dev/openocd.cfg -f ./stm32f1x.cfg 

Setup an embedded development enviroment for STM32

###Download the toolchain We should download the toolchain from the ARM employee maintained website, the download address is located at: https://launchpad.net/gcc-arm-embedded, use following command:

	$ wget https://launchpad.net/gcc-arm-embedded/4.7/4.7-2013-q3-update/+download/gcc-arm-none-eabi-4_7-2013q3-20130916-linux.tar.bz2

untar the downloaded package and then add it to your system path, my solution is directly add some alias into ~/.bashrc:

	### Add Cross_Compiler for eclipse based stm32
	#export PATH="/media/y/embedded/cortex/gcc-arm-none-eabi-4_7-2013q3/bin:$PATH"
	alias setstm='export PATH="/media/y/embedded/cortex/gcc-arm-none-eabi-4_7-2013q3/bin:$PATH"'

###Eclipse Configuration We have to install zylin for flashing the stm32 board. After installation, eclipse will be rebooted.

images/eclipseinstall.jpg

###OpenOCD OpenOCD is a open-source hardware debugger.

	community/openocd 0.7.0-2
	    Debugging, in-system programming and boundary-scan testing for embedded target devices
	[root@XXXyyy capscr]# pacman -S openocd

###Template prepration Download the template from :

	$ git clone https://github.com/JorgeAparicio/bareCortexM.git

Two Tips for setting

###Disable the vim wraping There is a line in ~/.vimrc:

	autocmd FileType text setlocal textwidth=78

comment this line then everything goes OK. ###Change Awesome theme and change the titlebar width Download the 3rd party themes from https://github.com/Morley93/awesome-themes-3.5, then copy them to your own theme location, normally under the “/usr/share/awesome/themes/", Choose whatever you want, and edit the ~/.config/awesome/default.rc.lua:

beautiful.init("/usr/share/awesome/themes/wabbit/theme.lua")

Save and exit then you got the new theme.
How to change the title bar?
In /usr/share/awesome/themes/wabbit/theme.lua, edit the following lines:

--theme.font          = "MonteCarlo medium 11"
theme.font          = "MonteCarlo medium 9"

I think 9 is good for me, but change this to 11 or bigger will make old men happy.
You can change this number into a very big or very small number, then some funny things will happen :)

Using IR-remote for controlling XBMC

###Wiring The Wiring is listed as following Picture, You got your IR receiver’s pins to corresponding pins on raspberry PI. Positive to Pin1(3.3v), negative to Pin6(GND), the signal pins to Pin12(GPIO 18).

rasp1.jpg ###Check the Kernel information Log on to the raspberry PI, then input dmesg to view the startup information, we can see the lirc has been added to kernel.

	$ dmesg
	[    4.976752] systemd-udevd[822]: starting version 208
	[    7.121052] lirc_dev: IR Remote Control driver registered, major 248 
	[    7.187858] lirc_rpi: module is from the staging directory, the quality is unknown, you have been warned.
	[    7.234864] lirc_rpi lirc_rpi.0: lirc_dev: driver lirc_rpi registered at minor = 0
	[    7.234894] lirc_rpi: driver registered!
	[    8.191460] lirc_rpi: auto-detected active low receiver on GPIO pin 18
	[    8.981462] input: lircd as /devices/virtual/input/input3

Now Let’s check the GPIO status:

	OpenELEC:~ # cat /sys/kernel/debug/gpio 
	GPIOs 0-53, bcm2708_gpio:
	 gpio-16  (led0                ) out hi
	 gpio-17  (lirc_rpi ir/out     ) in  lo
	 gpio-18  (lirc_rpi ir/in      ) in  hi

If it didn’t appear, using:

	modprobe lirc_rpi gpio_in_pin=18 gpio_out_pin=1

###Getting your own remote controller’s codes Now let’s kill all of the lircd related process, then use mode2 to detect the infra-red remote input.

	OpenELEC:~ # ps -ef | grep lirc
	1016 root       0:00 eventlircd --evmap=/etc/eventlircd.d --socket=/var/run/lirc/lircd --release=_UP
	1035 root       0:00 /usr/sbin/lircd --driver=default --device=/dev/lirc0 --uinput --output=/var/run/lirc/lircd-lirc0 --pidfile=/var/run/lirc/lircd-lirc0.pid /etc/lirc/lircd.conf.rpi
	1070 root      16:02 /usr/lib/xbmc/xbmc.bin --standalone -fs --lircdev /var/run/lirc/lircd
	1146 root       0:00 grep lirc
	OpenELEC:~ # killall lirc
What is mode2?  
	Trusty@SomethingMissing:~$ apt-cache search mode2
	lirc-x - infra-red remote control support - X utilities

Then Let’s listen the infra_remote’s input.The input is quite strange:

	space 4501241
	pulse 8917
	space 4415
	pulse 577

###Catching the code using irrecord The next step is turns these message into some code.

	OpenELEC:~/.config # pwd
	/storage/.config
	OpenELEC:~/.config # ls
	aacs                 samba.conf.sample    vpn-config
	hosts.conf           sysctl.conf.sample
	remote.conf          udev.rules.d.sample

Use irrecord for recording some signals and transform them into code:

	NAME
	       irrecord - application for recording IR-codes for usage with LIRC
	
	OpenELEC:~/.config # irrecord -d /dev/lirc0 lircd.conf

The method is, first long-press some keys, the result on screen will be several dots, then the program will change to another line, this time when you press some key, it only has one dot. Keep pressing keys until the irrecord tells you successful. Then you should input make some keys meaningful to the following images, when you feel satisfied, press enter to endup the program.

LIRCMAP.png

Now your lircd.conf file is generated, let see what’s in it.

	$ cat lircd.conf
	begin remote
	
	  name  lircd.conf
	  flags RAW_CODES|CONST_LENGTH
	  eps            30
	  aeps          100
	
	  gap          106707
	
	      begin raw_codes
	
	          name KEY_UP
	             8953    4401     581     527     595     503
	              613     506     588     539     581     510

If you want to use the pre-defined files, simply go to the lirc.sourceforge.net/remotes you can find almost all of the remote control information. ###Using the infra-remote for controlling Now call irw, but irw stunned with doing nothing. This command will show you all of the input signal

	OpenELEC:~ # irw
	6a 0 KEY_RIGHT devinput
	6a 0 KEY_RIGHT_UP devinput
	69 0 KEY_LEFT devinput
	69 0 KEY_LEFT_UP devinput
	6c 0 KEY_DOWN devinput
	6c 0 KEY_DOWN_UP devinput

Now in your XBMC window, you will see you can navigate and select something using your remote control.

Generate Your own epub book

###Using Wget to fetching the webpages wget could be used to fetch the webpages from a specified website, using following command could fetch all of the wiki related 1st layer pages from “awesome Wiki”

	$ wget -r -l 1 http://awesome.naquadah.org/wiki/Main_Page

After wget finished, you will found the 1st layer webpatges under your directory. ###Decide which you want for generating the book There are some rubbish pages in downloaed pages, thus we have to write a script for fetching the valuable ones, my script is listed as following:

[Trusty@DashArch wget]$ pwd
/home/Trusty/wget
[Trusty@DashArch wget]$ cd awesome.naquadah.org/
[Trusty@DashArch awesome.naquadah.org]$ ls
doc  download  images  index.html  robots.txt  wiki
[Trusty@DashArch awesome.naquadah.org]$ cd wiki
[Trusty@DashArch wiki]$ cat listitem.sh
#!/bin/sh
for file in `ls `
do
	#echo $file
	type=`file $file | awk {'print $2'}`
	#echo $type
	if [ "$type" = "HTML" ]
	then
		#echo $file
		#echo $type
		echo "<a href=\"$file\">$file</a><br/>"
	fi
done


simply run listitem.sh, we will get the file list tables like following:

<a href="Automounting">Automounting</a><br/>
<a href="Autostart">Autostart</a><br/>
<a href="Autostart_with_consolekit">Autostart_with_consolekit</a><br/>
<a href="Autostop">Autostop</a><br/>
<a href="Awesome_3.0_to_3.1">Awesome_3.0_to_3.1</a><br/>
..........................................

Add them into the html like:

<html>
   <body>
     <h1>Table of Contents</h1>
     <p style="text-indent:0pt">
	<a href="Automounting">Automounting</a><br/>
	<a href="Autostart">Autostart</a><br/>
......
	<a href="XRandR_Screen_Table">XRandR_Screen_Table</a><br/>
	<a href="Xscreensaver">Xscreensaver</a><br/>
     </p>
   </body>
</html>

###Generate the ebook Use Calibre, click “Add Book”, navigate to your directory which contains “index.html”, choose it, and now you can do whatever you want to generate epub, mobi, or 6 inch pdf. Just enjoy your ebook!!!

	[Trusty@DashArch Awesome (5)]$ ls -l -h
	total 4.5M
	-rw-r--r-- 1 Trusty root 887K Nov 20 21:07 Awesome - Dash.epub
	-rw-r--r-- 1 Trusty root 511K Nov 20 21:19 Awesome - Dash.mobi
	-rw-r--r-- 1 Trusty root 2.6M Nov 20 21:10 Awesome - Dash.pdf
	-rw-r--r-- 1 Trusty root 560K Nov 20 21:06 Awesome - Dash.zip
	-rw-r--r-- 1 Trusty root 1.1K Nov 20 21:18 metadata.opf

Depending on your settings, your generated ebook could be read on NOOK, Kindle, or other mobile equipment.