Arm cortex-m peripheral registers always 0

July 30, 2022

When writing a peripheral driver and writing to register values always read out as zero, what??

Sometimes things make no sense and you have to kill a lot of time figuring out why... like when you write a register and it does not do anything.

Code (zig)

// Omit bunch of comptime configuration code..
dac.instance.CTL = DAC_CTL_DACEN_Msk;

Run it and GDB shows...

(gdb) p *dac.instance
$1 = {CTL = 0, SWTRG = 0, DAT = 0, DATOUT = 0, STATUS = 0, TCTL = 0}

The peripheral clock is enabled, how does that make sense???

Well double check the datasheet.... and make sure the exact CPU actually has the peripheral! (Switches to another dev board)...

(db) p *dac.instance
$1 = {CTL = 1, SWTRG = 0, DAT = 82, DATOUT = 82, STATUS = 1, TCTL = 36}

Yay...

Cheers!