boards/arm/ht32f491x3: add ESK32 board support

Add the ESK32 board with nsh configuration, linker script,
board bring-up, flashing helper, and user LED support.

Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
This commit is contained in:
Felipe Moura
2026-03-25 08:19:45 -03:00
committed by Xiang Xiao
parent ba6ee9d559
commit 41c53e7fdc
13 changed files with 893 additions and 0 deletions
+11
View File
@@ -3481,6 +3481,13 @@ config ARCH_BOARD_AT32F437_MINI
---help---
AT32F437-MINI board based on the Artery AT32F437VMT7 MCU.
config ARCH_BOARD_ESK32
bool "ESK32 board"
depends on ARCH_CHIP_HT32F49163
select ARCH_HAVE_LEDS
---help---
ESK32 board based on the Holtek HT32F49163 MCU.
config ARCH_BOARD_FRDM_MCXN236
bool "NXP MCXN236 CPU EVK board"
depends on ARCH_CHIP_N236
@@ -3927,6 +3934,7 @@ config ARCH_BOARD
default "hpm6360evk" if ARCH_BOARD_HPM6360EVK
default "hpm6750evk2" if ARCH_BOARD_HPM6750EVK2
default "at32f437-mini" if ARCH_BOARD_AT32F437_MINI
default "esk32" if ARCH_BOARD_ESK32
default "csk6011a-nano" if ARCH_BOARD_CSK6011A_NANO
default "frdm-mcxn236" if ARCH_BOARD_FRDM_MCXN236
@@ -5041,6 +5049,9 @@ endif
if ARCH_BOARD_AT32F437_MINI
source "boards/arm/at32/at32f437-mini/Kconfig"
endif
if ARCH_BOARD_ESK32
source "boards/arm/ht32f491x3/esk32/Kconfig"
endif
if ARCH_BOARD_CSK6011A_NANO
source "boards/arm/csk6/csk6011a-nano/Kconfig"
endif
@@ -0,0 +1,23 @@
# ##############################################################################
# boards/arm/ht32f491x3/esk32/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you 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.
#
# ##############################################################################
add_subdirectory(src)
+10
View File
@@ -0,0 +1,10 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_ESK32
comment "ESK32 note: only USART1 pin routing is available in the current board port."
endif # ARCH_BOARD_ESK32
@@ -0,0 +1,54 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_ARCH_LEDS is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="esk32"
CONFIG_ARCH_BOARD_ESK32=y
CONFIG_ARCH_CHIP="ht32f491x3"
CONFIG_ARCH_CHIP_HT32F49163=y
CONFIG_ARCH_CHIP_HT32F491X3=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_LEDS=y
CONFIG_FS_BINFS=y
CONFIG_FS_PROCFS=y
CONFIG_HT32F491X3_PCLK1_FREQUENCY=75000000
CONFIG_HT32F491X3_SYSCLK_FREQUENCY=150000000
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_LINE_MAX=64
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=49152
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_START_YEAR=2026
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_TESTING_OSTEST=y
CONFIG_TESTING_OSTEST_NBARRIER_THREADS=3
CONFIG_TESTING_OSTEST_STACKSIZE=2048
CONFIG_USART1_RXBUFSIZE=256
CONFIG_USART1_SERIAL_CONSOLE=y
CONFIG_USART1_TXBUFSIZE=256
CONFIG_USERLED=y
CONFIG_USERLED_LOWER=y
@@ -0,0 +1,95 @@
/****************************************************************************
* boards/arm/ht32f491x3/esk32/include/board.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM_HT32F491X3_ESK32_INCLUDE_BOARD_H
#define __BOARDS_ARM_HT32F491X3_ESK32_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdint.h>
/****************************************************************************
* Board USART Pin Mapping
****************************************************************************/
/* Populate BOARD_USARTx_* for each routed USART on the board. The selected
* console still comes from CONFIG_USARTx_SERIAL_CONSOLE in the defconfig.
*/
#define BOARD_USART1_GPIO_CLKEN (1u << 0)
#define BOARD_USART1_TX_GPIO_BASE 0x40020000u
#define BOARD_USART1_RX_GPIO_BASE 0x40020000u
#define BOARD_USART1_TX_PIN 9u
#define BOARD_USART1_RX_PIN 10u
#define BOARD_USART1_TX_AF 7u
#define BOARD_USART1_RX_AF 7u
/****************************************************************************
* Board LED Pin Mapping
****************************************************************************/
#define BOARD_LED2_GPIO_CLKEN (1u << 3)
#define BOARD_LED2_GPIO_BASE 0x40020c00u
#define BOARD_LED2_GPIO_PIN 13u
#define BOARD_LED3_GPIO_CLKEN (1u << 3)
#define BOARD_LED3_GPIO_BASE 0x40020c00u
#define BOARD_LED3_GPIO_PIN 14u
#define BOARD_LED4_GPIO_CLKEN (1u << 3)
#define BOARD_LED4_GPIO_BASE 0x40020c00u
#define BOARD_LED4_GPIO_PIN 15u
#define BOARD_LED2 0
#define BOARD_LED3 1
#define BOARD_LED4 2
#define BOARD_NLEDS 3
#define BOARD_LED2_BIT (1 << BOARD_LED2)
#define BOARD_LED3_BIT (1 << BOARD_LED3)
#define BOARD_LED4_BIT (1 << BOARD_LED4)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
void ht32f491x3_clockconfig(void);
void ht32f491x3_boardinitialize(void);
int board_app_initialize(uintptr_t arg);
#if defined(CONFIG_USERLED) && !defined(CONFIG_ARCH_LEDS)
uint32_t board_userled_initialize(void);
void board_userled(int led, bool ledon);
void board_userled_all(uint32_t ledset);
#endif
#ifdef CONFIG_BOARD_LATE_INITIALIZE
void board_late_initialize(void);
#endif
#endif /* __BOARDS_ARM_HT32F491X3_ESK32_INCLUDE_BOARD_H */
@@ -0,0 +1,42 @@
############################################################################
# boards/arm/ht32f491x3/esk32/scripts/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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 $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
LDSCRIPT = ld.script
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
@@ -0,0 +1,119 @@
/****************************************************************************
* boards/arm/ht32f491x3/esk32/scripts/ld.script
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/
MEMORY
{
flash (rx) : ORIGIN = 0x08000000, LENGTH = 256K
sram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
}
OUTPUT_ARCH(arm)
ENTRY(__start)
EXTERN(_vectors)
SECTIONS
{
.text :
{
_stext = ABSOLUTE(.);
*(.vectors)
*(.entry)
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > flash
.init_section :
{
_sinit = ABSOLUTE(.);
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors))
_einit = ABSOLUTE(.);
} > flash
.ARM.extab :
{
*(.ARM.extab*)
} > flash
__exidx_start = ABSOLUTE(.);
.ARM.exidx :
{
*(.ARM.exidx*)
} > flash
__exidx_end = ABSOLUTE(.);
_eronly = ABSOLUTE(.);
.data :
{
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > flash
.ram_vectors :
{
*(.ram_vectors)
} > sram
.noinit :
{
_snoinit = ABSOLUTE(.);
*(.noinit*)
_enoinit = ABSOLUTE(.);
} > sram
.bss :
{
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}
@@ -0,0 +1,35 @@
# ##############################################################################
# boards/arm/ht32f491x3/esk32/src/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you 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.
#
# ##############################################################################
set(SRCS ht32_boot.c)
if(CONFIG_BOARDCTL OR CONFIG_BOARD_LATE_INITIALIZE)
list(APPEND SRCS ht32_appinit.c)
endif()
if(CONFIG_USERLED)
list(APPEND SRCS ht32_userleds.c)
endif()
target_sources(board PRIVATE ${SRCS})
set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/ld.script")
+37
View File
@@ -0,0 +1,37 @@
############################################################################
# boards/arm/ht32f491x3/esk32/src/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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 $(TOPDIR)/Make.defs
CSRCS += ht32_boot.c
ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += ht32_appinit.c
else ifeq ($(CONFIG_BOARD_LATE_INITIALIZE),y)
CSRCS += ht32_appinit.c
endif
ifeq ($(CONFIG_USERLED),y)
CSRCS += ht32_userleds.c
endif
include $(TOPDIR)/boards/Board.mk
@@ -0,0 +1,101 @@
/****************************************************************************
* boards/arm/ht32f491x3/esk32/src/ht32_appinit.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <sys/types.h>
#include <syslog.h>
#include <arch/board/board.h>
#include <nuttx/board.h>
#include <nuttx/fs/fs.h>
#include <nuttx/leds/userled.h>
/****************************************************************************
* Private Functions
****************************************************************************/
static int ht32_bringup(void)
{
int ret = OK;
int tmp;
#if defined(CONFIG_USERLED) && !defined(CONFIG_ARCH_LEDS)
# ifdef CONFIG_USERLED_LOWER
tmp = userled_lower_initialize("/dev/userleds");
if (tmp < 0 && tmp != -EEXIST)
{
syslog(LOG_ERR, "ERROR: Failed to register /dev/userleds: %d\n", tmp);
ret = tmp;
}
# else
board_userled_initialize();
# endif
#endif
#ifdef CONFIG_FS_BINFS
tmp = nx_mount(NULL, "/bin", "binfs", 0, NULL);
if (tmp < 0 && tmp != -EBUSY)
{
syslog(LOG_ERR, "ERROR: Failed to mount binfs at /bin: %d\n", tmp);
ret = tmp;
}
#endif
#ifdef CONFIG_FS_PROCFS
tmp = nx_mount(NULL, "/proc", "procfs", 0, NULL);
if (tmp < 0 && tmp != -EBUSY)
{
syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", tmp);
ret = tmp;
}
#endif
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
(void)arg;
#ifdef CONFIG_BOARD_LATE_INITIALIZE
return OK;
#else
return ht32_bringup();
#endif
}
#ifdef CONFIG_BOARD_LATE_INITIALIZE
void board_late_initialize(void)
{
ht32_bringup();
}
#endif
+117
View File
@@ -0,0 +1,117 @@
/****************************************************************************
* boards/arm/ht32f491x3/esk32/src/ht32_boot.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdint.h>
#include <arch/board/board.h>
#include "arm_internal.h"
#include "chip.h"
#include "hardware/ht32f491x3_crm.h"
#include "hardware/ht32f491x3_flash.h"
#include "hardware/ht32f491x3_gpio.h"
#include "hardware/ht32f491x3_memorymap.h"
#include "hardware/ht32f491x3_pwc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define HT32_BOARD_HEXT_FREQUENCY 8000000u
#define HT32_BOARD_PLL_150_NS 75u
#define HT32_BOARD_PLL_150_MS 1u
/****************************************************************************
* Public Functions
****************************************************************************/
void ht32f491x3_clockconfig(void)
{
/* The ESK32 board has an 8 MHz crystal, so follow Holtek's 150 MHz
* HEXT->PLL startup sequence for this board.
*/
modifyreg32(HT32_CRM_CTRL, 0, HT32_CRM_CTRL_HICKEN);
while ((getreg32(HT32_CRM_CTRL) & HT32_CRM_CTRL_HICKSTBL) == 0)
{
}
modifyreg32(HT32_CRM_CFG, HT32_CRM_CFG_SCLKSEL_MASK,
HT32_CRM_CFG_SEL_HICK);
while ((getreg32(HT32_CRM_CFG) & HT32_CRM_CFG_SCLKSTS_MASK) !=
HT32_CRM_CFG_STS_HICK)
{
}
modifyreg32(HT32_CRM_CFG,
HT32_CRM_CFG_AHBDIV_MASK |
HT32_CRM_CFG_APB1DIV_MASK |
HT32_CRM_CFG_APB2DIV_MASK,
HT32_CRM_CFG_AHBDIV_NONE |
HT32_CRM_CFG_APB1DIV_2 |
HT32_CRM_CFG_APB2DIV_1);
putreg32(HT32_FLASH_PSR_PROGRAM(HT32_FLASH_WAIT_CYCLE_4), HT32_FLASH_PSR);
modifyreg32(HT32_CRM_APB1EN, 0, HT32_CRM_APB1EN_PWCEN);
modifyreg32(HT32_PWC_LDOOV, HT32_PWC_LDOOVSEL_MASK,
HT32_PWC_LDO_OUTPUT_1V3);
modifyreg32(HT32_CRM_CTRL, HT32_CRM_CTRL_HEXTBYPS, HT32_CRM_CTRL_HEXTEN);
while ((getreg32(HT32_CRM_CTRL) & HT32_CRM_CTRL_HEXTSTBL) == 0)
{
}
putreg32((HT32_BOARD_PLL_150_MS << HT32_CRM_PLLCFG_PLLMS_SHIFT) |
(HT32_BOARD_PLL_150_NS << HT32_CRM_PLLCFG_PLLNS_SHIFT) |
HT32_CRM_PLLCFG_FR_2 |
HT32_CRM_PLLCFG_SOURCE_HEXT,
HT32_CRM_PLLCFG);
modifyreg32(HT32_CRM_CTRL, 0, HT32_CRM_CTRL_PLLEN);
while ((getreg32(HT32_CRM_CTRL) & HT32_CRM_CTRL_PLLSTBL) == 0)
{
}
modifyreg32(HT32_CRM_MISC2, HT32_CRM_MISC2_AUTOSTEP_MASK,
HT32_CRM_MISC2_AUTOSTEP_ENABLE);
modifyreg32(HT32_CRM_CFG, HT32_CRM_CFG_SCLKSEL_MASK,
HT32_CRM_CFG_SEL_PLL);
while ((getreg32(HT32_CRM_CFG) & HT32_CRM_CFG_SCLKSTS_MASK) !=
HT32_CRM_CFG_STS_PLL)
{
}
modifyreg32(HT32_CRM_MISC2, HT32_CRM_MISC2_AUTOSTEP_MASK, 0);
}
void ht32f491x3_boardinitialize(void)
{
}
@@ -0,0 +1,106 @@
/****************************************************************************
* boards/arm/ht32f491x3/esk32/src/ht32_userleds.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdint.h>
#include <arch/board/board.h>
#include "arm_internal.h"
#include "ht32f491x3_gpio.h"
#include "hardware/ht32f491x3_crm.h"
#ifndef CONFIG_ARCH_LEDS
/****************************************************************************
* Private Types
****************************************************************************/
struct ht32_ledcfg_s
{
uint32_t clken;
uintptr_t base;
uint8_t pin;
bool active_low;
};
/****************************************************************************
* Private Data
****************************************************************************/
static const struct ht32_ledcfg_s g_ledcfg[BOARD_NLEDS] =
{
{BOARD_LED2_GPIO_CLKEN, BOARD_LED2_GPIO_BASE, BOARD_LED2_GPIO_PIN, true},
{BOARD_LED3_GPIO_CLKEN, BOARD_LED3_GPIO_BASE, BOARD_LED3_GPIO_PIN, true},
{BOARD_LED4_GPIO_CLKEN, BOARD_LED4_GPIO_BASE, BOARD_LED4_GPIO_PIN, true},
};
/****************************************************************************
* Public Functions
****************************************************************************/
uint32_t board_userled_initialize(void)
{
unsigned int i;
for (i = 0; i < BOARD_NLEDS; i++)
{
modifyreg32(HT32_CRM_AHBEN1, 0, g_ledcfg[i].clken);
ht32f491x3_gpioconfig(g_ledcfg[i].base, g_ledcfg[i].pin,
HT32_GPIO_MODE_OUTPUT, false,
HT32_GPIO_DRIVE_MEDIUM,
HT32_GPIO_PULL_NONE, 0);
ht32f491x3_gpiowrite(g_ledcfg[i].base, g_ledcfg[i].pin,
g_ledcfg[i].active_low);
}
return BOARD_NLEDS;
}
void board_userled(int led, bool ledon)
{
if (led >= 0 && led < BOARD_NLEDS)
{
ht32f491x3_gpiowrite(g_ledcfg[led].base, g_ledcfg[led].pin,
g_ledcfg[led].active_low ? !ledon : ledon);
}
}
void board_userled_all(uint32_t ledset)
{
unsigned int i;
for (i = 0; i < BOARD_NLEDS; i++)
{
board_userled(i, (ledset & (1u << i)) != 0);
}
}
#endif /* !CONFIG_ARCH_LEDS */
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env bash
############################################################################
# boards/arm/ht32f491x3/esk32/tools/flash.sh
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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.
#
############################################################################
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TOPDIR="$(cd "${SCRIPT_DIR}/../../../../.." && pwd)"
DEFAULT_BIN="${TOPDIR}/nuttx.bin"
OPENOCD_ROOT="/mnt/c/Program Files (x86)/Holtek HT32 Series/HT32-IDE/xPack/xpack-openocd-0.11.0-4"
OPENOCD_EXE="${OPENOCD_ROOT}/bin/openocd.exe"
SCRIPTS_DIR="${OPENOCD_ROOT}/scripts"
FLASH_LOADER="${OPENOCD_ROOT}/FlashLoader/HT32F491x3_256.HLM"
DEVICE_NAME="HT32F49163_100LQFP"
FLASH_BASE="0x08000000"
FLASH_END="0x0803FFFF"
SRAM_BASE="0x20000000"
WORKAREA_SIZE="0xC000"
BIN_PATH="${DEFAULT_BIN}"
DRY_RUN=0
usage() {
cat <<EOF
Usage: $0 [options]
Options:
--bin PATH Binary to flash. Default: ${DEFAULT_BIN}
--device NAME Holtek expected device name. Default: ${DEVICE_NAME}
--openocd-root DIR Holtek xPack OpenOCD root.
--dry-run Print the OpenOCD command without executing it.
--help Show this help.
Examples:
$0
$0 --dry-run
$0 --device HT32F49163_64LQFP
EOF
}
while (($# > 0)); do
case "$1" in
--bin)
BIN_PATH="$2"
shift 2
;;
--device)
DEVICE_NAME="$2"
shift 2
;;
--openocd-root)
OPENOCD_ROOT="$2"
OPENOCD_EXE="${OPENOCD_ROOT}/bin/openocd.exe"
SCRIPTS_DIR="${OPENOCD_ROOT}/scripts"
FLASH_LOADER="${OPENOCD_ROOT}/FlashLoader/HT32F491x3_256.HLM"
shift 2
;;
--dry-run)
DRY_RUN=1
shift
;;
--help|-h)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 1
;;
esac
done
if [[ "${DRY_RUN}" -eq 0 ]]; then
if [[ ! -f "${BIN_PATH}" ]]; then
echo "Binary not found: ${BIN_PATH}" >&2
exit 1
fi
if [[ ! -f "${OPENOCD_EXE}" ]]; then
echo "OpenOCD executable not found: ${OPENOCD_EXE}" >&2
exit 1
fi
if [[ ! -f "${FLASH_LOADER}" ]]; then
echo "Flash loader not found: ${FLASH_LOADER}" >&2
exit 1
fi
fi
BIN_WIN="$(wslpath -m "${BIN_PATH}")"
SCRIPTS_WIN="$(wslpath -m "${SCRIPTS_DIR}")"
LOADER_WIN="$(wslpath -m "${FLASH_LOADER}")"
OPENOCD_CMD=(
"${OPENOCD_EXE}"
-s "${SCRIPTS_WIN}"
-c "hlm_SRAM ${SRAM_BASE} ${WORKAREA_SIZE}"
-c "hlm_loader {${LOADER_WIN}} ${FLASH_BASE} ${FLASH_END}"
-c "ht_flags erase_sector"
-c "set WORKAREASIZE ${WORKAREA_SIZE}"
-f interface/htlink.cfg
-f target/HLM491x3.cfg
-c "set_expected_name ${DEVICE_NAME}"
-c "program ${BIN_WIN} verify reset exit ${FLASH_BASE}"
)
printf 'TOPDIR : %s\n' "${TOPDIR}"
printf 'Binary : %s\n' "${BIN_PATH}"
printf 'Device : %s\n' "${DEVICE_NAME}"
printf 'OpenOCD : %s\n' "${OPENOCD_EXE}"
printf 'Flash loader: %s\n' "${FLASH_LOADER}"
if [[ "${DRY_RUN}" -eq 1 ]]; then
[[ -f "${BIN_PATH}" ]] || printf 'Warning : binary not found yet\n'
[[ -f "${OPENOCD_EXE}" ]] || printf 'Warning : OpenOCD executable not found\n'
[[ -f "${FLASH_LOADER}" ]] || printf 'Warning : flash loader not found\n'
printf 'Command :'
printf ' %q' "${OPENOCD_CMD[@]}"
printf '\n'
exit 0
fi
exec "${OPENOCD_CMD[@]}"