Skip to content

Commit

Permalink
Added AT32F415 support MCU (#1)
Browse files Browse the repository at this point in the history
* Added support for new AT32F415 MCU

* Added Generic AT32F415 board

* Added document of flashing and bootloader for new MCU

* Added support wear leveling driver

* Added support SPI driver

* Added support WS2812 driver

* Added support Serial driver

* Added support ADC driver

* Added AT-START-F415 onekey
  • Loading branch information
HorrorTroll authored Apr 9, 2024
1 parent b99143f commit 40a4420
Show file tree
Hide file tree
Showing 33 changed files with 990 additions and 62 deletions.
2 changes: 1 addition & 1 deletion builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ else
COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/flash
COMMON_VPATH += $(DRIVER_PATH)/flash
SRC += eeprom_driver.c eeprom_legacy_emulated_flash.c legacy_flash_ops.c
else ifneq ($(filter $(MCU_SERIES),STM32F1xx STM32F3xx STM32F4xx STM32L4xx STM32G4xx WB32F3G71xx WB32FQ95xx GD32VF103),)
else ifneq ($(filter $(MCU_SERIES),STM32F1xx STM32F3xx STM32F4xx STM32L4xx STM32G4xx WB32F3G71xx WB32FQ95xx AT32F415 GD32VF103),)
# Wear-leveling EEPROM implementation, backed by MCU flash
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_WEAR_LEVELING
SRC += eeprom_driver.c eeprom_wear_leveling.c
Expand Down
2 changes: 2 additions & 0 deletions data/schemas/keyboard.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"GD32VF103",
"WB32F3G71",
"WB32FQ95",
"AT32F415",
"atmega16u2",
"atmega32u2",
"atmega16u4",
Expand Down Expand Up @@ -212,6 +213,7 @@
"type": "string",
"enum": [
"apm32-dfu",
"at32-dfu",
"atmel-dfu",
"bootloadhid",
"caterina",
Expand Down
4 changes: 4 additions & 0 deletions docs/compatible_microcontrollers.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ You can also use any ARM chip with USB that [ChibiOS](https://www.chibios.org) s
* [WB32F3G71xx](http://www.westberrytech.com)
* [WB32FQ95xx](http://www.westberrytech.com)

### Artery (AT32)

* [AT32F415](https://www.arterychip.com/en/product/AT32F415.jsp)

### NXP (Kinetis)

* [MKL26Z64](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/kl-series-cortex-m0-plus/kinetis-kl2x-72-96-mhz-usb-ultra-low-power-microcontrollers-mcus-based-on-arm-cortex-m0-plus-core:KL2x)
Expand Down
1 change: 1 addition & 0 deletions docs/driver_installation_zadig.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ The device name here is the name that appears in Zadig, and may not be what the
|`bootloadhid` |HIDBoot |`16C0:05DF` |HidUsb |
|`usbasploader`|USBasp |`16C0:05DC` |libusbK|
|`apm32-dfu` |APM32 DFU ISP Mode |`314B:0106` |WinUSB |
|`at32-dfu` |AT32 Bootloader DFU |`2E3C:DF11` |WinUSB |
|`stm32-dfu` |STM32 BOOTLOADER |`0483:DF11` |WinUSB |
|`gd32v-dfu` |GD32V BOOTLOADER |`28E9:0189` |WinUSB |
|`kiibohd` |Kiibohd DFU Bootloader |`1C11:B007` |WinUSB |
Expand Down
34 changes: 34 additions & 0 deletions docs/flashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,40 @@ Flashing sequence:
3. Flash a .bin file
4. Reset the device into application mode (may be done automatically)

## AT32 DFU

All AT32 MCUs come preloaded with a factory bootloader that cannot be modified nor deleted.

To ensure compatibility with the AT32-DFU bootloader, make sure this block is present in your `rules.mk`:

```make
# Bootloader selection
BOOTLOADER = at32-dfu
```

Compatible flashers:

* [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
* [dfu-util](https://dfu-util.sourceforge.net/) / `:dfu-util` target in QMK (recommended command line)
```
dfu-util -a 0 -d 2E3C:DF11 -s 0x8000000:leave -D <filename>
```

Flashing sequence:

1. Enter the bootloader using any of the following methods:
* Tap the `QK_BOOT` keycode
* If a reset circuit is present, tap the `RESET` button on the PCB; some boards may also have a toggle switch that must be flipped
* Otherwise, you need to bridge `BOOT0` to VCC (via `BOOT0` button or jumper), short `RESET` to GND (via `RESET` button or jumper), and then let go of the `BOOT0` bridge
2. Wait for the OS to detect the device
3. Flash a .bin file
4. Reset the device into application mode (may be done automatically)

### `make` Targets

* `:dfu-util`: Waits until an AT32 bootloader device is available, and then flashes the firmware.
* `:dfu-util-split-left` and `:dfu-util-split-right`: Flashes the firmware as with `:dfu-util`, but also sets the handedness setting in EEPROM.

## tinyuf2

Keyboards may opt into supporting the tinyuf2 bootloader. This is currently only supported on F303/F401/F411.
Expand Down
10 changes: 10 additions & 0 deletions keyboards/handwired/onekey/at_start_f415/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include_next <board.h>

#undef AT32F415KB
#define AT32F415RC
7 changes: 7 additions & 0 deletions keyboards/handwired/onekey/at_start_f415/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#define ADC_PIN A0
11 changes: 11 additions & 0 deletions keyboards/handwired/onekey/at_start_f415/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#define HAL_USE_ADC TRUE

#define HAL_USE_I2C TRUE

#include_next <halconf.h>
12 changes: 12 additions & 0 deletions keyboards/handwired/onekey/at_start_f415/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"keyboard_name": "Onekey AT-START-F415",
"processor": "AT32F415",
"bootloader": "at32-dfu",
"matrix_pins": {
"cols": ["B3"],
"rows": ["B4"]
},
"ws2812": {
"pin": "B0"
}
}
13 changes: 13 additions & 0 deletions keyboards/handwired/onekey/at_start_f415/mcuconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include_next <mcuconf.h>

#undef AT32_ADC_USE_ADC1
#define AT32_ADC_USE_ADC1 TRUE

#undef AT32_I2C_USE_I2C1
#define AT32_I2C_USE_I2C1 TRUE
3 changes: 3 additions & 0 deletions keyboards/handwired/onekey/at_start_f415/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Artery AT-START-F415 Board Onekey

To trigger keypress, short together pins *B3* and *B4*.
1 change: 1 addition & 0 deletions keyboards/handwired/onekey/at_start_f415/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KEYBOARD_SHARED_EP = yes
4 changes: 3 additions & 1 deletion lib/python/qmk/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
MAX_KEYBOARD_SUBFOLDERS = 5

# Supported processor types
CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK64FX512', 'MK66FX1M0', 'RP2040', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32H723', 'STM32H733', 'STM32L412', 'STM32L422', 'STM32L432', 'STM32L433', 'STM32L442', 'STM32L443', 'GD32VF103', 'WB32F3G71', 'WB32FQ95'
CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MKL26Z64', 'MK20DX128', 'MK20DX256', 'MK64FX512', 'MK66FX1M0', 'RP2040', 'STM32F042', 'STM32F072', 'STM32F103', 'STM32F303', 'STM32F401', 'STM32F405', 'STM32F407', 'STM32F411', 'STM32F446', 'STM32G431', 'STM32G474', 'STM32H723', 'STM32H733', 'STM32L412', 'STM32L422', 'STM32L432', 'STM32L433', 'STM32L442', 'STM32L443', 'GD32VF103', 'WB32F3G71', 'WB32FQ95', 'AT32F415'
LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None
VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85'

Expand Down Expand Up @@ -55,6 +55,7 @@
"GD32VF103": "gd32v-dfu",
"WB32F3G71": "wb32-dfu",
"WB32FQ95": "wb32-dfu",
"AT32F415": "at32-dfu",
"atmega16u2": "atmel-dfu",
"atmega32u2": "atmel-dfu",
"atmega16u4": "atmel-dfu",
Expand Down Expand Up @@ -93,6 +94,7 @@
'apm32-dfu': {("314b", "0106")},
'gd32v-dfu': {("28e9", "0189")},
'wb32-dfu': {("342d", "dfa0")},
'at32-dfu': {("2e3c", "df11")},
'bootloadhid': {("16c0", "05df")},
'usbasploader': {("16c0", "05dc")},
'usbtinyisp': {("1782", "0c9f")},
Expand Down
55 changes: 55 additions & 0 deletions platforms/chibios/boards/GENERIC_AT32_F415XX/board/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
ChibiOS - Copyright (C) 2023..2024 HorrorTroll
ChibiOS - Copyright (C) 2023..2024 Zhaqian
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.
*/

#include "hal.h"

/**
* @brief PAL setup.
* @details Digital I/O ports static configuration as defined in @p board.h.
* This variable is used by the HAL when initializing the PAL driver.
*/
#if HAL_USE_PAL || defined(__DOXYGEN__)
const PALConfig pal_default_config =
{
{VAL_GPIOAODT, VAL_GPIOACFGLR, VAL_GPIOACFGHR},
{VAL_GPIOBODT, VAL_GPIOBCFGLR, VAL_GPIOBCFGHR},
#if AT32_HAS_GPIOC
{VAL_GPIOCODT, VAL_GPIOCCFGLR, VAL_GPIOCCFGHR},
#endif
{VAL_GPIODODT, VAL_GPIODCFGLR, VAL_GPIODCFGHR},
#if AT32_HAS_GPIOF
{VAL_GPIOFODT, VAL_GPIOFCFGLR, VAL_GPIOFCFGHR},
#endif
};
#endif

/*
* Early initialization code.
* This initialization must be performed just after stack setup and before
* any other initialization.
*/
void __early_init(void) {
at32_clock_init();
}

/*
* Board-specific initialization code.
*/
void boardInit(void) {
IOMUX->REMAP |= IOMUX_REMAP_SWJTAG_MUX_JTAGDIS;
}
Loading

0 comments on commit 40a4420

Please sign in to comment.