summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vlasov <sigprof@gmail.com>2022-08-12 00:37:41 +0300
committerGitHub <noreply@github.com>2022-08-11 22:37:41 +0100
commit9e443621796a150b244d49a784b77c744ea04d94 (patch)
tree3c5c5e1fa1421d2ceaabd375c8b2cba9eab09bc3
parent8c4269f98e107a9c98127464e6870798b1734a61 (diff)
Add minimal STM32F103C6 support (#17853)
Unfortunately, the crippled versions of “Bluepill” boards with STM32F103C6xx chips instead of STM32F103C8xx are now sold all over the place, sometimes advertised in a confusing way to make the difference not noticeable until too late. Add minimal support for these MCUs in the common “Bluepill with stm32duino” configuration, so that it could be possible to make something useful from those boards (although fitting QMK into the available 24 KiB of flash may be rather hard). (In fact, I'm not sure whether the “STM32” part of the chip name is actually correct for those boards of uncertain origin, so the onekey board name is `bluepill_f103c6`; another reason for that name is to match the existing `blackpill_f401` and `blackpill_f411`.) The EEPROM emulation support is not included on purpose, because enabling it without having a working firmware size check would be irresponsible with such flash size (the chance that someone would build a firmware where the EEPROM backing store ends up overlapping some firmware code is really high). Other than that, enabling the EEPROM emulation code is mostly trivial (the `wear_leveling` driver with the `embedded_flash` backing store even works without any custom configuration, although its code is significantly larger than the `vendor` driver, which may also be important for such flash size).
-rw-r--r--keyboards/handwired/onekey/bluepill_f103c6/board.h6
-rw-r--r--keyboards/handwired/onekey/bluepill_f103c6/config.h40
-rw-r--r--keyboards/handwired/onekey/bluepill_f103c6/halconf.h26
-rw-r--r--keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h30
-rw-r--r--keyboards/handwired/onekey/bluepill_f103c6/readme.md7
-rw-r--r--keyboards/handwired/onekey/bluepill_f103c6/rules.mk27
-rw-r--r--platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c2
-rw-r--r--platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino_bootloader.ld23
-rw-r--r--platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld1
-rw-r--r--platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld1
-rw-r--r--platforms/chibios/boards/STM32_F103_STM32DUINO/ld/stm32duino_bootloader_common.ld2
11 files changed, 164 insertions, 1 deletions
diff --git a/keyboards/handwired/onekey/bluepill_f103c6/board.h b/keyboards/handwired/onekey/bluepill_f103c6/board.h
new file mode 100644
index 0000000000..4889f351a6
--- /dev/null
+++ b/keyboards/handwired/onekey/bluepill_f103c6/board.h
@@ -0,0 +1,6 @@
+// Copyright 2022 Sergey Vlasov (@sigprof)
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include_next <board.h>
+
+#undef STM32F103xB
+#define STM32F103x6
diff --git a/keyboards/handwired/onekey/bluepill_f103c6/config.h b/keyboards/handwired/onekey/bluepill_f103c6/config.h
new file mode 100644
index 0000000000..e53aa63292
--- /dev/null
+++ b/keyboards/handwired/onekey/bluepill_f103c6/config.h
@@ -0,0 +1,40 @@
+/* Copyright 2019
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "config_common.h"
+
+#define PRODUCT Onekey Bluepill STM32F103C6
+
+#define MATRIX_COL_PINS { B0 }
+#define MATRIX_ROW_PINS { A7 }
+#define UNUSED_PINS
+
+#define BACKLIGHT_PIN A0
+#define BACKLIGHT_PWM_DRIVER PWMD2
+#define BACKLIGHT_PWM_CHANNEL 1
+
+#define RGB_DI_PIN A1
+
+#define ADC_PIN A0
+
+// This code does not fit into the really small flash of STM32F103x6 together
+// with CONSOLE_ENABLE=yes, and the debugging console is probably more
+// important for the "okeney" testing firmware. In a real firmware you may be
+// able to use these features if you keep the debugging console disabled.
+#define NO_ACTION_LAYER
+#define NO_ACTION_TAPPING
diff --git a/keyboards/handwired/onekey/bluepill_f103c6/halconf.h b/keyboards/handwired/onekey/bluepill_f103c6/halconf.h
new file mode 100644
index 0000000000..923b4e52d2
--- /dev/null
+++ b/keyboards/handwired/onekey/bluepill_f103c6/halconf.h
@@ -0,0 +1,26 @@
+/* Copyright 2020 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This file was auto-generated by:
+ * `qmk chibios-confmigrate -i keyboards/handwired/onekey/bluepill/halconf.h -r platforms/chibios/common/configs/halconf.h`
+ */
+
+#pragma once
+
+#define HAL_USE_PWM TRUE
+
+#include_next <halconf.h>
diff --git a/keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h b/keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h
new file mode 100644
index 0000000000..5e94a97e21
--- /dev/null
+++ b/keyboards/handwired/onekey/bluepill_f103c6/mcuconf.h
@@ -0,0 +1,30 @@
+/* Copyright 2020 QMK
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This file was auto-generated by:
+ * `qmk chibios-confmigrate -i keyboards/handwired/onekey/bluepill/mcuconf.h -r platforms/chibios/STM32_F103_STM32DUINO/configs/mcuconf.h`
+ */
+
+#pragma once
+
+#include_next <mcuconf.h>
+
+#undef STM32_PWM_USE_TIM2
+#define STM32_PWM_USE_TIM2 TRUE
+
+#undef STM32_SPI_USE_SPI2
+#define STM32_SPI_USE_SPI2 FALSE
diff --git a/keyboards/handwired/onekey/bluepill_f103c6/readme.md b/keyboards/handwired/onekey/bluepill_f103c6/readme.md
new file mode 100644
index 0000000000..65ba9b0d4f
--- /dev/null
+++ b/keyboards/handwired/onekey/bluepill_f103c6/readme.md
@@ -0,0 +1,7 @@
+# STM32F103C6xx Bluepill onekey
+
+* Supported hardware: Bluepill boards with the STM32F103C**6**xx chips
+
+Note that STM32F103C6xx chips have only 32 KiB of flash and 10 KiB of RAM, and the stm32duino bootloader occupies 8 KiB of flash, leaving only 24 KiB for the firmware, therefore the capabilities of this board are severely restricted in comparison to proper Bluepill boards with STM32F103CBxx or STM32F103C8xx chips (128 or 64 KiB of flash and 20 KiB of RAM). You may need to disable many features in the QMK firmware to bring its compiled size below 24 KiB. Please avoid designing new keyboards with these MCUs unless you are stuck with some hardware that you already have and don't want to just throw away.
+
+To trigger keypress, short together pins *B0* and *A7*.
diff --git a/keyboards/handwired/onekey/bluepill_f103c6/rules.mk b/keyboards/handwired/onekey/bluepill_f103c6/rules.mk
new file mode 100644
index 0000000000..f2280a1a59
--- /dev/null
+++ b/keyboards/handwired/onekey/bluepill_f103c6/rules.mk
@@ -0,0 +1,27 @@
+# MCU name
+MCU = STM32F103
+
+# Bootloader selection
+# Cannot use `BOOTLOADER = stm32duino` due to the need to override
+# `MCU_LDSCRIPT`, therefore all parameters need to be specified here manually.
+OPT_DEFS += -DBOOTLOADER_STM32DUINO
+MCU_LDSCRIPT = STM32F103x6_stm32duino_bootloader
+BOARD = STM32_F103_STM32DUINO
+BOOTLOADER_TYPE = stm32duino
+DFU_ARGS = -d 1EAF:0003 -a 2 -R
+DFU_SUFFIX_ARGS = -v 1EAF -p 0003
+
+# Enter lower-power sleep mode when on the ChibiOS idle thread
+OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE
+
+# LTO is required to fit the firmware into the available 24K of flash
+LTO_ENABLE = yes
+
+# Disable some features which still don't fit into flash even with LTO
+MOUSEKEY_ENABLE = no
+NKRO_ENABLE = no
+
+# EEPROM emulation not supported yet (need to implement a proper firmware size
+# check first, otherwise the chance of the EEPROM backing store overwriting
+# some part of the firmware code is really high).
+EEPROM_DRIVER = transient
diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c b/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c
index cba977da77..e82e1d37ce 100644
--- a/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c
+++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/board/board.c
@@ -28,7 +28,9 @@ const PALConfig pal_default_config =
{VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
{VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
{VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
+# if STM32_HAS_GPIOE
{VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
+# endif
};
#endif
diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino_bootloader.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino_bootloader.ld
new file mode 100644
index 0000000000..18aaff2a23
--- /dev/null
+++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x6_stm32duino_bootloader.ld
@@ -0,0 +1,23 @@
+/*
+ ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/*
+ * STM32F103x6 memory setup for use with the STM32Duino bootloader.
+ */
+f103_flash_size = 32k;
+f103_ram_size = 10k;
+
+INCLUDE stm32duino_bootloader_common.ld
diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld
index a4bd566b59..465af12cab 100644
--- a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld
+++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103x8_stm32duino_bootloader.ld
@@ -18,5 +18,6 @@
* STM32F103x8 memory setup for use with the STM32Duino bootloader.
*/
f103_flash_size = 64k;
+f103_ram_size = 20k;
INCLUDE stm32duino_bootloader_common.ld
diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld
index dc47400dc5..3a47a33156 100644
--- a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld
+++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/STM32F103xB_stm32duino_bootloader.ld
@@ -18,5 +18,6 @@
* STM32F103xB memory setup for use with the STM32Duino bootloader.
*/
f103_flash_size = 128k;
+f103_ram_size = 20k;
INCLUDE stm32duino_bootloader_common.ld
diff --git a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/stm32duino_bootloader_common.ld b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/stm32duino_bootloader_common.ld
index 76cd3153be..1466ae7ed2 100644
--- a/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/stm32duino_bootloader_common.ld
+++ b/platforms/chibios/boards/STM32_F103_STM32DUINO/ld/stm32duino_bootloader_common.ld
@@ -27,7 +27,7 @@ MEMORY
flash5 : org = 0x00000000, len = 0
flash6 : org = 0x00000000, len = 0
flash7 : org = 0x00000000, len = 0
- ram0 : org = 0x20000000, len = 20k
+ ram0 : org = 0x20000000, len = f103_ram_size
ram1 : org = 0x00000000, len = 0
ram2 : org = 0x00000000, len = 0
ram3 : org = 0x00000000, len = 0