diff --git a/README.md b/README.md
index de336d3cd3..af21a6992f 100644
--- a/README.md
+++ b/README.md
@@ -126,6 +126,7 @@ User can add a STM32 based board following this [wiki](https://github.com/stm32d
| Status | Device(s) | Name | Release | Notes |
| :----: | :-------: | ---- | :-----: | :---- |
| :green_heart: | STM32F031K6T | [Nucleo F031K6](https://www.st.com/en/evaluation-tools/nucleo-f031k6.html) | *1.9.0* | |
+| :yellow_heart: | STM32F042K6T | [Nucleo F042K6](https://www.st.com/en/evaluation-tools/nucleo-f042k6.html) | **2.1.0** | |
| :green_heart: | STM32F303K8 | [Nucleo F303K8](http://www.st.com/en/evaluation-tools/nucleo-f303k8.html) | *1.1.0* | |
| :green_heart: | STM32G031K8 | [Nucleo G031K8](https://www.st.com/en/evaluation-tools/nucleo-g031k8.html) | *2.0.0* |
| :green_heart: | STM32G431KB | [Nucleo G431KB](https://www.st.com/en/evaluation-tools/nucleo-g431kb.html) | *1.7.0* | |
@@ -174,6 +175,7 @@ User can add a STM32 based board following this [wiki](https://github.com/stm32d
| :green_heart: | STM32F030R8 | Generic Board | *2.0.0* | |
| :green_heart: | STM32F031K6T | Generic Board | *2.0.0* | |
| :green_heart: | STM32F042C4
STM32F042C6 | Generic Board | *2.0.0* | |
+| :yellow_heart: | STM32F042K4T
STM32F042K6T | Generic Board | **2.0.1** | |
| :green_heart: | STM32F051K6U
STM32F051K8U | Generic Board | *2.0.0* | |
| :green_heart: | STM32F070CB | Generic Board | *2.0.0* | |
| :green_heart: | STM32F070RB | Generic Board | *2.0.0* | |
diff --git a/boards.txt b/boards.txt
index 6f2199ca1c..0e84d1ada5 100644
--- a/boards.txt
+++ b/boards.txt
@@ -558,6 +558,18 @@ Nucleo_32.menu.pnum.NUCLEO_F031K6.build.product_line=STM32F031x6
Nucleo_32.menu.pnum.NUCLEO_F031K6.build.variant=STM32F0xx/F031K6T
Nucleo_32.menu.pnum.NUCLEO_F031K6.build.cmsis_lib_gcc=arm_cortexM0l_math
+# NUCLEO_F042K6 board
+Nucleo_32.menu.pnum.NUCLEO_F042K6=Nucleo F042K6
+Nucleo_32.menu.pnum.NUCLEO_F042K6.node=NODE_F042K6
+Nucleo_32.menu.pnum.NUCLEO_F042K6.upload.maximum_size=32768
+Nucleo_32.menu.pnum.NUCLEO_F042K6.upload.maximum_data_size=6144
+Nucleo_32.menu.pnum.NUCLEO_F042K6.build.mcu=cortex-m0
+Nucleo_32.menu.pnum.NUCLEO_F042K6.build.board=NUCLEO_F042K6
+Nucleo_32.menu.pnum.NUCLEO_F042K6.build.series=STM32F0xx
+Nucleo_32.menu.pnum.NUCLEO_F042K6.build.product_line=STM32F042x6
+Nucleo_32.menu.pnum.NUCLEO_F042K6.build.variant=STM32F0xx/F042K(4-6)T
+Nucleo_32.menu.pnum.NUCLEO_F042K6.build.cmsis_lib_gcc=arm_cortexM0l_math
+
# NUCLEO_F303K8 board
Nucleo_32.menu.pnum.NUCLEO_F303K8=Nucleo F303K8
Nucleo_32.menu.pnum.NUCLEO_F303K8.node=NODE_F303K8
@@ -1032,6 +1044,22 @@ 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)(T-U)
+# Generic F042K4Tx
+GenF0.menu.pnum.GENERIC_F042K4TX=Generic F042K4Tx
+GenF0.menu.pnum.GENERIC_F042K4TX.upload.maximum_size=16384
+GenF0.menu.pnum.GENERIC_F042K4TX.upload.maximum_data_size=6144
+GenF0.menu.pnum.GENERIC_F042K4TX.build.board=GENERIC_F042K4TX
+GenF0.menu.pnum.GENERIC_F042K4TX.build.product_line=STM32F042x6
+GenF0.menu.pnum.GENERIC_F042K4TX.build.variant=STM32F0xx/F042K(4-6)T
+
+# Generic F042K6Tx
+GenF0.menu.pnum.GENERIC_F042K6TX=Generic F042K6Tx
+GenF0.menu.pnum.GENERIC_F042K6TX.upload.maximum_size=32768
+GenF0.menu.pnum.GENERIC_F042K6TX.upload.maximum_data_size=6144
+GenF0.menu.pnum.GENERIC_F042K6TX.build.board=GENERIC_F042K6TX
+GenF0.menu.pnum.GENERIC_F042K6TX.build.product_line=STM32F042x6
+GenF0.menu.pnum.GENERIC_F042K6TX.build.variant=STM32F0xx/F042K(4-6)T
+
# Generic F051K6Ux
GenF0.menu.pnum.GENERIC_F051K6UX=Generic F051K6Ux
GenF0.menu.pnum.GENERIC_F051K6UX.upload.maximum_size=32768
diff --git a/variants/STM32F0xx/F042K(4-6)T/generic_clock.c b/variants/STM32F0xx/F042K(4-6)T/generic_clock.c
index c6574d7516..236887de1e 100644
--- a/variants/STM32F0xx/F042K(4-6)T/generic_clock.c
+++ b/variants/STM32F0xx/F042K(4-6)T/generic_clock.c
@@ -20,8 +20,41 @@
*/
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_HSI14 | RCC_OSCILLATORTYPE_HSI48;
+ RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
+ RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
+ RCC_OscInitStruct.HSI14CalibrationValue = 16;
+ 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 | RCC_PERIPHCLK_USART1
+ | RCC_PERIPHCLK_I2C1;
+ PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
+ PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
+ PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
+
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ Error_Handler();
+ }
}
#endif /* ARDUINO_GENERIC_* */
diff --git a/variants/STM32F0xx/F042K(4-6)T/ldscript.ld b/variants/STM32F0xx/F042K(4-6)T/ldscript.ld
new file mode 100644
index 0000000000..7523b470c6
--- /dev/null
+++ b/variants/STM32F0xx/F042K(4-6)T/ldscript.ld
@@ -0,0 +1,186 @@
+/*
+******************************************************************************
+**
+** @file : LinkerScript.ld
+**
+** @author : Auto-generated by STM32CubeIDE
+**
+** Abstract : Linker script for NUCLEO-F042K6 Board embedding STM32F042K6Tx 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
+**
+** Target : STMicroelectronics STM32
+**
+** Distribution: The file is distributed as is, without any warranty
+** of any kind.
+**
+******************************************************************************
+** @attention
+**
+**
© Copyright (c) 2021 STMicroelectronics.
+** All rights reserved.
+**
+** This software component is licensed by ST under BSD 3-Clause license,
+** the "License"; You may not use this file except in compliance with the
+** License. You may obtain a copy of the License at:
+** opensource.org/licenses/BSD-3-Clause
+**
+******************************************************************************
+*/
+
+/* 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 : {
+ . = ALIGN(4);
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+ . = ALIGN(4);
+ } >FLASH
+
+ .ARM : {
+ . = ALIGN(4);
+ __exidx_start = .;
+ *(.ARM.exidx*)
+ __exidx_end = .;
+ . = ALIGN(4);
+ } >FLASH
+
+ .preinit_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ . = ALIGN(4);
+ } >FLASH
+
+ .init_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ . = ALIGN(4);
+ } >FLASH
+
+ .fini_array :
+ {
+ . = 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) }
+}
diff --git a/variants/STM32F0xx/F042K(4-6)T/variant_NUCLEO_F042K6.cpp b/variants/STM32F0xx/F042K(4-6)T/variant_NUCLEO_F042K6.cpp
new file mode 100644
index 0000000000..a869d7d2a5
--- /dev/null
+++ b/variants/STM32F0xx/F042K(4-6)T/variant_NUCLEO_F042K6.cpp
@@ -0,0 +1,114 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2021, STMicroelectronics
+ * All rights reserved.
+ *
+ * This software component is licensed by ST under BSD 3-Clause license,
+ * the "License"; You may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ * opensource.org/licenses/BSD-3-Clause
+ *
+ *******************************************************************************
+ */
+#if defined(ARDUINO_NUCLEO_F042K6)
+#include "pins_arduino.h"
+
+// Digital PinName array
+const PinName digitalPin[] = {
+ PA_10, // D0
+ PA_9, // D1
+ PA_12, // D2
+ PB_0, // D3/A8
+ PB_7, // D4
+ PB_6, // D5
+ PB_1, // D6/A9
+ PF_0, // D7
+ PF_1, // D8
+ PA_8, // D9
+ PA_11, // D10
+ PB_5, // D11
+ PB_4, // D12
+ PB_3, // D13
+ PA_0, // D14/A0
+ PA_1, // D15/A1
+ PA_3, // D16/A2
+ PA_4, // D17/A3
+ PA_5, // D18/A4
+ PA_6, // D19/A5
+ PA_7, // D20/A6
+ PA_2, // D21/A7
+ PA_15, // D22
+ PA_13, // D23
+ PA_14, // D24
+ PB_8 // D25
+};
+
+// Analog (Ax) pin number array
+const uint32_t analogInputPin[] = {
+ 14, // A0, PA0
+ 15, // A1, PA1
+ 16, // A2, PA3
+ 17, // A3, PA4
+ 18, // A4, PA5
+ 19, // A5, PA6
+ 20, // A6, PA7
+ 21, // A7, PA2
+ 3, // A8, PB0
+ 6 // A9, PB1
+};
+
+// ----------------------------------------------------------------------------
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief System Clock Configuration
+ * @param None
+ * @retval None
+ */
+WEAK void SystemClock_Config(void)
+{
+ 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_HSI14 | RCC_OSCILLATORTYPE_HSI48;
+ RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
+ RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
+ RCC_OscInitStruct.HSI14CalibrationValue = 16;
+ 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 | RCC_PERIPHCLK_USART1
+ | RCC_PERIPHCLK_I2C1;
+ PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
+ PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
+ PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
+
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ Error_Handler();
+ }
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ARDUINO_NUCLEO_F042K6 */
diff --git a/variants/STM32F0xx/F042K(4-6)T/variant_NUCLEO_F042K6.h b/variants/STM32F0xx/F042K(4-6)T/variant_NUCLEO_F042K6.h
new file mode 100644
index 0000000000..f6c03ee74c
--- /dev/null
+++ b/variants/STM32F0xx/F042K(4-6)T/variant_NUCLEO_F042K6.h
@@ -0,0 +1,126 @@
+/*
+ *******************************************************************************
+ * Copyright (c) 2021, STMicroelectronics
+ * All rights reserved.
+ *
+ * This software component is licensed by ST under BSD 3-Clause license,
+ * the "License"; You may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ * opensource.org/licenses/BSD-3-Clause
+ *
+ *******************************************************************************
+ */
+#pragma once
+
+/*----------------------------------------------------------------------------
+ * STM32 pins number
+ *----------------------------------------------------------------------------*/
+// CN3
+#define PA10 0
+#define PA9 1
+#define PA12 2
+#define PB0 PIN_A8
+#define PB7 4 // Default, SB17 ON connected to A4
+#define PB6 5 // Default, SB16 ON connected to A5
+#define PB1 PIN_A9
+#define PF0 7
+#define PF1 8
+#define PA8 9
+#define PA11 10
+#define PB5 11
+#define PB4 12
+// CN4
+#define PB3 13 // LED
+#define PA0 PIN_A0
+#define PA1 PIN_A1
+#define PA3 PIN_A2
+#define PA4 PIN_A3
+#define PA5 PIN_A4
+#define PA6 PIN_A5
+#define PA7 PIN_A6
+#define PA2 PIN_A7 // VCP_TX
+#define PA15 22 // VCP_RX
+#define PA13 23 // SWDIO
+#define PA14 24 // SWCLK
+#define PB8 25 // Default SB12 ON (BOOT0 GND)
+
+// Alternate pins number
+#define PA6_ALT1 (PA6 | ALT1)
+#define PA7_ALT1 (PA7 | ALT1)
+#define PA7_ALT2 (PA7 | ALT2)
+#define PA7_ALT3 (PA7 | ALT3)
+#define PB0_ALT1 (PB0 | ALT1)
+#define PB1_ALT1 (PB1 | ALT1)
+#define PB1_ALT2 (PB1 | ALT2)
+
+#define NUM_DIGITAL_PINS 26
+#define NUM_ANALOG_INPUTS 10
+
+// On-board LED pin number
+#ifndef LED_BUILTIN
+ #define LED_BUILTIN PB3
+#endif
+
+// On-board user button
+#ifndef USER_BTN
+ #define USER_BTN PNUM_NOT_DEFINED
+#endif
+
+// I2C definitions
+#ifndef PIN_WIRE_SDA
+ #define PIN_WIRE_SDA PB7
+#endif
+#ifndef PIN_WIRE_SCL
+ #define PIN_WIRE_SCL PB6
+#endif
+
+// Timer Definitions
+// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
+#ifndef TIMER_TONE
+ #define TIMER_TONE TIM14
+#endif
+#ifndef TIMER_SERVO
+ #define TIMER_SERVO TIM16
+#endif
+
+// UART Definitions
+#ifndef SERIAL_UART_INSTANCE
+ #define SERIAL_UART_INSTANCE 2
+#endif
+
+// Default pin used for generic 'Serial' instance
+// Mandatory for Firmata
+#ifndef PIN_SERIAL_RX
+ #define PIN_SERIAL_RX PA15
+#endif
+#ifndef PIN_SERIAL_TX
+ #define PIN_SERIAL_TX PA2
+#endif
+
+/*----------------------------------------------------------------------------
+ * Arduino objects - C++ only
+ *----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+ // These serial port names are intended to allow libraries and architecture-neutral
+ // sketches to automatically default to the correct port name for a particular type
+ // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
+ // the first hardware serial port whose RX/TX pins are not dedicated to another use.
+ //
+ // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
+ //
+ // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
+ //
+ // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
+ //
+ // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
+ //
+ // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
+ // pins are NOT connected to anything by default.
+ #ifndef SERIAL_PORT_MONITOR
+ #define SERIAL_PORT_MONITOR Serial
+ #endif
+ #ifndef SERIAL_PORT_HARDWARE
+ #define SERIAL_PORT_HARDWARE Serial
+ #endif
+#endif