[SC64][SW] Removed _oscillator running after time set_ check in the RTC, lowered I2C clock speed

This commit is contained in:
Mateusz Faderewski 2024-01-12 03:12:14 +01:00
parent b84213b3e4
commit f7eb6a73b4
2 changed files with 12 additions and 20 deletions

View File

@ -460,7 +460,7 @@ static void hw_init_spi (void) {
static void hw_init_i2c (void) { static void hw_init_i2c (void) {
RCC->APBENR1 |= RCC_APBENR1_I2C1EN; 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); 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); hw_gpio_init(GPIO_ID_I2C_SCL, GPIO_ALT, GPIO_OD, GPIO_SPEED_VLOW, GPIO_PULL_NONE, GPIO_AF_6, 0);

View File

@ -93,18 +93,14 @@ static void rtc_sanitize_time (uint8_t *regs) {
} }
} }
static void rtc_wait_osc (bool running) { static void rtc_osc_stop (void) {
uint8_t rtcwkday; uint8_t tmp = 0x00;
while (1) { rtc_write(RTC_ADDRESS_RTCSEC, &tmp, 1);
rtc_read(RTC_ADDRESS_RTCWKDAY, &rtcwkday, 1);
if (running && (rtcwkday & RTC_RTCWKDAY_OSCRUN)) { do {
return; rtc_read(RTC_ADDRESS_RTCWKDAY, &tmp, 1);
} else if (!running && (!(rtcwkday & RTC_RTCWKDAY_OSCRUN))) { } while (tmp & RTC_RTCWKDAY_OSCRUN);
return;
}
}
} }
static void rtc_read_time (void) { static void rtc_read_time (void) {
@ -130,11 +126,7 @@ static void rtc_read_time (void) {
static void rtc_write_time (void) { static void rtc_write_time (void) {
uint8_t regs[7]; uint8_t regs[7];
regs[0] = 0x00; rtc_osc_stop();
rtc_write(RTC_ADDRESS_RTCSEC, regs, 1);
rtc_wait_osc(false);
regs[0] = rtc_time.second; regs[0] = rtc_time.second;
regs[1] = rtc_time.minute; regs[1] = rtc_time.minute;
@ -147,11 +139,10 @@ static void rtc_write_time (void) {
rtc_sanitize_time(regs); rtc_sanitize_time(regs);
regs[0] |= RTC_RTCSEC_ST; regs[0] |= RTC_RTCSEC_ST;
regs[3] |= (RTC_RTCWKDAY_OSCRUN | RTC_RTCWKDAY_VBATEN); regs[3] |= RTC_RTCWKDAY_VBATEN;
rtc_write(RTC_ADDRESS_RTCSEC, regs, 7); rtc_write(RTC_ADDRESS_RTCMIN, &regs[1], 6);
rtc_write(RTC_ADDRESS_RTCSEC, &regs[0], 1);
rtc_wait_osc(true);
} }
static void rtc_read_region (void) { static void rtc_read_region (void) {
@ -188,6 +179,7 @@ static void rtc_init (void) {
if (uninitialized) { if (uninitialized) {
buffer[0] = 0; buffer[0] = 0;
rtc_write(RTC_ADDRESS_SRAM_MAGIC, (uint8_t *) (magic), 4); 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(RTC_ADDRESS_OSCTRIM, buffer, 1);
rtc_write_time(); rtc_write_time();
rtc_write_region(); rtc_write_region();