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

Commit 98f8ea2

Browse files
stm32c0: Add ID codes for C0[5,7,9]x lines
Note that this doesn't distinguish yet between the C091 and C092 lines, despite them having different amounts of SRAM.
1 parent a0db591 commit 98f8ea2

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

src/target/stm32g0.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
#define FLASH_SIZE_MAX_G0B_C (512U * 1024U) // 512kiB
6363
#define FLASH_SIZE_MAX_C01 (32U * 1024U) // 32kiB
6464
#define FLASH_SIZE_MAX_C03 (32U * 1024U) // 32kiB
65+
#define FLASH_SIZE_MAX_C05 (64U * 1024U) // 64kiB
66+
#define FLASH_SIZE_MAX_C07 (128U * 1024U) // 128kiB
67+
#define FLASH_SIZE_MAX_C09 (256U * 1024U) // 256kiB
6568

6669
#define STM32G0_FLASH_PAGE_SIZE 0x800U
6770
#define STM32G0_FLASH_BANK2_START_PAGE 256U
@@ -128,16 +131,20 @@
128131
#define STM32G0_FPEC_OPTION_KEY2 0x4c5d6e7fU
129132
#define STM32G0_FPEC_OPTION_RDP_MASK 0xffU
130133
#define STM32G0x1_FPEC_OPTION_DEFAULT 0xfffffeaaU
131-
#define STM32C0x1_FPEC_OPTION_DEFAULT 0xffffffaaU
134+
#define STM32C0x1_FPEC_OPTION_DEFAULT 0x3fffffaaU
132135

133136
#define STM32G0_SRAM_BASE 0x20000000U
134137
#define STM32G03_4_SRAM_SIZE (8U * 1024U) // 8kiB
135138
#define STM32G05_6_SRAM_SIZE (18U * 1024U) // 18kiB
136139
#define STM32G07_8_SRAM_SIZE (36U * 1024U) // 36kiB
137140
#define STM32G0B_C_SRAM_SIZE (144U * 1024U) // 144kiB
138141

139-
#define STM32C01_SRAM_SIZE (6U * 1024U) // 6kiB
140-
#define STM32C03_SRAM_SIZE (12U * 1024U) // 12kiB
142+
#define STM32C01_SRAM_SIZE (6U * 1024U) // 6kiB
143+
#define STM32C03_SRAM_SIZE (12U * 1024U) // 12kiB
144+
#define STM32C05_SRAM_SIZE (12U * 1024U) // 12kiB
145+
#define STM32C07_SRAM_SIZE (24U * 1024U) // 24kiB
146+
#define STM32C091_SRAM_SIZE (36U * 1024U) // 36kiB
147+
#define STM32C092_SRAM_SIZE (30U * 1024U) // 30kiB
141148

142149
#define STM32U031_SRAM_SIZE (12U * 1024U) // 12kiB
143150
#define STM32U0x3_SRAM_SIZE (40U * 1024U) // 40kiB
@@ -166,8 +173,12 @@
166173
* The underscores in these definitions represent /'s, this means
167174
* that STM32G03_4 is supposed to refer to the G03/4 aka the G03 and G04.
168175
*/
176+
/* RM0490 §30.10.1 p1009 */
169177
#define ID_STM32C011 0x443U
170178
#define ID_STM32C031 0x453U
179+
#define ID_STM32C051 0x44CU
180+
#define ID_STM32C071 0x493U
181+
#define ID_STM32C09x 0x44DU /* STM32C091/092 */
171182
#define ID_STM32G03_4 0x466U
172183
#define ID_STM32G05_6 0x456U
173184
#define ID_STM32G07_8 0x460U
@@ -207,7 +218,7 @@ typedef struct stm32g0_option_register {
207218
* 1101 1111 1111 1111 1110 0001 1010 1010
208219
* *IRHEN * ****BOREN
209220
* C0x1: OPTR = FFFFFFAA
210-
* 1111 1111 1111 1111 1111 1111 1010 1010
221+
* 0011 1111 1111 1111 1111 1111 1010 1010
211222
* *BOREN
212223
* IRH and BOR are reserved on G0x0, it is safe to apply G0x1 options on G0x0.
213224
* The same for PCROP and SECR.
@@ -328,6 +339,25 @@ bool stm32g0_probe(target_s *const target)
328339
}
329340
target->part_id = dev_id;
330341
break;
342+
case ID_STM32C051:
343+
/* SRAM 12kiB, Flash up to 64kiB */
344+
ram_size = STM32C05_SRAM_SIZE;
345+
flash_size = FLASH_SIZE_MAX_C05;
346+
target->driver = "STM32C051";
347+
break;
348+
case ID_STM32C071:
349+
/* SRAM 24kiB, Flash up to 128kiB */
350+
ram_size = STM32C07_SRAM_SIZE;
351+
flash_size = FLASH_SIZE_MAX_C07;
352+
target->driver = "STM32C071";
353+
break;
354+
case ID_STM32C09x:
355+
/* TODO: determine how to tell C091 and C092 apart here */
356+
/* SRAM 30/36kiB, Flash up to 256kiB */
357+
ram_size = STM32C091_SRAM_SIZE;
358+
flash_size = FLASH_SIZE_MAX_C09;
359+
target->driver = "STM32C09x";
360+
break;
331361
case ID_STM32G05_6:
332362
/* SRAM 18kiB, Flash up to 64kiB */
333363
ram_size = STM32G05_6_SRAM_SIZE;
@@ -701,7 +731,8 @@ static bool stm32g0_cmd_option(target_s *const target, const int argc, const cha
701731
stm32g0_option_register_s options_req[OPT_REG_COUNT] = {{0}};
702732

703733
if (argc == 2 && strcasecmp(argv[1], "erase") == 0) {
704-
if (target->part_id == ID_STM32C011 || target->part_id == ID_STM32C031)
734+
if (target->part_id == ID_STM32C011 || target->part_id == ID_STM32C031 || target->part_id == ID_STM32C051 ||
735+
target->part_id == ID_STM32C071 || target->part_id == ID_STM32C09x)
705736
stm32g0_options_def[OPT_REG_OPTR].val = STM32C0x1_FPEC_OPTION_DEFAULT;
706737
if (!stm32g0_option_write(target, stm32g0_options_def))
707738
goto exit_error;
@@ -737,6 +768,9 @@ static bool stm32g0_cmd_uid(target_s *const target, const int argc, const char *
737768
switch (target->part_id) {
738769
case ID_STM32C011:
739770
case ID_STM32C031:
771+
case ID_STM32C051:
772+
case ID_STM32C071:
773+
case ID_STM32C09x:
740774
uid_base = STM32C0_UID_BASE;
741775
break;
742776
case ID_STM32U031:

0 commit comments

Comments
 (0)