Kernel changes for custom hardware

From Low cost, low power, android ARM system board by Mini-Box.com - pico WiKi
Jump to navigation Jump to search

Touchscreens

  • 1. Resistive: No changes needed.
  • 2. Capacitive: Transfer is made thru i2c and interrupt pin is AT91_PIN_PA27. Make sure you compile the proper support for your capacitive panel chip in kernel and you supply the proper interrupt pin to the driver.

How to compile kernel for a 7" touchscreen

By defaults kernels are compiled for 4.3" LCD. For 7" you will need to compile a new kernel or use the kernel from Android 4.0 build and overwrite the kernel from Android 2.3 built for example. If you want to compile a new kernel you wil have to add:

  1. define PICOSAM9G45_BIG_DISPLAY here

Using another LCD

You will need to recompile the kernel and setup the monitor and resolution from our board definition files.
To do this, follow this steps:

  • 1. Download kernel and toolchain from our gitorious repository as explained on Kernel building page.
  • 2. Edit the file kernel/arch/arm/mach-at91/board-picosam9g45.c and change the struct:
    "fb_videomode at91_tft_vga_modes" and "fb_monspecs at91fb_default_monspecs" to match your display configuration from the display datasheet.To understand translation between display datasheet naming and kernel read here
  • 3. Recompile the kernel and put it on your microSD BOOT partition.

Adding a GPIO as a key in kernel

  • 1. Edit arch/arm/mach-at91/board-picosam9g45.c and add on the struct struct gpio_keys_button picosam9g45_buttons[]:
      {       /* J14 USR2 pin 1 gnd + pin 6*/
              .code           = KEY_UP,
              .gpio           = AT91_PIN_PC20,
              .active_low     = 1,
              .desc           = "Up Arrow",
      },

The gpio-keys driver will automatically send KEY_UP event when USR2 pin is put to ground

Adding a GPIO as a led in kernel

  • 1. Edit arch/arm/mach-at91/board-picosam9g45.c and add on the struct struct gpio_led picosam9g45_leds[]:
       {       /* "usr3" led */                                                                                                                                                                                                               
               .name                   = "usr3",                                                                                                                                                                                              
               .gpio                   = AT91_PIN_PC21,                                                                                                                                                                                      
               .active_low             = 1,                                                                                                                                                                                                 
               .default_trigger        = "none",                                                                                                                                                                                            
       },

The led can be controlled by writing 0 or 1 to /sys/class/leds/usr3

Working with GPIOs

For GPIOs that aren't bound in kernel to a device/key/led, you can control them from sysfs interface from /sys/class/gpio/
There you have multiple gpiochip<nnn> each corresponding to the A,B,C,D,E peripheals.
For example PC is gpiochip96

To export PC19 (which you will find it as USR1 on J14 pin 5) do:

echo "115" > export

which means 96+19.

a directory will appear in /sys/class/gpio/gpio115/ with 2 files (direction and value)

echo out > direction
echo 0 > value

To set output of GPIO to 0

Example setting a GPIO as input

 cd /sys/class/gpio/
 echo "115" > /sys/class/gpio/export
 cd /sys/class/gpio/gpio115/
 echo in > direction
 cat value

Working with Analog-to-Digital Converter (ADC)

The ADC in picoSAM9G45 board provides 7 channels. 3 of these are used for the resistive touchscreen, the rest of 4 channels (available through J16) have a 10-bit resolution and can be used to perform analog to digital conversions.

The kernel will provide the following files to read values from the each ADC channel (note that this functionality is not yet in the releases images see atmel_adc)

 /sys/devices/platform/atmel_adc/ani0
 /sys/devices/platform/atmel_adc/ani1
 /sys/devices/platform/atmel_adc/ani2
 /sys/devices/platform/atmel_adc/ani3

How to read and interpret the values:

  cat /sys/devices/platform/atmel_adc/ani0 

should output an integer value, that will need to be scaled as: (ani value) * max voltage range / bit resolution.

For ani0 and ani1 (voltage in 0V-50V range): (ani0 value) * 50/1023
For ani2 and ani3 (voltage in 0V-5V range): (ani2 value) * 5 /1023

Note: The value for ani0 will always be the voltage that powers the picoSAM9G45 board.

The reads are rate limited to work concurrently with the resistive touchscreen. If a resistive touchscreen is not used the rate limit can be disabled by editing the driver source code.

J16 connector from pico-SAM9G45 board.
http://arm.mini-box.com/images/J16-connector.jpg
GND
http://arm.mini-box.com/images/J16-connector.jpg
ani0
Vin
http://arm.mini-box.com/images/J16-connector.jpg
ani1
http://arm.mini-box.com/images/J16-connector.jpg
ani2
http://arm.mini-box.com/images/J16-connector.jpg
ani3

Power cycle/Reset miniPCI-E cards or USB devices

Some miniPCI-E cards might not work after power-on. To fix this issue a software "reset" is needed:

 cd /sys/bus/usb/devices
 ls -l

Notice the folders with 1-2, 2-2 etc, to identify the product do:

 cat 1-2/product 

and repeat for all folders till you identify the card

To reset issue:

 echo 0 > 1-2/authorized
 echo 1 > 1-2/authorized

Working with SPI interface

SPI interface can be accessed from userspace through spidev kernel driver.
As of 12 Oct 2011 the spidev is included in binary releases.

By default the SPI devices from [[J7 connector|J7 Connector] and [[J9 Connector|J9 Connector] (SPI0.0 and SPI1.0) are bound to this spidev driver.
If you need to bound a spi device to another kernel driver edit arch/arm/mach-at91/board-picosam9g45.c around line 135 (SPI devices) and change .modalias to your driver name.

For testing spidev_test can be used.
A sample output is:

root@picosam9:~# /spidev_test -s 14814814 -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 14814814 Hz (14814 KHz)
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 

/dev/spidev0.0 means the spi device on bus 0 chipselect 0 (SPI0 SPI0_CS0 in schematics for J7 connector)

Working with I²C interface

I²C interface can be accessed from userspace through i2c-dev kernel driver.

For testing i2c-dev communication qtouch-control can be used as an example.
More advanced tools can be found here

Using the buzzer

You have to assign values between 0( which is no sound) to 255 to:

 echo 200 > /sys/devices/platform/leds-atmel-pwm/leds/buzzer/brightness

Change USART to RS-485 mode

by user Minsc04 from AT91SAM Community Forum
To change each USART in RS-485 mode, add this line in linux/drivers/serial/atmel_serial.c , in function atmel_set_termios, just before the instruction "UART_PUT_MR(port, mode);" that configures the USART mode.

mode |= ATMEL_US_USMODE_RS485; //Take effect for all USART that you configure

or if you want filter for a specific USART, use a dedicated IRQ number :

if (port->irq == AT91SAM9260_ID_US2) // USART2 is a rs485
{
mode |= ATMEL_US_USMODE_RS485;
}

Booting kernel from U-Boot

  • 1. Disable direct kernel loading from bootstrap by changing DIRECT_BOOT to off in compile.sh. Reference commit in bootstrap: Direct Kernel loading
  • 2. It will expect uboot.bin actually be named linux.bin but that can be changed with FILE_NAME option in compile.sh.
  • 3. Use a Atmel patched uboot source from here: uBoot for Atmel
  • 4. Compile the sources with: make CROSS_COMPILE=<your toolchain location> at91sam9m10g45ek_config
  • 5. Optionally you can apply a patch to automatically enable 256Mb on picoPC.Patch is File:0001-add-support-for-both-banks-of-memory-on-Atmel-G45-bo.patch.
  • 6. Copy the newly compiled BOOT.BIN (from step 1), uboot.bin (from step 4) to microSD card BOOT partition (the FAT partition). The BOOT partition should contain: BOOT.BIN (the bootstrap) uboot.bin (uboot) uImage (the kernel in uimage format)



picoSAM9G45 board schematics


- mechanical drawings
- detailed schematics
- top side view
- bottom side view
- connectors detailed pinout