I wanted to try and get a 1MHz clock out of the GPIOs so started looking at using the GPIO Clocks - see section 6.3 of the BCM2835 Peripherals doc.
I'm not having much luck getting it going and wondered if anyone else had tried.
I'm trying to set GPIO 4 to ALT0 function which should be GPCLK0. I'm then writing to the CM_GP0CTL and CM_GP0DIV registers to set it up.
Code is as follows:
Code: Select all
.section .init
.globl _start
_start:
b main
.section .text
/*---------------------*/
/* Function: heartbeat */
/*---------------------*/
heartbeat:
/* Store the return address */
push {lr}
/* Flash GPIO 16 */
mov r0, #16
mov r1, #0
bl SetGpio
ldr r0, =125000
bl Wait
mov r0, #16
mov r1, #1
bl SetGpio
ldr r0, =500000
bl Wait
/* Return */
pop {pc}
/*----------------*/
/* Function: main */
/*----------------*/
main:
/*
* Set the stack point to 0x8000.
*/
mov sp,#0x8000
/* Setup GPIO 16 as output for debug purposes */
mov r0, #16
mov r1, #1
bl SetGpioFunction
/* Setup GPIO 4 as ALT0 function i.e. GPCLK0 */
mov r0, #4
mov r1, #4 /* ALT0 */
bl SetGpioFunction
/* Get the clock base address */
ldr r1, =0x02101070
/* Set the clock register */
/* PASSWD - 5A */
/* MASH - 0 (Integer division) */
/* SRC - 6 (PLLD per) */
ldr r0, =0x5A000006
str r0, [r1, #0x00]
/* Set the clock divider - 200Mhz PLL divided by 200 = 1MHz */
ldr r0, =0x5A0C8000
str r0, [r1, #0x04]
/* Enable the clock */
/* PASSWD - 5A */
/* MASH - 0 (Integer division) */
/* ENAB - 1 */
/* SRC - 6 (PLLD per) */
ldr r0, =0x5A000016
str r0, [r1, #0x00]
Loop$:
/* Flash 'OK' */
bl heartbeat
b Loop$
I'm using a logic analyser to check the output of GPIO 4 but nothing is coming out.
Any ideas? Many thanks, David.