Thursday 4 June 2015

Installing DD-WRT on a TP-LINK TL-WR842ND

I love playing with routers and network gear in general - who doesn't?  In the past I've never run the same router at home for long while I swap them out with different software and/or hardware.  This has slowed a bit lately due to life, but hasn't completely stopped.

I ran an early model WRT54G with DD-WRT for a while a number of years ago.  That was my last foray into DD-WRT (it's been pfsense and now routeros since).  I wanted to give DD-WRT another go and so started looking through my box of bits to see what I might have that would work.  After a bit of digging in the parts box and reading online I soon realised most of my gear would run DD-WRT, but a 'micro' build.  I'm interested in having a play with some of the extra stuff that DD-WRT has to offer so I needed something with a little more Flash and RAM.

DD-WRT openly recommend a TP-Link TL-WR740N to start with, and for $19AUD from a local store it's a pretty awesome recommendation.  Getting into DD-WRT has come down in price since I last looked - which is awesome.  Looking at the supported devices list though and what else was available with a little more Flash and RAM (as well as a USB port if possible) I settled on a TP-Link TL-WR842ND v2 for $38AUD:



This router was solely purchased to be hacked, flashed and generally tinkered with, so the first thing I did after taking it out of the box was open it up.  I know these routers have a serial header thanks to this page (and many others) and I wanted to see if I could get a serial console first.  I found the connections, soldered on a four pin header and connected my 3.3v USB serial adapter:



Once I got the pinout correct, it worked without issue (115200, 8N1).  Typing tpl when you see "Autobooting in 1 seconds" will drop you into the uboot prompt:



Next step was to make this serial header externally accessible so I could close it back up but still access the serial console.  With a little bit of Dremel work I cut space for a 4 pin female header above the reset button on the back of the case.  I hot glued it in place and then soldered in some jumper wires.  In hindsight I probably could have removed the first header I soldered in and had the jumper wires run straight to the board, but the case has room so I left it in:


I closed the case back up and got ready to flash DD-WRT with my new serial console open to watch the process, which worked without issue (serial console not required, but super extra nerd cred for having it).  I flashed the latest version at the time which was 05-27-2015-r27086.  I first flashed the factory-to-ddwrt.bin through the TP-Link web interface, and then flashed the tl-wr842ndv2-webflash.bin through the DD-WRT web interface.

The final step was to add a sticker to complete things:


I'll need some time to get to know DD-WRT again, but I have the comfort of a serial console if things go sideways.

Monday 16 February 2015

Dev board "Stage One" - Part 2

Nowadays I'm a Python guy, so as per the previous post once I had the basics working with the BusPirate using it's inbuilt console I immediately went looking for Python based options for using the BusPirate.  I pretty quickly landed on pyBusPirate.

After cloning the code I jumped straight into the SPI samples and pretty quickly realised that while I could read the Python - I didn't actually know why the code was doing what it was doing.  I had no idea why different bytes were being sent, or what was being returned as a result.

So I took a breath and a step back.  I then went and read about the BusPirate in Biting mode, and then specifically SPI(Binary) mode.

Things make much more sense now - why each byte is being sent and what's being returned (or expected to be returned).  Those links make it pretty clear what I need to do to setup the BusPirate in SPI with my required options for this particular chip.

So I'm now looking at two main operations: write and erase.  The third operation i'll add in to support the first two is read, so I can check the result of a write or erase command.

I'll need a few bits of code to take in some options about which operation to call and the file associated (either to read to or from).  I'll also need to add the necessary bits in to set the registers for the chip for each operation.  That should be about it to get things moving with bulk write or erase commands.

I've setup a github repository for this work.

Hopefully the next post has a picture of the board running the firmware I was given with the board!


Tuesday 10 February 2015

Dev board "Stage One" - Part 1

A while ago one of my best mates gave me a dev board that he had done some work with that he thought I might like to do something with.  It's sat on my shelf for quite a long time, but this week I decided that it would be my next project.  This is not intended to be a short project, but if it goes the way I hope it will, it should be a medium term one with both some hardware and software involved.  Time will tell.

The board uses a ColdFire MCF52235 microcontroller, which has an SPI interface for programming called EzPort.

"Stage one" of this project consists of being able to flash this micro with new firmware over SPI using my BusPirate.  Initially i'll need to figure out the connection and can then test it with the just a console to the BusPirate.  Once that works i'll need to write some code to get the programming working.

According to the data sheet, to connect the BusPirate to the EzPort on the micro the following connections are required:

BusPirate EzPort
MISO QSPI_DOUT
CLK QSPI_CLK
MOSI QSPI_DIN
CS EZPCS
VPU 3.3V
GND GND

It should look something like this:


Again referring to the micro datasheet we can figure out the SPI parameters for configuring the BusPirate in SPI mode:

HiZ>m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)

(1)>5
Set speed:
 1. 30KHz
 2. 125KHz
 3. 250KHz
 4. 1MHz

(1)>2
Clock polarity:
 1. Idle low *default
 2. Idle high

(1)>1
Output clock edge:
 1. Idle to active
 2. Active to idle *default

(2)>1
Input sample phase:
 1. Middle *default
 2. End

(1)>1
CS:
 1. CS
 2. /CS *default

(2)>2
Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)

(1)>1
Ready
SPI>

With this done it was back to the data sheet again to look at how to enable the EzPort and interact with it to verify our setup.  Setting CS active low while powering up the board should be enough to enable the EzPort on the micro.  So on the BusPirate:

SPI>[
/CS ENABLED

I then powered up the board.  Time to see if we can read/write to the micro!  As suggested in the data sheet we'll read out the status register, set the write register and then read out the status register again to see if our change worked:

SPI>{0x05 0x00]
/CS ENABLED
WRITE: 0x05 READ: 0xFF 
WRITE: 0x00 READ: 0x00 
/CS DISABLED

SPI>[0x06]
/CS ENABLED
WRITE: 0x06 
/CS DISABLED

SPI>{0x05 0x00]
/CS ENABLED
WRITE: 0x05 READ: 0xFF 
WRITE: 0x00 READ: 0x02 
/CS DISABLED

It works!  Given the connection works I made up a slightly more permanent cable to replace the BusPirate probes:



Now the connection is sorted it's time to look at erasing and then programming the micro in Stage One - Part 2.  There was a little more trial and error involved in getting to this point - but nothing that was terribly interesting.  

Initially while developing the code to flash the micro, I will use an image that was provided.  Once the code for that is sorted I'll look at flashing something different (Stage 2)!

Saturday 31 January 2015

Bit of an update

I hope anyone reading this got some time out over the Christmas/New year period to unwind.

First off an update on the boat posted about previously.  We've had her out on the water a couple of times now and she runs great!  She hasn't skipped a beat thus far - so we're looking forward to having her our on the water a lot more for the rest of 2015.

Now that the boat is fixed I've been spending the bit of spare time I get on two bits of electronics related fun.  The first is learning to use Eagle to design PCBs.  My main resource for this is this book.  It's been fantastic.  I do intend to go right through to ordering some boards so when I get to that stage I'll post it here.

The other piece is this course.  I've completed all of the prior PyroEDU courses and think they are awesome.  If you are new to any of the subjects listed - the courses will take you through in a very hands on way with the most basic of hardware requirements.

Stay tuned - who knows what 2015 will bring.

Nixie Clock!

I've wanted a nixie clock for a long time.  A good mate and I talked about doing it over 10 years ago now - and he ordered some IN14 nix...