Can we fix the RTC?


#include "IRQManager.h"

volatile uint16_t result;
volatile bool fired = false;

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(115200);
  while (!Serial)
    ;
  Serial.println("Starting CAC Experiment!");

  setupCAC();

  Serial.println("End Setup!");
}

void loop() {

  heart();

  if (fired) {
    __disable_irq();
    uint16_t copy = result;
    fired = false;
    __enable_irq();
    Serial.print("Result : ");
    Serial.println(copy);
  }
}

void cacMendieHandler() {

  result = R_CAC->CACNTBR;
  // clear interrupt
  R_CAC->CAICR |= (R_CAC_CAICR_MENDFCL_Msk);

  fired = true;
}

void setupCAC() {

  //R_MSTP->MSTPCRC &= ~(R_MSTP_MSTPCRC_MSTPC0_Msk);
  /*
I'm caculating 48MHz on MOSC / 32.767kHz on LOCO should
give a ratio of around 1:1465.
*/
  // set lower limit
  R_CAC->CALLVR = 700;
  //set upper limit
  R_CAC->CAULVR = 2100;

  // Set source clock
  R_CAC->CACR1 = 0x34;

  // set reference clock
  R_CAC->CACR2 = 0x09;

  // set interrupt


  IRQManager::getInstance().addMaskableInterrupt(0x48, cacMendieHandler);

  R_CAC->CAICR = (R_CAC_CAICR_MENDIE_Msk | R_CAC_CAICR_MENDFCL_Msk);

  // Set CFME in CACR0 to turn on the unit
  R_CAC->CACR0 = (R_CAC_CACR0_CFME_Msk);
}


void heart() {
  static uint32_t pm = millis();
  uint32_t cm = millis();
  if (cm - pm >= 1000) {
    pm = cm;
    digitalWrite(13, !digitalRead(13));
  }
}

Along with the mod here:

Compiles and runs. But doesn't output anything outside of setup. If I uncomment the MSTPCRC line then the heartbeat stops.