lib: Add hc32f460 definitions
Signed-off-by: Steven Gotthardt <gotthardt@gmail.com>
This commit is contained in:
committed by
Kevin O'Connor
parent
1e7057e917
commit
94cbf5ff48
219
lib/hc32f460/mcu/common/hc32_common.h
Normal file
219
lib/hc32f460/mcu/common/hc32_common.h
Normal 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)
|
||||
******************************************************************************/
|
||||
30698
lib/hc32f460/mcu/common/hc32f460.h
Normal file
30698
lib/hc32f460/mcu/common/hc32f460.h
Normal file
File diff suppressed because it is too large
Load Diff
123
lib/hc32f460/mcu/common/system_hc32f460.c
Normal file
123
lib/hc32f460/mcu/common/system_hc32f460.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
// SystemCoreClock = 168000000ul;
|
||||
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
lib/hc32f460/mcu/common/system_hc32f460.h
Normal file
105
lib/hc32f460/mcu/common/system_hc32f460.h
Normal 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)
|
||||
******************************************************************************/
|
||||
Reference in New Issue
Block a user