Skip to content

Commit

Permalink
[SC64][SW] Removed _oscillator running after time set_ check in the R…
Browse files Browse the repository at this point in the history
…TC, lowered I2C clock speed
  • Loading branch information
Polprzewodnikowy committed Jan 12, 2024
1 parent b84213b commit f7eb6a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion sw/controller/src/hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ static void hw_init_spi (void) {
static void hw_init_i2c (void) {
RCC->APBENR1 |= RCC_APBENR1_I2C1EN;

I2C1->TIMINGR = 0x00C12166UL;
I2C1->TIMINGR = 0x80821B20UL;
I2C1->CR1 |= (I2C_CR1_TCIE | I2C_CR1_STOPIE | I2C_CR1_RXIE | I2C_CR1_TXIE | I2C_CR1_PE);

hw_gpio_init(GPIO_ID_I2C_SCL, GPIO_ALT, GPIO_OD, GPIO_SPEED_VLOW, GPIO_PULL_NONE, GPIO_AF_6, 0);
Expand Down
30 changes: 11 additions & 19 deletions sw/controller/src/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,14 @@ static void rtc_sanitize_time (uint8_t *regs) {
}
}

static void rtc_wait_osc (bool running) {
uint8_t rtcwkday;
static void rtc_osc_stop (void) {
uint8_t tmp = 0x00;

while (1) {
rtc_read(RTC_ADDRESS_RTCWKDAY, &rtcwkday, 1);
rtc_write(RTC_ADDRESS_RTCSEC, &tmp, 1);

if (running && (rtcwkday & RTC_RTCWKDAY_OSCRUN)) {
return;
} else if (!running && (!(rtcwkday & RTC_RTCWKDAY_OSCRUN))) {
return;
}
}
do {
rtc_read(RTC_ADDRESS_RTCWKDAY, &tmp, 1);
} while (tmp & RTC_RTCWKDAY_OSCRUN);
}

static void rtc_read_time (void) {
Expand All @@ -130,11 +126,7 @@ static void rtc_read_time (void) {
static void rtc_write_time (void) {
uint8_t regs[7];

regs[0] = 0x00;

rtc_write(RTC_ADDRESS_RTCSEC, regs, 1);

rtc_wait_osc(false);
rtc_osc_stop();

regs[0] = rtc_time.second;
regs[1] = rtc_time.minute;
Expand All @@ -147,11 +139,10 @@ static void rtc_write_time (void) {
rtc_sanitize_time(regs);

regs[0] |= RTC_RTCSEC_ST;
regs[3] |= (RTC_RTCWKDAY_OSCRUN | RTC_RTCWKDAY_VBATEN);

rtc_write(RTC_ADDRESS_RTCSEC, regs, 7);
regs[3] |= RTC_RTCWKDAY_VBATEN;

rtc_wait_osc(true);
rtc_write(RTC_ADDRESS_RTCMIN, &regs[1], 6);
rtc_write(RTC_ADDRESS_RTCSEC, &regs[0], 1);
}

static void rtc_read_region (void) {
Expand Down Expand Up @@ -188,6 +179,7 @@ static void rtc_init (void) {
if (uninitialized) {
buffer[0] = 0;
rtc_write(RTC_ADDRESS_SRAM_MAGIC, (uint8_t *) (magic), 4);
rtc_write(RTC_ADDRESS_CONTROL, buffer, 1);
rtc_write(RTC_ADDRESS_OSCTRIM, buffer, 1);
rtc_write_time();
rtc_write_region();
Expand Down

0 comments on commit f7eb6a7

Please sign in to comment.