Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 3df1a41

Browse files
perigosorg-silva
authored andcommitted
target/ch32f1: const correctness
1 parent 4949b54 commit 3df1a41

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

src/target/ch32f1.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ static bool ch32f1_flash_write(target_flash_s *flash, target_addr_t dest, const
7272
// #define MAGIC_WORD 0x1000U
7373

7474
/* "fast" Flash driver for CH32F10x chips */
75-
static void ch32f1_add_flash(target_s *target, uint32_t addr, size_t length, size_t erasesize)
75+
static void ch32f1_add_flash(target_s *const target, const uint32_t addr, const size_t length, const size_t erasesize)
7676
{
77-
target_flash_s *const flash = calloc(1, sizeof(*flash));
77+
target_flash_s *const flash = calloc(1U, sizeof(*flash));
7878
if (!flash) { /* calloc failed: heap exhaustion */
7979
DEBUG_ERROR("calloc: failed in %s\n", __func__);
8080
return;
@@ -137,7 +137,7 @@ static void ch32f1_flash_magic(target_s *const target, const uint32_t addr)
137137
}
138138

139139
/* Attempt unlock ch32f103 in fast mode */
140-
static bool ch32f1_flash_unlock(target_s *target)
140+
static bool ch32f1_flash_unlock(target_s *const target)
141141
{
142142
DEBUG_INFO("CH32: flash unlock \n");
143143

@@ -155,7 +155,7 @@ static bool ch32f1_flash_unlock(target_s *target)
155155
/*
156156
* lock ch32f103 in fast mode
157157
*/
158-
static bool ch32f1_flash_lock(target_s *target)
158+
static bool ch32f1_flash_lock(target_s *const target)
159159
{
160160
DEBUG_INFO("CH32: flash lock \n");
161161
/*
@@ -172,30 +172,30 @@ static bool ch32f1_flash_lock(target_s *target)
172172
/*
173173
*check fast_unlock is there, if so it is a CH32fx
174174
*/
175-
static bool ch32f1_has_fast_unlock(target_s *target)
175+
static bool ch32f1_has_fast_unlock(target_s *const target)
176176
{
177177
DEBUG_INFO("CH32: has fast unlock \n");
178178
// reset fast unlock
179179
ch32f1_flash_set_cr(target, FLASH_CR_FLOCK_CH32);
180-
platform_delay(1); // The flash controller is timing sensitive
180+
platform_delay(1U); // The flash controller is timing sensitive
181181
if (!(target_mem_read32(target, FLASH_CR) & FLASH_CR_FLOCK_CH32))
182182
return false;
183183
// send unlock sequence
184184
target_mem_write32(target, FLASH_KEYR, KEY1);
185185
target_mem_write32(target, FLASH_KEYR, KEY2);
186-
platform_delay(1); // The flash controller is timing sensitive
186+
platform_delay(1U); // The flash controller is timing sensitive
187187
// send fast unlock sequence
188188
target_mem_write32(target, FLASH_MODEKEYR_CH32, KEY1);
189189
target_mem_write32(target, FLASH_MODEKEYR_CH32, KEY2);
190-
platform_delay(1); // The flash controller is timing sensitive
190+
platform_delay(1U); // The flash controller is timing sensitive
191191
return !(target_mem_read32(target, FLASH_CR) & FLASH_CR_FLOCK_CH32);
192192
}
193193

194194
/*
195195
* Try to identify the ch32f1 chip family
196196
* (Actually grab all Cortex-M3 with designer == ARM not caught earlier...)
197197
*/
198-
bool ch32f1_probe(target_s *target)
198+
bool ch32f1_probe(target_s *const target)
199199
{
200200
if ((target->cpuid & CPUID_PARTNO_MASK) != CORTEX_M3)
201201
return false;
@@ -234,7 +234,7 @@ bool ch32f1_probe(target_s *target)
234234
}
235235

236236
/* Fast erase of CH32 devices */
237-
bool ch32f1_flash_erase(target_flash_s *flash, target_addr_t addr, size_t len)
237+
bool ch32f1_flash_erase(target_flash_s *const flash, target_addr_t addr, size_t len)
238238
{
239239
target_s *target = flash->t;
240240
DEBUG_INFO("CH32: flash erase \n");
@@ -275,11 +275,11 @@ bool ch32f1_flash_erase(target_flash_s *flash, target_addr_t addr, size_t len)
275275
* We do 32 to have a bit of headroom, then we check we read ffff (erased flash)
276276
* NB: Just reading fff is not enough as it could be a transient previous operation value
277277
*/
278-
static bool ch32f1_wait_flash_ready(target_s *target, uint32_t addr)
278+
static bool ch32f1_wait_flash_ready(target_s *const target, const uint32_t addr)
279279
{
280280
uint32_t flash_val = 0;
281281
/* Certain ch32f103c8t6 MCU's found on Blue Pill boards need some uninterrupted time (no SWD link activity) */
282-
platform_delay(2);
282+
platform_delay(2U);
283283
for (size_t cnt = 0; cnt < 32U && flash_val != 0xffffffffU; ++cnt)
284284
flash_val = target_mem_read32(target, addr);
285285
if (flash_val != 0xffffffffU) {
@@ -290,16 +290,16 @@ static bool ch32f1_wait_flash_ready(target_s *target, uint32_t addr)
290290
}
291291

292292
/* Fast flash for ch32. Load 128 bytes chunk and then write them */
293-
static int ch32f1_upload(target_s *target, uint32_t dest, const void *src, uint32_t offset)
293+
static int ch32f1_upload(target_s *const target, const uint32_t dest, const void *const src, const uint32_t offset)
294294
{
295295
const uint32_t *ss = (const uint32_t *)(src + offset);
296296
uint32_t dd = dest + offset;
297297

298298
ch32f1_flash_set_cr(target, FLASH_CR_FTPG_CH32);
299299
target_mem_write32(target, dd + 0, ss[0]);
300-
target_mem_write32(target, dd + 4U, ss[1]);
301-
target_mem_write32(target, dd + 8U, ss[2]);
302-
target_mem_write32(target, dd + 12U, ss[3]);
300+
target_mem_write32(target, dd + 4U, ss[1U]);
301+
target_mem_write32(target, dd + 8U, ss[2U]);
302+
target_mem_write32(target, dd + 12U, ss[3U]);
303303
ch32f1_flash_set_cr(target, FLASH_CR_BUF_LOAD_CH32); /* BUF LOAD */
304304
if (!ch32f1_flash_eop_wait(target))
305305
return -1;
@@ -310,7 +310,7 @@ static int ch32f1_upload(target_s *target, uint32_t dest, const void *src, uint3
310310
}
311311

312312
/* Clear the write buffer */
313-
static int ch32f1_buffer_clear(target_s *target)
313+
static int ch32f1_buffer_clear(target_s *const target)
314314
{
315315
ch32f1_flash_set_cr(target, FLASH_CR_FTPG_CH32); // Fast page program 4-
316316
ch32f1_flash_set_cr(target, FLASH_CR_BUF_RESET_CH32); // BUF_RESET 5-
@@ -323,7 +323,7 @@ static int ch32f1_buffer_clear(target_s *target)
323323
/*
324324
* CH32 implementation of Flash write using the CH32-specific fast write
325325
*/
326-
static bool ch32f1_flash_write(target_flash_s *flash, target_addr_t dest, const void *src, size_t len)
326+
static bool ch32f1_flash_write(target_flash_s *const flash, target_addr_t dest, const void *src, const size_t len)
327327
{
328328
target_s *target = flash->t;
329329
size_t length = len;

0 commit comments

Comments
 (0)