Skip to content

Commit ba6ee9d

Browse files
FelipeMdeOxiaoxiang781216
authored andcommitted
arch/arm/ht32f491x3: add initial support
Add initial HT32F491x3 support with startup, IRQ handling, serial console, GPIO helpers, custom vectors, and CMake build files. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
1 parent 3039184 commit ba6ee9d

27 files changed

Lines changed: 3060 additions & 0 deletions

arch/arm/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,14 @@ config ARCH_CHIP_CXD32XX
779779
---help---
780780
Sony CXD32XX (ARM Cortex-M4) architectures
781781

782+
config ARCH_CHIP_HT32F491X3
783+
bool "Holtek HT32F491x3"
784+
select ARCH_CORTEXM4
785+
select ARCH_HAVE_FPU
786+
select LIBC_ARCH_ATOMIC
787+
---help---
788+
Holtek HT32F491x3 (ARM Cortex-M4) architectures
789+
782790
config ARCH_CHIP_ARM_CUSTOM
783791
bool "Custom ARM chip"
784792
select ARCH_CHIP_CUSTOM
@@ -1207,6 +1215,7 @@ config ARCH_CHIP
12071215
default "goldfish" if ARCH_CHIP_GOLDFISH_ARM
12081216
default "at32" if ARCH_CHIP_AT32
12091217
default "cxd32xx" if ARCH_CHIP_CXD32XX
1218+
default "ht32f491x3" if ARCH_CHIP_HT32F491X3
12101219
default "csk6" if ARCH_CHIP_CSK6
12111220
default "mcx-nxxx" if ARCH_CHIP_MCX_NXXX
12121221

@@ -1748,6 +1757,9 @@ endif
17481757
if ARCH_CHIP_CXD32XX
17491758
source "arch/arm/src/cxd32xx/Kconfig"
17501759
endif
1760+
if ARCH_CHIP_HT32F491X3
1761+
source "arch/arm/src/ht32f491x3/Kconfig"
1762+
endif
17511763
if ARCH_CHIP_MCX_NXXX
17521764
source "arch/arm/src/mcx-nxxx/Kconfig"
17531765
endif

arch/arm/include/ht32f491x3/chip.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/****************************************************************************
2+
* arch/arm/include/ht32f491x3/chip.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __ARCH_ARM_INCLUDE_HT32F491X3_CHIP_H
24+
#define __ARCH_ARM_INCLUDE_HT32F491X3_CHIP_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
32+
/****************************************************************************
33+
* Pre-processor Definitions
34+
****************************************************************************/
35+
36+
#define HT32M4_SYSH_PRIORITY_MIN 0xe0
37+
#define HT32M4_SYSH_PRIORITY_DEFAULT 0x80
38+
#define HT32M4_SYSH_PRIORITY_MAX 0x00
39+
#define HT32M4_SYSH_PRIORITY_STEP 0x20
40+
41+
#define NVIC_SYSH_PRIORITY_MIN HT32M4_SYSH_PRIORITY_MIN
42+
#define NVIC_SYSH_PRIORITY_DEFAULT HT32M4_SYSH_PRIORITY_DEFAULT
43+
#define NVIC_SYSH_PRIORITY_MAX HT32M4_SYSH_PRIORITY_MAX
44+
#define NVIC_SYSH_PRIORITY_STEP HT32M4_SYSH_PRIORITY_STEP
45+
46+
#if defined(CONFIG_ARCH_CHIP_HT32F49153)
47+
# define HT32_FLASH_KB 128
48+
#elif defined(CONFIG_ARCH_CHIP_HT32F49163)
49+
# define HT32_FLASH_KB 256
50+
#else
51+
# error "Unsupported HT32F491x3 device"
52+
#endif
53+
54+
#define HT32_SRAM_KB 48
55+
#define HT32_NUSART 8
56+
#define HT32_NGPIO 6
57+
58+
#define HT32_HICK_FREQUENCY 8000000
59+
#define HT32_HICK48_FREQUENCY 48000000
60+
#define HT32_HEXT_MIN_FREQUENCY 4000000
61+
#define HT32_HEXT_MAX_FREQUENCY 25000000
62+
#define HT32_PLL_MAX_FREQUENCY 150000000
63+
64+
#define HT32_SYSCLK_FREQUENCY CONFIG_HT32F491X3_SYSCLK_FREQUENCY
65+
#define HT32_HCLK_FREQUENCY HT32_SYSCLK_FREQUENCY
66+
#define HT32_PCLK1_FREQUENCY CONFIG_HT32F491X3_PCLK1_FREQUENCY
67+
#define HT32_PCLK2_FREQUENCY CONFIG_HT32F491X3_PCLK2_FREQUENCY
68+
69+
#endif /* __ARCH_ARM_INCLUDE_HT32F491X3_CHIP_H */
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/****************************************************************************
2+
* arch/arm/include/ht32f491x3/ht32f491x3_irq.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/* This file should never be included directly but, rather,
24+
* only indirectly through nuttx/irq.h
25+
*/
26+
27+
#ifndef __ARCH_ARM_INCLUDE_HT32F491X3_HT32F491X3_IRQ_H
28+
#define __ARCH_ARM_INCLUDE_HT32F491X3_HT32F491X3_IRQ_H
29+
30+
/****************************************************************************
31+
* Included Files
32+
****************************************************************************/
33+
34+
#include <nuttx/config.h>
35+
#include <nuttx/irq.h>
36+
37+
/****************************************************************************
38+
* Pre-processor Definitions
39+
****************************************************************************/
40+
41+
/* External interrupts. These values follow the Holtek CMSIS device header
42+
* and startup vector table for the HT32F491x3 family.
43+
*/
44+
45+
#define HT32_IRQ_WWDT (HT32_IRQ_FIRST + 0)
46+
#define HT32_IRQ_PVM (HT32_IRQ_FIRST + 1)
47+
#define HT32_IRQ_PVD HT32_IRQ_PVM
48+
#define HT32_IRQ_TAMP_STAMP (HT32_IRQ_FIRST + 2)
49+
#define HT32_IRQ_TAMPER HT32_IRQ_TAMP_STAMP
50+
#define HT32_IRQ_TIMESTAMP HT32_IRQ_TAMP_STAMP
51+
#define HT32_IRQ_ERTCWAKEUP (HT32_IRQ_FIRST + 3)
52+
#define HT32_IRQ_FLASH (HT32_IRQ_FIRST + 4)
53+
#define HT32_IRQ_CRM (HT32_IRQ_FIRST + 5)
54+
#define HT32_IRQ_EXINT0 (HT32_IRQ_FIRST + 6)
55+
#define HT32_IRQ_EXINT1 (HT32_IRQ_FIRST + 7)
56+
#define HT32_IRQ_EXINT2 (HT32_IRQ_FIRST + 8)
57+
#define HT32_IRQ_EXINT3 (HT32_IRQ_FIRST + 9)
58+
#define HT32_IRQ_EXINT4 (HT32_IRQ_FIRST + 10)
59+
#define HT32_IRQ_DMA1CH1 (HT32_IRQ_FIRST + 11)
60+
#define HT32_IRQ_DMA1CH2 (HT32_IRQ_FIRST + 12)
61+
#define HT32_IRQ_DMA1CH3 (HT32_IRQ_FIRST + 13)
62+
#define HT32_IRQ_DMA1CH4 (HT32_IRQ_FIRST + 14)
63+
#define HT32_IRQ_DMA1CH5 (HT32_IRQ_FIRST + 15)
64+
#define HT32_IRQ_DMA1CH6 (HT32_IRQ_FIRST + 16)
65+
#define HT32_IRQ_DMA1CH7 (HT32_IRQ_FIRST + 17)
66+
#define HT32_IRQ_ADC1 (HT32_IRQ_FIRST + 18)
67+
#define HT32_IRQ_ADC HT32_IRQ_ADC1
68+
#define HT32_IRQ_CAN1TX (HT32_IRQ_FIRST + 19)
69+
#define HT32_IRQ_CAN1RX0 (HT32_IRQ_FIRST + 20)
70+
#define HT32_IRQ_CAN1RX1 (HT32_IRQ_FIRST + 21)
71+
#define HT32_IRQ_CAN1SE (HT32_IRQ_FIRST + 22)
72+
#define HT32_IRQ_CANSE HT32_IRQ_CAN1SE
73+
#define HT32_IRQ_EXINT95 (HT32_IRQ_FIRST + 23)
74+
#define HT32_IRQ_TMR1BRK (HT32_IRQ_FIRST + 24)
75+
#define HT32_IRQ_TMR9 HT32_IRQ_TMR1BRK
76+
#define HT32_IRQ_TMR1UP (HT32_IRQ_FIRST + 25)
77+
#define HT32_IRQ_TMR10 HT32_IRQ_TMR1UP
78+
#define HT32_IRQ_TMR1TRGCOM (HT32_IRQ_FIRST + 26)
79+
#define HT32_IRQ_TMR11 HT32_IRQ_TMR1TRGCOM
80+
#define HT32_IRQ_TMR1CC (HT32_IRQ_FIRST + 27)
81+
#define HT32_IRQ_TMR2 (HT32_IRQ_FIRST + 28)
82+
#define HT32_IRQ_TMR3 (HT32_IRQ_FIRST + 29)
83+
#define HT32_IRQ_TMR4 (HT32_IRQ_FIRST + 30)
84+
#define HT32_IRQ_I2C1EV (HT32_IRQ_FIRST + 31)
85+
#define HT32_IRQ_I2C1ERR (HT32_IRQ_FIRST + 32)
86+
#define HT32_IRQ_I2C2EV (HT32_IRQ_FIRST + 33)
87+
#define HT32_IRQ_I2C2ERR (HT32_IRQ_FIRST + 34)
88+
#define HT32_IRQ_SPI1 (HT32_IRQ_FIRST + 35)
89+
#define HT32_IRQ_SPI2 (HT32_IRQ_FIRST + 36)
90+
#define HT32_IRQ_USART1 (HT32_IRQ_FIRST + 37)
91+
#define HT32_IRQ_USART2 (HT32_IRQ_FIRST + 38)
92+
#define HT32_IRQ_USART3 (HT32_IRQ_FIRST + 39)
93+
#define HT32_IRQ_EXINT1510 (HT32_IRQ_FIRST + 40)
94+
#define HT32_IRQ_ERTCALARM (HT32_IRQ_FIRST + 41)
95+
#define HT32_IRQ_OTGFSWKUP (HT32_IRQ_FIRST + 42)
96+
#define HT32_IRQ_TMR12 (HT32_IRQ_FIRST + 43)
97+
#define HT32_IRQ_TMR13 (HT32_IRQ_FIRST + 44)
98+
#define HT32_IRQ_TMR14 (HT32_IRQ_FIRST + 45)
99+
#define HT32_IRQ_SPI3 (HT32_IRQ_FIRST + 51)
100+
#define HT32_IRQ_USART4 (HT32_IRQ_FIRST + 52)
101+
#define HT32_IRQ_USART5 (HT32_IRQ_FIRST + 53)
102+
#define HT32_IRQ_TMR6 (HT32_IRQ_FIRST + 54)
103+
#define HT32_IRQ_DAC HT32_IRQ_TMR6
104+
#define HT32_IRQ_TMR7 (HT32_IRQ_FIRST + 55)
105+
#define HT32_IRQ_DMA2CH1 (HT32_IRQ_FIRST + 56)
106+
#define HT32_IRQ_DMA2CH2 (HT32_IRQ_FIRST + 57)
107+
#define HT32_IRQ_DMA2CH3 (HT32_IRQ_FIRST + 58)
108+
#define HT32_IRQ_DMA2CH4 (HT32_IRQ_FIRST + 59)
109+
#define HT32_IRQ_DMA2CH5 (HT32_IRQ_FIRST + 60)
110+
#define HT32_IRQ_CAN2TX (HT32_IRQ_FIRST + 63)
111+
#define HT32_IRQ_CAN2RX0 (HT32_IRQ_FIRST + 64)
112+
#define HT32_IRQ_CAN2RX1 (HT32_IRQ_FIRST + 65)
113+
#define HT32_IRQ_CAN2SE (HT32_IRQ_FIRST + 66)
114+
#define HT32_IRQ_OTGFS1 (HT32_IRQ_FIRST + 67)
115+
#define HT32_IRQ_OTGFS HT32_IRQ_OTGFS1
116+
#define HT32_IRQ_DMA2CH6 (HT32_IRQ_FIRST + 68)
117+
#define HT32_IRQ_DMA2CH7 (HT32_IRQ_FIRST + 69)
118+
#define HT32_IRQ_USART6 (HT32_IRQ_FIRST + 71)
119+
#define HT32_IRQ_I2C3EV (HT32_IRQ_FIRST + 72)
120+
#define HT32_IRQ_I2C3ERR (HT32_IRQ_FIRST + 73)
121+
#define HT32_IRQ_FPU (HT32_IRQ_FIRST + 81)
122+
#define HT32_IRQ_USART7 (HT32_IRQ_FIRST + 82)
123+
#define HT32_IRQ_USART8 (HT32_IRQ_FIRST + 83)
124+
#define HT32_IRQ_DMAMUX (HT32_IRQ_FIRST + 94)
125+
#define HT32_IRQ_ACC (HT32_IRQ_FIRST + 103)
126+
127+
#define HT32_IRQ_NEXTINT (104)
128+
#define NR_IRQS (HT32_IRQ_FIRST + HT32_IRQ_NEXTINT)
129+
130+
#endif /* __ARCH_ARM_INCLUDE_HT32F491X3_HT32F491X3_IRQ_H */

arch/arm/include/ht32f491x3/irq.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/****************************************************************************
2+
* arch/arm/include/ht32f491x3/irq.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/* This file should never be included directly but, rather,
24+
* only indirectly through nuttx/irq.h
25+
*/
26+
27+
#ifndef __ARCH_ARM_INCLUDE_HT32F491X3_IRQ_H
28+
#define __ARCH_ARM_INCLUDE_HT32F491X3_IRQ_H
29+
30+
/****************************************************************************
31+
* Included Files
32+
****************************************************************************/
33+
34+
#include <nuttx/config.h>
35+
#include <nuttx/irq.h>
36+
#include <arch/ht32f491x3/chip.h>
37+
38+
/****************************************************************************
39+
* Pre-processor Definitions
40+
****************************************************************************/
41+
42+
#define HT32_IRQ_RESERVED (0)
43+
#define HT32_IRQ_NMI (2)
44+
#define HT32_IRQ_HARDFAULT (3)
45+
#define HT32_IRQ_MEMFAULT (4)
46+
#define HT32_IRQ_BUSFAULT (5)
47+
#define HT32_IRQ_USAGEFAULT (6)
48+
#define HT32_IRQ_SVCALL (11)
49+
#define HT32_IRQ_DBGMONITOR (12)
50+
#define HT32_IRQ_PENDSV (14)
51+
#define HT32_IRQ_SYSTICK (15)
52+
53+
#define HT32_IRQ_FIRST (16)
54+
55+
/****************************************************************************
56+
* Included Files
57+
****************************************************************************/
58+
59+
#include <arch/ht32f491x3/ht32f491x3_irq.h>
60+
61+
#endif /* __ARCH_ARM_INCLUDE_HT32F491X3_IRQ_H */

arch/arm/src/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
############################################################################
2222

2323
include $(TOPDIR)/tools/Make.defs
24+
25+
# Allow cleanup targets to run even if the configured chip dirlink is gone.
26+
CLEAN_GOALS = clean distclean
27+
ifeq ($(strip $(MAKECMDGOALS)),)
28+
include chip/Make.defs
29+
else ifeq ($(strip $(filter-out $(CLEAN_GOALS),$(MAKECMDGOALS))),)
30+
-include chip/Make.defs
31+
else
2432
include chip/Make.defs
33+
endif
2534

2635
ifeq ($(CONFIG_ARCH_ARMV7A),y) # ARMv7-A
2736
ARCH_SUBDIR = armv7-a
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ##############################################################################
2+
# arch/arm/src/ht32f491x3/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
list(
24+
APPEND
25+
SRCS
26+
ht32f491x3_start.c
27+
ht32f491x3_irq.c
28+
ht32f491x3_timerisr.c
29+
ht32f491x3_gpio.c
30+
ht32f491x3_lowputc.c
31+
ht32f491x3_serial.c)
32+
33+
if(CONFIG_ARCH_HAVE_CUSTOM_VECTORS)
34+
list(APPEND SRCS arm_vectors.c)
35+
endif()
36+
37+
target_sources(arch PRIVATE ${SRCS})

0 commit comments

Comments
 (0)