Skip to content

Commit 389dc03

Browse files
committed
Fix whitespace. Fix handling of PICO_FLASH_SIZE_BYTES == 0.
1 parent 7bd9b8d commit 389dc03

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

src/rp2_common/hardware_flash/flash.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,15 @@ flash_devinfo_size_t __no_inline_not_in_flash_func(flash_devinfo_get_cs_size)(ui
310310
if (cs == 0u) {
311311
#ifdef PICO_FLASH_SIZE_BYTES
312312
// A flash size explicitly specified for the build (e.g. from the board header) takes
313-
// precedence over whatever was found in OTP.
314-
return (flash_devinfo_size_t) (
315-
__builtin_ctz(PICO_FLASH_SIZE_BYTES / 8192u) + (uint)FLASH_DEVINFO_SIZE_8K
316-
);
313+
// precedence over whatever was found in OTP. Not using flash_devinfo_bytes_to_size() as
314+
// the call could be outlined, and this code must be in RAM.
315+
if (PICO_FLASH_SIZE_BYTES == 0) {
316+
return FLASH_DEVINFO_SIZE_NONE;
317+
} else {
318+
return (flash_devinfo_size_t) (
319+
__builtin_ctz(PICO_FLASH_SIZE_BYTES / 8192u) + (uint)FLASH_DEVINFO_SIZE_8K
320+
);
321+
}
317322
#else
318323
return (flash_devinfo_size_t) (
319324
(*devinfo & OTP_DATA_FLASH_DEVINFO_CS0_SIZE_BITS) >> OTP_DATA_FLASH_DEVINFO_CS0_SIZE_LSB

src/rp2_common/hardware_flash/include/hardware/flash.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,46 @@ void flash_flush_cache(void);
123123

124124
#if !PICO_RP2040
125125
typedef enum {
126-
FLASH_DEVINFO_SIZE_NONE = 0x0,
127-
FLASH_DEVINFO_SIZE_8K = 0x1,
128-
FLASH_DEVINFO_SIZE_16K = 0x2,
129-
FLASH_DEVINFO_SIZE_32K = 0x3,
130-
FLASH_DEVINFO_SIZE_64K = 0x4,
131-
FLASH_DEVINFO_SIZE_128K = 0x5,
132-
FLASH_DEVINFO_SIZE_256K = 0x6,
133-
FLASH_DEVINFO_SIZE_512K = 0x7,
134-
FLASH_DEVINFO_SIZE_1M = 0x8,
135-
FLASH_DEVINFO_SIZE_2M = 0x9,
136-
FLASH_DEVINFO_SIZE_4M = 0xa,
137-
FLASH_DEVINFO_SIZE_8M = 0xb,
138-
FLASH_DEVINFO_SIZE_16M = 0xc,
139-
FLASH_DEVINFO_SIZE_MAX = 0xc
126+
FLASH_DEVINFO_SIZE_NONE = 0x0,
127+
FLASH_DEVINFO_SIZE_8K = 0x1,
128+
FLASH_DEVINFO_SIZE_16K = 0x2,
129+
FLASH_DEVINFO_SIZE_32K = 0x3,
130+
FLASH_DEVINFO_SIZE_64K = 0x4,
131+
FLASH_DEVINFO_SIZE_128K = 0x5,
132+
FLASH_DEVINFO_SIZE_256K = 0x6,
133+
FLASH_DEVINFO_SIZE_512K = 0x7,
134+
FLASH_DEVINFO_SIZE_1M = 0x8,
135+
FLASH_DEVINFO_SIZE_2M = 0x9,
136+
FLASH_DEVINFO_SIZE_4M = 0xa,
137+
FLASH_DEVINFO_SIZE_8M = 0xb,
138+
FLASH_DEVINFO_SIZE_16M = 0xc,
139+
FLASH_DEVINFO_SIZE_MAX = 0xc
140140
} flash_devinfo_size_t;
141141

142142
/*! \brief Convert a flash/PSRAM size enum to an integer size in bytes
143143
* \ingroup hardware_flash
144144
*/
145145
static inline uint32_t flash_devinfo_size_to_bytes(flash_devinfo_size_t size) {
146-
if (size == FLASH_DEVINFO_SIZE_NONE) {
147-
return 0;
148-
} else {
149-
return 4096u << (uint)size;
150-
}
146+
if (size == FLASH_DEVINFO_SIZE_NONE) {
147+
return 0;
148+
} else {
149+
return 4096u << (uint)size;
150+
}
151151
}
152152

153153
/*! \brief Convert an integer flash/PSRAM size in bytes to a size enum, as
154154
! stored in OTP and used by the ROM.
155155
* \ingroup hardware_flash
156156
*/
157157
static inline flash_devinfo_size_t flash_devinfo_bytes_to_size(uint32_t bytes) {
158-
// Must be zero or a power of two
159-
valid_params_if(HARDWARE_FLASH, (bytes & (bytes - 1)) == 0u);
160-
uint sectors = bytes / 4096u;
161-
if (sectors <= 1u) {
162-
return FLASH_DEVINFO_SIZE_NONE;
163-
} else {
164-
return (flash_devinfo_size_t) __builtin_ctz(sectors);
165-
}
158+
// Must be zero or a power of two
159+
valid_params_if(HARDWARE_FLASH, (bytes & (bytes - 1)) == 0u);
160+
uint sectors = bytes / 4096u;
161+
if (sectors <= 1u) {
162+
return FLASH_DEVINFO_SIZE_NONE;
163+
} else {
164+
return (flash_devinfo_size_t) __builtin_ctz(sectors);
165+
}
166166
}
167167

168168
/*! \brief Get the size of the QSPI device attached to chip select cs, according to FLASH_DEVINFO

0 commit comments

Comments
 (0)