Close

The Travails of Using GPCLK0

A project log for CAT Board

The CAT Board is part of a Raspberry Pi-based hand-held FPGA programming system.

dave-vandenboutDave Vandenbout 12/02/2015 at 05:274 Comments

The CAT Board has a 100 MHz Si501 MEMS oscillator on board, but the iCE40 FPGA can also be clocked from the GPCLK0 pin on the Raspberry Pi GPIO header. All I had to do was enable that clock and program the output frequency.

I started off with RPi.GPIO. I modified a simple Python program I found here to get this:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
#set the alternate mode for pin 4 (GPCLK0)
GPIO.setup(4,GPIO.ALT0)
#set the clock frequency to 64 Khz)
GPIO.setclock(4,64000)
#turn on the clock
GPIO.output(4,1)
But when I ran it, it complained that GPIO.ALT0 was undefined. Sure enough, a little poking around in IDLE showed ALT0 was non-existent. One of the commenters in this thread from 2015 verified that none of the ALTx codes were supported in the current version of RPi.GPIO. I guess the code I modified came from a few years earlier.

So I got hold of the WiringPi library with its gpio command-line tool. I could (supposedly) put the GPCLK0 pin into the ALT0 mode using the command:

gpio -g mode 15 alt0
That seemed to do something to the GPCLK0 pin: it went from a 3.3V to ground.

Next, I ran my Python script with the GPIO.setup(4, GPIO.ALT0) disabled. Unfortunately, I got another error message that the setclock routine was undefined. At this point, I abandoned RPi.GPIO.

I looked through the WiringPi documentation but didn't find any facilities for working with the GPCLKx pins. So I abandoned that, too.

I found mention of a small program for getting a 10 MHz clock out of the GPCLK0 pin. After downloading and compiling the source code, the program would execute but stalled in a loop waiting for the clock pin's busy flag to go active. So that was a bust.

Most of the code I found that handles GPCLK0 seems to be from a few years ago and probably worked with the BCM2835 in the original Raspberry Pi B/B+. I have the RPi 2 that uses the BCM2836, so the register addresses and bit positions have probably changed enough to render the old code useless.

So I need to look further on how to unlock the power of the GPCLK0 pin. Thankfully I placed that 100 MHz oscillator on the CAT Board or else I would have been really stuck.

Of course, on top of all this, the Si501 chip was discontinued a few months ago...

Discussions

Yann Guidon / YGDES wrote 12/02/2015 at 09:51 point

Contact me if you are interested with some C code that handles that. I have to port my GPIO/SPI code to the new Pi2 but got delayed then forgot about those changes in base address...

  Are you sure? yes | no

Dave Vandenbout wrote 12/02/2015 at 13:00 point

Thanks, I would like to see that.

  Are you sure? yes | no

Kumar, Abhishek wrote 12/02/2015 at 08:24 point

Why would SiLabs discontiunue the MEMS oscillator series? Aren't CMEMS oscillators lower power than crystal oscillators?

  Are you sure? yes | no

Dave Vandenbout wrote 12/02/2015 at 13:35 point

I don't know. Perhaps there's a technical flaw that prevents their large-scale adoption by customers. The few I bought work fine and their unit cost is a lot lower than crystal oscillators, but I haven't looked closely at their stability/jitter specs.

  Are you sure? yes | no