Skip to content

Instantly share code, notes, and snippets.

@lromor
Last active December 27, 2017 22:26
Show Gist options
  • Save lromor/e303c88cfb8a065d411f2ba0bc52324b to your computer and use it in GitHub Desktop.
Save lromor/e303c88cfb8a065d411f2ba0bc52324b to your computer and use it in GitHub Desktop.
beaglebone black freezes.
// Tested kernel freeze on Linux beaglebone 4.4.91-ti-r137
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>
// Memory space mapped to the Clock Module registers
#define CM_BASE 0x44e00000
#define CM_SIZE 0x4000
// Clock Module Peripheral registers
#define CM_PER_TIMER4_CLKCTRL (0x000 + 0x88)
#define IDLEST_MASK (0x03 << 16)
#define MODULEMODE_ENABLE (0x02 << 0)
#define CLKSEL(x) (((x) & 0x3) << 0)
#define CLKSEL_CLK_M_OSC CLKSEL(1)
static void pwm_timers_ena_clk(volatile uint32_t *cm, uint32_t reg, int timer) {
uint32_t val;
val = cm[reg/4];
if (val & IDLEST_MASK) {
val |= MODULEMODE_ENABLE;
cm[reg/4] = val;
do {
val = cm[reg/4];
} while (val & IDLEST_MASK);
}
}
static int pwm_timers_enable_clocks(int fd) {
volatile uint32_t *cm = (volatile uint32_t*) mmap(0, CM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, CM_BASE);
if (cm == MAP_FAILED) { perror("mmap() CM"); return 0; }
// Enable the timer clocks
pwm_timers_ena_clk(cm, CM_PER_TIMER4_CLKCTRL, 4);
return 1;
}
int main(int argc, char *argv[]) {
int fd = open("/dev/mem", O_RDWR);
if (fd == -1) { perror("open()"); return 1; }
pwm_timers_enable_clocks(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment