USB OTG as an Extra USB Host in Allwinner A10, A20 etc

USB OTG port on Allwinner SoC based boards is a very useful tool. It can be used to flash an image to the flash memory or connect to a Host PC and making the board to act as a device.

Although there are many scenarios where USB OTG is useful, at times it is more useful to have an extra USB HOST on the board. All the settings of hardware configurations of allwinner SoCs are stored in a file named ` script.bin` that is compiled from a text file called fex file.We can learn more about the fex file from Sunxi Wiki in the Fex Guide.

A FEX file defines various aspects of how the SoC works. It configures the GPIO pins and sets up DRAM, Display, etc parameters.

Each line consists of a key = value pair combination under a [sectionheader]. All three, [sectionheader], key and value are case-sensitive. For comments a semi-colon (;) is used and everything following a semi-colon is ignored. The chip does not parse a textual version of a fex file, it gets cleaned and compiled by a fex-compiler. A reverse engineerd open source version exists in the sunxi-tools repository. Also a de-compiler which takes a binary script.bin and creates a textual script.fex. Usually, script.bin can be found on the nanda boot partition on A10 devices.

Changing script.bin file without removing the microSD card

The tools for script.bin changing are located in /opt/sunxi-tools directory:

  # cd /opt/sunxi-tools
  # ./chscr.sh

This will convert script.bin file from sdcard to script.fex file and the file will be opened using nano editor. Now you can change the board modules and parameters, save the changes (“CTRL”+”X”; confirm with “Y”) and exit (“CTRL”+”X” again) from nano editor.

  # ./wrscr.sh

this will convert script.fex to script.bin and the script.bin file will be written to sdcard.

  reboot

Reboot the board and the new settings would be enabled.

Changing script.bin file by removing the microSD card

The biggest part of the board configuration might be edited, changed or improved in a file called script.bin

The script.bin file can usually be found in the main directory of a microSD card prepared with official Debian image. The folder containing the script can be inspected under both Windows, Linux or Mac.

You can’t directly edit binary file so you would need to convert it to text format (it is called fex in this case), then edit the parameters via a text editor and finally switch it back to binary format.

IMPORTANT! ADJUSTING SCRIPT.BIN WITH IMPROPER VALUES MIGHT BREAK YOUR DEBIAN IMAGE AND IT IS ALWAYS RECOMMENDED TO KEEP A BACK-UP OF YOUR DEFAULT SCRIPT.BIN

To convert back and forth the script.bin you might use different tools. You can find Windows tools here: SUNXI TOOLS FOR WINDOWS . For Linux convertors please check the sunxi tools here: SUNXI TOOLS

Editing Fex File for USB OTG

Now open the Fex file and locate the USB section.

;——————————————————————————- 
;[usbc0]:  The configuration of controller 0 
;usb_used: Enable bit. If USB is enabled or not. 1: enable; 0: disable. 
;usb_port_type: Type of USB port. 0:device only;1:host only;2:OTG 
;usb_detect_type: Detect type. 0: Not detect; 1: detect vbus/id; 2: Detect id/dpdm
;——————————————————————————- 
;——————————————————————————- 

;——————————————————————————-
[usbc0]
usb_used = 1 
usb_port_type = 0 
usb_detect_type = 0 
usb_id_gpio = port:PH04<0><1><default><default> 
usb_det_vbus_gpio = “axp_ctrl” 
usb_drv_vbus_gpio = port:PB09<1><0><default><0> 
;usb_restrict_gpio = port:PH00<1><0><default><0> 
usb_host_init_state = 0 
usb_restric_flag = 0 
usb_restric_voltage = 3550000 
usb_restric_capacity= 5

We just need to change usb_port_type from 0 to 1 to make it a USB host.

Converting fex to script.bin:

The following commands are executed at sunxi-tools directory:

$./fex2bin script.fex >script.bin
$sudo cp script.bin /boot/script.bin
$sudo umount /boot
Now restart the board and you can use USB OTG as USB host.
 

Raspberry pi Zero launched , SBC priced at $5

This is awesome. The only thing I miss is the LAN interface but at $5 its still amazing. It has Broadcom BCM2835 processor and that also 40% faster than the pi 1 with 512 MB of Ram.

Today, I’m pleased to be able to announce the immediate availability of Raspberry Pi Zero, made in Wales and priced at just $5. Zero is a full-fledged member of the Raspberry Pi family, featuring:

  • A Broadcom BCM2835 application processor
    • 1GHz ARM11 core (40% faster than Raspberry Pi 1)
  • 512MB of LPDDR2 SDRAM
  • A micro-SD card slot
  • A mini-HDMI socket for 1080p60 video output
  • Micro-USB sockets for data and power
  • An unpopulated 40-pin GPIO header
    • Identical pinout to Model A+/B+/2B
  • An unpopulated composite video header
  • Our smallest ever form factor, at 65mm x 30mm x 5mm

Raspberry Pi Zero runs Raspbian and all your favourite applications, including Scratch, Minecraft and Sonic Pi.

RaspberryPi BLOG

 

Getting power and battery info from AXP209

Here is a script that gives some info about battery (when one is plugged)

I think that this page has mistakes (http://linux-sunxi.org/AXP209#Spec_Sheets) because discharging and charging current are inverted.

#!/bin/sh
# This program gets the battery info from PMU
# Voltage and current charging/discharging
#
# Nota : temperature can be more than real because of self heating
#######################################################################
# Copyright (c) 2014 by RzBo, Bellesserre, France
#
# Permission is granted to use the source code within this
# file in whole or in part for any use, personal or commercial,
# without restriction or limitation.
#
# No warranties, either explicit or implied, are made as to the
# suitability of this code for any purpose. Use at your own risk.
#######################################################################

# force ADC enable for battery voltage and current
i2cset -y -f 0 0x34 0x82 0xC3

################################
#read Power status register @00h
POWER_STATUS=$(i2cget -y -f 0 0x34 0x00)
#echo $POWER_STATUS

BAT_STATUS=$(($(($POWER_STATUS&0x02))/2))  # divide by 2 is like shifting rigth 1 times
#echo $(($POWER_STATUS&0x02))
echo "BAT_STATUS="$BAT_STATUS
# echo $BAT_STATUS

################################
#read Power OPERATING MODE register @01h
POWER_OP_MODE=$(i2cget -y -f 0 0x34 0x01)
#echo $POWER_OP_MODE

CHARG_IND=$(($(($POWER_OP_MODE&0x40))/64))  # divide by 64 is like shifting rigth 6 times
#echo $(($POWER_OP_MODE&0x40))
echo "CHARG_IND="$CHARG_IND
# echo $CHARG_IND

BAT_EXIST=$(($(($POWER_OP_MODE&0x20))/32))  # divide by 32 is like shifting rigth 5 times
#echo $(($POWER_OP_MODE&0x20))
echo "BAT_EXIST="$BAT_EXIST
# echo $BAT_EXIST

################################
#read Charge control register @33h
CHARGE_CTL=$(i2cget -y -f 0 0x34 0x33)
echo "CHARGE_CTL="$CHARGE_CTL
# echo $CHARGE_CTL


################################
#read Charge control register @34h
CHARGE_CTL2=$(i2cget -y -f 0 0x34 0x34)
echo "CHARGE_CTL2="$CHARGE_CTL2
# echo $CHARGE_CTL2


################################
#read battery voltage	79h, 78h	0 mV -> 000h,	1.1 mV/bit	FFFh -> 4.5045 V
BAT_VOLT_LSB=$(i2cget -y -f 0 0x34 0x79)
BAT_VOLT_MSB=$(i2cget -y -f 0 0x34 0x78)

#echo $BAT_VOLT_MSB $BAT_VOLT_LSB

BAT_BIN=$(( $(($BAT_VOLT_MSB << 4)) | $(($(($BAT_VOLT_LSB & 0xF0)) >> 4)) ))

BAT_VOLT=$(echo "($BAT_BIN*1.1)"|bc)
echo "Battery voltage = "$BAT_VOLT"mV"

###################
#read Battery Discharge Current	7Ah, 7Bh	0 mV -> 000h,	0.5 mA/bit	FFFh -> 4.095 V
BAT_IDISCHG_LSB=$(i2cget -y -f 0 0x34 0x7B)
BAT_IDISCHG_MSB=$(i2cget -y -f 0 0x34 0x7A)

#echo $BAT_IDISCHG_MSB $BAT_IDISCHG_LSB

BAT_IDISCHG_BIN=$(( $(($BAT_IDISCHG_MSB << 4)) | $(($(($BAT_IDISCHG_LSB & 0xF0)) >> 4)) ))

BAT_IDISCHG=$(echo "($BAT_IDISCHG_BIN*0.5)"|bc)
echo "Battery discharge current = "$BAT_IDISCHG"mA"

###################
#read Battery Charge Current	7Ch, 7Dh	0 mV -> 000h,	0.5 mA/bit	FFFh -> 4.095 V
BAT_ICHG_LSB=$(i2cget -y -f 0 0x34 0x7D)
BAT_ICHG_MSB=$(i2cget -y -f 0 0x34 0x7C)

#echo $BAT_ICHG_MSB $BAT_ICHG_LSB

BAT_ICHG_BIN=$(( $(($BAT_ICHG_MSB << 4)) | $(($(($BAT_ICHG_LSB & 0xF0)) >> 4)) ))

BAT_ICHG=$(echo "($BAT_ICHG_BIN*0.5)"|bc)
echo "Battery charge current = "$BAT_ICHG"mA"

this script gives the AC power status :

#!/bin/sh
# This program gets the power status (AC IN or BAT) for pcDuino3
# I2C interface with AXP209
#
#######################################################################
# Copyright (c) 2014 by RzBo, Bellesserre, France
#
# Permission is granted to use the source code within this
# file in whole or in part for any use, personal or commercial,
# without restriction or limitation.
#
# No warranties, either explicit or implied, are made as to the
# suitability of this code for any purpose. Use at your own risk.
#######################################################################

#read Power status register @00h
POWER_STATUS=$(i2cget -y -f 0 0x34 0x00)
#echo $POWER_STATUS

# bit 7 : Indicates ACIN presence 0: ACIN does not exist; 1: ACIN present
#echo "bit 7 : Indicates ACIN presence 0: ACIN does not exist; 1: ACIN present"
#echo "bit 2 : Indicates that the battery current direction 0: battery discharge; 1: The battery is charged"

AC_STATUS=$(($(($POWER_STATUS&0x80))/128))  # divide by 128 is like shifting rigth 8 times
#echo $(($POWER_STATUS&0x80))
echo "AC_STATUS="$AC_STATUS
# echo $AC_STATUS

Example :

battery charging

rzbo@ubuntu:~$ ./battery_info.sh
BAT_STATUS=0
CHARG_IND=1
BAT_EXIST=1
CHARGE_CTL=0xd0
CHARGE_CTL2=0x47
Battery voltage = 3895.1mV
Battery discharge current = 304.0mA
Battery charge current = 0mA

rzbo@ubuntu:~$ ./power_status.sh
AC_STATUS=1

Battery discharging (USB power unplugged)

rzbo@ubuntu:~$ ./battery_info.sh
BAT_STATUS=0
CHARG_IND=0
BAT_EXIST=1
CHARGE_CTL=0xd0
CHARGE_CTL2=0x47
Battery voltage = 3678.4mV
Battery discharge current = 0mA
Battery charge current = 176.0mA

rzbo@ubuntu:~$ ./power_status.sh
AC_STATUS=0

IMG_20140916_183651 IMG_20140916_183625

 

How to change ip address in linux

I wrote this draft quite ago . Just stumbled upon on it in the drafts section, may this would help someone

Change IP address

You can change ip address using ifconfig command itself. To set IP address 192.168.1.5, enter command:

# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up
# ifconfig eth0

To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

Here are some detailed posts:

 

Raspberry Pi 2 Model B

The Raspberry Pi Foundation is likely to provoke a global geekgasm today with the surprise release of the Raspberry Pi 2 Model B: a turbocharged version of the B+ boasting a new Broadcom BCM2836 900MHz quad-core system-on-chip with 1GB of RAM – all of which will drive performance “at least 6x” that of the B+.

At its heart, though, is the BCM2836 SoC, which according to Upton has been in development for a couple of years. It’s “very, very similar” to its predecessor – the BCM2835 – but with four cores and “a little tweak to allow us to address the gig of RAM”

The BCM2835, as used in previous Pis, is a Broadcom GPU – the VideoCore IV – with a single 700MHz ARM1176JZF-S application core glued in to run software. The system-on-chip is shipped with 256MB or 512MB of RAM stacked on top.

The new BCM2836, on the other hand, contains four ARMv7 Cortex-A7 cores with 1GB of RAM.

The Raspberry Pi 2 Model B  is the latest version of the Raspberry Pi, a tiny credit card size computer. Just add a keyboard, mouse, display,power supply, micro SD card with installed Linux Distribution and you’ll have a fully fledged computer that can run applications from word processors and spreadsheets to games.

What’s the same:

  • Same form factor as the model B+ (your enclosures and daughter boards should still fit).
  • Same full size HDMI port
  • Same 10/100 Ethernet port
  • Same CSI camera port and DSI display ports
  • Same micro USB power supply connection

What has changed:

  • A new turbocharged  Broadcom BCM2836 900MHz quad-core system-on-chip with performance at least 6x that of the B+.
  • 1GB of RAM

via theregister.co.uk

 

Asterisk for Banana Pi R1 (FreePBX Image included)

After doing the FreePBX Asterisk Image for Banana Pi, I was asked by SINOVOIP (Banana Pi Manufacturer) to do an Asterisk Image for their router board, i.e. the Banana Pi R1. SINOVOIP has been very kind to send me a complimentary BPi-R1 for testing and developing.

It took me some time to get this done, but the image is finally ready. This image differs from my earlier Banana Pi Asterisk image in that, the earlier image was created by simply replacing the rootfs of a Raspbian based BPi Image, with RasPBX Image’s rootfs. However, this time I have actually been able to compile Asterisk on the latest Bananian Image for R1. This means that you can now have a powerful, complete and rather flexible Asterisk 11 (upgradable to 12!) desktop system with FreePBX, running on the BPi-R1. Further, Bananian offers lightening fast boot and load times with remarkable performance. (You can compare the speed with my earlier RasPBX based Image to see for yourself.)

The image comes preloaded with Asterisk 11, along with most of the standard FreePBX modules. Upgrading to Asterisk 12 should be pretty easy.

Credentials:

  • Login: root
  • Password: root
  • FreePBX Username: asteriskuser
  • FreePBX Password: pi

Note: I have tested this image (before and after upgrading to Asterisk 12) successfully with a BPi-R1 for SIP (using Android devices running Zoiper), along with video calling. Please be aware that 2 extensions (made during testing) already exist in the image and can be removed (I somehow forgot to delete them ;)). Also note that video calling is disabled by default and needs to be enabled from the pbx settings.

DOWNLOAD :

Pay 22.50 USD  (this will support our work)




Download both files and then un-rar using WinRar or any other appropriate program

 

Asterix for Banana Pi (FreePBX img file for Banana Pi included)

What is Asterix?

Asterisk is a software implementation of a telephone private branch exchange (PBX); it was created in 1999 by Mark Spencer of Digium. Like any PBX, it allows attached telephones to make calls to one another, and to connect to other telephone services, such as the public switched telephone network (PSTN) and Voice over Internet Protocol (VoIP) services. Its name comes from the asterisk symbol, *. [Source: Wikipedia]

Asterisk is like a box of Legos for people who want to create communications applications. It includes all the building blocks needed to create a PBX, an IVR system, a conference bridge and virtually any other communications app you can imagine. [Source: Official Asterix Website]

What is Banana Pi?

Banana Pi is a single-board computer built with ARM Cortex-A7 Dual-core (Allwinner A20 based) CPU and Mali400MP2 GPU, and open source software, Banana Pi can serve as a platform to make lots of applications for different purposes.

The RasPBX Project

This is a project dedicated to Asterisk and FreePBX running on the Raspberry Pi. Later, the Beaglebone folks ported RasPBX for the BeagleBone Black (BBB).

Asterix for Banana Pi

Sadly, the RasPBX project doesn’t support the Banana Pi yet. I looked everywhere on the net for an Asterix based PBX image for Banana Pi, but looks like no one has done this yet or they did but didn’t share . So, I decided to make one myself.

I simply replaced the rootfs on the Banana Pi’s Raspbian based image with RasPBX’s rootfs. The image should work on any Banana Pi variant with the Allwinner A20 processor (including Banana Pi, Banana Pro and Sinovoip’s Banana Pi M1).

Download links

The image file is 3.7GB, I am uploading a winrar compressed version that is approximately 437MB . Use a suitable application to un-compress it after download.
Pay 22.5 USD  (this will support our work)




CREDENTIALS

root/raspberry

  • FreePBX Username: asteriskuser
  • FreePBX Password: pi

Screenshots

FreePBX UIFreePBX_admin_screen

Further  Resources:

Directions to write the image to SD card

Read Documentation from RasPBX’s official website

 

PS: I have tested the image and it’s working fine. If you are facing any problems with it, feel free to post a comment and I’ll be happy to help. 🙂