Saturday, April 28, 2012

Exploring OpenWRT


For a while I started using linux embedded OS. The idea is to replace ordinary 8/16 bit microcontrollers, that does't have yet very well desvolted Network support. I was looking for a low cost chip that can run linux OS. After some searching i fountd out about OpenWRT. So i started searchig a router to hack. I stopped at Tp-Link router TL-MR3020. It is small, low cost and has enouth power.

Some pictures :





It took 5 min to hack it :).

Unfortunatly you can't play with timer in linux like you can in ordinary microcontrollers. Or to manage GPIO, menaging interrupts. So i desided to use a low cost 8 bit microcontroller. Attiny2313 is good enouth. So our microcontroller will take data from ower sensors, but ower router will do some calculations and will send it over the network(Ethernet or WiFi).

So, the upcoming problem is: how to connect our microcontroller with our linux machine?
I see 3 choices:
  1. via GPIO
  2. via UART
  3. via USB 
For (3) we have to use USB to UART converter (ex. FT232), but this addes some additional costs to our system. Or we can emulate our USB slave in Attiny2313, but it will take our valuabale codesize and CPU performance.

It took me few days to explore the second choice. I was able only to transmit data from router to microcontroller. The problem is that the kernel ocupies the serial port for console. I think in order to repair this i have to recompile the kernel, but for now this is too advanced for me.

The only choice left is number one. There are some librarys that can be used to make an I2C over GPIO.
But i will try to emulate SPI using GPIO. In this table we have described some GPIO avaliable to us.


 GPIO ports are to used by kernel, but here we can release them. To do that we have to execute this commads :
       > rmmod leds_gpio
       > rmmod gpio_buttons

The second step is to export them in user space so we can use them. For example in order to export the Ethernet LED we have to write:
       > echo 17 > /sys/class/gpio/export
     , where 17 is pin number from above table.

In order to set direction of the pin we have to write in or out words in direction file. Ex.:
       > echo out > /sys/class/gpio/gpio17/direction
To set 1 or 0 for the output pin we ahve o write corespondin value in value file.

Pseudo dual core microcontroller

An example of Atmega128 and external memory:



 The ideea is to use two Atmega128 microcontrollers and one memory. So called shared memory. The memory i will be using is called Dual-ported RAM. There are actually some chips that can implement this kind of memory. I will try to use 7025E or IDT7130.

This is block schem of the IDT7130:



And here is the general idea: