Skip to content

Commit f7eb6a7

Browse files
[SC64][SW] Removed _oscillator running after time set_ check in the RTC, lowered I2C clock speed
1 parent b84213b commit f7eb6a7

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

sw/controller/src/hw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static void hw_init_spi (void) {
460460
static void hw_init_i2c (void) {
461461
RCC->APBENR1 |= RCC_APBENR1_I2C1EN;
462462

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

466466
hw_gpio_init(GPIO_ID_I2C_SCL, GPIO_ALT, GPIO_OD, GPIO_SPEED_VLOW, GPIO_PULL_NONE, GPIO_AF_6, 0);

sw/controller/src/rtc.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,14 @@ static void rtc_sanitize_time (uint8_t *regs) {
9393
}
9494
}
9595

96-
static void rtc_wait_osc (bool running) {
97-
uint8_t rtcwkday;
96+
static void rtc_osc_stop (void) {
97+
uint8_t tmp = 0x00;
9898

99-
while (1) {
100-
rtc_read(RTC_ADDRESS_RTCWKDAY, &rtcwkday, 1);
99+
rtc_write(RTC_ADDRESS_RTCSEC, &tmp, 1);
101100

102-
if (running && (rtcwkday & RTC_RTCWKDAY_OSCRUN)) {
103-
return;
104-
} else if (!running && (!(rtcwkday & RTC_RTCWKDAY_OSCRUN))) {
105-
return;
106-
}
107-
}
101+
do {
102+
rtc_read(RTC_ADDRESS_RTCWKDAY, &tmp, 1);
103+
} while (tmp & RTC_RTCWKDAY_OSCRUN);
108104
}
109105

110106
static void rtc_read_time (void) {
@@ -130,11 +126,7 @@ static void rtc_read_time (void) {
130126
static void rtc_write_time (void) {
131127
uint8_t regs[7];
132128

133-
regs[0] = 0x00;
134-
135-
rtc_write(RTC_ADDRESS_RTCSEC, regs, 1);
136-
137-
rtc_wait_osc(false);
129+
rtc_osc_stop();
138130

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

149141
regs[0] |= RTC_RTCSEC_ST;
150-
regs[3] |= (RTC_RTCWKDAY_OSCRUN | RTC_RTCWKDAY_VBATEN);
151-
152-
rtc_write(RTC_ADDRESS_RTCSEC, regs, 7);
142+
regs[3] |= RTC_RTCWKDAY_VBATEN;
153143

154-
rtc_wait_osc(true);
144+
rtc_write(RTC_ADDRESS_RTCMIN, &regs[1], 6);
145+
rtc_write(RTC_ADDRESS_RTCSEC, &regs[0], 1);
155146
}
156147

157148
static void rtc_read_region (void) {
@@ -188,6 +179,7 @@ static void rtc_init (void) {
188179
if (uninitialized) {
189180
buffer[0] = 0;
190181
rtc_write(RTC_ADDRESS_SRAM_MAGIC, (uint8_t *) (magic), 4);
182+
rtc_write(RTC_ADDRESS_CONTROL, buffer, 1);
191183
rtc_write(RTC_ADDRESS_OSCTRIM, buffer, 1);
192184
rtc_write_time();
193185
rtc_write_region();

0 commit comments

Comments
 (0)