worked around a dumb errata
diff --git a/gyro_board/src/usb/CAN.c b/gyro_board/src/usb/CAN.c
index 35f811f..61e7f47 100644
--- a/gyro_board/src/usb/CAN.c
+++ b/gyro_board/src/usb/CAN.c
@@ -231,10 +231,6 @@
vTaskDelete(NULL);
}
- // Set all of the CAN stuff to run at CCLK/6, which translates to about 1 Mbit
- // (1.042).
- SC->PCLKSEL0 |= 3 << 26 | 3 << 28 | 3 << 30;
-
// Enable CAN
SC->PCONP |= PCONP_PCCAN1;
@@ -279,6 +275,11 @@
}
}
+void CAN_PCLKSEL(void) {
+ // Set all of the CAN stuff to run at CCLK/6, which translates to about 1 Mbit
+ // (1.042).
+ SC->PCLKSEL0 |= 3 << 26 | 3 << 28 | 3 << 30;
+}
void initCAN(void){
xTaskCreate(vCAN1, (signed char *) "CAN1rx", configMINIMAL_STACK_SIZE + 400, NULL, tskIDLE_PRIORITY + 1, NULL);
diff --git a/gyro_board/src/usb/CAN.h b/gyro_board/src/usb/CAN.h
index 1ef39d5..60f2d10 100644
--- a/gyro_board/src/usb/CAN.h
+++ b/gyro_board/src/usb/CAN.h
@@ -14,6 +14,9 @@
} can_message;
int CAN_get(can_message *message);
+
+// Sets up PCLKSEL for CAN stuff (errata PCLKSELx.1).
+void CAN_PCLKSEL(void);
void initCAN(void);
#endif
diff --git a/gyro_board/src/usb/gyro.c b/gyro_board/src/usb/gyro.c
index ad49658..40734ff 100644
--- a/gyro_board/src/usb/gyro.c
+++ b/gyro_board/src/usb/gyro.c
@@ -187,10 +187,6 @@
static portTASK_FUNCTION(gyro_read_task, pvParameters) {
SC->PCONP |= PCONP_PCSSP0;
- // Make sure that the clock is set up right.
- SC->PCLKSEL1 &= ~(3 << 10);
- SC->PCLKSEL1 |= 1 << 10;
-
// Set up SSEL.
// It's is just a GPIO pin because we're the master (it would be special if we
// were a slave).
diff --git a/gyro_board/src/usb/main.c b/gyro_board/src/usb/main.c
index 4e74ce7..e186bba 100644
--- a/gyro_board/src/usb/main.c
+++ b/gyro_board/src/usb/main.c
@@ -149,14 +149,19 @@
setup_PLL1();
- // Set everything to run at full CCLK by default.
- SC->PCLKSEL0 = 0x55555555;
-
/* Configure the LEDs. */
vParTestInitialise();
}
int main(void) {
+ // Errata PCLKSELx.1 says that we have to do all of this BEFORE setting up
+ // PLL0 or it might not work.
+
+ // Set everything to run at full CCLK by default.
+ SC->PCLKSEL0 = 0x55555555;
+
+ CAN_PCLKSEL();
+
setup_hardware();
digital_init();
@@ -203,7 +208,6 @@
/* Power up and feed the timer. */
SC->PCONP |= 0x02UL;
- SC->PCLKSEL0 = (SC->PCLKSEL0 & (~(0x3 << 2))) | (0x01 << 2);
/* Reset Timer 0 */
TIM0->TCR = TCR_COUNT_RESET;