From 55ab9ee02ef7868eda9d8175b9bb0597976e1a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0pa=C4=8Dek?= Date: Thu, 15 May 2025 20:25:09 +0200 Subject: [PATCH 1/4] Add C071G(8-B)Ux board variant --- boards.txt | 23 +++ .../STM32C0xx/C071G(8-B)U/generic_clock.c | 39 +++- variants/STM32C0xx/C071G(8-B)U/ldscript.ld | 187 ++++++++++++++++++ 3 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 variants/STM32C0xx/C071G(8-B)U/ldscript.ld diff --git a/boards.txt b/boards.txt index 737597a70c..4949894b0d 100644 --- a/boards.txt +++ b/boards.txt @@ -1782,6 +1782,24 @@ GenC0.menu.pnum.GENERIC_C031F6PX.build.product_line=STM32C031xx GenC0.menu.pnum.GENERIC_C031F6PX.build.variant=STM32C0xx/C031F(4-6)P GenC0.menu.pnum.GENERIC_C031F6PX.debug.svd_file={runtime.tools.STM32_SVD.path}/svd/STM32C0xx/STM32C031.svd +# Generic C071G8Ux +GenC0.menu.pnum.GENERIC_C071G8UX=Generic C071G8Ux +GenC0.menu.pnum.GENERIC_C071G8UX.upload.maximum_size=65536 +GenC0.menu.pnum.GENERIC_C071G8UX.upload.maximum_data_size=24576 +GenC0.menu.pnum.GENERIC_C071G8UX.build.board=GENERIC_C071G8UX +GenC0.menu.pnum.GENERIC_C071G8UX.build.product_line=STM32C071xx +GenC0.menu.pnum.GENERIC_C071G8UX.build.variant=STM32C0xx/C071G(8-B)U +GenC0.menu.pnum.GENERIC_C071G8UX.debug.svd_file={runtime.tools.STM32_SVD.path}/svd/STM32C0xx/STM32C071.svd + +# Generic C071GBUx +GenC0.menu.pnum.GENERIC_C071GBUX=Generic C071GBUx +GenC0.menu.pnum.GENERIC_C071GBUX.upload.maximum_size=131072 +GenC0.menu.pnum.GENERIC_C071GBUX.upload.maximum_data_size=24576 +GenC0.menu.pnum.GENERIC_C071GBUX.build.board=GENERIC_C071GBUX +GenC0.menu.pnum.GENERIC_C071GBUX.build.product_line=STM32C071xx +GenC0.menu.pnum.GENERIC_C071GBUX.build.variant=STM32C0xx/C071G(8-B)U +GenC0.menu.pnum.GENERIC_C071GBUX.debug.svd_file={runtime.tools.STM32_SVD.path}/svd/STM32C0xx/STM32C071.svd + # Generic C071R8Tx GenC0.menu.pnum.GENERIC_C071R8TX=Generic C071R8Tx GenC0.menu.pnum.GENERIC_C071R8TX.upload.maximum_size=65536 @@ -1816,6 +1834,11 @@ GenC0.menu.upload_method.serialMethod.upload.protocol=serial GenC0.menu.upload_method.serialMethod.upload.options=-c {serial.port.file} GenC0.menu.upload_method.serialMethod.upload.tool=stm32CubeProg +GenC0.menu.upload_method.dfuMethod=STM32CubeProgrammer (DFU) +GenC0.menu.upload_method.dfuMethod.upload.protocol=dfu +GenC0.menu.upload_method.dfuMethod.upload.options=-v {upload.vid} -p {upload.pid} +GenC0.menu.upload_method.dfuMethod.upload.tool=stm32CubeProg + GenC0.menu.upload_method.bmpMethod=BMP (Black Magic Probe) GenC0.menu.upload_method.bmpMethod.upload.protocol=gdb_bmp GenC0.menu.upload_method.bmpMethod.upload.tool=bmp_upload diff --git a/variants/STM32C0xx/C071G(8-B)U/generic_clock.c b/variants/STM32C0xx/C071G(8-B)U/generic_clock.c index 2949052fd4..cf5c096a49 100644 --- a/variants/STM32C0xx/C071G(8-B)U/generic_clock.c +++ b/variants/STM32C0xx/C071G(8-B)U/generic_clock.c @@ -12,6 +12,7 @@ */ #if defined(ARDUINO_GENERIC_C071G8UX) || defined(ARDUINO_GENERIC_C071GBUX) #include "pins_arduino.h" +#include "stm32yyxx_ll_utils.h" /** * @brief System Clock Configuration @@ -20,8 +21,42 @@ */ WEAK void SystemClock_Config(void) { - /* SystemClock_Config can be generated by STM32CubeMX */ -#warning "SystemClock_Config() is empty. Default clock at reset is used." + LL_FLASH_SetLatency(LL_FLASH_LATENCY_1); + + /* HSI configuration and activation */ + LL_RCC_HSI_Enable(); + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_SetHSIDiv(LL_RCC_HSI_DIV_1); + LL_RCC_HSI48_Enable(); + + /* Wait till HSI48 is ready */ + while(LL_RCC_HSI48_IsReady() != 1) + { + } + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_HCLK_DIV_1); + + /* Sysclk activation on the HSI */ + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) + { + } + + /* Set APB1 prescaler*/ + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ + LL_SetSystemCoreClock(48000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } #endif /* ARDUINO_GENERIC_* */ diff --git a/variants/STM32C0xx/C071G(8-B)U/ldscript.ld b/variants/STM32C0xx/C071G(8-B)U/ldscript.ld new file mode 100644 index 0000000000..9b17805ade --- /dev/null +++ b/variants/STM32C0xx/C071G(8-B)U/ldscript.ld @@ -0,0 +1,187 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32C071G8Ux Device from STM32C0 series +** 64KBytes FLASH +** 24KBytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +** Copyright (c) 2025 STMicroelectronics. +** All rights reserved. +** +** This software is licensed under terms that can be found in the LICENSE file +** in the root directory of this software component. +** If no LICENSE file comes with this software, it is provided AS-IS. +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE + FLASH (rx) : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET +} + +/* Sections */ +SECTIONS +{ + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} From 9b93d73c59b3706d14a984a06806931316b6bcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0pa=C4=8Dek?= Date: Thu, 15 May 2025 20:44:11 +0200 Subject: [PATCH 2/4] Fix {build.enable_usb} missing in GenC0.build.st_extra_flags --- boards.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards.txt b/boards.txt index 4949894b0d..5f2842c6ff 100644 --- a/boards.txt +++ b/boards.txt @@ -1659,7 +1659,7 @@ GenC0.build.core=arduino GenC0.build.board=GenC0 GenC0.build.mcu=cortex-m0plus GenC0.build.series=STM32C0xx -GenC0.build.st_extra_flags=-D{build.product_line} {build.xSerial} -D__CORTEX_SC=0 +GenC0.build.st_extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} -D__CORTEX_SC=0 GenC0.build.flash_offset=0x0 GenC0.upload.maximum_size=0 GenC0.upload.maximum_data_size=0 From ccb34d432a64961cee77b8906d32b2329db264aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0pa=C4=8Dek?= Date: Thu, 15 May 2025 20:59:58 +0200 Subject: [PATCH 3/4] Add the C071G(8-B)U variant to the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 70b2e3275a..3264f0f33c 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,7 @@ User can add a STM32 based board following this [wiki](https://github.com/stm32d | :green_heart: | STM32C011J4
STM32C011J6 | Generic Board | *2.8.0* | | | :green_heart: | STM32C031C4
STM32C031C6 | Generic Board | *2.5.0* | | | :green_heart: | STM32C031F4
STM32C031F6 | Generic Board | *2.6.0* | | +| :yellow_heart: | STM32C071G8
STM32C071GB | Generic Board | **2.11.0** | | | :green_heart: | STM32C071R8
STM32C071RB | Generic Board | *2.9.0* | | ### Generic STM32F0 boards From 3060143dcb27108045bd674f5d23e53c35a7afc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0pa=C4=8Dek?= Date: Fri, 16 May 2025 06:04:53 +0200 Subject: [PATCH 4/4] Fix astyle errors for C071G(8-B)U variant --- variants/STM32C0xx/C071G(8-B)U/generic_clock.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/variants/STM32C0xx/C071G(8-B)U/generic_clock.c b/variants/STM32C0xx/C071G(8-B)U/generic_clock.c index cf5c096a49..c20147de69 100644 --- a/variants/STM32C0xx/C071G(8-B)U/generic_clock.c +++ b/variants/STM32C0xx/C071G(8-B)U/generic_clock.c @@ -25,17 +25,15 @@ WEAK void SystemClock_Config(void) /* HSI configuration and activation */ LL_RCC_HSI_Enable(); - while(LL_RCC_HSI_IsReady() != 1) - { + while (LL_RCC_HSI_IsReady() != 1) { } LL_RCC_HSI_SetCalibTrimming(64); LL_RCC_SetHSIDiv(LL_RCC_HSI_DIV_1); LL_RCC_HSI48_Enable(); - /* Wait till HSI48 is ready */ - while(LL_RCC_HSI48_IsReady() != 1) - { + /* Wait till HSI48 is ready */ + while (LL_RCC_HSI48_IsReady() != 1) { } /* Set AHB prescaler*/ @@ -43,8 +41,7 @@ WEAK void SystemClock_Config(void) /* Sysclk activation on the HSI */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) - { + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) { } /* Set APB1 prescaler*/ @@ -52,9 +49,8 @@ WEAK void SystemClock_Config(void) /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(48000000); - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { Error_Handler(); } }