Added MCU support for ArteryTek AT32F415 (#23445)
This commit is contained in:
parent
074bbbfb21
commit
39161b9ee7
32 changed files with 1065 additions and 63 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@
|
|||
"GD32VF103",
|
||||
"WB32F3G71",
|
||||
"WB32FQ95",
|
||||
"AT32F415",
|
||||
"atmega16u2",
|
||||
"atmega32u2",
|
||||
"atmega16u4",
|
||||
|
|
@ -216,6 +217,7 @@
|
|||
"type": "string",
|
||||
"enum": [
|
||||
"apm32-dfu",
|
||||
"at32-dfu",
|
||||
"atmel-dfu",
|
||||
"bootloadhid",
|
||||
"caterina",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -98,6 +98,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 |
|
||||
|
|
|
|||
|
|
@ -345,6 +345,39 @@ 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:
|
||||
|
||||
* [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.
|
||||
|
|
|
|||
10
keyboards/handwired/onekey/at_start_f415/board.h
Normal file
10
keyboards/handwired/onekey/at_start_f415/board.h
Normal file
|
|
@ -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
|
||||
10
keyboards/handwired/onekey/at_start_f415/config.h
Normal file
10
keyboards/handwired/onekey/at_start_f415/config.h
Normal file
|
|
@ -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
|
||||
|
||||
#define ADC_PIN A0
|
||||
|
||||
#define BACKLIGHT_PWM_DRIVER PWMD5
|
||||
#define BACKLIGHT_PWM_CHANNEL 1
|
||||
13
keyboards/handwired/onekey/at_start_f415/halconf.h
Normal file
13
keyboards/handwired/onekey/at_start_f415/halconf.h
Normal file
|
|
@ -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
|
||||
|
||||
#define HAL_USE_ADC TRUE
|
||||
|
||||
#define HAL_USE_I2C TRUE
|
||||
|
||||
#define HAL_USE_PWM TRUE
|
||||
|
||||
#include_next <halconf.h>
|
||||
20
keyboards/handwired/onekey/at_start_f415/keyboard.json
Normal file
20
keyboards/handwired/onekey/at_start_f415/keyboard.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"keyboard_name": "Onekey AT-START-F415",
|
||||
"processor": "AT32F415",
|
||||
"bootloader": "at32-dfu",
|
||||
"usb": {
|
||||
"shared_endpoint": {
|
||||
"keyboard": true
|
||||
}
|
||||
},
|
||||
"matrix_pins": {
|
||||
"cols": ["B3"],
|
||||
"rows": ["B4"]
|
||||
},
|
||||
"backlight": {
|
||||
"pin": "A0"
|
||||
},
|
||||
"ws2812": {
|
||||
"pin": "B0"
|
||||
}
|
||||
}
|
||||
16
keyboards/handwired/onekey/at_start_f415/mcuconf.h
Normal file
16
keyboards/handwired/onekey/at_start_f415/mcuconf.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// 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
|
||||
|
||||
#undef AT32_PWM_USE_TMR5
|
||||
#define AT32_PWM_USE_TMR5 TRUE
|
||||
3
keyboards/handwired/onekey/at_start_f415/readme.md
Normal file
3
keyboards/handwired/onekey/at_start_f415/readme.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Artery AT-START-F415 Board Onekey
|
||||
|
||||
To trigger keypress, short together pins *B3* and *B4*.
|
||||
|
|
@ -22,7 +22,7 @@ QMK_FIRMWARE_UPSTREAM = 'qmk/qmk_firmware'
|
|||
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'
|
||||
|
||||
|
|
@ -55,6 +55,7 @@ MCU2BOOTLOADER = {
|
|||
"GD32VF103": "gd32v-dfu",
|
||||
"WB32F3G71": "wb32-dfu",
|
||||
"WB32FQ95": "wb32-dfu",
|
||||
"AT32F415": "at32-dfu",
|
||||
"atmega16u2": "atmel-dfu",
|
||||
"atmega32u2": "atmel-dfu",
|
||||
"atmega16u4": "atmel-dfu",
|
||||
|
|
@ -93,6 +94,7 @@ BOOTLOADER_VIDS_PIDS = {
|
|||
'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")},
|
||||
|
|
|
|||
101
platforms/chibios/boards/GENERIC_AT32_F415XX/board/board.c
Normal file
101
platforms/chibios/boards/GENERIC_AT32_F415XX/board/board.c
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
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"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Early initialization code.
|
||||
* @details System clocks are initialized before everything else.
|
||||
*/
|
||||
void __early_init(void) {
|
||||
at32_clock_init();
|
||||
}
|
||||
|
||||
#if HAL_USE_SDC || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief SDC card detection.
|
||||
*/
|
||||
bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
|
||||
static bool last_status = false;
|
||||
|
||||
if (blkIsTransferring(sdcp))
|
||||
return last_status;
|
||||
return last_status = (bool)palReadPad(GPIOC, GPIOC_PIN11);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDC card write protection detection.
|
||||
*/
|
||||
bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
|
||||
|
||||
(void)sdcp;
|
||||
return false;
|
||||
}
|
||||
#endif /* HAL_USE_SDC */
|
||||
|
||||
/**
|
||||
* @brief Board-specific initialization code.
|
||||
* @note You can add your board-specific code here.
|
||||
*/
|
||||
void boardInit(void) {
|
||||
IOMUX->REMAP |= IOMUX_REMAP_SWJTAG_MUX_JTAGDIS;
|
||||
}
|
||||
207
platforms/chibios/boards/GENERIC_AT32_F415XX/board/board.h
Normal file
207
platforms/chibios/boards/GENERIC_AT32_F415XX/board/board.h
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*
|
||||
* Setup for a Generic AT32F415 board.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Board identifier.
|
||||
*/
|
||||
#define BOARD_GENERIC_AT32_F415XX
|
||||
#define BOARD_NAME "GENERIC AT32F415 board"
|
||||
|
||||
/*
|
||||
* Board oscillators-related settings.
|
||||
*/
|
||||
#if !defined(AT32_LEXTCLK)
|
||||
#define AT32_LEXTCLK 32768
|
||||
#endif
|
||||
|
||||
#if !defined(AT32_HEXTCLK)
|
||||
#define AT32_HEXTCLK 8000000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
|
||||
*/
|
||||
#define AT32F415KB
|
||||
|
||||
/*
|
||||
* IO pins assignments.
|
||||
*/
|
||||
#define GPIOA_PIN0 0U
|
||||
#define GPIOA_PIN1 1U
|
||||
#define GPIOA_PIN2 2U
|
||||
#define GPIOA_PIN3 3U
|
||||
#define GPIOA_PIN4 4U
|
||||
#define GPIOA_PIN5 5U
|
||||
#define GPIOA_PIN6 6U
|
||||
#define GPIOA_PIN7 7U
|
||||
#define GPIOA_PIN8 8U
|
||||
#define GPIOA_PIN9 9U
|
||||
#define GPIOA_PIN10 10U
|
||||
#define GPIOA_PIN11 11U
|
||||
#define GPIOA_PIN12 12U
|
||||
#define GPIOA_SWDIO 13U
|
||||
#define GPIOA_SWCLK 14U
|
||||
#define GPIOA_PIN15 15U
|
||||
|
||||
#define GPIOB_PIN0 0U
|
||||
#define GPIOB_PIN1 1U
|
||||
#define GPIOB_PIN2 2U
|
||||
#define GPIOB_PIN3 3U
|
||||
#define GPIOB_PIN4 4U
|
||||
#define GPIOB_PIN5 5U
|
||||
#define GPIOB_PIN6 6U
|
||||
#define GPIOB_PIN7 7U
|
||||
#define GPIOB_PIN8 8U
|
||||
#define GPIOB_PIN9 9U
|
||||
#define GPIOB_PIN10 10U
|
||||
#define GPIOB_PIN11 11U
|
||||
#define GPIOB_PIN12 12U
|
||||
#define GPIOB_PIN13 13U
|
||||
#define GPIOB_PIN14 14U
|
||||
#define GPIOB_PIN15 15U
|
||||
|
||||
#define GPIOC_PIN0 0U
|
||||
#define GPIOC_PIN1 1U
|
||||
#define GPIOC_PIN2 2U
|
||||
#define GPIOC_PIN3 3U
|
||||
#define GPIOC_PIN4 4U
|
||||
#define GPIOC_PIN5 5U
|
||||
#define GPIOC_PIN6 6U
|
||||
#define GPIOC_PIN7 7U
|
||||
#define GPIOC_PIN8 8U
|
||||
#define GPIOC_PIN9 9U
|
||||
#define GPIOC_PIN10 10U
|
||||
#define GPIOC_PIN11 11U
|
||||
#define GPIOC_PIN12 12U
|
||||
#define GPIOC_PIN13 13U
|
||||
#define GPIOC_PIN14 14U
|
||||
#define GPIOC_PIN15 15U
|
||||
|
||||
#define GPIOD_HEXT_IN 0U
|
||||
#define GPIOD_HEXT_OUT 1U
|
||||
#define GPIOD_PIN2 2U
|
||||
|
||||
#define GPIOF_PIN4 4U
|
||||
#define GPIOF_PIN5 5U
|
||||
#define GPIOF_PIN6 6U
|
||||
#define GPIOF_PIN7 7U
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*
|
||||
* I/O ports initial setup, this configuration is established soon after reset
|
||||
* in the initialization code.
|
||||
*
|
||||
* The digits have the following meaning:
|
||||
* 0 - Analog input.
|
||||
* 1 - Push Pull output 10MHz.
|
||||
* 2 - Push Pull output 2MHz.
|
||||
* 3 - Push Pull output 50MHz.
|
||||
* 4 - Digital input.
|
||||
* 5 - Open Drain output 10MHz.
|
||||
* 6 - Open Drain output 2MHz.
|
||||
* 7 - Open Drain output 50MHz.
|
||||
* 8 - Digital input with Pull-Up or Pull-Down resistor depending on ODT.
|
||||
* 9 - Alternate Push Pull output 10MHz.
|
||||
* A - Alternate Push Pull output 2MHz.
|
||||
* B - Alternate Push Pull output 50MHz.
|
||||
* C - Reserved.
|
||||
* D - Alternate Open Drain output 10MHz.
|
||||
* E - Alternate Open Drain output 2MHz.
|
||||
* F - Alternate Open Drain output 50MHz.
|
||||
* Please refer to the AT32 Reference Manual for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Port A setup.
|
||||
*/
|
||||
#define VAL_GPIOACFGLR 0x88888B88 /* PA7...PA0 */
|
||||
#define VAL_GPIOACFGHR 0x888888B8 /* PA15...PA8 */
|
||||
#define VAL_GPIOAODT 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port B setup.
|
||||
*/
|
||||
#define VAL_GPIOBCFGLR 0x88888888 /* PB7...PB0 */
|
||||
#define VAL_GPIOBCFGHR 0x88888888 /* PB15...PB8 */
|
||||
#define VAL_GPIOBODT 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port C setup.
|
||||
*/
|
||||
#define VAL_GPIOCCFGLR 0x88888888 /* PC7...PC0 */
|
||||
#define VAL_GPIOCCFGHR 0x88888888 /* PC15...PC8 */
|
||||
#define VAL_GPIOCODT 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port D setup.
|
||||
* Everything input with pull-up except:
|
||||
* PD0 - Normal input (GPIOD_HEXT_IN).
|
||||
* PD1 - Normal input (GPIOD_HEXT_OUT).
|
||||
*/
|
||||
#define VAL_GPIODCFGLR 0x88888844 /* PD7...PD0 */
|
||||
#define VAL_GPIODCFGHR 0x88888888 /* PD15...PD8 */
|
||||
#define VAL_GPIODODT 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port F setup.
|
||||
*/
|
||||
#define VAL_GPIOFCFGLR 0x88888888 /* PF7...PF0 */
|
||||
#define VAL_GPIOFCFGHR 0x88888888 /* PF15...PF8 */
|
||||
#define VAL_GPIOFODT 0xFFFFFFFF
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#if !defined(_FROM_ASM_)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void boardInit(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _FROM_ASM_ */
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# List of all the board related files.
|
||||
BOARDSRC = $(BOARD_PATH)/board/board.c
|
||||
|
||||
# Required include directories
|
||||
BOARDINC = $(BOARD_PATH)/board
|
||||
|
||||
# Shared variables
|
||||
ALLCSRC += $(BOARDSRC)
|
||||
ALLINC += $(BOARDINC)
|
||||
|
|
@ -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
|
||||
|
||||
#define BOARD_OTG_VBUSIG
|
||||
|
||||
#define USB_ENDPOINTS_ARE_REORDERABLE
|
||||
|
||||
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
|
||||
# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE
|
||||
#endif
|
||||
236
platforms/chibios/boards/GENERIC_AT32_F415XX/configs/mcuconf.h
Normal file
236
platforms/chibios/boards/GENERIC_AT32_F415XX/configs/mcuconf.h
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
ChibiOS - Copyright (C) 2006..2020 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.
|
||||
*/
|
||||
|
||||
#ifndef MCUCONF_H
|
||||
#define MCUCONF_H
|
||||
|
||||
/*
|
||||
* AT32F415 drivers configuration.
|
||||
* The following settings override the default settings present in
|
||||
* the various device driver implementation headers.
|
||||
* Note that the settings for each driver only have effect if the whole
|
||||
* driver is enabled in halconf.h.
|
||||
*
|
||||
* IRQ priorities:
|
||||
* 15...0 Lowest...Highest.
|
||||
*
|
||||
* DMA priorities:
|
||||
* 0...3 Lowest...Highest.
|
||||
*/
|
||||
|
||||
#define AT32F415_MCUCONF
|
||||
|
||||
/*
|
||||
* General settings.
|
||||
*/
|
||||
#define AT32_NO_INIT FALSE
|
||||
|
||||
/*
|
||||
* HAL driver system settings.
|
||||
*/
|
||||
#define AT32_HICK_ENABLED TRUE
|
||||
#define AT32_LICK_ENABLED FALSE
|
||||
#define AT32_HEXT_ENABLED TRUE
|
||||
#define AT32_LEXT_ENABLED FALSE
|
||||
#define AT32_SCLKSEL AT32_SCLKSEL_PLL
|
||||
#define AT32_PLLRCS AT32_PLLRCS_HEXT
|
||||
#define AT32_PLLHEXTDIV AT32_PLLHEXTDIV_DIV1
|
||||
#define AT32_PLLCFGEN AT32_PLLCFGEN_SOLID
|
||||
#define AT32_PLLMULT_VALUE 18
|
||||
#define AT32_PLL_FR_VALUE 4
|
||||
#define AT32_PLL_MS_VALUE 1
|
||||
#define AT32_PLL_NS_VALUE 72
|
||||
#define AT32_AHBDIV AT32_AHBDIV_DIV1
|
||||
#define AT32_APB1DIV AT32_APB1DIV_DIV2
|
||||
#define AT32_APB2DIV AT32_APB2DIV_DIV2
|
||||
#define AT32_ADCDIV AT32_ADCDIV_DIV4
|
||||
#define AT32_USB_CLOCK_REQUIRED TRUE
|
||||
#define AT32_USBDIV AT32_USBDIV_DIV3
|
||||
#define AT32_CLKOUT_SEL AT32_CLKOUT_SEL_NOCLOCK
|
||||
#define AT32_CLKOUTDIV AT32_CLKOUTDIV_DIV1
|
||||
#define AT32_ERTCSEL AT32_ERTCSEL_HEXTDIV
|
||||
#define AT32_PVM_ENABLE FALSE
|
||||
#define AT32_PVMSEL AT32_PVMSEL_LEV1
|
||||
|
||||
/*
|
||||
* IRQ system settings.
|
||||
*/
|
||||
#define AT32_IRQ_EXINT0_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT1_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT2_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT3_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT4_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT5_9_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT10_15_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT16_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT17_PRIORITY 15
|
||||
#define AT32_IRQ_EXINT18_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT19_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT20_PRIORITY 6
|
||||
#define AT32_IRQ_EXINT21_PRIORITY 15
|
||||
#define AT32_IRQ_EXINT22_PRIORITY 15
|
||||
|
||||
#define AT32_IRQ_TMR1_BRK_TMR9_PRIORITY 7
|
||||
#define AT32_IRQ_TMR1_OVF_TMR10_PRIORITY 7
|
||||
#define AT32_IRQ_TMR1_HALL_TMR11_PRIORITY 7
|
||||
#define AT32_IRQ_TMR1_CH_PRIORITY 7
|
||||
#define AT32_IRQ_TMR2_PRIORITY 7
|
||||
#define AT32_IRQ_TMR3_PRIORITY 7
|
||||
#define AT32_IRQ_TMR4_PRIORITY 7
|
||||
#define AT32_IRQ_TMR5_PRIORITY 7
|
||||
|
||||
#define AT32_IRQ_USART1_PRIORITY 12
|
||||
#define AT32_IRQ_USART2_PRIORITY 12
|
||||
#define AT32_IRQ_USART3_PRIORITY 12
|
||||
#define AT32_IRQ_UART4_PRIORITY 12
|
||||
#define AT32_IRQ_UART5_PRIORITY 12
|
||||
|
||||
/*
|
||||
* ADC driver system settings.
|
||||
*/
|
||||
#define AT32_ADC_USE_ADC1 FALSE
|
||||
#define AT32_ADC_ADC1_DMA_PRIORITY 2
|
||||
#define AT32_ADC_ADC1_IRQ_PRIORITY 6
|
||||
|
||||
/*
|
||||
* CAN driver system settings.
|
||||
*/
|
||||
#define AT32_CAN_USE_CAN1 FALSE
|
||||
#define AT32_CAN_CAN1_IRQ_PRIORITY 11
|
||||
|
||||
/*
|
||||
* DMA driver system settings.
|
||||
*/
|
||||
#define AT32_DMA_USE_DMAMUX TRUE
|
||||
|
||||
/*
|
||||
* GPT driver system settings.
|
||||
*/
|
||||
#define AT32_GPT_USE_TMR1 FALSE
|
||||
#define AT32_GPT_USE_TMR2 FALSE
|
||||
#define AT32_GPT_USE_TMR3 FALSE
|
||||
#define AT32_GPT_USE_TMR4 FALSE
|
||||
#define AT32_GPT_USE_TMR5 FALSE
|
||||
#define AT32_GPT_USE_TMR9 FALSE
|
||||
#define AT32_GPT_USE_TMR10 FALSE
|
||||
#define AT32_GPT_USE_TMR11 FALSE
|
||||
|
||||
/*
|
||||
* I2C driver system settings.
|
||||
*/
|
||||
#define AT32_I2C_USE_I2C1 FALSE
|
||||
#define AT32_I2C_USE_I2C2 FALSE
|
||||
#define AT32_I2C_BUSY_TIMEOUT 50
|
||||
#define AT32_I2C_I2C1_IRQ_PRIORITY 5
|
||||
#define AT32_I2C_I2C2_IRQ_PRIORITY 5
|
||||
#define AT32_I2C_I2C1_DMA_PRIORITY 3
|
||||
#define AT32_I2C_I2C2_DMA_PRIORITY 3
|
||||
#define AT32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
|
||||
|
||||
/*
|
||||
* ICU driver system settings.
|
||||
*/
|
||||
#define AT32_ICU_USE_TMR1 FALSE
|
||||
#define AT32_ICU_USE_TMR2 FALSE
|
||||
#define AT32_ICU_USE_TMR3 FALSE
|
||||
#define AT32_ICU_USE_TMR4 FALSE
|
||||
#define AT32_ICU_USE_TMR5 FALSE
|
||||
#define AT32_ICU_USE_TMR9 FALSE
|
||||
#define AT32_ICU_USE_TMR10 FALSE
|
||||
#define AT32_ICU_USE_TMR11 FALSE
|
||||
|
||||
/*
|
||||
* PWM driver system settings.
|
||||
*/
|
||||
#define AT32_PWM_USE_TMR1 FALSE
|
||||
#define AT32_PWM_USE_TMR2 FALSE
|
||||
#define AT32_PWM_USE_TMR3 FALSE
|
||||
#define AT32_PWM_USE_TMR4 FALSE
|
||||
#define AT32_PWM_USE_TMR5 FALSE
|
||||
#define AT32_PWM_USE_TMR9 FALSE
|
||||
#define AT32_PWM_USE_TMR10 FALSE
|
||||
#define AT32_PWM_USE_TMR11 FALSE
|
||||
|
||||
/*
|
||||
* RTC driver system settings.
|
||||
*/
|
||||
#define AT32_ERTC_DIVA_VALUE 32
|
||||
#define AT32_ERTC_DIVB_VALUE 1024
|
||||
#define AT32_ERTC_CTRL_INIT 0
|
||||
#define AT32_ERTC_TAMP_INIT 0
|
||||
|
||||
/*
|
||||
* SDC driver system settings.
|
||||
*/
|
||||
#define AT32_SDC_SDIO_DMA_PRIORITY 3
|
||||
#define AT32_SDC_SDIO_IRQ_PRIORITY 9
|
||||
#define AT32_SDC_WRITE_TIMEOUT_MS 1000
|
||||
#define AT32_SDC_READ_TIMEOUT_MS 1000
|
||||
#define AT32_SDC_CLOCK_ACTIVATION_DELAY 10
|
||||
#define AT32_SDC_SDIO_UNALIGNED_SUPPORT TRUE
|
||||
|
||||
/*
|
||||
* SERIAL driver system settings.
|
||||
*/
|
||||
#define AT32_SERIAL_USE_USART1 FALSE
|
||||
#define AT32_SERIAL_USE_USART2 FALSE
|
||||
#define AT32_SERIAL_USE_USART3 FALSE
|
||||
#define AT32_SERIAL_USE_UART4 FALSE
|
||||
#define AT32_SERIAL_USE_UART5 FALSE
|
||||
|
||||
/*
|
||||
* SPI driver system settings.
|
||||
*/
|
||||
#define AT32_SPI_USE_SPI1 FALSE
|
||||
#define AT32_SPI_USE_SPI2 FALSE
|
||||
#define AT32_SPI_SPI1_DMA_PRIORITY 1
|
||||
#define AT32_SPI_SPI2_DMA_PRIORITY 1
|
||||
#define AT32_SPI_SPI1_IRQ_PRIORITY 10
|
||||
#define AT32_SPI_SPI2_IRQ_PRIORITY 10
|
||||
#define AT32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
|
||||
|
||||
/*
|
||||
* ST driver system settings.
|
||||
*/
|
||||
#define AT32_ST_IRQ_PRIORITY 8
|
||||
#define AT32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
#define AT32_UART_USE_USART1 FALSE
|
||||
#define AT32_UART_USE_USART2 FALSE
|
||||
#define AT32_UART_USE_USART3 FALSE
|
||||
#define AT32_UART_USART1_DMA_PRIORITY 0
|
||||
#define AT32_UART_USART2_DMA_PRIORITY 0
|
||||
#define AT32_UART_USART3_DMA_PRIORITY 0
|
||||
#define AT32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
|
||||
|
||||
/*
|
||||
* USB driver system settings.
|
||||
*/
|
||||
#define AT32_USB_USE_OTG1 TRUE
|
||||
#define AT32_USB_OTG1_IRQ_PRIORITY 14
|
||||
#define AT32_USB_OTG1_RX_FIFO_SIZE 512
|
||||
|
||||
/*
|
||||
* WDG driver system settings.
|
||||
*/
|
||||
#define AT32_WDG_USE_WDT FALSE
|
||||
|
||||
#endif /* MCUCONF_H */
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
# stm32-dfu STM32 USB DFU in ROM
|
||||
# apm32-dfu APM32 USB DFU in ROM
|
||||
# wb32-dfu WB32 USB DFU in ROM
|
||||
# at32-dfu AT32 USB DFU in ROM
|
||||
# tinyuf2 TinyUF2
|
||||
# rp2040 Raspberry Pi RP2040
|
||||
# Current options for RISC-V:
|
||||
|
|
@ -119,6 +120,14 @@ ifeq ($(strip $(BOOTLOADER)), wb32-dfu)
|
|||
OPT_DEFS += -DBOOTLOADER_WB32_DFU
|
||||
BOOTLOADER_TYPE = wb32_dfu
|
||||
endif
|
||||
ifeq ($(strip $(BOOTLOADER)), at32-dfu)
|
||||
OPT_DEFS += -DBOOTLOADER_AT32_DFU
|
||||
BOOTLOADER_TYPE = at32_dfu
|
||||
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 2E3C:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 2E3C -p DF11
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(BOOTLOADER_TYPE)),)
|
||||
ifneq ($(strip $(BOOTLOADER)),)
|
||||
|
|
|
|||
83
platforms/chibios/bootloaders/at32_dfu.c
Normal file
83
platforms/chibios/bootloaders/at32_dfu.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright 2021-2023 QMK
|
||||
// Copyright 2023-2024 HorrorTroll <https://github.com/HorrorTroll>
|
||||
// Copyright 2023-2024 Zhaqian <https://github.com/zhaqian12>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "bootloader.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <ch.h>
|
||||
#include <hal.h>
|
||||
#include "wait.h"
|
||||
|
||||
#ifndef AT32_BOOTLOADER_RAM_SYMBOL
|
||||
# define AT32_BOOTLOADER_RAM_SYMBOL __ram0_end__
|
||||
#endif
|
||||
|
||||
extern uint32_t AT32_BOOTLOADER_RAM_SYMBOL;
|
||||
|
||||
/* This code should be checked whether it runs correctly on platforms */
|
||||
#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
|
||||
#define BOOTLOADER_MAGIC 0xDEADBEEF
|
||||
#define MAGIC_ADDR (unsigned long *)(SYMVAL(AT32_BOOTLOADER_RAM_SYMBOL) - 4)
|
||||
|
||||
__attribute__((weak)) void bootloader_marker_enable(void) {
|
||||
uint32_t *marker = (uint32_t *)MAGIC_ADDR;
|
||||
*marker = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
|
||||
}
|
||||
|
||||
__attribute__((weak)) bool bootloader_marker_active(void) {
|
||||
const uint32_t *marker = (const uint32_t *)MAGIC_ADDR;
|
||||
return (*marker == BOOTLOADER_MAGIC) ? true : false;
|
||||
}
|
||||
|
||||
__attribute__((weak)) void bootloader_marker_disable(void) {
|
||||
uint32_t *marker = (uint32_t *)MAGIC_ADDR;
|
||||
*marker = 0;
|
||||
}
|
||||
|
||||
__attribute__((weak)) void bootloader_jump(void) {
|
||||
bootloader_marker_enable();
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
__attribute__((weak)) void mcu_reset(void) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
void enter_bootloader_mode_if_requested(void) {
|
||||
if (bootloader_marker_active()) {
|
||||
bootloader_marker_disable();
|
||||
|
||||
struct system_memory_vector_t {
|
||||
uint32_t stack_top;
|
||||
void (*entrypoint)(void);
|
||||
};
|
||||
const struct system_memory_vector_t *bootloader = (const struct system_memory_vector_t *)(AT32_BOOTLOADER_ADDRESS);
|
||||
|
||||
__disable_irq();
|
||||
|
||||
#if defined(__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||
ARM_MPU_Disable();
|
||||
#endif
|
||||
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->VAL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
|
||||
// Clear interrupt enable and interrupt pending registers
|
||||
for (int i = 0; i < ARRAY_SIZE(NVIC->ICER); i++) {
|
||||
NVIC->ICER[i] = 0xFFFFFFFF;
|
||||
NVIC->ICPR[i] = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
__set_CONTROL(0);
|
||||
__set_MSP(bootloader->stack_top);
|
||||
__enable_irq();
|
||||
|
||||
// Jump to bootloader
|
||||
bootloader->entrypoint();
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -142,6 +142,19 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
// AT32 compatibility
|
||||
#if defined(MCU_AT32)
|
||||
# define CPU_CLOCK AT32_SYSCLK
|
||||
|
||||
# if defined(AT32F415)
|
||||
# define USE_GPIOV1
|
||||
# define USE_I2CV1
|
||||
# define PAL_MODE_ALTERNATE_OPENDRAIN PAL_MODE_AT32_ALTERNATE_OPENDRAIN
|
||||
# define PAL_MODE_ALTERNATE_PUSHPULL PAL_MODE_AT32_ALTERNATE_PUSHPULL
|
||||
# define AUDIO_PWM_PAL_MODE PAL_MODE_ALTERNATE_PUSHPULL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(GD32VF103)
|
||||
/* This chip has the same API as STM32F103, but uses different names for literally the same thing.
|
||||
* As of 4.7.2021 QMK is tailored to use STM32 defines/names, for compatibility sake
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue