diff --git a/README.md b/README.md
index 44eb169fe0..00967d719c 100644
--- a/README.md
+++ b/README.md
@@ -158,6 +158,7 @@ User can add a STM32 based board following this [wiki](https://github.com/stm32d
| :yellow_heart: | STM32F030F4 | Generic Board | **2.0.0** | |
| :yellow_heart: | STM32F030R8 | Generic Board | **2.0.0** | |
| :yellow_heart: | STM32F031K6T | Generic Board | **2.0.0** | |
+| :yellow_heart: | STM32F042C4
STM32F042C6 | Generic Board | **2.0.0** | |
| :yellow_heart: | STM32F051K6U
STM32F051K8U | Generic Board | **2.0.0** | |
| :yellow_heart: | STM32F070CB | Generic Board | **2.0.0** | |
| :yellow_heart: | STM32F072C8
STM32F072CB | Generic Board | **2.0.0** | |
diff --git a/boards.txt b/boards.txt
index 3df8048324..46ebae00cd 100644
--- a/boards.txt
+++ b/boards.txt
@@ -846,7 +846,7 @@ GenF0.build.board=GenF0
GenF0.build.mcu=cortex-m0
GenF0.build.series=STM32F0xx
GenF0.build.cmsis_lib_gcc=arm_cortexM0l_math
-GenF0.build.extra_flags=-D{build.product_line} {build.xSerial}
+GenF0.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial}
# DEMO_F030F4 board
GenF0.menu.pnum.DEMO_F030F4=STM32F030F4 Demo board (HSE 8Mhz)
@@ -907,6 +907,38 @@ GenF0.menu.pnum.GENERIC_F031K6TX.build.board=GENERIC_F031K6TX
GenF0.menu.pnum.GENERIC_F031K6TX.build.product_line=STM32F031x6
GenF0.menu.pnum.GENERIC_F031K6TX.build.variant=STM32F0xx/F031K6Tx
+# Generic F042C4Tx
+GenF0.menu.pnum.GENERIC_F042C4TX=Generic F042C4Tx
+GenF0.menu.pnum.GENERIC_F042C4TX.upload.maximum_size=16384
+GenF0.menu.pnum.GENERIC_F042C4TX.upload.maximum_data_size=6144
+GenF0.menu.pnum.GENERIC_F042C4TX.build.board=GENERIC_F042C4TX
+GenF0.menu.pnum.GENERIC_F042C4TX.build.product_line=STM32F042x6
+GenF0.menu.pnum.GENERIC_F042C4TX.build.variant=STM32F0xx/F042C(4-6)
+
+# Generic F042C6Tx
+GenF0.menu.pnum.GENERIC_F042C6TX=Generic F042C6Tx
+GenF0.menu.pnum.GENERIC_F042C6TX.upload.maximum_size=32768
+GenF0.menu.pnum.GENERIC_F042C6TX.upload.maximum_data_size=6144
+GenF0.menu.pnum.GENERIC_F042C6TX.build.board=GENERIC_F042C6TX
+GenF0.menu.pnum.GENERIC_F042C6TX.build.product_line=STM32F042x6
+GenF0.menu.pnum.GENERIC_F042C6TX.build.variant=STM32F0xx/F042C(4-6)
+
+# Generic F042C4Ux
+GenF0.menu.pnum.GENERIC_F042C4UX=Generic F042C4Ux
+GenF0.menu.pnum.GENERIC_F042C4UX.upload.maximum_size=16384
+GenF0.menu.pnum.GENERIC_F042C4UX.upload.maximum_data_size=6144
+GenF0.menu.pnum.GENERIC_F042C4UX.build.board=GENERIC_F042C4UX
+GenF0.menu.pnum.GENERIC_F042C4UX.build.product_line=STM32F042x6
+GenF0.menu.pnum.GENERIC_F042C4UX.build.variant=STM32F0xx/F042C(4-6)
+
+# Generic F042C6Ux
+GenF0.menu.pnum.GENERIC_F042C6UX=Generic F042C6Ux
+GenF0.menu.pnum.GENERIC_F042C6UX.upload.maximum_size=32768
+GenF0.menu.pnum.GENERIC_F042C6UX.upload.maximum_data_size=6144
+GenF0.menu.pnum.GENERIC_F042C6UX.build.board=GENERIC_F042C6UX
+GenF0.menu.pnum.GENERIC_F042C6UX.build.product_line=STM32F042x6
+GenF0.menu.pnum.GENERIC_F042C6UX.build.variant=STM32F0xx/F042C(4-6)
+
# Generic F051K6Ux
GenF0.menu.pnum.GENERIC_F051K6UX=Generic F051K6Ux
GenF0.menu.pnum.GENERIC_F051K6UX.upload.maximum_size=32768
@@ -3555,6 +3587,14 @@ Eval.menu.xusb.HS.build.usb_speed=-DUSE_USB_HS
Eval.menu.xusb.HSFS=High Speed in Full Speed mode
Eval.menu.xusb.HSFS.build.usb_speed=-DUSE_USB_HS -DUSE_USB_HS_IN_FS
+GenF0.menu.usb.none=None
+GenF0.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
+GenF0.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
+GenF0.menu.usb.CDC=CDC (no generic 'Serial')
+GenF0.menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
+GenF0.menu.usb.HID=HID (keyboard and mouse)
+GenF0.menu.usb.HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
+
GenF1.menu.usb.none=None
GenF1.menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
GenF1.menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
diff --git a/variants/STM32F0xx/F042C(4-6)/generic_clock.c b/variants/STM32F0xx/F042C(4-6)/generic_clock.c
index 19093de0d8..0534eb3601 100644
--- a/variants/STM32F0xx/F042C(4-6)/generic_clock.c
+++ b/variants/STM32F0xx/F042C(4-6)/generic_clock.c
@@ -21,8 +21,36 @@
*/
WEAK void SystemClock_Config(void)
{
- /* SystemClock_Config can be generated by STM32CubeMX */
-#warning "SystemClock_Config() is empty. Default clock at reset is used."
+ RCC_OscInitTypeDef RCC_OscInitStruct = {};
+ RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
+ RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
+
+ /** Initializes the RCC Oscillators according to the specified parameters
+ * in the RCC_OscInitTypeDef structure.
+ */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
+ RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+ Error_Handler();
+ }
+ /** Initializes the CPU, AHB and APB buses clocks
+ */
+ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
+ | RCC_CLOCKTYPE_PCLK1;
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
+
+ if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
+ Error_Handler();
+ }
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
+ PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
+
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ Error_Handler();
+ }
}
#endif /* ARDUINO_GENERIC_* */
diff --git a/variants/STM32F0xx/F042C(4-6)/ldscript.ld b/variants/STM32F0xx/F042C(4-6)/ldscript.ld
new file mode 100644
index 0000000000..014a79669b
--- /dev/null
+++ b/variants/STM32F0xx/F042C(4-6)/ldscript.ld
@@ -0,0 +1,177 @@
+/**
+ ******************************************************************************
+ * @file LinkerScript.ld
+ * @author Auto-generated by STM32CubeIDE
+ * @brief Linker script for STM32F042C6Tx Device from STM32F0 series
+ * 32Kbytes FLASH
+ * 6Kbytes RAM
+ *
+ * Set heap size, stack size and stack location according
+ * to application requirements.
+ *
+ * Set memory bank area and size if external memory is used
+ ******************************************************************************
+ * @attention
+ *
+ *