2021-03-19 10:05:24 -07:00
|
|
|
/*
|
|
|
|
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
|
|
|
ChibiOS - Copyright (C) 2021 Stefan Kerkmann
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-03-31 02:52:05 -07:00
|
|
|
* @file GD32VF103/hal_lld.h
|
|
|
|
* @brief GD32VF103 HAL subsystem low level driver header.
|
2021-03-19 10:05:24 -07:00
|
|
|
* @pre This module requires the following macros to be defined in the
|
|
|
|
* @p board.h file:
|
2021-03-31 06:17:51 -07:00
|
|
|
* - GD32_LXTALCLK.
|
|
|
|
* - GD32_LXTAL_BYPASS (optionally).
|
|
|
|
* - GD32_HXTALCLK.
|
|
|
|
* - GD32_HXTAL_BYPASS (optionally).
|
2021-03-19 10:05:24 -07:00
|
|
|
*
|
|
|
|
* @addtogroup HAL
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAL_LLD_H
|
|
|
|
#define HAL_LLD_H
|
|
|
|
|
2021-04-01 11:28:16 -07:00
|
|
|
#define STRING2(x) #x
|
|
|
|
#define STRING(x) STRING2(x)
|
|
|
|
|
2021-03-19 10:05:24 -07:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Platform identification
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#if defined(__DOXYGEN__) || \
|
|
|
|
defined(GD32VF103TB) || defined(GD32VF103T8) || defined(GD32VF103T6) || defined(GD32VF103T4) || \
|
|
|
|
defined(GD32VF103CB) || defined(GD32VF103C8) || defined(GD32VF103C6) || defined(GD32VF103C4) || \
|
|
|
|
defined(GD32VF103RB) || defined(GD32VF103R8) || defined(GD32VF103R6) || defined(GD32VF103R4) || \
|
|
|
|
defined(GD32VF103VB) || defined(GD32VF103V8)
|
|
|
|
#define PLATFORM_NAME "GigaDevice GD32VF103 RISC-V"
|
|
|
|
#define GD32VF103
|
|
|
|
#else
|
|
|
|
#error "unsupported or unrecognized GD32VF103 member"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sub-family identifier.
|
|
|
|
*/
|
2021-03-31 02:52:05 -07:00
|
|
|
#if !defined(GD32VF103) || defined(__DOXYGEN__)
|
2021-03-19 10:05:24 -07:00
|
|
|
#define GD32VF103
|
|
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Internal clock sources
|
|
|
|
* @{
|
|
|
|
*/
|
2021-03-31 06:17:51 -07:00
|
|
|
#define GD32_IRC8MCLK 8000000 /**< High speed internal clock. */
|
|
|
|
#define GD32_IRC40KCLK 40000 /**< Low speed internal clock. */
|
2021-03-19 10:05:24 -07:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
2021-03-31 02:52:05 -07:00
|
|
|
* @name PMU_CTL register bits definitions
|
2021-03-19 10:05:24 -07:00
|
|
|
* @{
|
|
|
|
*/
|
2021-03-31 02:52:05 -07:00
|
|
|
#define GD32_LVDT_MASK (7 << 5) /**< LVDT bits mask. */
|
|
|
|
#define GD32_LVDT_LEV0 (0 << 5) /**< LVDT level 0. */
|
|
|
|
#define GD32_LVDT_LEV1 (1 << 5) /**< LVDT level 1. */
|
|
|
|
#define GD32_LVDT_LEV2 (2 << 5) /**< LVDT level 2. */
|
|
|
|
#define GD32_LVDT_LEV3 (3 << 5) /**< LVDT level 3. */
|
|
|
|
#define GD32_LVDT_LEV4 (4 << 5) /**< LVDT level 4. */
|
|
|
|
#define GD32_LVDT_LEV5 (5 << 5) /**< LVDT level 5. */
|
|
|
|
#define GD32_LVDT_LEV6 (6 << 5) /**< LVDT level 6. */
|
|
|
|
#define GD32_LVDT_LEV7 (7 << 5) /**< LVDT level 7. */
|
2021-03-19 10:05:24 -07:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Platform capabilities. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Configuration options
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
2021-03-31 02:38:28 -07:00
|
|
|
* @brief Disables the PMU/RCU initialization in the HAL.
|
2021-03-19 10:05:24 -07:00
|
|
|
*/
|
2021-03-20 11:47:59 -07:00
|
|
|
#if !defined(GD32_NO_INIT) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_NO_INIT FALSE
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enables or disables the programmable voltage detector.
|
|
|
|
*/
|
2021-03-20 11:47:59 -07:00
|
|
|
#if !defined(GD32_PVD_ENABLE) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_PVD_ENABLE FALSE
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets voltage level for programmable voltage detector.
|
|
|
|
*/
|
2021-03-31 02:52:05 -07:00
|
|
|
#if !defined(GD32_LVDT) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_LVDT GD32_LVDT_LEV0
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-03-31 06:17:51 -07:00
|
|
|
* @brief Enables or disables the IRC8M clock source.
|
2021-03-19 10:05:24 -07:00
|
|
|
*/
|
2021-03-31 06:17:51 -07:00
|
|
|
#if !defined(GD32_IRC8M_ENABLED) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_IRC8M_ENABLED TRUE
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-03-31 06:17:51 -07:00
|
|
|
* @brief Enables or disables the IRC40K clock source.
|
2021-03-19 10:05:24 -07:00
|
|
|
*/
|
2021-03-31 06:17:51 -07:00
|
|
|
#if !defined(GD32_IRC40K_ENABLED) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_IRC40K_ENABLED FALSE
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-03-31 06:17:51 -07:00
|
|
|
* @brief Enables or disables the HXTAL clock source.
|
2021-03-19 10:05:24 -07:00
|
|
|
*/
|
2021-03-31 06:17:51 -07:00
|
|
|
#if !defined(GD32_HXTAL_ENABLED) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_HXTAL_ENABLED TRUE
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-03-31 06:17:51 -07:00
|
|
|
* @brief Enables or disables the LXTAL clock source.
|
2021-03-19 10:05:24 -07:00
|
|
|
*/
|
2021-03-31 06:17:51 -07:00
|
|
|
#if !defined(GD32_LXTAL_ENABLED) || defined(__DOXYGEN__)
|
|
|
|
#define GD32_LXTAL_ENABLED FALSE
|
2021-03-19 10:05:24 -07:00
|
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "gd32_registry.h"
|
|
|
|
#include "stm32f105xc.h"
|
|
|
|
|
2021-04-01 11:28:16 -07:00
|
|
|
//#include "hal_lld_f103.h"
|
|
|
|
#include "hal_lld_f105_f107.h"
|
2021-03-19 10:05:24 -07:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/* Various helpers.*/
|
|
|
|
#include "eclic.h"
|
|
|
|
#include "gd32_isr.h"
|
2021-03-20 12:53:26 -07:00
|
|
|
#include "gd32_dma.h"
|
2021-03-31 02:24:51 -07:00
|
|
|
#include "gd32_rcu.h"
|
2021-03-20 12:53:26 -07:00
|
|
|
#include "gd32_tim.h"
|
2021-03-19 10:05:24 -07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void hal_lld_init(void);
|
|
|
|
void gd32_clock_init(void);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* HAL_LLD_H */
|
|
|
|
|
|
|
|
/** @} */
|