Skip to content

Commit 9644399

Browse files
authored
Suppress new GCC 12 warning (#842)
1 parent b3c56e7 commit 9644399

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

src/rp2_common/hardware_rtc/rtc.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ bool rtc_set_datetime(datetime_t *t) {
6565
}
6666

6767
// Write to setup registers
68-
rtc_hw->setup_0 = (((uint)t->year) << RTC_SETUP_0_YEAR_LSB ) |
69-
(((uint)t->month) << RTC_SETUP_0_MONTH_LSB) |
70-
(((uint)t->day) << RTC_SETUP_0_DAY_LSB);
71-
rtc_hw->setup_1 = (((uint)t->dotw) << RTC_SETUP_1_DOTW_LSB) |
72-
(((uint)t->hour) << RTC_SETUP_1_HOUR_LSB) |
73-
(((uint)t->min) << RTC_SETUP_1_MIN_LSB) |
74-
(((uint)t->sec) << RTC_SETUP_1_SEC_LSB);
68+
rtc_hw->setup_0 = (((uint32_t)t->year) << RTC_SETUP_0_YEAR_LSB ) |
69+
(((uint32_t)t->month) << RTC_SETUP_0_MONTH_LSB) |
70+
(((uint32_t)t->day) << RTC_SETUP_0_DAY_LSB);
71+
rtc_hw->setup_1 = (((uint32_t)t->dotw) << RTC_SETUP_1_DOTW_LSB) |
72+
(((uint32_t)t->hour) << RTC_SETUP_1_HOUR_LSB) |
73+
(((uint32_t)t->min) << RTC_SETUP_1_MIN_LSB) |
74+
(((uint32_t)t->sec) << RTC_SETUP_1_SEC_LSB);
7575

7676
// Load setup values into rtc clock domain
7777
rtc_hw->ctrl = RTC_CTRL_LOAD_BITS;
@@ -95,13 +95,13 @@ bool rtc_get_datetime(datetime_t *t) {
9595
uint32_t rtc_0 = rtc_hw->rtc_0;
9696
uint32_t rtc_1 = rtc_hw->rtc_1;
9797

98-
t->dotw = (rtc_0 & RTC_RTC_0_DOTW_BITS ) >> RTC_RTC_0_DOTW_LSB;
99-
t->hour = (rtc_0 & RTC_RTC_0_HOUR_BITS ) >> RTC_RTC_0_HOUR_LSB;
100-
t->min = (rtc_0 & RTC_RTC_0_MIN_BITS ) >> RTC_RTC_0_MIN_LSB;
101-
t->sec = (rtc_0 & RTC_RTC_0_SEC_BITS ) >> RTC_RTC_0_SEC_LSB;
102-
t->year = (rtc_1 & RTC_RTC_1_YEAR_BITS ) >> RTC_RTC_1_YEAR_LSB;
103-
t->month = (rtc_1 & RTC_RTC_1_MONTH_BITS) >> RTC_RTC_1_MONTH_LSB;
104-
t->day = (rtc_1 & RTC_RTC_1_DAY_BITS ) >> RTC_RTC_1_DAY_LSB;
98+
t->dotw = (int8_t) ((rtc_0 & RTC_RTC_0_DOTW_BITS ) >> RTC_RTC_0_DOTW_LSB);
99+
t->hour = (int8_t) ((rtc_0 & RTC_RTC_0_HOUR_BITS ) >> RTC_RTC_0_HOUR_LSB);
100+
t->min = (int8_t) ((rtc_0 & RTC_RTC_0_MIN_BITS ) >> RTC_RTC_0_MIN_LSB);
101+
t->sec = (int8_t) ((rtc_0 & RTC_RTC_0_SEC_BITS ) >> RTC_RTC_0_SEC_LSB);
102+
t->year = (int16_t) ((rtc_1 & RTC_RTC_1_YEAR_BITS ) >> RTC_RTC_1_YEAR_LSB);
103+
t->month = (int8_t) ((rtc_1 & RTC_RTC_1_MONTH_BITS) >> RTC_RTC_1_MONTH_LSB);
104+
t->day = (int8_t) ((rtc_1 & RTC_RTC_1_DAY_BITS ) >> RTC_RTC_1_DAY_LSB);
105105

106106
return true;
107107
}
@@ -148,13 +148,13 @@ void rtc_set_alarm(datetime_t *t, rtc_callback_t user_callback) {
148148
rtc_disable_alarm();
149149

150150
// Only add to setup if it isn't -1
151-
rtc_hw->irq_setup_0 = ((t->year < 0) ? 0 : (((uint)t->year) << RTC_IRQ_SETUP_0_YEAR_LSB )) |
152-
((t->month < 0) ? 0 : (((uint)t->month) << RTC_IRQ_SETUP_0_MONTH_LSB)) |
153-
((t->day < 0) ? 0 : (((uint)t->day) << RTC_IRQ_SETUP_0_DAY_LSB ));
154-
rtc_hw->irq_setup_1 = ((t->dotw < 0) ? 0 : (((uint)t->dotw) << RTC_IRQ_SETUP_1_DOTW_LSB)) |
155-
((t->hour < 0) ? 0 : (((uint)t->hour) << RTC_IRQ_SETUP_1_HOUR_LSB)) |
156-
((t->min < 0) ? 0 : (((uint)t->min) << RTC_IRQ_SETUP_1_MIN_LSB )) |
157-
((t->sec < 0) ? 0 : (((uint)t->sec) << RTC_IRQ_SETUP_1_SEC_LSB ));
151+
rtc_hw->irq_setup_0 = ((t->year < 0) ? 0 : (((uint32_t)t->year) << RTC_IRQ_SETUP_0_YEAR_LSB )) |
152+
((t->month < 0) ? 0 : (((uint32_t)t->month) << RTC_IRQ_SETUP_0_MONTH_LSB)) |
153+
((t->day < 0) ? 0 : (((uint32_t)t->day) << RTC_IRQ_SETUP_0_DAY_LSB ));
154+
rtc_hw->irq_setup_1 = ((t->dotw < 0) ? 0 : (((uint32_t)t->dotw) << RTC_IRQ_SETUP_1_DOTW_LSB)) |
155+
((t->hour < 0) ? 0 : (((uint32_t)t->hour) << RTC_IRQ_SETUP_1_HOUR_LSB)) |
156+
((t->min < 0) ? 0 : (((uint32_t)t->min) << RTC_IRQ_SETUP_1_MIN_LSB )) |
157+
((t->sec < 0) ? 0 : (((uint32_t)t->sec) << RTC_IRQ_SETUP_1_SEC_LSB ));
158158

159159
// Set the match enable bits for things we care about
160160
if (t->year >= 0) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_YEAR_ENA_BITS);

src/rp2_common/pico_bootrom/bootrom.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
// Returns the 32 bit pointer into the ROM if found or NULL otherwise.
1313
typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);
1414

15-
// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
16-
#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address)
17-
1815
void *rom_func_lookup(uint32_t code) {
1916
return rom_func_lookup_inline(code);
2017
}

src/rp2_common/pico_bootrom/include/pico/bootrom.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,18 @@ bool rom_funcs_lookup(uint32_t *table, unsigned int count);
116116
// Returns the 32 bit pointer into the ROM if found or NULL otherwise.
117117
typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);
118118

119+
#if defined(__GNUC__) && (__GNUC__ >= 12)
119120
// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
120-
#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address)
121+
static inline void *rom_hword_as_ptr(uint16_t rom_address) {
122+
#pragma GCC diagnostic push
123+
#pragma GCC diagnostic ignored "-Warray-bounds"
124+
return (void *)(uintptr_t)*(uint16_t *)(uintptr_t)rom_address;
125+
#pragma GCC diagnostic pop
126+
}
127+
#else
128+
// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
129+
#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)(uintptr_t)(rom_address))
130+
#endif
121131

122132
/*!
123133
* \brief Lookup a bootrom function by code. This method is forceably inlined into the caller for FLASH/RAM sensitive code usage

src/rp2_common/pico_platform/include/pico/platform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ uint8_t rp2040_chip_version(void);
336336
* @return the RP2040 rom version number (1 for RP2040-B0, 2 for RP2040-B1, 3 for RP2040-B2)
337337
*/
338338
static inline uint8_t rp2040_rom_version(void) {
339+
#pragma GCC diagnostic push
340+
#pragma GCC diagnostic ignored "-Warray-bounds"
339341
return *(uint8_t*)0x13;
342+
#pragma GCC diagnostic pop
340343
}
341344

342345
/*! \brief No-op function for the body of tight loops

0 commit comments

Comments
 (0)