初始版本

This commit is contained in:
2026-06-22 09:19:00 +08:00
parent 85a1478489
commit 0723faf209
240 changed files with 131805 additions and 0 deletions
+219
View File
@@ -0,0 +1,219 @@
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file hc32_common.h
**
** A detailed description is available at
** @link Hc32CommonGroup Hc32 Series Comm Part description @endlink
**
** - 2018-10-18 CDT First version for Hc32 Series of common part.
**
******************************************************************************/
#ifndef __HC32_COMMON_H__
#define __HC32_COMMON_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup Hc32CommonGroup Hc32 Series Common Part(HC32COMMON)
**
******************************************************************************/
//@{
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
/**
*******************************************************************************
** \brief single precision floating point number (4 byte)
******************************************************************************/
typedef float float32_t;
/**
*******************************************************************************
** \brief double precision floating point number (8 byte)
******************************************************************************/
typedef double float64_t;
/**
*******************************************************************************
** \brief function pointer type to void/void function
******************************************************************************/
typedef void (*func_ptr_t)(void);
/**
*******************************************************************************
** \brief function pointer type to void/uint8_t function
******************************************************************************/
typedef void (*func_ptr_arg1_t)(uint8_t);
/**
*******************************************************************************
** \brief functional state
******************************************************************************/
typedef enum en_functional_state
{
Disable = 0u,
Enable = 1u,
} en_functional_state_t;
/**
*******************************************************************************
** \brief flag status
******************************************************************************/
typedef enum en_flag_status
{
Reset = 0u,
Set = 1u,
} en_flag_status_t, en_int_status_t;
/**
*******************************************************************************
** \brief generic error codes
******************************************************************************/
typedef enum en_result
{
Ok = 0u, ///< No error
Error = 1u, ///< Non-specific error code
ErrorAddressAlignment = 2u, ///< Address alignment does not match
ErrorAccessRights = 3u, ///< Wrong mode (e.g. user/system) mode is set
ErrorInvalidParameter = 4u, ///< Provided parameter is not valid
ErrorOperationInProgress = 5u, ///< A conflicting or requested operation is still in progress
ErrorInvalidMode = 6u, ///< Operation not allowed in current mode
ErrorUninitialized = 7u, ///< Module (or part of it) was not initialized properly
ErrorBufferFull = 8u, ///< Circular buffer can not be written because the buffer is full
ErrorTimeout = 9u, ///< Time Out error occurred (e.g. I2C arbitration lost, Flash time-out, etc.)
ErrorNotReady = 10u, ///< A requested final state is not reached
OperationInProgress = 11u, ///< Indicator for operation in progress (e.g. ADC conversion not finished, DMA channel used, etc.)
} en_result_t;
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/**
*******************************************************************************
** \brief Device include
******************************************************************************/
#if defined(HC32F460)
#include "hc32f460.h"
#include "system_hc32f460.h"
#elif defined(HC32xxxx)
#include "hc32xxxx.h"
#include "system_hc32xxxx.h"
#else
#error "Please select first the target HC32xxxx device used in your application (in hc32xxxx.h file)"
#endif
/*! Weak and Align compiler definition */
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
#ifndef __WEAKDEF
#define __WEAKDEF __attribute__((weak))
#endif /* __WEAKDEF */
#ifndef __ALIGN_BEGIN
#define __ALIGN_BEGIN __attribute__((aligned (4)))
#endif /* __ALIGN_BEGIN */
#ifndef __NOINLINE
#define __NOINLINE __attribute__((noinline))
#endif /* __NOINLINE */
#ifndef __UNUSED
#define __UNUSED __attribute__((unused))
#endif /* __UNUSED */
#ifndef __RAM_FUNC
#define __RAM_FUNC __attribute__((long_call, section(".ramfunc")))
/* Usage: void __RAM_FUNC foo(void) */
#endif /* __RAM_FUNC */
#elif defined (__ICCARM__) ///< IAR Compiler
#define __WEAKDEF __weak
#define __ALIGN_BEGIN _Pragma("data_alignment=4")
#define __NOINLINE _Pragma("optimize = no_inline")
#define __UNUSED __attribute__((unused))
#define __RAM_FUNC __ramfunc
#elif defined (__CC_ARM) ///< ARM Compiler
#define __WEAKDEF __attribute__((weak))
#define __ALIGN_BEGIN __align(4)
#define __NOINLINE __attribute__((noinline))
#define __UNUSED __attribute__((unused))
/* RAM functions are defined using the toolchain options.
Functions that are executed in RAM should reside in a separate source module.
Using the 'Options for File' dialog you can simply change the 'Code / Const'
area of a module to a memory space in physical RAM. */
#define __RAM_FUNC
#else
#error "unsupported compiler!!"
#endif /* __GNUC__ */
/*! Pointer correspond to zero value */
#if !defined (NULL)
#define NULL (0)
#endif
/*! Memory clear */
#define MEM_ZERO_STRUCT(x) do { \
memset((void*)&(x), 0l, (sizeof(x))); \
}while(0)
/*! Decimal to BCD */
#define DEC2BCD(x) ((((x) / 10u) << 4u) + ((x) % 10u))
/*! BCD to decimal */
#define BCD2DEC(x) ((((x) >> 4u) * 10u) + ((x) & 0x0Fu))
/*! Returns the minimum value out of two values */
#define MIN(x, y) ((x) < (y) ? (x) : (y))
/*! Returns the maximum value out of two values */
#define MAX(x, y) ((x) > (y) ? (x) : (y))
/*! Returns the dimension of an array */
#define ARRAY_SZ(X) (sizeof((X)) / sizeof((X)[0]))
/*! Check if it is a functional state */
#define IS_FUNCTIONAL_STATE(state) (((state) == Disable) || ((state) == Enable))
#define BIT_SET(value,bit) ((value) |= (bit))
#define BIT_CLEAR(value,bit) ((value) &= ~(bit))
#define BIT_READ(value,bit) ((value) & (bit))
#define BIT_VALUE(index) (1ul << (index))
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//@} // Hc32CommonGroup
#ifdef __cplusplus
}
#endif
#endif /* __HC32_COMMON_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+267
View File
@@ -0,0 +1,267 @@
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file hc32_ddl.h
**
** A detailed description is available at
** @link Hc32DdlGroup Hc32 Series Ddl description @endlink
**
** - 2018-10-22 CDT First version for Hc32 Series Device Driver
** Library.
**
******************************************************************************/
#ifndef __HC32_DDL_H__
#define __HC32_DDL_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32_common.h"
#include "ddl_config.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup Hc32DdlGroup Hc32 Series Device Driver Library(HC32DDL)
**
******************************************************************************/
//@{
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/*! Defined use device driver library */
#if !defined (USE_DEVICE_DRIVER_LIB)
/**
*******************************************************************************
** \brief Comment the line below if you will not use the device driver library.
** In this case, the application code will be based on direct access to
** peripherals registers.
******************************************************************************/
/* #define USE_DEVICE_DRIVER_LIB */
#endif /* USE_DEVICE_DRIVER_LIB */
/**
*******************************************************************************
** \brief Hc32 Series device driver library version number
******************************************************************************/
#define HC32_DDL_VERSION_MAIN (0x02u) ///< [31:24] main version
#define HC32_DDL_VERSION_SUB1 (0x00u) ///< [23:16] sub1 version
#define HC32_DDL_VERSION_SUB2 (0x00u) ///< [15:8] sub2 version
#define HC32_DDL_VERSION_RC (0x00u) ///< [7:0] release candidate
#define HC32_DDL_VERSION ((HC32_DDL_VERSION_MAIN << 24) | \
(HC32_DDL_VERSION_SUB1 << 16) | \
(HC32_DDL_VERSION_SUB2 << 8 ) | \
(HC32_DDL_VERSION_RC))
/*! Use device driver library */
#if defined (USE_DEVICE_DRIVER_LIB)
/**
*******************************************************************************
** \brief Include module's header file
******************************************************************************/
#if (DDL_ADC_ENABLE == DDL_ON)
#include "hc32f460_adc.h"
#endif /* DDL_ADC_ENABLE */
#if (DDL_AES_ENABLE == DDL_ON)
#include "hc32f460_aes.h"
#endif /* DDL_AES_ENABLE */
#if (DDL_CAN_ENABLE == DDL_ON)
#include "hc32f460_can.h"
#endif /* DDL_CAN_ENABLE */
#if (DDL_CLK_ENABLE == DDL_ON)
#include "hc32f460_clk.h"
#endif /* DDL_CLK_ENABLE */
#if (DDL_CMP_ENABLE == DDL_ON)
#include "hc32f460_cmp.h"
#endif /* DDL_CMP_ENABLE */
#if (DDL_CRC_ENABLE == DDL_ON)
#include "hc32f460_crc.h"
#endif /* DDL_CRC_ENABLE */
#if (DDL_DCU_ENABLE == DDL_ON)
#include "hc32f460_dcu.h"
#endif /* DDL_DCU_ENABLE */
#if (DDL_DMAC_ENABLE == DDL_ON)
#include "hc32f460_dmac.h"
#endif /* DDL_DMAC_ENABLE */
#if (DDL_EFM_ENABLE == DDL_ON)
#include "hc32f460_efm.h"
#endif /* DDL_EFM_ENABLE */
#if (DDL_EMB_ENABLE == DDL_ON)
#include "hc32f460_emb.h"
#endif /* DDL_EMB_ENABLE */
#if (DDL_EVENT_PORT_ENABLE == DDL_ON)
#include "hc32f460_event_port.h"
#endif /* DDL_EVENT_PORT_ENABLE */
#if (DDL_EXINT_NMI_SWI_ENABLE == DDL_ON)
#include "hc32f460_exint_nmi_swi.h"
#endif /* DDL_EXINT_NMI_SWI_ENABLE */
#if (DDL_GPIO_ENABLE == DDL_ON)
#include "hc32f460_gpio.h"
#endif /* DDL_GPIO_ENABLE */
#if (DDL_HASH_ENABLE == DDL_ON)
#include "hc32f460_hash.h"
#endif /* DDL_HASH_ENABLE */
#if (DDL_I2C_ENABLE == DDL_ON)
#include "hc32f460_i2c.h"
#endif /* DDL_I2C_ENABLE */
#if (DDL_I2S_ENABLE == DDL_ON)
#include "hc32f460_i2s.h"
#endif /* DDL_I2S_ENABLE */
#if (DDL_ICG_ENABLE == DDL_ON)
#include "hc32f460_icg.h"
#endif /* DDL_ICG_ENABLE */
#if (DDL_INTERRUPTS_ENABLE == DDL_ON)
#include "hc32f460_interrupts.h"
#endif /* DDL_INTERRUPTS_ENABLE */
#if (DDL_KEYSCAN_ENABLE == DDL_ON)
#include "hc32f460_keyscan.h"
#endif /* DDL_KEYSCAN_ENABLE */
#if (DDL_MPU_ENABLE == DDL_ON)
#include "hc32f460_mpu.h"
#endif /* DDL_MPU_ENABLE */
#if (DDL_OTS_ENABLE == DDL_ON)
#include "hc32f460_ots.h"
#endif /* DDL_OTS_ENABLE */
#if (DDL_PWC_ENABLE == DDL_ON)
#include "hc32f460_pwc.h"
#endif /* DDL_PWC_ENABLE */
#if (DDL_QSPI_ENABLE == DDL_ON)
#include "hc32f460_qspi.h"
#endif /* DDL_QSPI_ENABLE */
#if (DDL_RMU_ENABLE == DDL_ON)
#include "hc32f460_rmu.h"
#endif /* DDL_RMU_ENABLE */
#if (DDL_RTC_ENABLE == DDL_ON)
#include "hc32f460_rtc.h"
#endif /* DDL_RTC_ENABLE */
#if (DDL_SDIOC_ENABLE == DDL_ON)
#include "hc32f460_sdioc.h"
#endif /* DDL_SDIOC_ENABLE */
#if (DDL_SPI_ENABLE == DDL_ON)
#include "hc32f460_spi.h"
#endif /* DDL_SPI_ENABLE */
#if (DDL_SRAM_ENABLE == DDL_ON)
#include "hc32f460_sram.h"
#endif /* DDL_SRAM_ENABLE */
#if (DDL_SWDT_ENABLE == DDL_ON)
#include "hc32f460_swdt.h"
#endif /* DDL_SWDT_ENABLE */
#if (DDL_TIMER0_ENABLE == DDL_ON)
#include "hc32f460_timer0.h"
#endif /* DDL_TIMER0_ENABLE */
#if (DDL_TIMER4_CNT_ENABLE == DDL_ON)
#include "hc32f460_timer4_cnt.h"
#endif /* DDL_TIMER4_CNT_ENABLE */
#if (DDL_TIMER4_EMB_ENABLE == DDL_ON)
#include "hc32f460_timer4_emb.h"
#endif /* DDL_TIMER4_EMB_ENABLE */
#if (DDL_TIMER4_OCO_ENABLE == DDL_ON)
#include "hc32f460_timer4_oco.h"
#endif /* DDL_TIMER4_OCO_ENABLE */
#if (DDL_TIMER4_PWM_ENABLE == DDL_ON)
#include "hc32f460_timer4_pwm.h"
#endif /* DDL_TIMER4_PWM_ENABLE */
#if (DDL_TIMER4_SEVT_ENABLE == DDL_ON)
#include "hc32f460_timer4_sevt.h"
#endif /* DDL_TIMER4_SEVT_ENABLE */
#if (DDL_TIMER6_ENABLE == DDL_ON)
#include "hc32f460_timer6.h"
#endif /* DDL_TIMER6_ENABLE */
#if (DDL_TIMERA_ENABLE == DDL_ON)
#include "hc32f460_timera.h"
#endif /* DDL_TIMERA_ENABLE */
#if (DDL_TRNG_ENABLE == DDL_ON)
#include "hc32f460_trng.h"
#endif /* DDL_TRNG_ENABLE */
#if (DDL_USART_ENABLE == DDL_ON)
#include "hc32f460_usart.h"
#endif /* DDL_USART_ENABLE */
#if (DDL_USBFS_ENABLE == DDL_ON)
#include "hc32f460_usbfs.h"
#endif /* DDL_USBFS_ENABLE */
#if (DDL_UTILITY_ENABLE == DDL_ON)
#include "hc32f460_utility.h"
#endif /* DDL_UTILITY_ENABLE */
#if (DDL_WDT_ENABLE == DDL_ON)
#include "hc32f460_wdt.h"
#endif /* DDL_WDT_ENABLE */
#endif /* USE_DEVICE_DRIVER_LIB */
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//@} // Hc32DdlGroup
#ifdef __cplusplus
}
#endif
#endif /* __HC32_DDL_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+30602
View File
File diff suppressed because it is too large Load Diff
+122
View File
@@ -0,0 +1,122 @@
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file system_hc32f460.c
**
** A detailed description is available at
** @link Hc32f460SystemGroup Hc32f460System description @endlink
**
** - 2018-10-15 CDT First version
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32_common.h"
/**
*******************************************************************************
** \addtogroup Hc32f460SystemGroup
******************************************************************************/
/*******************************************************************************
* Global pre-processor symbols/macros ('define')
******************************************************************************/
//@{
/**
******************************************************************************
** System Clock Frequency (Core Clock) Variable according CMSIS
******************************************************************************/
uint32_t HRC_VALUE = HRC_16MHz_VALUE;
uint32_t SystemCoreClock = MRC_VALUE;
/**
******************************************************************************
** \brief Setup the microcontroller system. Initialize the System and update
** the SystemCoreClock variable.
**
** \param None
** \return None
******************************************************************************/
void SystemInit(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 20) | (3UL << 22)); /* set CP10 and CP11 Full Access */
#endif
SystemCoreClockUpdate();
}
void SystemCoreClockUpdate(void) // Update SystemCoreClock variable
{
uint8_t tmp = 0u;
uint32_t plln = 19u, pllp = 1u, pllm = 0u, pllsource = 0u;
/* Select proper HRC_VALUE according to ICG1.HRCFREQSEL bit */
/* ICG1.HRCFREQSEL = '0' represent HRC_VALUE = 20000000UL */
/* ICG1.HRCFREQSEL = '1' represent HRC_VALUE = 16000000UL */
if (1UL == (HRC_FREQ_MON() & 1UL))
{
HRC_VALUE = HRC_16MHz_VALUE;
}
else
{
HRC_VALUE = HRC_20MHz_VALUE;
}
tmp = M4_SYSREG->CMU_CKSWR_f.CKSW;
switch (tmp)
{
case 0x00: /* use internal high speed RC */
SystemCoreClock = HRC_VALUE;
break;
case 0x01: /* use internal middle speed RC */
SystemCoreClock = MRC_VALUE;
break;
case 0x02: /* use internal low speed RC */
SystemCoreClock = LRC_VALUE;
break;
case 0x03: /* use external high speed OSC */
SystemCoreClock = XTAL_VALUE;
break;
case 0x04: /* use external low speed OSC */
SystemCoreClock = XTAL32_VALUE;
break;
case 0x05: /* use MPLL */
/* PLLCLK = ((pllsrc / pllm) * plln) / pllp */
pllsource = M4_SYSREG->CMU_PLLCFGR_f.PLLSRC;
plln = M4_SYSREG->CMU_PLLCFGR_f.MPLLN;
pllp = M4_SYSREG->CMU_PLLCFGR_f.MPLLP;
pllm = M4_SYSREG->CMU_PLLCFGR_f.MPLLM;
/* use exteranl high speed OSC as PLL source */
if (0ul == pllsource)
{
SystemCoreClock = (XTAL_VALUE) / (pllm + 1ul) * (plln + 1ul) / (pllp + 1ul);
}
/* use interanl high RC as PLL source */
else if (1ul == pllsource)
{
SystemCoreClock = (HRC_VALUE) / (pllm + 1ul) * (plln + 1ul) / (pllp + 1ul);
}
else
{
/* Reserved */
}
break;
}
}
//@} // UsartGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
+105
View File
@@ -0,0 +1,105 @@
/*******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file system_hc32f460.h
**
** A detailed description is available at
** @link Hc32f460SystemGroup Hc32f460System description @endlink
**
** - 2018-10-15 CDT First version.
**
******************************************************************************/
#ifndef __SYSTEM_HC32F460_H__
#define __SYSTEM_HC32F460_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include <stdint.h>
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C" {
#endif
/**
*******************************************************************************
** \defgroup Hc32f460SystemGroup HC32F460 System Configure
**
******************************************************************************/
//@{
/*******************************************************************************
* Global pre-processor symbols/macros ('define')
******************************************************************************/
/**
******************************************************************************
** \brief Clock Setup macro definition
**
** - 0: CLOCK_SETTING_NONE - User provides own clock setting in application
** - 1: CLOCK_SETTING_CMSIS -
******************************************************************************/
#define CLOCK_SETTING_NONE 0u
#define CLOCK_SETTING_CMSIS 1u
#define HRC_FREQ_MON() (*((volatile unsigned int*)(0x40010684UL)))
#if !defined (HRC_16MHz_VALUE)
#define HRC_16MHz_VALUE ((uint32_t)16000000UL) /*!< Internal high speed RC freq.(16MHz) */
#endif
#if !defined (HRC_20MHz_VALUE)
#define HRC_20MHz_VALUE ((uint32_t)20000000UL) /*!< Internal high speed RC freq.(20MHz) */
#endif
#if !defined (MRC_VALUE)
#define MRC_VALUE ((uint32_t)8000000) /*!< Internal middle speed RC freq. */
#endif
#if !defined (LRC_VALUE)
#define LRC_VALUE ((uint32_t)32768) /*!< Internal low speed RC freq. */
#endif
#if !defined (XTAL_VALUE)
#define XTAL_VALUE ((uint32_t)8000000) /*!< External high speed OSC freq. */
#endif
#if !defined (XTAL32_VALUE)
#define XTAL32_VALUE ((uint32_t)32768) /*!< External low speed OSC freq. */
#endif
/******************************************************************************/
/* */
/* START OF USER SETTINGS HERE */
/* =========================== */
/* */
/* All lines with '<<<' can be set by user. */
/* */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
extern uint32_t HRC_VALUE; // HRC Clock Frequency (Core Clock)
extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
extern void SystemInit(void); // Initialize the system
extern void SystemCoreClockUpdate(void); // Update SystemCoreClock variable
//@} // Hc32f460SystemGroup
#ifdef __cplusplus
}
#endif
#endif /* __SYSTEM_HC32F460_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/