Friday, 13 November 2015

Vocore tutorial: blinking an LED, using software SPI and unbricking

 Introduction


Hello everyone, I've recently laid my hands on this interesting piece of hardware and this article will describe my experience with it. It is an attempt to gather together all those scattered pieces of information I found on Internet to get this thing running.
Predictably, I managed to brick Vocore while messing around with its operating system (the only working thing left in memory was the bootloader), so I'll describe how to easily get it running again.

Requirements

  • PC running Linux (I used Arch Linux)
  • LED, any value resistor, any button or switch.
  • Any USB to Serial board- Only for unbricking!


Some helpful links we'll frequently use

One page you're going to look at a lot is its layout.
Hardware: descriptions, schematics, etc.

Let's start!

So, you have this board in front of you. You probably already connected 5v to it, switched on your power supply and login'd via ssh. If you didn't, go to this link and do it!
What's next? First, to be able to configure the kernel of Vocore and, more importantly, to get a cross-compilation toolchain, we will have to compile OpenWrt, which is the OS that runs Vocore.

 Building OpenWrt

1) Download OpenWrt
2) Configure feeds
Optional: install some (or all) feeds. I just installed nano because that's my favorite text editor in Linux
3) Apply Vocore patch
It makes OpenWrt use 16Mb flash instead 8Mb, sets the access point SSID to VoCore, turns the radio on by default, sets the root password to "vocore" and ip to 192.168.61.1
Optional: you can change whatever you want - e.g. change the SSID to something you like more, change the root password, add security to Wifi etc..
4) Configure the kernel.
The first 3 selections have to be:
Now go to
and tick the following:
Optional: add or delete utilities, modules, features. Unset menu items only if you are sure what they mean. When I did it first time I went on a rampage and wiped all unnecessary (or so I thought) features which resulted in perfectly working kernel that didn't have WiFi drivers in it.
I would definitely include dmesg which is a handy program that displays system log so you know exactly why doesn't something work. To make use of software SPI you will need to check

and to test if it works okay you should also check

Using GPIOs that have alternative function (like JTAG, PCM, UART etc)? You're in for a surprise. Lunux kernel probably won't let you export (or use) those GPIOs. If you're sure you'll never need this pin's function, you can modify

and remove the section that corresponds to the pin you need, for me it was
and use it freely!
5) Run make and wait patiently...
-jN is the number of your CPU cores + 1.
6) Flash the new firmware
We are going to use the easiest method. I even made a script update_openwrt_on_vocore.sh to assist that (requires packages zenity and sshpass):
Just connect to Vocore AP and run
Text that pops up in a windows is what you have to type in telnet window (Couldn't make ssh run a command even though it should be as easy as ssh user@host 'COMMAND'. Know how to do it? Please write a comment).
That's it! Wait for the AP to reappear and you can telnet to your brand new custom OpenWrt.

Adding some hardware

My aim was to make Vocore work with REYAX CC110LM boards (containing TI's CC110L):


However, as an old microcontroller enthusiast I decided to add a blinky light and a button to see if I can make Linux blink an LED and read the state of a button. So I got to soldering this all on, I hope you can make your soldering look less messy:


Schematic:
led -        gpio7
button - gpio19

cc110l:
SI -        gpio12
SO -      gpio13
SCLK - gpio14
CSN -   gpio21
GDO -  gpio0

As you can see, I also hotglued miniUSB jack as a power connector. Quite handy.

First program - Blink

To switch GPIO 7 (with LED connected to it) on and off from shell you can telnet into Vocore and type the following:
If you can't export GPIO, that most likely means it's allocated for some other purpose. Either put the LED on the pin you can export or you can free the pin of it's function  when you compile OpenWrt (go to item 4 of section "Building OpenWrt")
Controlling GPIO from command line is nice, but that's not how it should work, so let's compile and launch our first program that blinks an LED. I'm using makefiles to automate compiling and uploading.
Program structure is simple, and so is makefile. To compile and upload to target you only have to change  this line:

to where your toolchain is located (it was built when you compiled OpenWrt) and run make in Blink directory.
Make system will compile your program, copy it to vocore's /root and login you to telnet.
You only have to launch it ./blink and look at the LED.

Next up - buttons

Now that we've dealt with GPIOs in output mode, we have input mode ahead of us - that's what the button is for.
To assess the button's state (gpio19) from command line enter the following:
Writing the program that will utilise the button is up to you ;-)

SPI

I'll be using software SPI via spi-gpio-custom kernel module. Adding an SPI device is as simple as launching
where 1 is device id,
14 is pin for SCK
12 is pin for MOSI
13 is pin for MISO
0 is SPI mode,
1000000 is max clock freq. (in Hz, so 1Mhz in this case)
21 is pin for SS
and using the resulting /dev/spidev1.0 like this:

To check if SPI really works without having any slave device connected to your board simply short MISO to MOSI on Vocore (gpio12 to gpio13 in my case) and run
and that's what it's supposed to yield:
 If what you see is a page of '0's, 'F's or some rubbish that is inconsistent between spidev_test launches, check if your wiring (and insmod command) is correct and try again.

So you spoiled it

In fact, I bricked Vocore so many times I made a script that automatically restores the default firmware. You can get it HERE
Let's begin by connecting USB-Serial adaptor to Vocore's UART at pins 15 and 16. Then install putty , open it and create a profile "ttyUSB0@57600" that is just a serial port on ttyUSB0 at 57600 baud. Launch ./unbrick_ckermit_uart.sh and wait for it to do the job.

The end.

I'll write about using CC110L with Vocore if I'll have enough time.

2 comments:

  1. Thanks Vadim for sharing, have a question.
    Is it possible to set wifi tx power to 0dBm on VoCore.

    Thanks in advance
    Mat

    ReplyDelete
    Replies
    1. Hi, MathewK, unfortunately I don't have Vocore anymore, but I can blindly suggest something like
      iwconfig wlan0 txpower 0
      Let me know if it works ;-)

      Delete