Vocore v. 1.0 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 post will contain everything I'll manage to learn about this board while I'm playing with it. This is an attempt to get together all those scattered pieces of information I found on the Internet.

 Quite 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 up and running again.

Requirements

  • PC running Linux (I used Arch Linux),
  • LED, any value resistor, any button or switch.

Some helpful links you'll frequently use

 One page you're going to look at a lot is this one.. All the essential information such as board layout, pin-out etc. is there.
 Vocore's operating system is OpenWrt, so you'll definitely pay a visit to their site once you've decided to rewrite the out-of-the-box  OpenWrt build - for example, to get SPI working.

Let's start!

 First off, I advice you get some miniature pin headers when you order Vocore:

1.27mm pin headers on the left, 2.56mm headers to the right are for scale.

 Their pitch is 1.27mm and you should get female as well as male pin headers. 
 At first I was happy to just solder wires to Vocore's plated holes, but then I realized I needed more flexibility and a bunch of wires was the wrong way to achieve it,  BUT the solder was already on most of the holes so I ended up soldering the pin header sideways:

Sideways pin header is still better than wires sticking out of every corner.

 So, you've finally got the package and 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, do it now.
 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 the feeds
Optional: install some (or all) of the feeds. I just installed nano because that's my favorite text editor in Linux
3) Apply 2 patches: noblepepper's and vonger's. Backup links (just in case): noblepepper, vonger
Note: these patches may intersect, it's up to you to resolve conflicts - they are probably doing the same changes. With patches applied, OpenWrt will use 16Mb of flash memory instead of 8Mb, the access point name is set to VoCore, it also turns the radio on by default, sets the root password to "vocore" and IP address 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

UPDATE 2018.06.13: updated the script (got rid of zenity dependency), made some improvements in workflow description.

In fact, I bricked Vocore so many times I made a script that automatically restores the default firmware. You can get it HERE or at my github repo with shell scripts.

1) Let's begin by connecting USB-Serial adapter to Vocore's UART at pins 15 and 16.

Using an Arduino Uno as a serial adapter.

A close up of my piss-poor job at connecting RX and TX wires to Vocore. But hey, at least it's removable!

That's me reflashing another Vocore, as you can see this one looks decent with pin headers and all.
 
2) Install putty. Add it to $PATH if you package manager hadn't done that yet.
3) Don't power up Vocore yet.
4) Launch


5) Follow the on-screen instructions:


The process itself will take about 5 minutes, you can watch the progress bar in the console window:

Firmware mid-upload.

6) You can key in reset  in putty window when the script is finished uploading:


By the way, if you'd like to use this script to upload different firmware to your Vocore, you can totally do it. Just recalculate the firmware size - it's in hexadecimal - and plug the new figure into ckermit.sh file like so:

The end.

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

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

Post a Comment