From b53e3be3eab6fdeee667f815e1afda207875d578 Mon Sep 17 00:00:00 2001 From: Hansem Ro Date: Sat, 4 May 2024 17:47:53 -0700 Subject: [PATCH 1/6] HT32: Rename HT32F523x2 related ld scripts This renames HT32F523x2 linker scripts to prevent reuse for HT32F523x4 models due to differing flash page sizes (512 B vs 1024 B). --- .../ARMCMx/compilers/GCC/ld/{HT32F5234x.ld => HT32F52342.ld} | 4 ++-- .../ARMCMx/compilers/GCC/ld/{HT32F5235x.ld => HT32F52352.ld} | 4 ++-- .../ld/{HT32F523xx_rules_code.ld => HT32F523x2_rules_code.ld} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename os/common/startup/ARMCMx/compilers/GCC/ld/{HT32F5234x.ld => HT32F52342.ld} (98%) rename os/common/startup/ARMCMx/compilers/GCC/ld/{HT32F5235x.ld => HT32F52352.ld} (98%) rename os/common/startup/ARMCMx/compilers/GCC/ld/{HT32F523xx_rules_code.ld => HT32F523x2_rules_code.ld} (100%) diff --git a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F5234x.ld b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F52342.ld similarity index 98% rename from os/common/startup/ARMCMx/compilers/GCC/ld/HT32F5234x.ld rename to os/common/startup/ARMCMx/compilers/GCC/ld/HT32F52342.ld index 7a85a29c69..9cdca3ed2d 100644 --- a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F5234x.ld +++ b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F52342.ld @@ -23,7 +23,7 @@ /* - * HT32F5234x memory setup + * HT32F52342 memory setup */ MEMORY { @@ -93,7 +93,7 @@ REGION_ALIAS("HEAP_RAM", ram0); INCLUDE rules_stacks.ld /* Code rules inclusion.*/ -INCLUDE HT32F523xx_rules_code.ld +INCLUDE HT32F523x2_rules_code.ld /* Data rules inclusion.*/ INCLUDE rules_data.ld diff --git a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F5235x.ld b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F52352.ld similarity index 98% rename from os/common/startup/ARMCMx/compilers/GCC/ld/HT32F5235x.ld rename to os/common/startup/ARMCMx/compilers/GCC/ld/HT32F52352.ld index 4cba8957f2..920fb770b6 100644 --- a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F5235x.ld +++ b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F52352.ld @@ -23,7 +23,7 @@ /* - * HT32F5235x memory setup + * HT32F52352 memory setup */ MEMORY { @@ -93,7 +93,7 @@ REGION_ALIAS("HEAP_RAM", ram0); INCLUDE rules_stacks.ld /* Code rules inclusion.*/ -INCLUDE HT32F523xx_rules_code.ld +INCLUDE HT32F523x2_rules_code.ld /* Data rules inclusion.*/ INCLUDE rules_data.ld diff --git a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F523xx_rules_code.ld b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F523x2_rules_code.ld similarity index 100% rename from os/common/startup/ARMCMx/compilers/GCC/ld/HT32F523xx_rules_code.ld rename to os/common/startup/ARMCMx/compilers/GCC/ld/HT32F523x2_rules_code.ld From 4f359bd741919aa98bf0e6c3046bb4d731d041e5 Mon Sep 17 00:00:00 2001 From: Hansem Ro Date: Sat, 4 May 2024 18:44:32 -0700 Subject: [PATCH 2/6] HT32: Add GCC/ld scripts for HT32F1655 and HT32F1656 --- .../ARMCMx/compilers/GCC/ld/HT32F1655.ld | 93 +++++++++++++++++++ .../ARMCMx/compilers/GCC/ld/HT32F1656.ld | 93 +++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1655.ld create mode 100644 os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1656.ld diff --git a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1655.ld b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1655.ld new file mode 100644 index 0000000000..ff32eecc29 --- /dev/null +++ b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1655.ld @@ -0,0 +1,93 @@ +/* + * Copyright (C) Yaotian Feng, http://github.com/Codetector1374 + * codetector@codetector.cn + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +/* + * HT32F1655 memory setup + */ + +MEMORY { + flash0 : org = 0x00000000, len = 128k + flash1 : org = 0x00000000, len = 0 + flash2 : org = 0x00000000, len = 0 + flash3 : org = 0x00000000, len = 0 + flash4 : org = 0x00000000, len = 0 + flash5 : org = 0x00000000, len = 0 + flash6 : org = 0x00000000, len = 0 + flash7 : org = 0x00000000, len = 0 + ram0 : org = 0x20000000, len = 32k + ram1 : org = 0x00000000, len = 0 + ram2 : org = 0x00000000, len = 0 + ram3 : org = 0x00000000, len = 0 + ram4 : org = 0x00000000, len = 0 + ram5 : org = 0x00000000, len = 0 + ram6 : org = 0x00000000, len = 0 + ram7 : org = 0x00000000, len = 0 +} + +/* For each data/text section two region are defined, a virtual region + and a load region (_LMA suffix).*/ + +/* Flash region to be used for exception vectors.*/ +REGION_ALIAS("VECTORS_FLASH", flash0); +REGION_ALIAS("VECTORS_FLASH_LMA", flash0); + +/* Flash region to be used for constructors and destructors.*/ +REGION_ALIAS("XTORS_FLASH", flash0); +REGION_ALIAS("XTORS_FLASH_LMA", flash0); + +/* Flash region to be used for code text.*/ +REGION_ALIAS("TEXT_FLASH", flash0); +REGION_ALIAS("TEXT_FLASH_LMA", flash0); + +/* Flash region to be used for read only data.*/ +REGION_ALIAS("RODATA_FLASH", flash0); +REGION_ALIAS("RODATA_FLASH_LMA", flash0); + +/* Flash region to be used for various.*/ +REGION_ALIAS("VARIOUS_FLASH", flash0); +REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); + +/* Flash region to be used for RAM(n) initialization data.*/ +REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); + +/* RAM region to be used for Main stack. This stack accommodates the processing + of all exceptions and interrupts.*/ +REGION_ALIAS("MAIN_STACK_RAM", ram0); + +/* RAM region to be used for the process stack. This is the stack used by + the main() function.*/ +REGION_ALIAS("PROCESS_STACK_RAM", ram0); + +/* RAM region to be used for data segment.*/ +REGION_ALIAS("DATA_RAM", ram0); +REGION_ALIAS("DATA_RAM_LMA", flash0); + +/* RAM region to be used for BSS segment.*/ +REGION_ALIAS("BSS_RAM", ram0); + +/* RAM region to be used for the default heap.*/ +REGION_ALIAS("HEAP_RAM", ram0); + +/* Generic rules inclusion.*/ +INCLUDE rules.ld diff --git a/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1656.ld b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1656.ld new file mode 100644 index 0000000000..3800ec827d --- /dev/null +++ b/os/common/startup/ARMCMx/compilers/GCC/ld/HT32F1656.ld @@ -0,0 +1,93 @@ +/* + * Copyright (C) Yaotian Feng, http://github.com/Codetector1374 + * codetector@codetector.cn + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +/* + * HT32F1656 memory setup + */ + +MEMORY { + flash0 : org = 0x00000000, len = 255k + flash1 : org = 0x00000000, len = 0 + flash2 : org = 0x00000000, len = 0 + flash3 : org = 0x00000000, len = 0 + flash4 : org = 0x00000000, len = 0 + flash5 : org = 0x00000000, len = 0 + flash6 : org = 0x00000000, len = 0 + flash7 : org = 0x00000000, len = 0 + ram0 : org = 0x20000000, len = 32k + ram1 : org = 0x00000000, len = 0 + ram2 : org = 0x00000000, len = 0 + ram3 : org = 0x00000000, len = 0 + ram4 : org = 0x00000000, len = 0 + ram5 : org = 0x00000000, len = 0 + ram6 : org = 0x00000000, len = 0 + ram7 : org = 0x00000000, len = 0 +} + +/* For each data/text section two region are defined, a virtual region + and a load region (_LMA suffix).*/ + +/* Flash region to be used for exception vectors.*/ +REGION_ALIAS("VECTORS_FLASH", flash0); +REGION_ALIAS("VECTORS_FLASH_LMA", flash0); + +/* Flash region to be used for constructors and destructors.*/ +REGION_ALIAS("XTORS_FLASH", flash0); +REGION_ALIAS("XTORS_FLASH_LMA", flash0); + +/* Flash region to be used for code text.*/ +REGION_ALIAS("TEXT_FLASH", flash0); +REGION_ALIAS("TEXT_FLASH_LMA", flash0); + +/* Flash region to be used for read only data.*/ +REGION_ALIAS("RODATA_FLASH", flash0); +REGION_ALIAS("RODATA_FLASH_LMA", flash0); + +/* Flash region to be used for various.*/ +REGION_ALIAS("VARIOUS_FLASH", flash0); +REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); + +/* Flash region to be used for RAM(n) initialization data.*/ +REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); + +/* RAM region to be used for Main stack. This stack accommodates the processing + of all exceptions and interrupts.*/ +REGION_ALIAS("MAIN_STACK_RAM", ram0); + +/* RAM region to be used for the process stack. This is the stack used by + the main() function.*/ +REGION_ALIAS("PROCESS_STACK_RAM", ram0); + +/* RAM region to be used for data segment.*/ +REGION_ALIAS("DATA_RAM", ram0); +REGION_ALIAS("DATA_RAM_LMA", flash0); + +/* RAM region to be used for BSS segment.*/ +REGION_ALIAS("BSS_RAM", ram0); + +/* RAM region to be used for the default heap.*/ +REGION_ALIAS("HEAP_RAM", ram0); + +/* Generic rules inclusion.*/ +INCLUDE rules.ld From b5157d3e8f6e3a3aa878f7292fb7828151d8bfc1 Mon Sep 17 00:00:00 2001 From: Hansem Ro Date: Sat, 4 May 2024 21:34:39 -0700 Subject: [PATCH 3/6] HT32: Add generic HT32F1653/4 board --- os/hal/boards/HT_HT32F1653_4/board.c | 99 ++++ os/hal/boards/HT_HT32F1653_4/board.h | 622 ++++++++++++++++++++++++++ os/hal/boards/HT_HT32F1653_4/board.mk | 9 + 3 files changed, 730 insertions(+) create mode 100644 os/hal/boards/HT_HT32F1653_4/board.c create mode 100644 os/hal/boards/HT_HT32F1653_4/board.h create mode 100644 os/hal/boards/HT_HT32F1653_4/board.mk diff --git a/os/hal/boards/HT_HT32F1653_4/board.c b/os/hal/boards/HT_HT32F1653_4/board.c new file mode 100644 index 0000000000..346d60c1d9 --- /dev/null +++ b/os/hal/boards/HT_HT32F1653_4/board.c @@ -0,0 +1,99 @@ +/* + ChibiOS - Copyright (C) 2006..2015 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. +*/ + +#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 = { + // GPIO A + .setup[0] = + { + .DIR = VAL_GPIOA_DIRCR, + .INE = VAL_GPIOA_INER, + .PU = VAL_GPIOA_PUR, + .PD = VAL_GPIOA_PDR, + .OD = VAL_GPIOA_ODR, + .DRV = VAL_GPIOA_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOA_AFCFGR0, + .CFG[1] = VAL_GPIOA_AFCFGR1, + }, + // GPIO B + .setup[1] = + { + .DIR = VAL_GPIOB_DIRCR, + .INE = VAL_GPIOB_INER, + .PU = VAL_GPIOB_PUR, + .PD = VAL_GPIOB_PDR, + .OD = VAL_GPIOB_ODR, + .DRV = VAL_GPIOB_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOB_AFCFGR0, + .CFG[1] = VAL_GPIOB_AFCFGR1, + }, + // GPIO C + .setup[2] = + { + .DIR = VAL_GPIOC_DIRCR, + .INE = VAL_GPIOC_INER, + .PU = VAL_GPIOC_PUR, + .PD = VAL_GPIOC_PDR, + .OD = VAL_GPIOC_ODR, + .DRV = VAL_GPIOC_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOC_AFCFGR0, + .CFG[1] = VAL_GPIOC_AFCFGR1, + }, + // GPIO D + .setup[3] = + { + .DIR = VAL_GPIOD_DIRCR, + .INE = VAL_GPIOD_INER, + .PU = VAL_GPIOD_PUR, + .PD = VAL_GPIOD_PDR, + .OD = VAL_GPIOD_ODR, + .DRV = VAL_GPIOD_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOD_AFCFGR0, + .CFG[1] = VAL_GPIOD_AFCFGR1, + }, + .ESSR[0] = VAL_ESSR0, + .ESSR[1] = VAL_ESSR1, +}; +#endif + +/* + * Early initialization code. + * This initialization must be performed just after stack setup and before + * any other initialization. + */ +void __early_init(void) { + ht32_clock_init(); +} + +/* + * Board-specific initialization code. + */ +void boardInit(void) {} diff --git a/os/hal/boards/HT_HT32F1653_4/board.h b/os/hal/boards/HT_HT32F1653_4/board.h new file mode 100644 index 0000000000..29f6e3cd7f --- /dev/null +++ b/os/hal/boards/HT_HT32F1653_4/board.h @@ -0,0 +1,622 @@ +/* + ChibiOS - Copyright (C) 2006..2015 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. +*/ + +#pragma once + +/* + * Setup for a Generic HT32F1653/4 board. + */ + +/* + * Board identifier. + */ +#define BOARD_HT32_F1653_4 +#define BOARD_NAME "Generic HT32F1653/4 Board" + +/* + * Board frequencies. + */ +#define HT32_LSECLK 32768 +#define HT32_HSECLK 8000000 + +/* + * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h. + */ +#define HT32F1654 + +/* + * 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_PIN13 13U +#define GPIOA_PIN14 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_PIN0 0U +#define GPIOD_PIN1 1U +#define GPIOD_PIN2 2U +#define GPIOD_PIN3 3U +#define GPIOD_PIN4 4U +#define GPIOD_PIN5 5U +#define GPIOD_PIN6 6U +#define GPIOD_PIN7 7U +#define GPIOD_PIN8 8U +#define GPIOD_PIN9 9U +#define GPIOD_PIN10 10U +#define GPIOD_PIN11 11U +#define GPIOD_PIN12 12U +#define GPIOD_PIN13 13U +#define GPIOD_PIN14 14U +#define GPIOD_PIN15 15U + +/* + * I/O ports initial setup, this configuration is established soon after reset + * in the initialization code. + * Please refer to the HT32 Reference Manual for details. + */ +#define PIN_MODE_INPUT(n) (0U << (n)) +#define PIN_MODE_OUTPUT(n) (1U << (n)) +#define PIN_INPUT_DISABLE(n) (0U << (n)) +#define PIN_INPUT_ENABLE(n) (1U << (n)) +#define PIN_PULLUP_DISABLE(n) (0U << (n)) +#define PIN_PULLUP_ENABLE(n) (1U << (n)) +#define PIN_PULLDOWN_DISABLE(n) (0U << (n)) +#define PIN_PULLDOWN_ENABLE(n) (1U << (n)) +#define PIN_ODR_PUSHPULL(n) (0U << (n)) +#define PIN_ODR_OPENDRAIN(n) (1U << (n)) +#define PIN_DRVR_4MA(n) (0U << (n)) +#define PIN_DRVR_8MA(n) (0U << (n)) +#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) + +/* + * Port A setup. + * Everything GPIO input with pull-up except: + * PA12 - AF0 - SWCLK + * PA13 - AF0 - SWDIO + */ +#define VAL_GPIOA_DIRCR (PIN_MODE_INPUT(GPIOA_PIN0) | \ + PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_INPUT(GPIOA_PIN4) | \ + PIN_MODE_INPUT(GPIOA_PIN5) | \ + PIN_MODE_INPUT(GPIOA_PIN6) | \ + PIN_MODE_INPUT(GPIOA_PIN7) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_PIN9) | \ + PIN_MODE_INPUT(GPIOA_PIN10) | \ + PIN_MODE_INPUT(GPIOA_PIN11) | \ + PIN_MODE_INPUT(GPIOA_PIN12) | \ + PIN_MODE_INPUT(GPIOA_PIN13) | \ + PIN_MODE_INPUT(GPIOA_PIN14) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) +#define VAL_GPIOA_INER (PIN_INPUT_ENABLE(GPIOA_PIN0) | \ + PIN_INPUT_ENABLE(GPIOA_PIN1) | \ + PIN_INPUT_ENABLE(GPIOA_PIN2) | \ + PIN_INPUT_ENABLE(GPIOA_PIN3) | \ + PIN_INPUT_ENABLE(GPIOA_PIN4) | \ + PIN_INPUT_ENABLE(GPIOA_PIN5) | \ + PIN_INPUT_ENABLE(GPIOA_PIN6) | \ + PIN_INPUT_ENABLE(GPIOA_PIN7) | \ + PIN_INPUT_ENABLE(GPIOA_PIN8) | \ + PIN_INPUT_ENABLE(GPIOA_PIN9) | \ + PIN_INPUT_ENABLE(GPIOA_PIN10) | \ + PIN_INPUT_ENABLE(GPIOA_PIN11) | \ + PIN_INPUT_DISABLE(GPIOA_PIN12) | \ + PIN_INPUT_DISABLE(GPIOA_PIN13) | \ + PIN_INPUT_ENABLE(GPIOA_PIN14) | \ + PIN_INPUT_ENABLE(GPIOA_PIN15)) +#define VAL_GPIOA_PUR (PIN_PULLUP_ENABLE(GPIOA_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN11) | \ + PIN_PULLUP_DISABLE(GPIOA_PIN12) | \ + PIN_PULLUP_DISABLE(GPIOA_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN15)) +#define VAL_GPIOA_PDR (PIN_PULLDOWN_DISABLE(GPIOA_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN15)) +#define VAL_GPIOA_ODR (PIN_ODR_PUSHPULL(GPIOA_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN15)) +#define VAL_GPIOA_DRVR (PIN_DRVR_4MA(GPIOA_PIN0) | \ + PIN_DRVR_4MA(GPIOA_PIN1) | \ + PIN_DRVR_4MA(GPIOA_PIN2) | \ + PIN_DRVR_4MA(GPIOA_PIN3) | \ + PIN_DRVR_4MA(GPIOA_PIN4) | \ + PIN_DRVR_4MA(GPIOA_PIN5) | \ + PIN_DRVR_4MA(GPIOA_PIN6) | \ + PIN_DRVR_4MA(GPIOA_PIN7) | \ + PIN_DRVR_4MA(GPIOA_PIN8) | \ + PIN_DRVR_4MA(GPIOA_PIN9) | \ + PIN_DRVR_4MA(GPIOA_PIN10) | \ + PIN_DRVR_4MA(GPIOA_PIN11) | \ + PIN_DRVR_4MA(GPIOA_PIN12) | \ + PIN_DRVR_4MA(GPIOA_PIN13) | \ + PIN_DRVR_4MA(GPIOA_PIN14) | \ + PIN_DRVR_4MA(GPIOA_PIN15)) +#define VAL_GPIOA_AFCFGR0 (PIN_AFIO_AF(GPIOA_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN7, AFIO_GPIO)) +#define VAL_GPIOA_AFCFGR1 (PIN_AFIO_AF(GPIOA_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN12, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOA_PIN13, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOA_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN15, AFIO_GPIO)) + +/* + * Port B setup. + * Everything GPIO input with pull-up except: + * PB12 - AF0 - USBD- + * PB13 - AF0 - USBD+ + * PB14 - AF0 - XTALIN + * PB15 - AF0 - XTALOUT + */ +#define VAL_GPIOB_DIRCR (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_INPUT(GPIOB_PIN3) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_INPUT(GPIOB_PIN6) | \ + PIN_MODE_INPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_PIN9) | \ + PIN_MODE_INPUT(GPIOB_PIN10) | \ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) +#define VAL_GPIOB_INER (PIN_INPUT_ENABLE(GPIOB_PIN0) | \ + PIN_INPUT_ENABLE(GPIOB_PIN1) | \ + PIN_INPUT_ENABLE(GPIOB_PIN2) | \ + PIN_INPUT_ENABLE(GPIOB_PIN3) | \ + PIN_INPUT_ENABLE(GPIOB_PIN4) | \ + PIN_INPUT_ENABLE(GPIOB_PIN5) | \ + PIN_INPUT_ENABLE(GPIOB_PIN6) | \ + PIN_INPUT_ENABLE(GPIOB_PIN7) | \ + PIN_INPUT_ENABLE(GPIOB_PIN8) | \ + PIN_INPUT_ENABLE(GPIOB_PIN9) | \ + PIN_INPUT_ENABLE(GPIOB_PIN10) | \ + PIN_INPUT_ENABLE(GPIOB_PIN11) | \ + PIN_INPUT_DISABLE(GPIOB_PIN12) | \ + PIN_INPUT_DISABLE(GPIOB_PIN13) | \ + PIN_INPUT_DISABLE(GPIOB_PIN14) | \ + PIN_INPUT_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_PUR (PIN_PULLUP_ENABLE(GPIOB_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN11) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN12) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN13) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN14) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_PDR (PIN_PULLDOWN_DISABLE(GPIOB_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_ODR (PIN_ODR_PUSHPULL(GPIOB_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN15)) +#define VAL_GPIOB_DRVR (PIN_DRVR_4MA(GPIOB_PIN0) | \ + PIN_DRVR_4MA(GPIOB_PIN1) | \ + PIN_DRVR_4MA(GPIOB_PIN2) | \ + PIN_DRVR_4MA(GPIOB_PIN3) | \ + PIN_DRVR_4MA(GPIOB_PIN4) | \ + PIN_DRVR_4MA(GPIOB_PIN5) | \ + PIN_DRVR_4MA(GPIOB_PIN6) | \ + PIN_DRVR_4MA(GPIOB_PIN7) | \ + PIN_DRVR_4MA(GPIOB_PIN8) | \ + PIN_DRVR_4MA(GPIOB_PIN9) | \ + PIN_DRVR_4MA(GPIOB_PIN10) | \ + PIN_DRVR_4MA(GPIOB_PIN11) | \ + PIN_DRVR_4MA(GPIOB_PIN12) | \ + PIN_DRVR_4MA(GPIOB_PIN13) | \ + PIN_DRVR_4MA(GPIOB_PIN14) | \ + PIN_DRVR_4MA(GPIOB_PIN15)) +#define VAL_GPIOB_AFCFGR0 (PIN_AFIO_AF(GPIOB_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN7, AFIO_GPIO)) +#define VAL_GPIOB_AFCFGR1 (PIN_AFIO_AF(GPIOB_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN12, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN13, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN14, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN15, AFIO_DEFAULT)) + +/* + * Port C setup. + * Everything GPIO input with pull-up + */ +#define VAL_GPIOC_DIRCR (PIN_MODE_INPUT(GPIOC_PIN0) | \ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_PIN3) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_PIN7) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_PIN10) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_PIN12) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_PIN14) | \ + PIN_MODE_INPUT(GPIOC_PIN15)) +#define VAL_GPIOC_INER (PIN_INPUT_ENABLE(GPIOC_PIN0) | \ + PIN_INPUT_ENABLE(GPIOC_PIN1) | \ + PIN_INPUT_ENABLE(GPIOC_PIN2) | \ + PIN_INPUT_ENABLE(GPIOC_PIN3) | \ + PIN_INPUT_ENABLE(GPIOC_PIN4) | \ + PIN_INPUT_ENABLE(GPIOC_PIN5) | \ + PIN_INPUT_ENABLE(GPIOC_PIN6) | \ + PIN_INPUT_ENABLE(GPIOC_PIN7) | \ + PIN_INPUT_ENABLE(GPIOC_PIN8) | \ + PIN_INPUT_ENABLE(GPIOC_PIN9) | \ + PIN_INPUT_ENABLE(GPIOC_PIN10) | \ + PIN_INPUT_ENABLE(GPIOC_PIN11) | \ + PIN_INPUT_ENABLE(GPIOC_PIN12) | \ + PIN_INPUT_ENABLE(GPIOC_PIN13) | \ + PIN_INPUT_ENABLE(GPIOC_PIN14) | \ + PIN_INPUT_ENABLE(GPIOC_PIN15)) +#define VAL_GPIOC_PUR (PIN_PULLUP_ENABLE(GPIOC_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN15)) +#define VAL_GPIOC_PDR (PIN_PULLDOWN_DISABLE(GPIOC_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN15)) +#define VAL_GPIOC_ODR (PIN_ODR_PUSHPULL(GPIOC_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN15)) +#define VAL_GPIOC_DRVR (PIN_DRVR_4MA(GPIOC_PIN0) | \ + PIN_DRVR_4MA(GPIOC_PIN1) | \ + PIN_DRVR_4MA(GPIOC_PIN2) | \ + PIN_DRVR_4MA(GPIOC_PIN3) | \ + PIN_DRVR_4MA(GPIOC_PIN4) | \ + PIN_DRVR_4MA(GPIOC_PIN5) | \ + PIN_DRVR_4MA(GPIOC_PIN6) | \ + PIN_DRVR_4MA(GPIOC_PIN7) | \ + PIN_DRVR_4MA(GPIOC_PIN8) | \ + PIN_DRVR_4MA(GPIOC_PIN9) | \ + PIN_DRVR_4MA(GPIOC_PIN10) | \ + PIN_DRVR_4MA(GPIOC_PIN11) | \ + PIN_DRVR_4MA(GPIOC_PIN12) | \ + PIN_DRVR_4MA(GPIOC_PIN13) | \ + PIN_DRVR_4MA(GPIOC_PIN14) | \ + PIN_DRVR_4MA(GPIOC_PIN15)) +#define VAL_GPIOC_AFCFGR0 (PIN_AFIO_AF(GPIOC_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN7, AFIO_GPIO)) +#define VAL_GPIOC_AFCFGR1 (PIN_AFIO_AF(GPIOC_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN15, AFIO_GPIO)) + +/* + * Port D setup. + * Everything GPIO input with pull-up + */ +#define VAL_GPIOD_DIRCR (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_PIN4) | \ + PIN_MODE_INPUT(GPIOD_PIN5) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_PIN12) | \ + PIN_MODE_INPUT(GPIOD_PIN13) | \ + PIN_MODE_INPUT(GPIOD_PIN14) | \ + PIN_MODE_INPUT(GPIOD_PIN15)) +#define VAL_GPIOD_INER (PIN_INPUT_ENABLE(GPIOD_PIN0) | \ + PIN_INPUT_ENABLE(GPIOD_PIN1) | \ + PIN_INPUT_ENABLE(GPIOD_PIN2) | \ + PIN_INPUT_ENABLE(GPIOD_PIN3) | \ + PIN_INPUT_ENABLE(GPIOD_PIN4) | \ + PIN_INPUT_ENABLE(GPIOD_PIN5) | \ + PIN_INPUT_ENABLE(GPIOD_PIN6) | \ + PIN_INPUT_ENABLE(GPIOD_PIN7) | \ + PIN_INPUT_ENABLE(GPIOD_PIN8) | \ + PIN_INPUT_ENABLE(GPIOD_PIN9) | \ + PIN_INPUT_ENABLE(GPIOD_PIN10) | \ + PIN_INPUT_ENABLE(GPIOD_PIN11) | \ + PIN_INPUT_ENABLE(GPIOD_PIN12) | \ + PIN_INPUT_ENABLE(GPIOD_PIN13) | \ + PIN_INPUT_ENABLE(GPIOD_PIN14) | \ + PIN_INPUT_ENABLE(GPIOD_PIN15)) +#define VAL_GPIOD_PUR (PIN_PULLUP_ENABLE(GPIOD_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN15)) +#define VAL_GPIOD_PDR (PIN_PULLDOWN_DISABLE(GPIOD_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN15)) +#define VAL_GPIOD_ODR (PIN_ODR_PUSHPULL(GPIOD_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN15)) +#define VAL_GPIOD_DRVR (PIN_DRVR_4MA(GPIOD_PIN0) | \ + PIN_DRVR_4MA(GPIOD_PIN1) | \ + PIN_DRVR_4MA(GPIOD_PIN2) | \ + PIN_DRVR_4MA(GPIOD_PIN3) | \ + PIN_DRVR_4MA(GPIOD_PIN4) | \ + PIN_DRVR_4MA(GPIOD_PIN5) | \ + PIN_DRVR_4MA(GPIOD_PIN6) | \ + PIN_DRVR_4MA(GPIOD_PIN7) | \ + PIN_DRVR_4MA(GPIOD_PIN8) | \ + PIN_DRVR_4MA(GPIOD_PIN9) | \ + PIN_DRVR_4MA(GPIOD_PIN10) | \ + PIN_DRVR_4MA(GPIOD_PIN11) | \ + PIN_DRVR_4MA(GPIOD_PIN12) | \ + PIN_DRVR_4MA(GPIOD_PIN13) | \ + PIN_DRVR_4MA(GPIOD_PIN14) | \ + PIN_DRVR_4MA(GPIOD_PIN15)) +#define VAL_GPIOD_AFCFGR0 (PIN_AFIO_AF(GPIOD_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN7, AFIO_GPIO)) +#define VAL_GPIOD_AFCFGR1 (PIN_AFIO_AF(GPIOD_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN15, AFIO_GPIO)) + +/* + * EXTI setup. + */ +#define VAL_ESSR0 0x00000000 +#define VAL_ESSR1 0x00000000 + +#if !defined(_FROM_ASM_) +#ifdef __cplusplus +extern "C" { +#endif + void boardInit(void); +#ifdef __cplusplus +} +#endif +#endif /* _FROM_ASM_ */ diff --git a/os/hal/boards/HT_HT32F1653_4/board.mk b/os/hal/boards/HT_HT32F1653_4/board.mk new file mode 100644 index 0000000000..b8cfd11754 --- /dev/null +++ b/os/hal/boards/HT_HT32F1653_4/board.mk @@ -0,0 +1,9 @@ +# List of all the board related files. +BOARDSRC = $(CHIBIOS_CONTRIB)/os/hal/boards/HT_HT32F1653_4/board.c + +# Required include directories +BOARDINC = $(CHIBIOS_CONTRIB)/os/hal/boards/HT_HT32F1653_4 + +# Shared variables +ALLCSRC += $(BOARDSRC) +ALLINC += $(BOARDINC) From 1018516872d22080b30c678e1d6914d805eb0e4b Mon Sep 17 00:00:00 2001 From: Hansem Ro Date: Sat, 4 May 2024 21:34:50 -0700 Subject: [PATCH 4/6] HT32: Add generic HT32F52342/52 board --- os/hal/boards/HT_HT32F52342_52/board.c | 99 ++++ os/hal/boards/HT_HT32F52342_52/board.h | 630 ++++++++++++++++++++++++ os/hal/boards/HT_HT32F52342_52/board.mk | 9 + 3 files changed, 738 insertions(+) create mode 100644 os/hal/boards/HT_HT32F52342_52/board.c create mode 100644 os/hal/boards/HT_HT32F52342_52/board.h create mode 100644 os/hal/boards/HT_HT32F52342_52/board.mk diff --git a/os/hal/boards/HT_HT32F52342_52/board.c b/os/hal/boards/HT_HT32F52342_52/board.c new file mode 100644 index 0000000000..7c162e3eb4 --- /dev/null +++ b/os/hal/boards/HT_HT32F52342_52/board.c @@ -0,0 +1,99 @@ +/* + ChibiOS - Copyright (C) 2006..2015 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. +*/ + +#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 = { + // GPIO A + .setup[0] = + { + .DIR = VAL_GPIOA_DIRCR, + .INE = VAL_GPIOA_INER, + .PU = VAL_GPIOA_PUR, + .PD = VAL_GPIOA_PDR, + .OD = VAL_GPIOA_ODR, + .DRV = VAL_GPIOA_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOA_AFCFGR0, + .CFG[1] = VAL_GPIOA_AFCFGR1, + }, + // GPIO B + .setup[1] = + { + .DIR = VAL_GPIOB_DIRCR, + .INE = VAL_GPIOB_INER, + .PU = VAL_GPIOB_PUR, + .PD = VAL_GPIOB_PDR, + .OD = VAL_GPIOB_ODR, + .DRV = VAL_GPIOB_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOB_AFCFGR0, + .CFG[1] = VAL_GPIOB_AFCFGR1, + }, + // GPIO C + .setup[2] = + { + .DIR = VAL_GPIOC_DIRCR, + .INE = VAL_GPIOC_INER, + .PU = VAL_GPIOC_PUR, + .PD = VAL_GPIOC_PDR, + .OD = VAL_GPIOC_ODR, + .DRV = VAL_GPIOC_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOC_AFCFGR0, + .CFG[1] = VAL_GPIOC_AFCFGR1, + }, + // GPIO D + .setup[3] = + { + .DIR = VAL_GPIOD_DIRCR, + .INE = VAL_GPIOD_INER, + .PU = VAL_GPIOD_PUR, + .PD = VAL_GPIOD_PDR, + .OD = VAL_GPIOD_ODR, + .DRV = VAL_GPIOD_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOD_AFCFGR0, + .CFG[1] = VAL_GPIOD_AFCFGR1, + }, + .ESSR[0] = VAL_ESSR0, + .ESSR[1] = VAL_ESSR1, +}; +#endif + +/* + * Early initialization code. + * This initialization must be performed just after stack setup and before + * any other initialization. + */ +void __early_init(void) { + ht32_clock_init(); +} + +/* + * Board-specific initialization code. + */ +void boardInit(void) {} diff --git a/os/hal/boards/HT_HT32F52342_52/board.h b/os/hal/boards/HT_HT32F52342_52/board.h new file mode 100644 index 0000000000..bcbef1902f --- /dev/null +++ b/os/hal/boards/HT_HT32F52342_52/board.h @@ -0,0 +1,630 @@ +/* + ChibiOS - Copyright (C) 2006..2015 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. +*/ + +#pragma once + +/* + * Setup for a Generic HT32F52342/52 board. + */ + +/* + * Board identifier. + */ +#define BOARD_HT32_F52342_52 +#define BOARD_NAME "Generic HT32F52342/52 Board" + +/* + * Board frequencies. + */ +#define HT32_LSECLK 32768 +#define HT32_HSECLK 8000000 + +/* + * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h. + */ +#define HT32F52352 + +/* + * 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_PIN13 13U +#define GPIOA_PIN14 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_PIN0 0U +#define GPIOD_PIN1 1U +#define GPIOD_PIN2 2U +#define GPIOD_PIN3 3U +#define GPIOD_PIN4 4U +#define GPIOD_PIN5 5U +#define GPIOD_PIN6 6U +#define GPIOD_PIN7 7U +#define GPIOD_PIN8 8U +#define GPIOD_PIN9 9U +#define GPIOD_PIN10 10U +#define GPIOD_PIN11 11U +#define GPIOD_PIN12 12U +#define GPIOD_PIN13 13U +#define GPIOD_PIN14 14U +#define GPIOD_PIN15 15U + +/* + * I/O ports initial setup, this configuration is established soon after reset + * in the initialization code. + * Please refer to the HT32 Reference Manual for details. + */ +#define PIN_MODE_INPUT(n) (0U << (n)) +#define PIN_MODE_OUTPUT(n) (1U << (n)) +#define PIN_INPUT_DISABLE(n) (0U << (n)) +#define PIN_INPUT_ENABLE(n) (1U << (n)) +#define PIN_PULLUP_DISABLE(n) (0U << (n)) +#define PIN_PULLUP_ENABLE(n) (1U << (n)) +#define PIN_PULLDOWN_DISABLE(n) (0U << (n)) +#define PIN_PULLDOWN_ENABLE(n) (1U << (n)) +#define PIN_ODR_PUSHPULL(n) (0U << (n)) +#define PIN_ODR_OPENDRAIN(n) (1U << (n)) +#define PIN_DRVR_4MA(n) (0U << (n)) +#define PIN_DRVR_8MA(n) (0U << (n)) +#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) + +/* + * Port A setup. + * Everything GPIO input with pull-up except: + * PA12 - AF0 - SWCLK + * PA13 - AF0 - SWDIO + */ +#define VAL_GPIOA_DIRCR (PIN_MODE_INPUT(GPIOA_PIN0) | \ + PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_INPUT(GPIOA_PIN4) | \ + PIN_MODE_INPUT(GPIOA_PIN5) | \ + PIN_MODE_INPUT(GPIOA_PIN6) | \ + PIN_MODE_INPUT(GPIOA_PIN7) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_PIN9) | \ + PIN_MODE_INPUT(GPIOA_PIN10) | \ + PIN_MODE_INPUT(GPIOA_PIN11) | \ + PIN_MODE_INPUT(GPIOA_PIN12) | \ + PIN_MODE_INPUT(GPIOA_PIN13) | \ + PIN_MODE_INPUT(GPIOA_PIN14) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) +#define VAL_GPIOA_INER (PIN_INPUT_ENABLE(GPIOA_PIN0) | \ + PIN_INPUT_ENABLE(GPIOA_PIN1) | \ + PIN_INPUT_ENABLE(GPIOA_PIN2) | \ + PIN_INPUT_ENABLE(GPIOA_PIN3) | \ + PIN_INPUT_ENABLE(GPIOA_PIN4) | \ + PIN_INPUT_ENABLE(GPIOA_PIN5) | \ + PIN_INPUT_ENABLE(GPIOA_PIN6) | \ + PIN_INPUT_ENABLE(GPIOA_PIN7) | \ + PIN_INPUT_ENABLE(GPIOA_PIN8) | \ + PIN_INPUT_ENABLE(GPIOA_PIN9) | \ + PIN_INPUT_ENABLE(GPIOA_PIN10) | \ + PIN_INPUT_ENABLE(GPIOA_PIN11) | \ + PIN_INPUT_DISABLE(GPIOA_PIN12) | \ + PIN_INPUT_DISABLE(GPIOA_PIN13) | \ + PIN_INPUT_ENABLE(GPIOA_PIN14) | \ + PIN_INPUT_ENABLE(GPIOA_PIN15)) +#define VAL_GPIOA_PUR (PIN_PULLUP_ENABLE(GPIOA_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN11) | \ + PIN_PULLUP_DISABLE(GPIOA_PIN12) | \ + PIN_PULLUP_DISABLE(GPIOA_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN15)) +#define VAL_GPIOA_PDR (PIN_PULLDOWN_DISABLE(GPIOA_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN15)) +#define VAL_GPIOA_ODR (PIN_ODR_PUSHPULL(GPIOA_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN15)) +#define VAL_GPIOA_DRVR (PIN_DRVR_4MA(GPIOA_PIN0) | \ + PIN_DRVR_4MA(GPIOA_PIN1) | \ + PIN_DRVR_4MA(GPIOA_PIN2) | \ + PIN_DRVR_4MA(GPIOA_PIN3) | \ + PIN_DRVR_4MA(GPIOA_PIN4) | \ + PIN_DRVR_4MA(GPIOA_PIN5) | \ + PIN_DRVR_4MA(GPIOA_PIN6) | \ + PIN_DRVR_4MA(GPIOA_PIN7) | \ + PIN_DRVR_4MA(GPIOA_PIN8) | \ + PIN_DRVR_4MA(GPIOA_PIN9) | \ + PIN_DRVR_4MA(GPIOA_PIN10) | \ + PIN_DRVR_4MA(GPIOA_PIN11) | \ + PIN_DRVR_4MA(GPIOA_PIN12) | \ + PIN_DRVR_4MA(GPIOA_PIN13) | \ + PIN_DRVR_4MA(GPIOA_PIN14) | \ + PIN_DRVR_4MA(GPIOA_PIN15)) +#define VAL_GPIOA_AFCFGR0 (PIN_AFIO_AF(GPIOA_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN7, AFIO_GPIO)) +#define VAL_GPIOA_AFCFGR1 (PIN_AFIO_AF(GPIOA_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN12, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOA_PIN13, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOA_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN15, AFIO_GPIO)) + +/* + * Port B setup. + * Everything GPIO input with pull-up except: + * PB13 - AF0 - XTALIN + * PB14 - AF0 - XTALOUT + */ +#define VAL_GPIOB_DIRCR (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_INPUT(GPIOB_PIN3) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_INPUT(GPIOB_PIN6) | \ + PIN_MODE_INPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_PIN9) | \ + PIN_MODE_INPUT(GPIOB_PIN10) | \ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) +#define VAL_GPIOB_INER (PIN_INPUT_ENABLE(GPIOB_PIN0) | \ + PIN_INPUT_ENABLE(GPIOB_PIN1) | \ + PIN_INPUT_ENABLE(GPIOB_PIN2) | \ + PIN_INPUT_ENABLE(GPIOB_PIN3) | \ + PIN_INPUT_ENABLE(GPIOB_PIN4) | \ + PIN_INPUT_ENABLE(GPIOB_PIN5) | \ + PIN_INPUT_ENABLE(GPIOB_PIN6) | \ + PIN_INPUT_ENABLE(GPIOB_PIN7) | \ + PIN_INPUT_ENABLE(GPIOB_PIN8) | \ + PIN_INPUT_ENABLE(GPIOB_PIN9) | \ + PIN_INPUT_ENABLE(GPIOB_PIN10) | \ + PIN_INPUT_ENABLE(GPIOB_PIN11) | \ + PIN_INPUT_ENABLE(GPIOB_PIN12) | \ + PIN_INPUT_DISABLE(GPIOB_PIN13) | \ + PIN_INPUT_DISABLE(GPIOB_PIN14) | \ + PIN_INPUT_ENABLE(GPIOB_PIN15)) +#define VAL_GPIOB_PUR (PIN_PULLUP_ENABLE(GPIOB_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN12) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN13) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN15)) +#define VAL_GPIOB_PDR (PIN_PULLDOWN_DISABLE(GPIOB_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_ODR (PIN_ODR_PUSHPULL(GPIOB_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN15)) +#define VAL_GPIOB_DRVR (PIN_DRVR_4MA(GPIOB_PIN0) | \ + PIN_DRVR_4MA(GPIOB_PIN1) | \ + PIN_DRVR_4MA(GPIOB_PIN2) | \ + PIN_DRVR_4MA(GPIOB_PIN3) | \ + PIN_DRVR_4MA(GPIOB_PIN4) | \ + PIN_DRVR_4MA(GPIOB_PIN5) | \ + PIN_DRVR_4MA(GPIOB_PIN6) | \ + PIN_DRVR_4MA(GPIOB_PIN7) | \ + PIN_DRVR_4MA(GPIOB_PIN8) | \ + PIN_DRVR_4MA(GPIOB_PIN9) | \ + PIN_DRVR_4MA(GPIOB_PIN10) | \ + PIN_DRVR_4MA(GPIOB_PIN11) | \ + PIN_DRVR_4MA(GPIOB_PIN12) | \ + PIN_DRVR_4MA(GPIOB_PIN13) | \ + PIN_DRVR_4MA(GPIOB_PIN14) | \ + PIN_DRVR_4MA(GPIOB_PIN15)) +#define VAL_GPIOB_AFCFGR0 (PIN_AFIO_AF(GPIOB_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN7, AFIO_GPIO)) +#define VAL_GPIOB_AFCFGR1 (PIN_AFIO_AF(GPIOB_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN13, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN14, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN15, AFIO_GPIO)) + +/* + * Port C setup. + * Everything GPIO input with pull-up + * PC6 - AF0 - USBD- + * PC7 - AF0 - USBD+ + */ +#define VAL_GPIOC_DIR 0x0000 /* PC15...PC0 */ +#define VAL_GPIOC_INE 0xFF3F /* PC15...PC0 */ +#define VAL_GPIOC_PU 0xFF3F /* PC15...PC0 */ +#define VAL_GPIOC_PD 0x0000 /* PC15...PC0 */ +#define VAL_GPIOC_OD 0x0000 /* PC15...PC0 */ +#define VAL_GPIOC_DRV 0x0000 /* PC15...PC0 */ +#define VAL_GPIOC_AFCFG0 0x00111111 /* PC7...PC0 */ +#define VAL_GPIOC_AFCFG1 0x11111111 /* PC15...PC8 */ +#define VAL_GPIOC_DIRCR (PIN_MODE_INPUT(GPIOC_PIN0) | \ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_PIN3) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_PIN7) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_PIN10) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_PIN12) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_PIN14) | \ + PIN_MODE_INPUT(GPIOC_PIN15)) +#define VAL_GPIOC_INER (PIN_INPUT_ENABLE(GPIOC_PIN0) | \ + PIN_INPUT_ENABLE(GPIOC_PIN1) | \ + PIN_INPUT_ENABLE(GPIOC_PIN2) | \ + PIN_INPUT_ENABLE(GPIOC_PIN3) | \ + PIN_INPUT_ENABLE(GPIOC_PIN4) | \ + PIN_INPUT_ENABLE(GPIOC_PIN5) | \ + PIN_INPUT_DISABLE(GPIOC_PIN6) | \ + PIN_INPUT_DISABLE(GPIOC_PIN7) | \ + PIN_INPUT_ENABLE(GPIOC_PIN8) | \ + PIN_INPUT_ENABLE(GPIOC_PIN9) | \ + PIN_INPUT_ENABLE(GPIOC_PIN10) | \ + PIN_INPUT_ENABLE(GPIOC_PIN11) | \ + PIN_INPUT_ENABLE(GPIOC_PIN12) | \ + PIN_INPUT_ENABLE(GPIOC_PIN13) | \ + PIN_INPUT_ENABLE(GPIOC_PIN14) | \ + PIN_INPUT_ENABLE(GPIOC_PIN15)) +#define VAL_GPIOC_PUR (PIN_PULLUP_ENABLE(GPIOC_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN5) | \ + PIN_PULLUP_DISABLE(GPIOC_PIN6) | \ + PIN_PULLUP_DISABLE(GPIOC_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN15)) +#define VAL_GPIOC_PDR (PIN_PULLDOWN_DISABLE(GPIOC_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN15)) +#define VAL_GPIOC_ODR (PIN_ODR_PUSHPULL(GPIOC_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN15)) +#define VAL_GPIOC_DRVR (PIN_DRVR_4MA(GPIOC_PIN0) | \ + PIN_DRVR_4MA(GPIOC_PIN1) | \ + PIN_DRVR_4MA(GPIOC_PIN2) | \ + PIN_DRVR_4MA(GPIOC_PIN3) | \ + PIN_DRVR_4MA(GPIOC_PIN4) | \ + PIN_DRVR_4MA(GPIOC_PIN5) | \ + PIN_DRVR_4MA(GPIOC_PIN6) | \ + PIN_DRVR_4MA(GPIOC_PIN7) | \ + PIN_DRVR_4MA(GPIOC_PIN8) | \ + PIN_DRVR_4MA(GPIOC_PIN9) | \ + PIN_DRVR_4MA(GPIOC_PIN10) | \ + PIN_DRVR_4MA(GPIOC_PIN11) | \ + PIN_DRVR_4MA(GPIOC_PIN12) | \ + PIN_DRVR_4MA(GPIOC_PIN13) | \ + PIN_DRVR_4MA(GPIOC_PIN14) | \ + PIN_DRVR_4MA(GPIOC_PIN15)) +#define VAL_GPIOC_AFCFGR0 (PIN_AFIO_AF(GPIOC_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN6, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOC_PIN7, AFIO_DEFAULT)) +#define VAL_GPIOC_AFCFGR1 (PIN_AFIO_AF(GPIOC_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN15, AFIO_GPIO)) + +/* + * Port D setup. + * Everything GPIO input with pull-up + */ +#define VAL_GPIOD_DIRCR (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_PIN4) | \ + PIN_MODE_INPUT(GPIOD_PIN5) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_PIN12) | \ + PIN_MODE_INPUT(GPIOD_PIN13) | \ + PIN_MODE_INPUT(GPIOD_PIN14) | \ + PIN_MODE_INPUT(GPIOD_PIN15)) +#define VAL_GPIOD_INER (PIN_INPUT_ENABLE(GPIOD_PIN0) | \ + PIN_INPUT_ENABLE(GPIOD_PIN1) | \ + PIN_INPUT_ENABLE(GPIOD_PIN2) | \ + PIN_INPUT_ENABLE(GPIOD_PIN3) | \ + PIN_INPUT_ENABLE(GPIOD_PIN4) | \ + PIN_INPUT_ENABLE(GPIOD_PIN5) | \ + PIN_INPUT_ENABLE(GPIOD_PIN6) | \ + PIN_INPUT_ENABLE(GPIOD_PIN7) | \ + PIN_INPUT_ENABLE(GPIOD_PIN8) | \ + PIN_INPUT_ENABLE(GPIOD_PIN9) | \ + PIN_INPUT_ENABLE(GPIOD_PIN10) | \ + PIN_INPUT_ENABLE(GPIOD_PIN11) | \ + PIN_INPUT_ENABLE(GPIOD_PIN12) | \ + PIN_INPUT_ENABLE(GPIOD_PIN13) | \ + PIN_INPUT_ENABLE(GPIOD_PIN14) | \ + PIN_INPUT_ENABLE(GPIOD_PIN15)) +#define VAL_GPIOD_PUR (PIN_PULLUP_ENABLE(GPIOD_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN15)) +#define VAL_GPIOD_PDR (PIN_PULLDOWN_DISABLE(GPIOD_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN15)) +#define VAL_GPIOD_ODR (PIN_ODR_PUSHPULL(GPIOD_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN15)) +#define VAL_GPIOD_DRVR (PIN_DRVR_4MA(GPIOD_PIN0) | \ + PIN_DRVR_4MA(GPIOD_PIN1) | \ + PIN_DRVR_4MA(GPIOD_PIN2) | \ + PIN_DRVR_4MA(GPIOD_PIN3) | \ + PIN_DRVR_4MA(GPIOD_PIN4) | \ + PIN_DRVR_4MA(GPIOD_PIN5) | \ + PIN_DRVR_4MA(GPIOD_PIN6) | \ + PIN_DRVR_4MA(GPIOD_PIN7) | \ + PIN_DRVR_4MA(GPIOD_PIN8) | \ + PIN_DRVR_4MA(GPIOD_PIN9) | \ + PIN_DRVR_4MA(GPIOD_PIN10) | \ + PIN_DRVR_4MA(GPIOD_PIN11) | \ + PIN_DRVR_4MA(GPIOD_PIN12) | \ + PIN_DRVR_4MA(GPIOD_PIN13) | \ + PIN_DRVR_4MA(GPIOD_PIN14) | \ + PIN_DRVR_4MA(GPIOD_PIN15)) +#define VAL_GPIOD_AFCFGR0 (PIN_AFIO_AF(GPIOD_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN7, AFIO_GPIO)) +#define VAL_GPIOD_AFCFGR1 (PIN_AFIO_AF(GPIOD_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN15, AFIO_GPIO)) + +/* + * EXTI setup. + */ +#define VAL_ESSR0 0x00000000 +#define VAL_ESSR1 0x00000000 + +#if !defined(_FROM_ASM_) +#ifdef __cplusplus +extern "C" { +#endif + void boardInit(void); +#ifdef __cplusplus +} +#endif +#endif /* _FROM_ASM_ */ diff --git a/os/hal/boards/HT_HT32F52342_52/board.mk b/os/hal/boards/HT_HT32F52342_52/board.mk new file mode 100644 index 0000000000..c26f0ddfbe --- /dev/null +++ b/os/hal/boards/HT_HT32F52342_52/board.mk @@ -0,0 +1,9 @@ +# List of all the board related files. +BOARDSRC = $(CHIBIOS_CONTRIB)/os/hal/boards/HT_HT32F52342_52/board.c + +# Required include directories +BOARDINC = $(CHIBIOS_CONTRIB)/os/hal/boards/HT_HT32F52342_52 + +# Shared variables +ALLCSRC += $(BOARDSRC) +ALLINC += $(BOARDINC) From 0689ae86297ebb36c0416ee6da9e218ca8c8e030 Mon Sep 17 00:00:00 2001 From: Hansem Ro Date: Sat, 4 May 2024 22:24:30 -0700 Subject: [PATCH 5/6] HT32: Add generic HT32F1655/6 board --- os/hal/boards/HT_HT32F1655_6/board.c | 113 ++++ os/hal/boards/HT_HT32F1655_6/board.h | 757 ++++++++++++++++++++++++++ os/hal/boards/HT_HT32F1655_6/board.mk | 9 + 3 files changed, 879 insertions(+) create mode 100644 os/hal/boards/HT_HT32F1655_6/board.c create mode 100644 os/hal/boards/HT_HT32F1655_6/board.h create mode 100644 os/hal/boards/HT_HT32F1655_6/board.mk diff --git a/os/hal/boards/HT_HT32F1655_6/board.c b/os/hal/boards/HT_HT32F1655_6/board.c new file mode 100644 index 0000000000..a03581b6c6 --- /dev/null +++ b/os/hal/boards/HT_HT32F1655_6/board.c @@ -0,0 +1,113 @@ +/* + ChibiOS - Copyright (C) 2006..2015 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. +*/ + +#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 = { + // GPIO A + .setup[0] = + { + .DIR = VAL_GPIOA_DIRCR, + .INE = VAL_GPIOA_INER, + .PU = VAL_GPIOA_PUR, + .PD = VAL_GPIOA_PDR, + .OD = VAL_GPIOA_ODR, + .DRV = VAL_GPIOA_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOA_AFCFGR0, + .CFG[1] = VAL_GPIOA_AFCFGR1, + }, + // GPIO B + .setup[1] = + { + .DIR = VAL_GPIOB_DIRCR, + .INE = VAL_GPIOB_INER, + .PU = VAL_GPIOB_PUR, + .PD = VAL_GPIOB_PDR, + .OD = VAL_GPIOB_ODR, + .DRV = VAL_GPIOB_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOB_AFCFGR0, + .CFG[1] = VAL_GPIOB_AFCFGR1, + }, + // GPIO C + .setup[2] = + { + .DIR = VAL_GPIOC_DIRCR, + .INE = VAL_GPIOC_INER, + .PU = VAL_GPIOC_PUR, + .PD = VAL_GPIOC_PDR, + .OD = VAL_GPIOC_ODR, + .DRV = VAL_GPIOC_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOC_AFCFGR0, + .CFG[1] = VAL_GPIOC_AFCFGR1, + }, + // GPIO D + .setup[3] = + { + .DIR = VAL_GPIOD_DIRCR, + .INE = VAL_GPIOD_INER, + .PU = VAL_GPIOD_PUR, + .PD = VAL_GPIOD_PDR, + .OD = VAL_GPIOD_ODR, + .DRV = VAL_GPIOD_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOD_AFCFGR0, + .CFG[1] = VAL_GPIOD_AFCFGR1, + }, + // GPIO E + .setup[4] = + { + .DIR = VAL_GPIOE_DIRCR, + .INE = VAL_GPIOE_INER, + .PU = VAL_GPIOE_PUR, + .PD = VAL_GPIOE_PDR, + .OD = VAL_GPIOE_ODR, + .DRV = VAL_GPIOE_DRVR, + .LOCK = 0x0000, + .OUT = 0x0000, + .CFG[0] = VAL_GPIOE_AFCFGR0, + .CFG[1] = VAL_GPIOE_AFCFGR1, + }, + .ESSR[0] = VAL_ESSR0, + .ESSR[1] = VAL_ESSR1, +}; +#endif + +/* + * Early initialization code. + * This initialization must be performed just after stack setup and before + * any other initialization. + */ +void __early_init(void) { + ht32_clock_init(); +} + +/* + * Board-specific initialization code. + */ +void boardInit(void) {} diff --git a/os/hal/boards/HT_HT32F1655_6/board.h b/os/hal/boards/HT_HT32F1655_6/board.h new file mode 100644 index 0000000000..fe9ec9c876 --- /dev/null +++ b/os/hal/boards/HT_HT32F1655_6/board.h @@ -0,0 +1,757 @@ +/* + ChibiOS - Copyright (C) 2006..2015 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. +*/ + +#pragma once + +/* + * Setup for a Generic HT32F1655/6 board. + */ + +/* + * Board identifier. + */ +#define BOARD_HT32_F1655_6 +#define BOARD_NAME "Generic HT32F1655/6 Board" + +/* + * Board frequencies. + */ +#define HT32_LSECLK 32768 +#define HT32_HSECLK 8000000 + +/* + * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h. + */ +#define HT32F1656 + +/* + * 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_PIN13 13U +#define GPIOA_PIN14 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_PIN0 0U +#define GPIOD_PIN1 1U +#define GPIOD_PIN2 2U +#define GPIOD_PIN3 3U +#define GPIOD_PIN4 4U +#define GPIOD_PIN5 5U +#define GPIOD_PIN6 6U +#define GPIOD_PIN7 7U +#define GPIOD_PIN8 8U +#define GPIOD_PIN9 9U +#define GPIOD_PIN10 10U +#define GPIOD_PIN11 11U +#define GPIOD_PIN12 12U +#define GPIOD_PIN13 13U +#define GPIOD_PIN14 14U +#define GPIOD_PIN15 15U + +#define GPIOE_PIN0 0U +#define GPIOE_PIN1 1U +#define GPIOE_PIN2 2U +#define GPIOE_PIN3 3U +#define GPIOE_PIN4 4U +#define GPIOE_PIN5 5U +#define GPIOE_PIN6 6U +#define GPIOE_PIN7 7U +#define GPIOE_PIN8 8U +#define GPIOE_PIN9 9U +#define GPIOE_PIN10 10U +#define GPIOE_PIN11 11U +#define GPIOE_PIN12 12U +#define GPIOE_PIN13 13U +#define GPIOE_PIN14 14U +#define GPIOE_PIN15 15U + +/* + * I/O ports initial setup, this configuration is established soon after reset + * in the initialization code. + * Please refer to the HT32 Reference Manual for details. + */ +#define PIN_MODE_INPUT(n) (0U << (n)) +#define PIN_MODE_OUTPUT(n) (1U << (n)) +#define PIN_INPUT_DISABLE(n) (0U << (n)) +#define PIN_INPUT_ENABLE(n) (1U << (n)) +#define PIN_PULLUP_DISABLE(n) (0U << (n)) +#define PIN_PULLUP_ENABLE(n) (1U << (n)) +#define PIN_PULLDOWN_DISABLE(n) (0U << (n)) +#define PIN_PULLDOWN_ENABLE(n) (1U << (n)) +#define PIN_ODR_PUSHPULL(n) (0U << (n)) +#define PIN_ODR_OPENDRAIN(n) (1U << (n)) +#define PIN_DRVR_4MA(n) (0U << (n)) +#define PIN_DRVR_8MA(n) (0U << (n)) +#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) + +/* + * Port A setup. + * Everything GPIO input with pull-up except: + * PA12 - AF0 - SWCLK + * PA13 - AF0 - SWDIO + */ +#define VAL_GPIOA_DIRCR (PIN_MODE_INPUT(GPIOA_PIN0) | \ + PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_INPUT(GPIOA_PIN4) | \ + PIN_MODE_INPUT(GPIOA_PIN5) | \ + PIN_MODE_INPUT(GPIOA_PIN6) | \ + PIN_MODE_INPUT(GPIOA_PIN7) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_PIN9) | \ + PIN_MODE_INPUT(GPIOA_PIN10) | \ + PIN_MODE_INPUT(GPIOA_PIN11) | \ + PIN_MODE_INPUT(GPIOA_PIN12) | \ + PIN_MODE_INPUT(GPIOA_PIN13) | \ + PIN_MODE_INPUT(GPIOA_PIN14) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) +#define VAL_GPIOA_INER (PIN_INPUT_ENABLE(GPIOA_PIN0) | \ + PIN_INPUT_ENABLE(GPIOA_PIN1) | \ + PIN_INPUT_ENABLE(GPIOA_PIN2) | \ + PIN_INPUT_ENABLE(GPIOA_PIN3) | \ + PIN_INPUT_ENABLE(GPIOA_PIN4) | \ + PIN_INPUT_ENABLE(GPIOA_PIN5) | \ + PIN_INPUT_ENABLE(GPIOA_PIN6) | \ + PIN_INPUT_ENABLE(GPIOA_PIN7) | \ + PIN_INPUT_ENABLE(GPIOA_PIN8) | \ + PIN_INPUT_ENABLE(GPIOA_PIN9) | \ + PIN_INPUT_ENABLE(GPIOA_PIN10) | \ + PIN_INPUT_ENABLE(GPIOA_PIN11) | \ + PIN_INPUT_DISABLE(GPIOA_PIN12) | \ + PIN_INPUT_DISABLE(GPIOA_PIN13) | \ + PIN_INPUT_ENABLE(GPIOA_PIN14) | \ + PIN_INPUT_ENABLE(GPIOA_PIN15)) +#define VAL_GPIOA_PUR (PIN_PULLUP_ENABLE(GPIOA_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN11) | \ + PIN_PULLUP_DISABLE(GPIOA_PIN12) | \ + PIN_PULLUP_DISABLE(GPIOA_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOA_PIN15)) +#define VAL_GPIOA_PDR (PIN_PULLDOWN_DISABLE(GPIOA_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOA_PIN15)) +#define VAL_GPIOA_ODR (PIN_ODR_PUSHPULL(GPIOA_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOA_PIN15)) +#define VAL_GPIOA_DRVR (PIN_DRVR_4MA(GPIOA_PIN0) | \ + PIN_DRVR_4MA(GPIOA_PIN1) | \ + PIN_DRVR_4MA(GPIOA_PIN2) | \ + PIN_DRVR_4MA(GPIOA_PIN3) | \ + PIN_DRVR_4MA(GPIOA_PIN4) | \ + PIN_DRVR_4MA(GPIOA_PIN5) | \ + PIN_DRVR_4MA(GPIOA_PIN6) | \ + PIN_DRVR_4MA(GPIOA_PIN7) | \ + PIN_DRVR_4MA(GPIOA_PIN8) | \ + PIN_DRVR_4MA(GPIOA_PIN9) | \ + PIN_DRVR_4MA(GPIOA_PIN10) | \ + PIN_DRVR_4MA(GPIOA_PIN11) | \ + PIN_DRVR_4MA(GPIOA_PIN12) | \ + PIN_DRVR_4MA(GPIOA_PIN13) | \ + PIN_DRVR_4MA(GPIOA_PIN14) | \ + PIN_DRVR_4MA(GPIOA_PIN15)) +#define VAL_GPIOA_AFCFGR0 (PIN_AFIO_AF(GPIOA_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN7, AFIO_GPIO)) +#define VAL_GPIOA_AFCFGR1 (PIN_AFIO_AF(GPIOA_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN12, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOA_PIN13, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOA_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOA_PIN15, AFIO_GPIO)) + +/* + * Port B setup. + * Everything GPIO input with pull-up except: + * PB12 - AF0 - USBD- + * PB13 - AF0 - USBD+ + * PB14 - AF0 - XTALIN + * PB15 - AF0 - XTALOUT + */ +#define VAL_GPIOB_DIRCR (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_INPUT(GPIOB_PIN3) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_INPUT(GPIOB_PIN6) | \ + PIN_MODE_INPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_PIN9) | \ + PIN_MODE_INPUT(GPIOB_PIN10) | \ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) +#define VAL_GPIOB_INER (PIN_INPUT_ENABLE(GPIOB_PIN0) | \ + PIN_INPUT_ENABLE(GPIOB_PIN1) | \ + PIN_INPUT_ENABLE(GPIOB_PIN2) | \ + PIN_INPUT_ENABLE(GPIOB_PIN3) | \ + PIN_INPUT_ENABLE(GPIOB_PIN4) | \ + PIN_INPUT_ENABLE(GPIOB_PIN5) | \ + PIN_INPUT_ENABLE(GPIOB_PIN6) | \ + PIN_INPUT_ENABLE(GPIOB_PIN7) | \ + PIN_INPUT_ENABLE(GPIOB_PIN8) | \ + PIN_INPUT_ENABLE(GPIOB_PIN9) | \ + PIN_INPUT_ENABLE(GPIOB_PIN10) | \ + PIN_INPUT_ENABLE(GPIOB_PIN11) | \ + PIN_INPUT_DISABLE(GPIOB_PIN12) | \ + PIN_INPUT_DISABLE(GPIOB_PIN13) | \ + PIN_INPUT_DISABLE(GPIOB_PIN14) | \ + PIN_INPUT_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_PUR (PIN_PULLUP_ENABLE(GPIOB_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOB_PIN11) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN12) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN13) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN14) | \ + PIN_PULLUP_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_PDR (PIN_PULLDOWN_DISABLE(GPIOB_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOB_PIN15)) +#define VAL_GPIOB_ODR (PIN_ODR_PUSHPULL(GPIOB_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOB_PIN15)) +#define VAL_GPIOB_DRVR (PIN_DRVR_4MA(GPIOB_PIN0) | \ + PIN_DRVR_4MA(GPIOB_PIN1) | \ + PIN_DRVR_4MA(GPIOB_PIN2) | \ + PIN_DRVR_4MA(GPIOB_PIN3) | \ + PIN_DRVR_4MA(GPIOB_PIN4) | \ + PIN_DRVR_4MA(GPIOB_PIN5) | \ + PIN_DRVR_4MA(GPIOB_PIN6) | \ + PIN_DRVR_4MA(GPIOB_PIN7) | \ + PIN_DRVR_4MA(GPIOB_PIN8) | \ + PIN_DRVR_4MA(GPIOB_PIN9) | \ + PIN_DRVR_4MA(GPIOB_PIN10) | \ + PIN_DRVR_4MA(GPIOB_PIN11) | \ + PIN_DRVR_4MA(GPIOB_PIN12) | \ + PIN_DRVR_4MA(GPIOB_PIN13) | \ + PIN_DRVR_4MA(GPIOB_PIN14) | \ + PIN_DRVR_4MA(GPIOB_PIN15)) +#define VAL_GPIOB_AFCFGR0 (PIN_AFIO_AF(GPIOB_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN7, AFIO_GPIO)) +#define VAL_GPIOB_AFCFGR1 (PIN_AFIO_AF(GPIOB_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOB_PIN12, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN13, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN14, AFIO_DEFAULT) | \ + PIN_AFIO_AF(GPIOB_PIN15, AFIO_DEFAULT)) + +/* + * Port C setup. + * Everything GPIO input with pull-up + */ +#define VAL_GPIOC_DIRCR (PIN_MODE_INPUT(GPIOC_PIN0) | \ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_PIN3) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_PIN7) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_PIN10) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_PIN12) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_PIN14) | \ + PIN_MODE_INPUT(GPIOC_PIN15)) +#define VAL_GPIOC_INER (PIN_INPUT_ENABLE(GPIOC_PIN0) | \ + PIN_INPUT_ENABLE(GPIOC_PIN1) | \ + PIN_INPUT_ENABLE(GPIOC_PIN2) | \ + PIN_INPUT_ENABLE(GPIOC_PIN3) | \ + PIN_INPUT_ENABLE(GPIOC_PIN4) | \ + PIN_INPUT_ENABLE(GPIOC_PIN5) | \ + PIN_INPUT_ENABLE(GPIOC_PIN6) | \ + PIN_INPUT_ENABLE(GPIOC_PIN7) | \ + PIN_INPUT_ENABLE(GPIOC_PIN8) | \ + PIN_INPUT_ENABLE(GPIOC_PIN9) | \ + PIN_INPUT_ENABLE(GPIOC_PIN10) | \ + PIN_INPUT_ENABLE(GPIOC_PIN11) | \ + PIN_INPUT_ENABLE(GPIOC_PIN12) | \ + PIN_INPUT_ENABLE(GPIOC_PIN13) | \ + PIN_INPUT_ENABLE(GPIOC_PIN14) | \ + PIN_INPUT_ENABLE(GPIOC_PIN15)) +#define VAL_GPIOC_PUR (PIN_PULLUP_ENABLE(GPIOC_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOC_PIN15)) +#define VAL_GPIOC_PDR (PIN_PULLDOWN_DISABLE(GPIOC_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOC_PIN15)) +#define VAL_GPIOC_ODR (PIN_ODR_PUSHPULL(GPIOC_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOC_PIN15)) +#define VAL_GPIOC_DRVR (PIN_DRVR_4MA(GPIOC_PIN0) | \ + PIN_DRVR_4MA(GPIOC_PIN1) | \ + PIN_DRVR_4MA(GPIOC_PIN2) | \ + PIN_DRVR_4MA(GPIOC_PIN3) | \ + PIN_DRVR_4MA(GPIOC_PIN4) | \ + PIN_DRVR_4MA(GPIOC_PIN5) | \ + PIN_DRVR_4MA(GPIOC_PIN6) | \ + PIN_DRVR_4MA(GPIOC_PIN7) | \ + PIN_DRVR_4MA(GPIOC_PIN8) | \ + PIN_DRVR_4MA(GPIOC_PIN9) | \ + PIN_DRVR_4MA(GPIOC_PIN10) | \ + PIN_DRVR_4MA(GPIOC_PIN11) | \ + PIN_DRVR_4MA(GPIOC_PIN12) | \ + PIN_DRVR_4MA(GPIOC_PIN13) | \ + PIN_DRVR_4MA(GPIOC_PIN14) | \ + PIN_DRVR_4MA(GPIOC_PIN15)) +#define VAL_GPIOC_AFCFGR0 (PIN_AFIO_AF(GPIOC_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN7, AFIO_GPIO)) +#define VAL_GPIOC_AFCFGR1 (PIN_AFIO_AF(GPIOC_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOC_PIN15, AFIO_GPIO)) + +/* + * Port D setup. + * Everything GPIO input with pull-up + */ +#define VAL_GPIOD_DIRCR (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_PIN4) | \ + PIN_MODE_INPUT(GPIOD_PIN5) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_PIN12) | \ + PIN_MODE_INPUT(GPIOD_PIN13) | \ + PIN_MODE_INPUT(GPIOD_PIN14) | \ + PIN_MODE_INPUT(GPIOD_PIN15)) +#define VAL_GPIOD_INER (PIN_INPUT_ENABLE(GPIOD_PIN0) | \ + PIN_INPUT_ENABLE(GPIOD_PIN1) | \ + PIN_INPUT_ENABLE(GPIOD_PIN2) | \ + PIN_INPUT_ENABLE(GPIOD_PIN3) | \ + PIN_INPUT_ENABLE(GPIOD_PIN4) | \ + PIN_INPUT_ENABLE(GPIOD_PIN5) | \ + PIN_INPUT_ENABLE(GPIOD_PIN6) | \ + PIN_INPUT_ENABLE(GPIOD_PIN7) | \ + PIN_INPUT_ENABLE(GPIOD_PIN8) | \ + PIN_INPUT_ENABLE(GPIOD_PIN9) | \ + PIN_INPUT_ENABLE(GPIOD_PIN10) | \ + PIN_INPUT_ENABLE(GPIOD_PIN11) | \ + PIN_INPUT_ENABLE(GPIOD_PIN12) | \ + PIN_INPUT_ENABLE(GPIOD_PIN13) | \ + PIN_INPUT_ENABLE(GPIOD_PIN14) | \ + PIN_INPUT_ENABLE(GPIOD_PIN15)) +#define VAL_GPIOD_PUR (PIN_PULLUP_ENABLE(GPIOD_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOD_PIN15)) +#define VAL_GPIOD_PDR (PIN_PULLDOWN_DISABLE(GPIOD_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOD_PIN15)) +#define VAL_GPIOD_ODR (PIN_ODR_PUSHPULL(GPIOD_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOD_PIN15)) +#define VAL_GPIOD_DRVR (PIN_DRVR_4MA(GPIOD_PIN0) | \ + PIN_DRVR_4MA(GPIOD_PIN1) | \ + PIN_DRVR_4MA(GPIOD_PIN2) | \ + PIN_DRVR_4MA(GPIOD_PIN3) | \ + PIN_DRVR_4MA(GPIOD_PIN4) | \ + PIN_DRVR_4MA(GPIOD_PIN5) | \ + PIN_DRVR_4MA(GPIOD_PIN6) | \ + PIN_DRVR_4MA(GPIOD_PIN7) | \ + PIN_DRVR_4MA(GPIOD_PIN8) | \ + PIN_DRVR_4MA(GPIOD_PIN9) | \ + PIN_DRVR_4MA(GPIOD_PIN10) | \ + PIN_DRVR_4MA(GPIOD_PIN11) | \ + PIN_DRVR_4MA(GPIOD_PIN12) | \ + PIN_DRVR_4MA(GPIOD_PIN13) | \ + PIN_DRVR_4MA(GPIOD_PIN14) | \ + PIN_DRVR_4MA(GPIOD_PIN15)) +#define VAL_GPIOD_AFCFGR0 (PIN_AFIO_AF(GPIOD_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN7, AFIO_GPIO)) +#define VAL_GPIOD_AFCFGR1 (PIN_AFIO_AF(GPIOD_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOD_PIN15, AFIO_GPIO)) + +/* + * Port E setup. + * Everything GPIO input with pull-up + */ +#define VAL_GPIOE_DIRCR (PIN_MODE_INPUT(GPIOE_PIN0) | \ + PIN_MODE_INPUT(GPIOE_PIN1) | \ + PIN_MODE_INPUT(GPIOE_PIN2) | \ + PIN_MODE_INPUT(GPIOE_PIN3) | \ + PIN_MODE_INPUT(GPIOE_PIN4) | \ + PIN_MODE_INPUT(GPIOE_PIN5) | \ + PIN_MODE_INPUT(GPIOE_PIN6) | \ + PIN_MODE_INPUT(GPIOE_PIN7) | \ + PIN_MODE_INPUT(GPIOE_PIN8) | \ + PIN_MODE_INPUT(GPIOE_PIN9) | \ + PIN_MODE_INPUT(GPIOE_PIN10) | \ + PIN_MODE_INPUT(GPIOE_PIN11) | \ + PIN_MODE_INPUT(GPIOE_PIN12) | \ + PIN_MODE_INPUT(GPIOE_PIN13) | \ + PIN_MODE_INPUT(GPIOE_PIN14) | \ + PIN_MODE_INPUT(GPIOE_PIN15)) +#define VAL_GPIOE_INER (PIN_INPUT_ENABLE(GPIOE_PIN0) | \ + PIN_INPUT_ENABLE(GPIOE_PIN1) | \ + PIN_INPUT_ENABLE(GPIOE_PIN2) | \ + PIN_INPUT_ENABLE(GPIOE_PIN3) | \ + PIN_INPUT_ENABLE(GPIOE_PIN4) | \ + PIN_INPUT_ENABLE(GPIOE_PIN5) | \ + PIN_INPUT_ENABLE(GPIOE_PIN6) | \ + PIN_INPUT_ENABLE(GPIOE_PIN7) | \ + PIN_INPUT_ENABLE(GPIOE_PIN8) | \ + PIN_INPUT_ENABLE(GPIOE_PIN9) | \ + PIN_INPUT_ENABLE(GPIOE_PIN10) | \ + PIN_INPUT_ENABLE(GPIOE_PIN11) | \ + PIN_INPUT_ENABLE(GPIOE_PIN12) | \ + PIN_INPUT_ENABLE(GPIOE_PIN13) | \ + PIN_INPUT_ENABLE(GPIOE_PIN14) | \ + PIN_INPUT_ENABLE(GPIOE_PIN15)) +#define VAL_GPIOE_PUR (PIN_PULLUP_ENABLE(GPIOE_PIN0) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN1) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN2) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN3) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN4) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN5) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN6) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN7) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN8) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN9) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN10) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN11) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN12) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN13) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN14) | \ + PIN_PULLUP_ENABLE(GPIOE_PIN15)) +#define VAL_GPIOE_PDR (PIN_PULLDOWN_DISABLE(GPIOE_PIN0) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN1) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN2) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN3) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN4) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN5) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN6) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN7) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN8) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN9) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN10) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN11) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN12) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN13) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN14) | \ + PIN_PULLDOWN_DISABLE(GPIOE_PIN15)) +#define VAL_GPIOE_ODR (PIN_ODR_PUSHPULL(GPIOE_PIN0) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN1) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN2) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN3) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN4) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN5) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN6) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN7) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN8) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN9) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN10) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN11) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN12) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN13) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN14) | \ + PIN_ODR_PUSHPULL(GPIOE_PIN15)) +#define VAL_GPIOE_DRVR (PIN_DRVR_4MA(GPIOE_PIN0) | \ + PIN_DRVR_4MA(GPIOE_PIN1) | \ + PIN_DRVR_4MA(GPIOE_PIN2) | \ + PIN_DRVR_4MA(GPIOE_PIN3) | \ + PIN_DRVR_4MA(GPIOE_PIN4) | \ + PIN_DRVR_4MA(GPIOE_PIN5) | \ + PIN_DRVR_4MA(GPIOE_PIN6) | \ + PIN_DRVR_4MA(GPIOE_PIN7) | \ + PIN_DRVR_4MA(GPIOE_PIN8) | \ + PIN_DRVR_4MA(GPIOE_PIN9) | \ + PIN_DRVR_4MA(GPIOE_PIN10) | \ + PIN_DRVR_4MA(GPIOE_PIN11) | \ + PIN_DRVR_4MA(GPIOE_PIN12) | \ + PIN_DRVR_4MA(GPIOE_PIN13) | \ + PIN_DRVR_4MA(GPIOE_PIN14) | \ + PIN_DRVR_4MA(GPIOE_PIN15)) +#define VAL_GPIOE_AFCFGR0 (PIN_AFIO_AF(GPIOE_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN1, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN2, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN3, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN4, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN5, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN6, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN7, AFIO_GPIO)) +#define VAL_GPIOE_AFCFGR1 (PIN_AFIO_AF(GPIOE_PIN0, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN8, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN9, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN10, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN11, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN12, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN13, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN14, AFIO_GPIO) | \ + PIN_AFIO_AF(GPIOE_PIN15, AFIO_GPIO)) + +/* + * EXTI setup. + */ +#define VAL_ESSR0 0x00000000 +#define VAL_ESSR1 0x00000000 + +#if !defined(_FROM_ASM_) +#ifdef __cplusplus +extern "C" { +#endif + void boardInit(void); +#ifdef __cplusplus +} +#endif +#endif /* _FROM_ASM_ */ diff --git a/os/hal/boards/HT_HT32F1655_6/board.mk b/os/hal/boards/HT_HT32F1655_6/board.mk new file mode 100644 index 0000000000..96ce816866 --- /dev/null +++ b/os/hal/boards/HT_HT32F1655_6/board.mk @@ -0,0 +1,9 @@ +# List of all the board related files. +BOARDSRC = $(CHIBIOS_CONTRIB)/os/hal/boards/HT_HT32F1655_6/board.c + +# Required include directories +BOARDINC = $(CHIBIOS_CONTRIB)/os/hal/boards/HT_HT32F1655_6 + +# Shared variables +ALLCSRC += $(BOARDSRC) +ALLINC += $(BOARDINC) From 8a560acd96fcb3561ae972ca003d28a277038df0 Mon Sep 17 00:00:00 2001 From: Hansem Ro Date: Tue, 7 May 2024 00:17:46 -0700 Subject: [PATCH 6/6] HT32: fix PIN_DRVR_8MA macro --- os/hal/boards/HT_HT32F1653_4/board.h | 2 +- os/hal/boards/HT_HT32F1655_6/board.h | 2 +- os/hal/boards/HT_HT32F52342_52/board.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/os/hal/boards/HT_HT32F1653_4/board.h b/os/hal/boards/HT_HT32F1653_4/board.h index 29f6e3cd7f..b414dc3cba 100644 --- a/os/hal/boards/HT_HT32F1653_4/board.h +++ b/os/hal/boards/HT_HT32F1653_4/board.h @@ -124,7 +124,7 @@ #define PIN_ODR_PUSHPULL(n) (0U << (n)) #define PIN_ODR_OPENDRAIN(n) (1U << (n)) #define PIN_DRVR_4MA(n) (0U << (n)) -#define PIN_DRVR_8MA(n) (0U << (n)) +#define PIN_DRVR_8MA(n) (1U << (n)) #define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) /* diff --git a/os/hal/boards/HT_HT32F1655_6/board.h b/os/hal/boards/HT_HT32F1655_6/board.h index fe9ec9c876..52ef5709d4 100644 --- a/os/hal/boards/HT_HT32F1655_6/board.h +++ b/os/hal/boards/HT_HT32F1655_6/board.h @@ -141,7 +141,7 @@ #define PIN_ODR_PUSHPULL(n) (0U << (n)) #define PIN_ODR_OPENDRAIN(n) (1U << (n)) #define PIN_DRVR_4MA(n) (0U << (n)) -#define PIN_DRVR_8MA(n) (0U << (n)) +#define PIN_DRVR_8MA(n) (1U << (n)) #define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) /* diff --git a/os/hal/boards/HT_HT32F52342_52/board.h b/os/hal/boards/HT_HT32F52342_52/board.h index bcbef1902f..2cca557957 100644 --- a/os/hal/boards/HT_HT32F52342_52/board.h +++ b/os/hal/boards/HT_HT32F52342_52/board.h @@ -124,7 +124,7 @@ #define PIN_ODR_PUSHPULL(n) (0U << (n)) #define PIN_ODR_OPENDRAIN(n) (1U << (n)) #define PIN_DRVR_4MA(n) (0U << (n)) -#define PIN_DRVR_8MA(n) (0U << (n)) +#define PIN_DRVR_8MA(n) (1U << (n)) #define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) /*