diff --git a/.gitignore b/.gitignore
index f665c38..4fbe939 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,5 +49,8 @@
*/lib_gd32/*
*.bin
-*.list
-*.map
+*.list
+*.map
+
+FreeRTOS.mk
+Artnet.mk
diff --git a/CMSIS/.cproject b/CMSIS/.cproject
new file mode 100644
index 0000000..5f16a37
--- /dev/null
+++ b/CMSIS/.cproject
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib-c/.project b/CMSIS/.project
similarity index 97%
rename from lib-c/.project
rename to CMSIS/.project
index 0a92347..e2e0ca7 100644
--- a/lib-c/.project
+++ b/CMSIS/.project
@@ -1,6 +1,6 @@
- lib-c
+ CMSIS
diff --git a/lib-c/.settings/language.settings.xml b/CMSIS/.settings/language.settings.xml
similarity index 50%
rename from lib-c/.settings/language.settings.xml
rename to CMSIS/.settings/language.settings.xml
index ccca099..ed16b20 100644
--- a/lib-c/.settings/language.settings.xml
+++ b/CMSIS/.settings/language.settings.xml
@@ -1,14 +1,11 @@
-
+
+
-
-
-
-
diff --git a/GD32F20x_Demo_Suites_V2.2.1/.settings/org.eclipse.core.resources.prefs b/CMSIS/.settings/org.eclipse.core.resources.prefs
similarity index 100%
rename from GD32F20x_Demo_Suites_V2.2.1/.settings/org.eclipse.core.resources.prefs
rename to CMSIS/.settings/org.eclipse.core.resources.prefs
diff --git a/CMSIS/Core/Include/cachel1_armv7.h b/CMSIS/Core/Include/cachel1_armv7.h
new file mode 100644
index 0000000..abebc95
--- /dev/null
+++ b/CMSIS/Core/Include/cachel1_armv7.h
@@ -0,0 +1,411 @@
+/******************************************************************************
+ * @file cachel1_armv7.h
+ * @brief CMSIS Level 1 Cache API for Armv7-M and later
+ * @version V1.0.1
+ * @date 19. April 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2020-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef ARM_CACHEL1_ARMV7_H
+#define ARM_CACHEL1_ARMV7_H
+
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_CacheFunctions Cache Functions
+ \brief Functions that configure Instruction and Data cache.
+ @{
+ */
+
+/* Cache Size ID Register Macros */
+#define CCSIDR_WAYS(x) (((x) & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos)
+#define CCSIDR_SETS(x) (((x) & SCB_CCSIDR_NUMSETS_Msk ) >> SCB_CCSIDR_NUMSETS_Pos )
+
+#ifndef __SCB_DCACHE_LINE_SIZE
+#define __SCB_DCACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */
+#endif
+
+#ifndef __SCB_ICACHE_LINE_SIZE
+#define __SCB_ICACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */
+#endif
+
+/**
+ \brief Enable I-Cache
+ \details Turns on I-Cache
+ */
+__STATIC_FORCEINLINE void SCB_EnableICache (void)
+{
+ #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)
+ if (SCB->CCR & SCB_CCR_IC_Msk) return; /* return if ICache is already enabled */
+
+ __DSB();
+ __ISB();
+ SCB->ICIALLU = 0UL; /* invalidate I-Cache */
+ __DSB();
+ __ISB();
+ SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief Disable I-Cache
+ \details Turns off I-Cache
+ */
+__STATIC_FORCEINLINE void SCB_DisableICache (void)
+{
+ #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)
+ __DSB();
+ __ISB();
+ SCB->CCR &= ~(uint32_t)SCB_CCR_IC_Msk; /* disable I-Cache */
+ SCB->ICIALLU = 0UL; /* invalidate I-Cache */
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief Invalidate I-Cache
+ \details Invalidates I-Cache
+ */
+__STATIC_FORCEINLINE void SCB_InvalidateICache (void)
+{
+ #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)
+ __DSB();
+ __ISB();
+ SCB->ICIALLU = 0UL;
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief I-Cache Invalidate by address
+ \details Invalidates I-Cache for the given address.
+ I-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity.
+ I-Cache memory blocks which are part of given address + given size are invalidated.
+ \param[in] addr address
+ \param[in] isize size of memory block (in number of bytes)
+*/
+__STATIC_FORCEINLINE void SCB_InvalidateICache_by_Addr (volatile void *addr, int32_t isize)
+{
+ #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)
+ if ( isize > 0 ) {
+ int32_t op_size = isize + (((uint32_t)addr) & (__SCB_ICACHE_LINE_SIZE - 1U));
+ uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_ICACHE_LINE_SIZE - 1U) */;
+
+ __DSB();
+
+ do {
+ SCB->ICIMVAU = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */
+ op_addr += __SCB_ICACHE_LINE_SIZE;
+ op_size -= __SCB_ICACHE_LINE_SIZE;
+ } while ( op_size > 0 );
+
+ __DSB();
+ __ISB();
+ }
+ #endif
+}
+
+
+/**
+ \brief Enable D-Cache
+ \details Turns on D-Cache
+ */
+__STATIC_FORCEINLINE void SCB_EnableDCache (void)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ uint32_t ccsidr;
+ uint32_t sets;
+ uint32_t ways;
+
+ if (SCB->CCR & SCB_CCR_DC_Msk) return; /* return if DCache is already enabled */
+
+ SCB->CSSELR = 0U; /* select Level 1 data cache */
+ __DSB();
+
+ ccsidr = SCB->CCSIDR;
+
+ /* invalidate D-Cache */
+ sets = (uint32_t)(CCSIDR_SETS(ccsidr));
+ do {
+ ways = (uint32_t)(CCSIDR_WAYS(ccsidr));
+ do {
+ SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) |
+ ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) );
+ #if defined ( __CC_ARM )
+ __schedule_barrier();
+ #endif
+ } while (ways-- != 0U);
+ } while(sets-- != 0U);
+ __DSB();
+
+ SCB->CCR |= (uint32_t)SCB_CCR_DC_Msk; /* enable D-Cache */
+
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief Disable D-Cache
+ \details Turns off D-Cache
+ */
+__STATIC_FORCEINLINE void SCB_DisableDCache (void)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ uint32_t ccsidr;
+ uint32_t sets;
+ uint32_t ways;
+
+ SCB->CSSELR = 0U; /* select Level 1 data cache */
+ __DSB();
+
+ SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */
+ __DSB();
+
+ ccsidr = SCB->CCSIDR;
+
+ /* clean & invalidate D-Cache */
+ sets = (uint32_t)(CCSIDR_SETS(ccsidr));
+ do {
+ ways = (uint32_t)(CCSIDR_WAYS(ccsidr));
+ do {
+ SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) |
+ ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) );
+ #if defined ( __CC_ARM )
+ __schedule_barrier();
+ #endif
+ } while (ways-- != 0U);
+ } while(sets-- != 0U);
+
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief Invalidate D-Cache
+ \details Invalidates D-Cache
+ */
+__STATIC_FORCEINLINE void SCB_InvalidateDCache (void)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ uint32_t ccsidr;
+ uint32_t sets;
+ uint32_t ways;
+
+ SCB->CSSELR = 0U; /* select Level 1 data cache */
+ __DSB();
+
+ ccsidr = SCB->CCSIDR;
+
+ /* invalidate D-Cache */
+ sets = (uint32_t)(CCSIDR_SETS(ccsidr));
+ do {
+ ways = (uint32_t)(CCSIDR_WAYS(ccsidr));
+ do {
+ SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) |
+ ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) );
+ #if defined ( __CC_ARM )
+ __schedule_barrier();
+ #endif
+ } while (ways-- != 0U);
+ } while(sets-- != 0U);
+
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief Clean D-Cache
+ \details Cleans D-Cache
+ */
+__STATIC_FORCEINLINE void SCB_CleanDCache (void)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ uint32_t ccsidr;
+ uint32_t sets;
+ uint32_t ways;
+
+ SCB->CSSELR = 0U; /* select Level 1 data cache */
+ __DSB();
+
+ ccsidr = SCB->CCSIDR;
+
+ /* clean D-Cache */
+ sets = (uint32_t)(CCSIDR_SETS(ccsidr));
+ do {
+ ways = (uint32_t)(CCSIDR_WAYS(ccsidr));
+ do {
+ SCB->DCCSW = (((sets << SCB_DCCSW_SET_Pos) & SCB_DCCSW_SET_Msk) |
+ ((ways << SCB_DCCSW_WAY_Pos) & SCB_DCCSW_WAY_Msk) );
+ #if defined ( __CC_ARM )
+ __schedule_barrier();
+ #endif
+ } while (ways-- != 0U);
+ } while(sets-- != 0U);
+
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief Clean & Invalidate D-Cache
+ \details Cleans and Invalidates D-Cache
+ */
+__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache (void)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ uint32_t ccsidr;
+ uint32_t sets;
+ uint32_t ways;
+
+ SCB->CSSELR = 0U; /* select Level 1 data cache */
+ __DSB();
+
+ ccsidr = SCB->CCSIDR;
+
+ /* clean & invalidate D-Cache */
+ sets = (uint32_t)(CCSIDR_SETS(ccsidr));
+ do {
+ ways = (uint32_t)(CCSIDR_WAYS(ccsidr));
+ do {
+ SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) |
+ ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) );
+ #if defined ( __CC_ARM )
+ __schedule_barrier();
+ #endif
+ } while (ways-- != 0U);
+ } while(sets-- != 0U);
+
+ __DSB();
+ __ISB();
+ #endif
+}
+
+
+/**
+ \brief D-Cache Invalidate by address
+ \details Invalidates D-Cache for the given address.
+ D-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity.
+ D-Cache memory blocks which are part of given address + given size are invalidated.
+ \param[in] addr address
+ \param[in] dsize size of memory block (in number of bytes)
+*/
+__STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr (volatile void *addr, int32_t dsize)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ if ( dsize > 0 ) {
+ int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U));
+ uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */;
+
+ __DSB();
+
+ do {
+ SCB->DCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */
+ op_addr += __SCB_DCACHE_LINE_SIZE;
+ op_size -= __SCB_DCACHE_LINE_SIZE;
+ } while ( op_size > 0 );
+
+ __DSB();
+ __ISB();
+ }
+ #endif
+}
+
+
+/**
+ \brief D-Cache Clean by address
+ \details Cleans D-Cache for the given address
+ D-Cache is cleaned starting from a 32 byte aligned address in 32 byte granularity.
+ D-Cache memory blocks which are part of given address + given size are cleaned.
+ \param[in] addr address
+ \param[in] dsize size of memory block (in number of bytes)
+*/
+__STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr (volatile void *addr, int32_t dsize)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ if ( dsize > 0 ) {
+ int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U));
+ uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */;
+
+ __DSB();
+
+ do {
+ SCB->DCCMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */
+ op_addr += __SCB_DCACHE_LINE_SIZE;
+ op_size -= __SCB_DCACHE_LINE_SIZE;
+ } while ( op_size > 0 );
+
+ __DSB();
+ __ISB();
+ }
+ #endif
+}
+
+
+/**
+ \brief D-Cache Clean and Invalidate by address
+ \details Cleans and invalidates D_Cache for the given address
+ D-Cache is cleaned and invalidated starting from a 32 byte aligned address in 32 byte granularity.
+ D-Cache memory blocks which are part of given address + given size are cleaned and invalidated.
+ \param[in] addr address (aligned to 32-byte boundary)
+ \param[in] dsize size of memory block (in number of bytes)
+*/
+__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr (volatile void *addr, int32_t dsize)
+{
+ #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
+ if ( dsize > 0 ) {
+ int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U));
+ uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */;
+
+ __DSB();
+
+ do {
+ SCB->DCCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */
+ op_addr += __SCB_DCACHE_LINE_SIZE;
+ op_size -= __SCB_DCACHE_LINE_SIZE;
+ } while ( op_size > 0 );
+
+ __DSB();
+ __ISB();
+ }
+ #endif
+}
+
+/*@} end of CMSIS_Core_CacheFunctions */
+
+#endif /* ARM_CACHEL1_ARMV7_H */
diff --git a/lib-gd32/gd32f20x/CMSIS/cmsis_armcc.h b/CMSIS/Core/Include/cmsis_armcc.h
similarity index 71%
rename from lib-gd32/gd32f20x/CMSIS/cmsis_armcc.h
rename to CMSIS/Core/Include/cmsis_armcc.h
index f2bb66a..a955d47 100644
--- a/lib-gd32/gd32f20x/CMSIS/cmsis_armcc.h
+++ b/CMSIS/Core/Include/cmsis_armcc.h
@@ -1,734 +1,888 @@
-/**************************************************************************//**
- * @file cmsis_armcc.h
- * @brief CMSIS Cortex-M Core Function/Instruction Header File
- * @version V4.30
- * @date 20. October 2015
- ******************************************************************************/
-/* Copyright (c) 2009 - 2015 ARM LIMITED
-
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- - Neither the name of ARM nor the names of its contributors may be used
- to endorse or promote products derived from this software without
- specific prior written permission.
- *
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- ---------------------------------------------------------------------------*/
-
-
-#ifndef __CMSIS_ARMCC_H
-#define __CMSIS_ARMCC_H
-
-
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
- #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
-#endif
-
-/* ########################### Core Function Access ########################### */
-/** \ingroup CMSIS_Core_FunctionInterface
- \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
- @{
- */
-
-/* intrinsic void __enable_irq(); */
-/* intrinsic void __disable_irq(); */
-
-/**
- \brief Get Control Register
- \details Returns the content of the Control Register.
- \return Control Register value
- */
-__STATIC_INLINE uint32_t __get_CONTROL(void)
-{
- register uint32_t __regControl __ASM("control");
- return(__regControl);
-}
-
-
-/**
- \brief Set Control Register
- \details Writes the given value to the Control Register.
- \param [in] control Control Register value to set
- */
-__STATIC_INLINE void __set_CONTROL(uint32_t control)
-{
- register uint32_t __regControl __ASM("control");
- __regControl = control;
-}
-
-
-/**
- \brief Get IPSR Register
- \details Returns the content of the IPSR Register.
- \return IPSR Register value
- */
-__STATIC_INLINE uint32_t __get_IPSR(void)
-{
- register uint32_t __regIPSR __ASM("ipsr");
- return(__regIPSR);
-}
-
-
-/**
- \brief Get APSR Register
- \details Returns the content of the APSR Register.
- \return APSR Register value
- */
-__STATIC_INLINE uint32_t __get_APSR(void)
-{
- register uint32_t __regAPSR __ASM("apsr");
- return(__regAPSR);
-}
-
-
-/**
- \brief Get xPSR Register
- \details Returns the content of the xPSR Register.
- \return xPSR Register value
- */
-__STATIC_INLINE uint32_t __get_xPSR(void)
-{
- register uint32_t __regXPSR __ASM("xpsr");
- return(__regXPSR);
-}
-
-
-/**
- \brief Get Process Stack Pointer
- \details Returns the current value of the Process Stack Pointer (PSP).
- \return PSP Register value
- */
-__STATIC_INLINE uint32_t __get_PSP(void)
-{
- register uint32_t __regProcessStackPointer __ASM("psp");
- return(__regProcessStackPointer);
-}
-
-
-/**
- \brief Set Process Stack Pointer
- \details Assigns the given value to the Process Stack Pointer (PSP).
- \param [in] topOfProcStack Process Stack Pointer value to set
- */
-__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
-{
- register uint32_t __regProcessStackPointer __ASM("psp");
- __regProcessStackPointer = topOfProcStack;
-}
-
-
-/**
- \brief Get Main Stack Pointer
- \details Returns the current value of the Main Stack Pointer (MSP).
- \return MSP Register value
- */
-__STATIC_INLINE uint32_t __get_MSP(void)
-{
- register uint32_t __regMainStackPointer __ASM("msp");
- return(__regMainStackPointer);
-}
-
-
-/**
- \brief Set Main Stack Pointer
- \details Assigns the given value to the Main Stack Pointer (MSP).
- \param [in] topOfMainStack Main Stack Pointer value to set
- */
-__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
-{
- register uint32_t __regMainStackPointer __ASM("msp");
- __regMainStackPointer = topOfMainStack;
-}
-
-
-/**
- \brief Get Priority Mask
- \details Returns the current state of the priority mask bit from the Priority Mask Register.
- \return Priority Mask value
- */
-__STATIC_INLINE uint32_t __get_PRIMASK(void)
-{
- register uint32_t __regPriMask __ASM("primask");
- return(__regPriMask);
-}
-
-
-/**
- \brief Set Priority Mask
- \details Assigns the given value to the Priority Mask Register.
- \param [in] priMask Priority Mask
- */
-__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
-{
- register uint32_t __regPriMask __ASM("primask");
- __regPriMask = (priMask);
-}
-
-
-#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
-
-/**
- \brief Enable FIQ
- \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-#define __enable_fault_irq __enable_fiq
-
-
-/**
- \brief Disable FIQ
- \details Disables FIQ interrupts by setting the F-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-#define __disable_fault_irq __disable_fiq
-
-
-/**
- \brief Get Base Priority
- \details Returns the current value of the Base Priority register.
- \return Base Priority register value
- */
-__STATIC_INLINE uint32_t __get_BASEPRI(void)
-{
- register uint32_t __regBasePri __ASM("basepri");
- return(__regBasePri);
-}
-
-
-/**
- \brief Set Base Priority
- \details Assigns the given value to the Base Priority register.
- \param [in] basePri Base Priority value to set
- */
-__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
-{
- register uint32_t __regBasePri __ASM("basepri");
- __regBasePri = (basePri & 0xFFU);
-}
-
-
-/**
- \brief Set Base Priority with condition
- \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
- or the new value increases the BASEPRI priority level.
- \param [in] basePri Base Priority value to set
- */
-__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
-{
- register uint32_t __regBasePriMax __ASM("basepri_max");
- __regBasePriMax = (basePri & 0xFFU);
-}
-
-
-/**
- \brief Get Fault Mask
- \details Returns the current value of the Fault Mask register.
- \return Fault Mask register value
- */
-__STATIC_INLINE uint32_t __get_FAULTMASK(void)
-{
- register uint32_t __regFaultMask __ASM("faultmask");
- return(__regFaultMask);
-}
-
-
-/**
- \brief Set Fault Mask
- \details Assigns the given value to the Fault Mask register.
- \param [in] faultMask Fault Mask value to set
- */
-__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
-{
- register uint32_t __regFaultMask __ASM("faultmask");
- __regFaultMask = (faultMask & (uint32_t)1);
-}
-
-#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
-
-
-#if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U)
-
-/**
- \brief Get FPSCR
- \details Returns the current value of the Floating Point Status/Control register.
- \return Floating Point Status/Control register value
- */
-__STATIC_INLINE uint32_t __get_FPSCR(void)
-{
-#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
- register uint32_t __regfpscr __ASM("fpscr");
- return(__regfpscr);
-#else
- return(0U);
-#endif
-}
-
-
-/**
- \brief Set FPSCR
- \details Assigns the given value to the Floating Point Status/Control register.
- \param [in] fpscr Floating Point Status/Control value to set
- */
-__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
-{
-#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
- register uint32_t __regfpscr __ASM("fpscr");
- __regfpscr = (fpscr);
-#endif
-}
-
-#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */
-
-
-
-/*@} end of CMSIS_Core_RegAccFunctions */
-
-
-/* ########################## Core Instruction Access ######################### */
-/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
- Access to dedicated instructions
- @{
-*/
-
-/**
- \brief No Operation
- \details No Operation does nothing. This instruction can be used for code alignment purposes.
- */
-#define __NOP __nop
-
-
-/**
- \brief Wait For Interrupt
- \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
- */
-#define __WFI __wfi
-
-
-/**
- \brief Wait For Event
- \details Wait For Event is a hint instruction that permits the processor to enter
- a low-power state until one of a number of events occurs.
- */
-#define __WFE __wfe
-
-
-/**
- \brief Send Event
- \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
- */
-#define __SEV __sev
-
-
-/**
- \brief Instruction Synchronization Barrier
- \details Instruction Synchronization Barrier flushes the pipeline in the processor,
- so that all instructions following the ISB are fetched from cache or memory,
- after the instruction has been completed.
- */
-#define __ISB() do {\
- __schedule_barrier();\
- __isb(0xF);\
- __schedule_barrier();\
- } while (0U)
-
-/**
- \brief Data Synchronization Barrier
- \details Acts as a special kind of Data Memory Barrier.
- It completes when all explicit memory accesses before this instruction complete.
- */
-#define __DSB() do {\
- __schedule_barrier();\
- __dsb(0xF);\
- __schedule_barrier();\
- } while (0U)
-
-/**
- \brief Data Memory Barrier
- \details Ensures the apparent order of the explicit memory operations before
- and after the instruction, without ensuring their completion.
- */
-#define __DMB() do {\
- __schedule_barrier();\
- __dmb(0xF);\
- __schedule_barrier();\
- } while (0U)
-
-/**
- \brief Reverse byte order (32 bit)
- \details Reverses the byte order in integer value.
- \param [in] value Value to reverse
- \return Reversed value
- */
-#define __REV __rev
-
-
-/**
- \brief Reverse byte order (16 bit)
- \details Reverses the byte order in two unsigned short values.
- \param [in] value Value to reverse
- \return Reversed value
- */
-#ifndef __NO_EMBEDDED_ASM
-__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
-{
- rev16 r0, r0
- bx lr
-}
-#endif
-
-/**
- \brief Reverse byte order in signed short value
- \details Reverses the byte order in a signed short value with sign extension to integer.
- \param [in] value Value to reverse
- \return Reversed value
- */
-#ifndef __NO_EMBEDDED_ASM
-__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
-{
- revsh r0, r0
- bx lr
-}
-#endif
-
-
-/**
- \brief Rotate Right in unsigned value (32 bit)
- \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
- \param [in] value Value to rotate
- \param [in] value Number of Bits to rotate
- \return Rotated value
- */
-#define __ROR __ror
-
-
-/**
- \brief Breakpoint
- \details Causes the processor to enter Debug state.
- Debug tools can use this to investigate system state when the instruction at a particular address is reached.
- \param [in] value is ignored by the processor.
- If required, a debugger can use it to store additional information about the breakpoint.
- */
-#define __BKPT(value) __breakpoint(value)
-
-
-/**
- \brief Reverse bit order of value
- \details Reverses the bit order of the given value.
- \param [in] value Value to reverse
- \return Reversed value
- */
-#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
- #define __RBIT __rbit
-#else
-__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
-{
- uint32_t result;
- int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
-
- result = value; /* r will be reversed bits of v; first get LSB of v */
- for (value >>= 1U; value; value >>= 1U)
- {
- result <<= 1U;
- result |= value & 1U;
- s--;
- }
- result <<= s; /* shift when v's highest bits are zero */
- return(result);
-}
-#endif
-
-
-/**
- \brief Count leading zeros
- \details Counts the number of leading zeros of a data value.
- \param [in] value Value to count the leading zeros
- \return number of leading zeros in value
- */
-#define __CLZ __clz
-
-
-#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
-
-/**
- \brief LDR Exclusive (8 bit)
- \details Executes a exclusive LDR instruction for 8 bit value.
- \param [in] ptr Pointer to data
- \return value of type uint8_t at (*ptr)
- */
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
- #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
-#else
- #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
-#endif
-
-
-/**
- \brief LDR Exclusive (16 bit)
- \details Executes a exclusive LDR instruction for 16 bit values.
- \param [in] ptr Pointer to data
- \return value of type uint16_t at (*ptr)
- */
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
- #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
-#else
- #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
-#endif
-
-
-/**
- \brief LDR Exclusive (32 bit)
- \details Executes a exclusive LDR instruction for 32 bit values.
- \param [in] ptr Pointer to data
- \return value of type uint32_t at (*ptr)
- */
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
- #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
-#else
- #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
-#endif
-
-
-/**
- \brief STR Exclusive (8 bit)
- \details Executes a exclusive STR instruction for 8 bit values.
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
- #define __STREXB(value, ptr) __strex(value, ptr)
-#else
- #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
-#endif
-
-
-/**
- \brief STR Exclusive (16 bit)
- \details Executes a exclusive STR instruction for 16 bit values.
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
- #define __STREXH(value, ptr) __strex(value, ptr)
-#else
- #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
-#endif
-
-
-/**
- \brief STR Exclusive (32 bit)
- \details Executes a exclusive STR instruction for 32 bit values.
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
- #define __STREXW(value, ptr) __strex(value, ptr)
-#else
- #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
-#endif
-
-
-/**
- \brief Remove the exclusive lock
- \details Removes the exclusive lock which is created by LDREX.
- */
-#define __CLREX __clrex
-
-
-/**
- \brief Signed Saturate
- \details Saturates a signed value.
- \param [in] value Value to be saturated
- \param [in] sat Bit position to saturate to (1..32)
- \return Saturated value
- */
-#define __SSAT __ssat
-
-
-/**
- \brief Unsigned Saturate
- \details Saturates an unsigned value.
- \param [in] value Value to be saturated
- \param [in] sat Bit position to saturate to (0..31)
- \return Saturated value
- */
-#define __USAT __usat
-
-
-/**
- \brief Rotate Right with Extend (32 bit)
- \details Moves each bit of a bitstring right by one bit.
- The carry input is shifted in at the left end of the bitstring.
- \param [in] value Value to rotate
- \return Rotated value
- */
-#ifndef __NO_EMBEDDED_ASM
-__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
-{
- rrx r0, r0
- bx lr
-}
-#endif
-
-
-/**
- \brief LDRT Unprivileged (8 bit)
- \details Executes a Unprivileged LDRT instruction for 8 bit value.
- \param [in] ptr Pointer to data
- \return value of type uint8_t at (*ptr)
- */
-#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
-
-
-/**
- \brief LDRT Unprivileged (16 bit)
- \details Executes a Unprivileged LDRT instruction for 16 bit values.
- \param [in] ptr Pointer to data
- \return value of type uint16_t at (*ptr)
- */
-#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
-
-
-/**
- \brief LDRT Unprivileged (32 bit)
- \details Executes a Unprivileged LDRT instruction for 32 bit values.
- \param [in] ptr Pointer to data
- \return value of type uint32_t at (*ptr)
- */
-#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
-
-
-/**
- \brief STRT Unprivileged (8 bit)
- \details Executes a Unprivileged STRT instruction for 8 bit values.
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- */
-#define __STRBT(value, ptr) __strt(value, ptr)
-
-
-/**
- \brief STRT Unprivileged (16 bit)
- \details Executes a Unprivileged STRT instruction for 16 bit values.
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- */
-#define __STRHT(value, ptr) __strt(value, ptr)
-
-
-/**
- \brief STRT Unprivileged (32 bit)
- \details Executes a Unprivileged STRT instruction for 32 bit values.
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- */
-#define __STRT(value, ptr) __strt(value, ptr)
-
-#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
-
-/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
-
-
-/* ################### Compiler specific Intrinsics ########################### */
-/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
- Access to dedicated SIMD instructions
- @{
-*/
-
-#if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */
-
-#define __SADD8 __sadd8
-#define __QADD8 __qadd8
-#define __SHADD8 __shadd8
-#define __UADD8 __uadd8
-#define __UQADD8 __uqadd8
-#define __UHADD8 __uhadd8
-#define __SSUB8 __ssub8
-#define __QSUB8 __qsub8
-#define __SHSUB8 __shsub8
-#define __USUB8 __usub8
-#define __UQSUB8 __uqsub8
-#define __UHSUB8 __uhsub8
-#define __SADD16 __sadd16
-#define __QADD16 __qadd16
-#define __SHADD16 __shadd16
-#define __UADD16 __uadd16
-#define __UQADD16 __uqadd16
-#define __UHADD16 __uhadd16
-#define __SSUB16 __ssub16
-#define __QSUB16 __qsub16
-#define __SHSUB16 __shsub16
-#define __USUB16 __usub16
-#define __UQSUB16 __uqsub16
-#define __UHSUB16 __uhsub16
-#define __SASX __sasx
-#define __QASX __qasx
-#define __SHASX __shasx
-#define __UASX __uasx
-#define __UQASX __uqasx
-#define __UHASX __uhasx
-#define __SSAX __ssax
-#define __QSAX __qsax
-#define __SHSAX __shsax
-#define __USAX __usax
-#define __UQSAX __uqsax
-#define __UHSAX __uhsax
-#define __USAD8 __usad8
-#define __USADA8 __usada8
-#define __SSAT16 __ssat16
-#define __USAT16 __usat16
-#define __UXTB16 __uxtb16
-#define __UXTAB16 __uxtab16
-#define __SXTB16 __sxtb16
-#define __SXTAB16 __sxtab16
-#define __SMUAD __smuad
-#define __SMUADX __smuadx
-#define __SMLAD __smlad
-#define __SMLADX __smladx
-#define __SMLALD __smlald
-#define __SMLALDX __smlaldx
-#define __SMUSD __smusd
-#define __SMUSDX __smusdx
-#define __SMLSD __smlsd
-#define __SMLSDX __smlsdx
-#define __SMLSLD __smlsld
-#define __SMLSLDX __smlsldx
-#define __SEL __sel
-#define __QADD __qadd
-#define __QSUB __qsub
-
-#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
- ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
-
-#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
- ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
-
-#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
- ((int64_t)(ARG3) << 32U) ) >> 32U))
-
-#endif /* (__CORTEX_M >= 0x04) */
-/*@} end of group CMSIS_SIMD_intrinsics */
-
-
-#endif /* __CMSIS_ARMCC_H */
+/**************************************************************************//**
+ * @file cmsis_armcc.h
+ * @brief CMSIS compiler ARMCC (Arm Compiler 5) header file
+ * @version V5.3.2
+ * @date 27. May 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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 __CMSIS_ARMCC_H
+#define __CMSIS_ARMCC_H
+
+
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
+ #error "Please use Arm Compiler Toolchain V4.0.677 or later!"
+#endif
+
+/* CMSIS compiler control architecture macros */
+#if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \
+ (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) )
+ #define __ARM_ARCH_6M__ 1
+#endif
+
+#if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1))
+ #define __ARM_ARCH_7M__ 1
+#endif
+
+#if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
+ #define __ARM_ARCH_7EM__ 1
+#endif
+
+ /* __ARM_ARCH_8M_BASE__ not applicable */
+ /* __ARM_ARCH_8M_MAIN__ not applicable */
+ /* __ARM_ARCH_8_1M_MAIN__ not applicable */
+
+/* CMSIS compiler control DSP macros */
+#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
+ #define __ARM_FEATURE_DSP 1
+#endif
+
+/* CMSIS compiler specific defines */
+#ifndef __ASM
+ #define __ASM __asm
+#endif
+#ifndef __INLINE
+ #define __INLINE __inline
+#endif
+#ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static __inline
+#endif
+#ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE static __forceinline
+#endif
+#ifndef __NO_RETURN
+ #define __NO_RETURN __declspec(noreturn)
+#endif
+#ifndef __USED
+ #define __USED __attribute__((used))
+#endif
+#ifndef __WEAK
+ #define __WEAK __attribute__((weak))
+#endif
+#ifndef __PACKED
+ #define __PACKED __attribute__((packed))
+#endif
+#ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT __packed struct
+#endif
+#ifndef __PACKED_UNION
+ #define __PACKED_UNION __packed union
+#endif
+#ifndef __UNALIGNED_UINT32 /* deprecated */
+ #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
+#endif
+#ifndef __UNALIGNED_UINT16_WRITE
+ #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val))
+#endif
+#ifndef __UNALIGNED_UINT16_READ
+ #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr)))
+#endif
+#ifndef __UNALIGNED_UINT32_WRITE
+ #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
+#endif
+#ifndef __UNALIGNED_UINT32_READ
+ #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
+#endif
+#ifndef __ALIGNED
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+#endif
+#ifndef __RESTRICT
+ #define __RESTRICT __restrict
+#endif
+#ifndef __COMPILER_BARRIER
+ #define __COMPILER_BARRIER() __memory_changed()
+#endif
+
+/* ######################### Startup and Lowlevel Init ######################## */
+
+#ifndef __PROGRAM_START
+#define __PROGRAM_START __main
+#endif
+
+#ifndef __INITIAL_SP
+#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
+#endif
+
+#ifndef __STACK_LIMIT
+#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base
+#endif
+
+#ifndef __VECTOR_TABLE
+#define __VECTOR_TABLE __Vectors
+#endif
+
+#ifndef __VECTOR_TABLE_ATTRIBUTE
+#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET")))
+#endif
+
+/* ########################## Core Instruction Access ######################### */
+/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
+ Access to dedicated instructions
+ @{
+*/
+
+/**
+ \brief No Operation
+ \details No Operation does nothing. This instruction can be used for code alignment purposes.
+ */
+#define __NOP __nop
+
+
+/**
+ \brief Wait For Interrupt
+ \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
+ */
+#define __WFI __wfi
+
+
+/**
+ \brief Wait For Event
+ \details Wait For Event is a hint instruction that permits the processor to enter
+ a low-power state until one of a number of events occurs.
+ */
+#define __WFE __wfe
+
+
+/**
+ \brief Send Event
+ \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
+ */
+#define __SEV __sev
+
+
+/**
+ \brief Instruction Synchronization Barrier
+ \details Instruction Synchronization Barrier flushes the pipeline in the processor,
+ so that all instructions following the ISB are fetched from cache or memory,
+ after the instruction has been completed.
+ */
+#define __ISB() __isb(0xF)
+
+/**
+ \brief Data Synchronization Barrier
+ \details Acts as a special kind of Data Memory Barrier.
+ It completes when all explicit memory accesses before this instruction complete.
+ */
+#define __DSB() __dsb(0xF)
+
+/**
+ \brief Data Memory Barrier
+ \details Ensures the apparent order of the explicit memory operations before
+ and after the instruction, without ensuring their completion.
+ */
+#define __DMB() __dmb(0xF)
+
+
+/**
+ \brief Reverse byte order (32 bit)
+ \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REV __rev
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#ifndef __NO_EMBEDDED_ASM
+__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
+{
+ rev16 r0, r0
+ bx lr
+}
+#endif
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#ifndef __NO_EMBEDDED_ASM
+__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
+{
+ revsh r0, r0
+ bx lr
+}
+#endif
+
+
+/**
+ \brief Rotate Right in unsigned value (32 bit)
+ \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
+ \param [in] op1 Value to rotate
+ \param [in] op2 Number of Bits to rotate
+ \return Rotated value
+ */
+#define __ROR __ror
+
+
+/**
+ \brief Breakpoint
+ \details Causes the processor to enter Debug state.
+ Debug tools can use this to investigate system state when the instruction at a particular address is reached.
+ \param [in] value is ignored by the processor.
+ If required, a debugger can use it to store additional information about the breakpoint.
+ */
+#define __BKPT(value) __breakpoint(value)
+
+
+/**
+ \brief Reverse bit order of value
+ \details Reverses the bit order of the given value.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
+ #define __RBIT __rbit
+#else
+__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
+{
+ uint32_t result;
+ uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
+
+ result = value; /* r will be reversed bits of v; first get LSB of v */
+ for (value >>= 1U; value != 0U; value >>= 1U)
+ {
+ result <<= 1U;
+ result |= value & 1U;
+ s--;
+ }
+ result <<= s; /* shift when v's highest bits are zero */
+ return result;
+}
+#endif
+
+
+/**
+ \brief Count leading zeros
+ \details Counts the number of leading zeros of a data value.
+ \param [in] value Value to count the leading zeros
+ \return number of leading zeros in value
+ */
+#define __CLZ __clz
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
+
+/**
+ \brief LDR Exclusive (8 bit)
+ \details Executes a exclusive LDR instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
+ #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
+#else
+ #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
+#endif
+
+
+/**
+ \brief LDR Exclusive (16 bit)
+ \details Executes a exclusive LDR instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
+ #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
+#else
+ #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
+#endif
+
+
+/**
+ \brief LDR Exclusive (32 bit)
+ \details Executes a exclusive LDR instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
+ #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
+#else
+ #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
+#endif
+
+
+/**
+ \brief STR Exclusive (8 bit)
+ \details Executes a exclusive STR instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
+ #define __STREXB(value, ptr) __strex(value, ptr)
+#else
+ #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
+#endif
+
+
+/**
+ \brief STR Exclusive (16 bit)
+ \details Executes a exclusive STR instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
+ #define __STREXH(value, ptr) __strex(value, ptr)
+#else
+ #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
+#endif
+
+
+/**
+ \brief STR Exclusive (32 bit)
+ \details Executes a exclusive STR instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
+ #define __STREXW(value, ptr) __strex(value, ptr)
+#else
+ #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
+#endif
+
+
+/**
+ \brief Remove the exclusive lock
+ \details Removes the exclusive lock which is created by LDREX.
+ */
+#define __CLREX __clrex
+
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+#define __SSAT __ssat
+
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+#define __USAT __usat
+
+
+/**
+ \brief Rotate Right with Extend (32 bit)
+ \details Moves each bit of a bitstring right by one bit.
+ The carry input is shifted in at the left end of the bitstring.
+ \param [in] value Value to rotate
+ \return Rotated value
+ */
+#ifndef __NO_EMBEDDED_ASM
+__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
+{
+ rrx r0, r0
+ bx lr
+}
+#endif
+
+
+/**
+ \brief LDRT Unprivileged (8 bit)
+ \details Executes a Unprivileged LDRT instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
+
+
+/**
+ \brief LDRT Unprivileged (16 bit)
+ \details Executes a Unprivileged LDRT instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
+
+
+/**
+ \brief LDRT Unprivileged (32 bit)
+ \details Executes a Unprivileged LDRT instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
+
+
+/**
+ \brief STRT Unprivileged (8 bit)
+ \details Executes a Unprivileged STRT instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+#define __STRBT(value, ptr) __strt(value, ptr)
+
+
+/**
+ \brief STRT Unprivileged (16 bit)
+ \details Executes a Unprivileged STRT instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+#define __STRHT(value, ptr) __strt(value, ptr)
+
+
+/**
+ \brief STRT Unprivileged (32 bit)
+ \details Executes a Unprivileged STRT instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+#define __STRT(value, ptr) __strt(value, ptr)
+
+#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
+{
+ if ((sat >= 1U) && (sat <= 32U))
+ {
+ const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
+ const int32_t min = -1 - max ;
+ if (val > max)
+ {
+ return max;
+ }
+ else if (val < min)
+ {
+ return min;
+ }
+ }
+ return val;
+}
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
+{
+ if (sat <= 31U)
+ {
+ const uint32_t max = ((1U << sat) - 1U);
+ if (val > (int32_t)max)
+ {
+ return max;
+ }
+ else if (val < 0)
+ {
+ return 0U;
+ }
+ }
+ return (uint32_t)val;
+}
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
+
+/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
+
+
+/* ########################### Core Function Access ########################### */
+/** \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
+ @{
+ */
+
+/**
+ \brief Enable IRQ Interrupts
+ \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+/* intrinsic void __enable_irq(); */
+
+
+/**
+ \brief Disable IRQ Interrupts
+ \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+/* intrinsic void __disable_irq(); */
+
+/**
+ \brief Get Control Register
+ \details Returns the content of the Control Register.
+ \return Control Register value
+ */
+__STATIC_INLINE uint32_t __get_CONTROL(void)
+{
+ register uint32_t __regControl __ASM("control");
+ return(__regControl);
+}
+
+
+/**
+ \brief Set Control Register
+ \details Writes the given value to the Control Register.
+ \param [in] control Control Register value to set
+ */
+__STATIC_INLINE void __set_CONTROL(uint32_t control)
+{
+ register uint32_t __regControl __ASM("control");
+ __regControl = control;
+ __ISB();
+}
+
+
+/**
+ \brief Get IPSR Register
+ \details Returns the content of the IPSR Register.
+ \return IPSR Register value
+ */
+__STATIC_INLINE uint32_t __get_IPSR(void)
+{
+ register uint32_t __regIPSR __ASM("ipsr");
+ return(__regIPSR);
+}
+
+
+/**
+ \brief Get APSR Register
+ \details Returns the content of the APSR Register.
+ \return APSR Register value
+ */
+__STATIC_INLINE uint32_t __get_APSR(void)
+{
+ register uint32_t __regAPSR __ASM("apsr");
+ return(__regAPSR);
+}
+
+
+/**
+ \brief Get xPSR Register
+ \details Returns the content of the xPSR Register.
+ \return xPSR Register value
+ */
+__STATIC_INLINE uint32_t __get_xPSR(void)
+{
+ register uint32_t __regXPSR __ASM("xpsr");
+ return(__regXPSR);
+}
+
+
+/**
+ \brief Get Process Stack Pointer
+ \details Returns the current value of the Process Stack Pointer (PSP).
+ \return PSP Register value
+ */
+__STATIC_INLINE uint32_t __get_PSP(void)
+{
+ register uint32_t __regProcessStackPointer __ASM("psp");
+ return(__regProcessStackPointer);
+}
+
+
+/**
+ \brief Set Process Stack Pointer
+ \details Assigns the given value to the Process Stack Pointer (PSP).
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
+{
+ register uint32_t __regProcessStackPointer __ASM("psp");
+ __regProcessStackPointer = topOfProcStack;
+}
+
+
+/**
+ \brief Get Main Stack Pointer
+ \details Returns the current value of the Main Stack Pointer (MSP).
+ \return MSP Register value
+ */
+__STATIC_INLINE uint32_t __get_MSP(void)
+{
+ register uint32_t __regMainStackPointer __ASM("msp");
+ return(__regMainStackPointer);
+}
+
+
+/**
+ \brief Set Main Stack Pointer
+ \details Assigns the given value to the Main Stack Pointer (MSP).
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
+{
+ register uint32_t __regMainStackPointer __ASM("msp");
+ __regMainStackPointer = topOfMainStack;
+}
+
+
+/**
+ \brief Get Priority Mask
+ \details Returns the current state of the priority mask bit from the Priority Mask Register.
+ \return Priority Mask value
+ */
+__STATIC_INLINE uint32_t __get_PRIMASK(void)
+{
+ register uint32_t __regPriMask __ASM("primask");
+ return(__regPriMask);
+}
+
+
+/**
+ \brief Set Priority Mask
+ \details Assigns the given value to the Priority Mask Register.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
+{
+ register uint32_t __regPriMask __ASM("primask");
+ __regPriMask = (priMask);
+}
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
+
+/**
+ \brief Enable FIQ
+ \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+#define __enable_fault_irq __enable_fiq
+
+
+/**
+ \brief Disable FIQ
+ \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+#define __disable_fault_irq __disable_fiq
+
+
+/**
+ \brief Get Base Priority
+ \details Returns the current value of the Base Priority register.
+ \return Base Priority register value
+ */
+__STATIC_INLINE uint32_t __get_BASEPRI(void)
+{
+ register uint32_t __regBasePri __ASM("basepri");
+ return(__regBasePri);
+}
+
+
+/**
+ \brief Set Base Priority
+ \details Assigns the given value to the Base Priority register.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
+{
+ register uint32_t __regBasePri __ASM("basepri");
+ __regBasePri = (basePri & 0xFFU);
+}
+
+
+/**
+ \brief Set Base Priority with condition
+ \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
+ or the new value increases the BASEPRI priority level.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
+{
+ register uint32_t __regBasePriMax __ASM("basepri_max");
+ __regBasePriMax = (basePri & 0xFFU);
+}
+
+
+/**
+ \brief Get Fault Mask
+ \details Returns the current value of the Fault Mask register.
+ \return Fault Mask register value
+ */
+__STATIC_INLINE uint32_t __get_FAULTMASK(void)
+{
+ register uint32_t __regFaultMask __ASM("faultmask");
+ return(__regFaultMask);
+}
+
+
+/**
+ \brief Set Fault Mask
+ \details Assigns the given value to the Fault Mask register.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
+{
+ register uint32_t __regFaultMask __ASM("faultmask");
+ __regFaultMask = (faultMask & (uint32_t)1U);
+}
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
+
+
+/**
+ \brief Get FPSCR
+ \details Returns the current value of the Floating Point Status/Control register.
+ \return Floating Point Status/Control register value
+ */
+__STATIC_INLINE uint32_t __get_FPSCR(void)
+{
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+ register uint32_t __regfpscr __ASM("fpscr");
+ return(__regfpscr);
+#else
+ return(0U);
+#endif
+}
+
+
+/**
+ \brief Set FPSCR
+ \details Assigns the given value to the Floating Point Status/Control register.
+ \param [in] fpscr Floating Point Status/Control value to set
+ */
+__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
+{
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+ register uint32_t __regfpscr __ASM("fpscr");
+ __regfpscr = (fpscr);
+#else
+ (void)fpscr;
+#endif
+}
+
+
+/*@} end of CMSIS_Core_RegAccFunctions */
+
+
+/* ################### Compiler specific Intrinsics ########################### */
+/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
+ Access to dedicated SIMD instructions
+ @{
+*/
+
+#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
+
+#define __SADD8 __sadd8
+#define __QADD8 __qadd8
+#define __SHADD8 __shadd8
+#define __UADD8 __uadd8
+#define __UQADD8 __uqadd8
+#define __UHADD8 __uhadd8
+#define __SSUB8 __ssub8
+#define __QSUB8 __qsub8
+#define __SHSUB8 __shsub8
+#define __USUB8 __usub8
+#define __UQSUB8 __uqsub8
+#define __UHSUB8 __uhsub8
+#define __SADD16 __sadd16
+#define __QADD16 __qadd16
+#define __SHADD16 __shadd16
+#define __UADD16 __uadd16
+#define __UQADD16 __uqadd16
+#define __UHADD16 __uhadd16
+#define __SSUB16 __ssub16
+#define __QSUB16 __qsub16
+#define __SHSUB16 __shsub16
+#define __USUB16 __usub16
+#define __UQSUB16 __uqsub16
+#define __UHSUB16 __uhsub16
+#define __SASX __sasx
+#define __QASX __qasx
+#define __SHASX __shasx
+#define __UASX __uasx
+#define __UQASX __uqasx
+#define __UHASX __uhasx
+#define __SSAX __ssax
+#define __QSAX __qsax
+#define __SHSAX __shsax
+#define __USAX __usax
+#define __UQSAX __uqsax
+#define __UHSAX __uhsax
+#define __USAD8 __usad8
+#define __USADA8 __usada8
+#define __SSAT16 __ssat16
+#define __USAT16 __usat16
+#define __UXTB16 __uxtb16
+#define __UXTAB16 __uxtab16
+#define __SXTB16 __sxtb16
+#define __SXTAB16 __sxtab16
+#define __SMUAD __smuad
+#define __SMUADX __smuadx
+#define __SMLAD __smlad
+#define __SMLADX __smladx
+#define __SMLALD __smlald
+#define __SMLALDX __smlaldx
+#define __SMUSD __smusd
+#define __SMUSDX __smusdx
+#define __SMLSD __smlsd
+#define __SMLSDX __smlsdx
+#define __SMLSLD __smlsld
+#define __SMLSLDX __smlsldx
+#define __SEL __sel
+#define __QADD __qadd
+#define __QSUB __qsub
+
+#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
+ ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
+
+#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
+ ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
+
+#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
+ ((int64_t)(ARG3) << 32U) ) >> 32U))
+
+#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
+
+#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
+
+#endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
+/*@} end of group CMSIS_SIMD_intrinsics */
+
+
+#endif /* __CMSIS_ARMCC_H */
diff --git a/CMSIS/Core/Include/cmsis_armclang.h b/CMSIS/Core/Include/cmsis_armclang.h
new file mode 100644
index 0000000..6911417
--- /dev/null
+++ b/CMSIS/Core/Include/cmsis_armclang.h
@@ -0,0 +1,1503 @@
+/**************************************************************************//**
+ * @file cmsis_armclang.h
+ * @brief CMSIS compiler armclang (Arm Compiler 6) header file
+ * @version V5.4.3
+ * @date 27. May 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+/*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */
+
+#ifndef __CMSIS_ARMCLANG_H
+#define __CMSIS_ARMCLANG_H
+
+#pragma clang system_header /* treat file as system include file */
+
+/* CMSIS compiler specific defines */
+#ifndef __ASM
+ #define __ASM __asm
+#endif
+#ifndef __INLINE
+ #define __INLINE __inline
+#endif
+#ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static __inline
+#endif
+#ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
+#endif
+#ifndef __NO_RETURN
+ #define __NO_RETURN __attribute__((__noreturn__))
+#endif
+#ifndef __USED
+ #define __USED __attribute__((used))
+#endif
+#ifndef __WEAK
+ #define __WEAK __attribute__((weak))
+#endif
+#ifndef __PACKED
+ #define __PACKED __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_UNION
+ #define __PACKED_UNION union __attribute__((packed, aligned(1)))
+#endif
+#ifndef __UNALIGNED_UINT32 /* deprecated */
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */
+ struct __attribute__((packed)) T_UINT32 { uint32_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
+#endif
+#ifndef __UNALIGNED_UINT16_WRITE
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
+ __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
+#endif
+#ifndef __UNALIGNED_UINT16_READ
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
+ __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
+#endif
+#ifndef __UNALIGNED_UINT32_WRITE
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
+ __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
+#endif
+#ifndef __UNALIGNED_UINT32_READ
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
+ __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
+#endif
+#ifndef __ALIGNED
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+#endif
+#ifndef __RESTRICT
+ #define __RESTRICT __restrict
+#endif
+#ifndef __COMPILER_BARRIER
+ #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
+#endif
+
+/* ######################### Startup and Lowlevel Init ######################## */
+
+#ifndef __PROGRAM_START
+#define __PROGRAM_START __main
+#endif
+
+#ifndef __INITIAL_SP
+#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
+#endif
+
+#ifndef __STACK_LIMIT
+#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base
+#endif
+
+#ifndef __VECTOR_TABLE
+#define __VECTOR_TABLE __Vectors
+#endif
+
+#ifndef __VECTOR_TABLE_ATTRIBUTE
+#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET")))
+#endif
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#ifndef __STACK_SEAL
+#define __STACK_SEAL Image$$STACKSEAL$$ZI$$Base
+#endif
+
+#ifndef __TZ_STACK_SEAL_SIZE
+#define __TZ_STACK_SEAL_SIZE 8U
+#endif
+
+#ifndef __TZ_STACK_SEAL_VALUE
+#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
+#endif
+
+
+__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
+ *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
+}
+#endif
+
+
+/* ########################## Core Instruction Access ######################### */
+/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
+ Access to dedicated instructions
+ @{
+*/
+
+/* Define macros for porting to both thumb1 and thumb2.
+ * For thumb1, use low register (r0-r7), specified by constraint "l"
+ * Otherwise, use general registers, specified by constraint "r" */
+#if defined (__thumb__) && !defined (__thumb2__)
+#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
+#define __CMSIS_GCC_RW_REG(r) "+l" (r)
+#define __CMSIS_GCC_USE_REG(r) "l" (r)
+#else
+#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
+#define __CMSIS_GCC_RW_REG(r) "+r" (r)
+#define __CMSIS_GCC_USE_REG(r) "r" (r)
+#endif
+
+/**
+ \brief No Operation
+ \details No Operation does nothing. This instruction can be used for code alignment purposes.
+ */
+#define __NOP __builtin_arm_nop
+
+/**
+ \brief Wait For Interrupt
+ \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
+ */
+#define __WFI __builtin_arm_wfi
+
+
+/**
+ \brief Wait For Event
+ \details Wait For Event is a hint instruction that permits the processor to enter
+ a low-power state until one of a number of events occurs.
+ */
+#define __WFE __builtin_arm_wfe
+
+
+/**
+ \brief Send Event
+ \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
+ */
+#define __SEV __builtin_arm_sev
+
+
+/**
+ \brief Instruction Synchronization Barrier
+ \details Instruction Synchronization Barrier flushes the pipeline in the processor,
+ so that all instructions following the ISB are fetched from cache or memory,
+ after the instruction has been completed.
+ */
+#define __ISB() __builtin_arm_isb(0xF)
+
+/**
+ \brief Data Synchronization Barrier
+ \details Acts as a special kind of Data Memory Barrier.
+ It completes when all explicit memory accesses before this instruction complete.
+ */
+#define __DSB() __builtin_arm_dsb(0xF)
+
+
+/**
+ \brief Data Memory Barrier
+ \details Ensures the apparent order of the explicit memory operations before
+ and after the instruction, without ensuring their completion.
+ */
+#define __DMB() __builtin_arm_dmb(0xF)
+
+
+/**
+ \brief Reverse byte order (32 bit)
+ \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REV(value) __builtin_bswap32(value)
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REV16(value) __ROR(__REV(value), 16)
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REVSH(value) (int16_t)__builtin_bswap16(value)
+
+
+/**
+ \brief Rotate Right in unsigned value (32 bit)
+ \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
+ \param [in] op1 Value to rotate
+ \param [in] op2 Number of Bits to rotate
+ \return Rotated value
+ */
+__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
+{
+ op2 %= 32U;
+ if (op2 == 0U)
+ {
+ return op1;
+ }
+ return (op1 >> op2) | (op1 << (32U - op2));
+}
+
+
+/**
+ \brief Breakpoint
+ \details Causes the processor to enter Debug state.
+ Debug tools can use this to investigate system state when the instruction at a particular address is reached.
+ \param [in] value is ignored by the processor.
+ If required, a debugger can use it to store additional information about the breakpoint.
+ */
+#define __BKPT(value) __ASM volatile ("bkpt "#value)
+
+
+/**
+ \brief Reverse bit order of value
+ \details Reverses the bit order of the given value.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __RBIT __builtin_arm_rbit
+
+/**
+ \brief Count leading zeros
+ \details Counts the number of leading zeros of a data value.
+ \param [in] value Value to count the leading zeros
+ \return number of leading zeros in value
+ */
+__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
+{
+ /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
+ __builtin_clz(0) is undefined behaviour, so handle this case specially.
+ This guarantees ARM-compatible results if happening to compile on a non-ARM
+ target, and ensures the compiler doesn't decide to activate any
+ optimisations using the logic "value was passed to __builtin_clz, so it
+ is non-zero".
+ ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a
+ single CLZ instruction.
+ */
+ if (value == 0U)
+ {
+ return 32U;
+ }
+ return __builtin_clz(value);
+}
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
+
+/**
+ \brief LDR Exclusive (8 bit)
+ \details Executes a exclusive LDR instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+#define __LDREXB (uint8_t)__builtin_arm_ldrex
+
+
+/**
+ \brief LDR Exclusive (16 bit)
+ \details Executes a exclusive LDR instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+#define __LDREXH (uint16_t)__builtin_arm_ldrex
+
+
+/**
+ \brief LDR Exclusive (32 bit)
+ \details Executes a exclusive LDR instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+#define __LDREXW (uint32_t)__builtin_arm_ldrex
+
+
+/**
+ \brief STR Exclusive (8 bit)
+ \details Executes a exclusive STR instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STREXB (uint32_t)__builtin_arm_strex
+
+
+/**
+ \brief STR Exclusive (16 bit)
+ \details Executes a exclusive STR instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STREXH (uint32_t)__builtin_arm_strex
+
+
+/**
+ \brief STR Exclusive (32 bit)
+ \details Executes a exclusive STR instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STREXW (uint32_t)__builtin_arm_strex
+
+
+/**
+ \brief Remove the exclusive lock
+ \details Removes the exclusive lock which is created by LDREX.
+ */
+#define __CLREX __builtin_arm_clrex
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+#define __SSAT __builtin_arm_ssat
+
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+#define __USAT __builtin_arm_usat
+
+
+/**
+ \brief Rotate Right with Extend (32 bit)
+ \details Moves each bit of a bitstring right by one bit.
+ The carry input is shifted in at the left end of the bitstring.
+ \param [in] value Value to rotate
+ \return Rotated value
+ */
+__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
+{
+ uint32_t result;
+
+ __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
+ return(result);
+}
+
+
+/**
+ \brief LDRT Unprivileged (8 bit)
+ \details Executes a Unprivileged LDRT instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return ((uint8_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDRT Unprivileged (16 bit)
+ \details Executes a Unprivileged LDRT instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return ((uint16_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDRT Unprivileged (32 bit)
+ \details Executes a Unprivileged LDRT instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return(result);
+}
+
+
+/**
+ \brief STRT Unprivileged (8 bit)
+ \details Executes a Unprivileged STRT instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
+{
+ __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
+}
+
+
+/**
+ \brief STRT Unprivileged (16 bit)
+ \details Executes a Unprivileged STRT instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
+{
+ __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
+}
+
+
+/**
+ \brief STRT Unprivileged (32 bit)
+ \details Executes a Unprivileged STRT instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
+{
+ __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
+}
+
+#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
+{
+ if ((sat >= 1U) && (sat <= 32U))
+ {
+ const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
+ const int32_t min = -1 - max ;
+ if (val > max)
+ {
+ return max;
+ }
+ else if (val < min)
+ {
+ return min;
+ }
+ }
+ return val;
+}
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
+{
+ if (sat <= 31U)
+ {
+ const uint32_t max = ((1U << sat) - 1U);
+ if (val > (int32_t)max)
+ {
+ return max;
+ }
+ else if (val < 0)
+ {
+ return 0U;
+ }
+ }
+ return (uint32_t)val;
+}
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
+
+/**
+ \brief Load-Acquire (8 bit)
+ \details Executes a LDAB instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint8_t) result);
+}
+
+
+/**
+ \brief Load-Acquire (16 bit)
+ \details Executes a LDAH instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint16_t) result);
+}
+
+
+/**
+ \brief Load-Acquire (32 bit)
+ \details Executes a LDA instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return(result);
+}
+
+
+/**
+ \brief Store-Release (8 bit)
+ \details Executes a STLB instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
+{
+ __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Store-Release (16 bit)
+ \details Executes a STLH instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
+{
+ __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Store-Release (32 bit)
+ \details Executes a STL instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
+{
+ __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Load-Acquire Exclusive (8 bit)
+ \details Executes a LDAB exclusive instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+#define __LDAEXB (uint8_t)__builtin_arm_ldaex
+
+
+/**
+ \brief Load-Acquire Exclusive (16 bit)
+ \details Executes a LDAH exclusive instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+#define __LDAEXH (uint16_t)__builtin_arm_ldaex
+
+
+/**
+ \brief Load-Acquire Exclusive (32 bit)
+ \details Executes a LDA exclusive instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+#define __LDAEX (uint32_t)__builtin_arm_ldaex
+
+
+/**
+ \brief Store-Release Exclusive (8 bit)
+ \details Executes a STLB exclusive instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STLEXB (uint32_t)__builtin_arm_stlex
+
+
+/**
+ \brief Store-Release Exclusive (16 bit)
+ \details Executes a STLH exclusive instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STLEXH (uint32_t)__builtin_arm_stlex
+
+
+/**
+ \brief Store-Release Exclusive (32 bit)
+ \details Executes a STL exclusive instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STLEX (uint32_t)__builtin_arm_stlex
+
+#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */
+
+/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
+
+
+/* ########################### Core Function Access ########################### */
+/** \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
+ @{
+ */
+
+/**
+ \brief Enable IRQ Interrupts
+ \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+#ifndef __ARM_COMPAT_H
+__STATIC_FORCEINLINE void __enable_irq(void)
+{
+ __ASM volatile ("cpsie i" : : : "memory");
+}
+#endif
+
+
+/**
+ \brief Disable IRQ Interrupts
+ \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+#ifndef __ARM_COMPAT_H
+__STATIC_FORCEINLINE void __disable_irq(void)
+{
+ __ASM volatile ("cpsid i" : : : "memory");
+}
+#endif
+
+
+/**
+ \brief Get Control Register
+ \details Returns the content of the Control Register.
+ \return Control Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, control" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Control Register (non-secure)
+ \details Returns the content of the non-secure Control Register when in secure mode.
+ \return non-secure Control Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Control Register
+ \details Writes the given value to the Control Register.
+ \param [in] control Control Register value to set
+ */
+__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
+{
+ __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
+ __ISB();
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Control Register (non-secure)
+ \details Writes the given value to the non-secure Control Register when in secure state.
+ \param [in] control Control Register value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
+{
+ __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
+ __ISB();
+}
+#endif
+
+
+/**
+ \brief Get IPSR Register
+ \details Returns the content of the IPSR Register.
+ \return IPSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_IPSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get APSR Register
+ \details Returns the content of the APSR Register.
+ \return APSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_APSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, apsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get xPSR Register
+ \details Returns the content of the xPSR Register.
+ \return xPSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_xPSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get Process Stack Pointer
+ \details Returns the current value of the Process Stack Pointer (PSP).
+ \return PSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PSP(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, psp" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Process Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
+ \return PSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Process Stack Pointer
+ \details Assigns the given value to the Process Stack Pointer (PSP).
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
+{
+ __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Process Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
+{
+ __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
+}
+#endif
+
+
+/**
+ \brief Get Main Stack Pointer
+ \details Returns the current value of the Main Stack Pointer (MSP).
+ \return MSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_MSP(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, msp" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Main Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
+ \return MSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Main Stack Pointer
+ \details Assigns the given value to the Main Stack Pointer (MSP).
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
+{
+ __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Main Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
+{
+ __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
+}
+#endif
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
+ \return SP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Set Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
+ \param [in] topOfStack Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
+{
+ __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
+}
+#endif
+
+
+/**
+ \brief Get Priority Mask
+ \details Returns the current state of the priority mask bit from the Priority Mask Register.
+ \return Priority Mask value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, primask" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Priority Mask (non-secure)
+ \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
+ \return Priority Mask value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Priority Mask
+ \details Assigns the given value to the Priority Mask Register.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
+{
+ __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Priority Mask (non-secure)
+ \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
+{
+ __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
+}
+#endif
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
+/**
+ \brief Enable FIQ
+ \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __enable_fault_irq(void)
+{
+ __ASM volatile ("cpsie f" : : : "memory");
+}
+
+
+/**
+ \brief Disable FIQ
+ \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __disable_fault_irq(void)
+{
+ __ASM volatile ("cpsid f" : : : "memory");
+}
+
+
+/**
+ \brief Get Base Priority
+ \details Returns the current value of the Base Priority register.
+ \return Base Priority register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, basepri" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Base Priority (non-secure)
+ \details Returns the current value of the non-secure Base Priority register when in secure state.
+ \return Base Priority register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Base Priority
+ \details Assigns the given value to the Base Priority register.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Base Priority (non-secure)
+ \details Assigns the given value to the non-secure Base Priority register when in secure state.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
+}
+#endif
+
+
+/**
+ \brief Set Base Priority with condition
+ \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
+ or the new value increases the BASEPRI priority level.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
+}
+
+
+/**
+ \brief Get Fault Mask
+ \details Returns the current value of the Fault Mask register.
+ \return Fault Mask register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Fault Mask (non-secure)
+ \details Returns the current value of the non-secure Fault Mask register when in secure state.
+ \return Fault Mask register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Fault Mask
+ \details Assigns the given value to the Fault Mask register.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
+{
+ __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Fault Mask (non-secure)
+ \details Assigns the given value to the non-secure Fault Mask register when in secure state.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
+{
+ __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
+}
+#endif
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
+
+/**
+ \brief Get Process Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always in non-secure
+ mode.
+
+ \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
+ \return PSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, psplim" : "=r" (result) );
+ return result;
+#endif
+}
+
+#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Process Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always in non-secure
+ mode.
+
+ \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
+ \return PSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) )
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
+ return result;
+#endif
+}
+#endif
+
+
+/**
+ \brief Set Process Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored in non-secure
+ mode.
+
+ \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
+ \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)ProcStackPtrLimit;
+#else
+ __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Process Stack Pointer (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored in non-secure
+ mode.
+
+ \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
+ \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) )
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)ProcStackPtrLimit;
+#else
+ __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
+#endif
+}
+#endif
+
+
+/**
+ \brief Get Main Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always.
+
+ \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
+ \return MSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, msplim" : "=r" (result) );
+ return result;
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Main Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always.
+
+ \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
+ \return MSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) )
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
+ return result;
+#endif
+}
+#endif
+
+
+/**
+ \brief Set Main Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored.
+
+ \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
+ \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)MainStackPtrLimit;
+#else
+ __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Main Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored.
+
+ \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
+ \param [in] MainStackPtrLimit Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
+{
+#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) )
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)MainStackPtrLimit;
+#else
+ __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
+#endif
+}
+#endif
+
+#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
+ (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */
+
+/**
+ \brief Get FPSCR
+ \details Returns the current value of the Floating Point Status/Control register.
+ \return Floating Point Status/Control register value
+ */
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr
+#else
+#define __get_FPSCR() ((uint32_t)0U)
+#endif
+
+/**
+ \brief Set FPSCR
+ \details Assigns the given value to the Floating Point Status/Control register.
+ \param [in] fpscr Floating Point Status/Control value to set
+ */
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+#define __set_FPSCR __builtin_arm_set_fpscr
+#else
+#define __set_FPSCR(x) ((void)(x))
+#endif
+
+
+/*@} end of CMSIS_Core_RegAccFunctions */
+
+
+/* ################### Compiler specific Intrinsics ########################### */
+/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
+ Access to dedicated SIMD instructions
+ @{
+*/
+
+#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
+
+#define __SADD8 __builtin_arm_sadd8
+#define __QADD8 __builtin_arm_qadd8
+#define __SHADD8 __builtin_arm_shadd8
+#define __UADD8 __builtin_arm_uadd8
+#define __UQADD8 __builtin_arm_uqadd8
+#define __UHADD8 __builtin_arm_uhadd8
+#define __SSUB8 __builtin_arm_ssub8
+#define __QSUB8 __builtin_arm_qsub8
+#define __SHSUB8 __builtin_arm_shsub8
+#define __USUB8 __builtin_arm_usub8
+#define __UQSUB8 __builtin_arm_uqsub8
+#define __UHSUB8 __builtin_arm_uhsub8
+#define __SADD16 __builtin_arm_sadd16
+#define __QADD16 __builtin_arm_qadd16
+#define __SHADD16 __builtin_arm_shadd16
+#define __UADD16 __builtin_arm_uadd16
+#define __UQADD16 __builtin_arm_uqadd16
+#define __UHADD16 __builtin_arm_uhadd16
+#define __SSUB16 __builtin_arm_ssub16
+#define __QSUB16 __builtin_arm_qsub16
+#define __SHSUB16 __builtin_arm_shsub16
+#define __USUB16 __builtin_arm_usub16
+#define __UQSUB16 __builtin_arm_uqsub16
+#define __UHSUB16 __builtin_arm_uhsub16
+#define __SASX __builtin_arm_sasx
+#define __QASX __builtin_arm_qasx
+#define __SHASX __builtin_arm_shasx
+#define __UASX __builtin_arm_uasx
+#define __UQASX __builtin_arm_uqasx
+#define __UHASX __builtin_arm_uhasx
+#define __SSAX __builtin_arm_ssax
+#define __QSAX __builtin_arm_qsax
+#define __SHSAX __builtin_arm_shsax
+#define __USAX __builtin_arm_usax
+#define __UQSAX __builtin_arm_uqsax
+#define __UHSAX __builtin_arm_uhsax
+#define __USAD8 __builtin_arm_usad8
+#define __USADA8 __builtin_arm_usada8
+#define __SSAT16 __builtin_arm_ssat16
+#define __USAT16 __builtin_arm_usat16
+#define __UXTB16 __builtin_arm_uxtb16
+#define __UXTAB16 __builtin_arm_uxtab16
+#define __SXTB16 __builtin_arm_sxtb16
+#define __SXTAB16 __builtin_arm_sxtab16
+#define __SMUAD __builtin_arm_smuad
+#define __SMUADX __builtin_arm_smuadx
+#define __SMLAD __builtin_arm_smlad
+#define __SMLADX __builtin_arm_smladx
+#define __SMLALD __builtin_arm_smlald
+#define __SMLALDX __builtin_arm_smlaldx
+#define __SMUSD __builtin_arm_smusd
+#define __SMUSDX __builtin_arm_smusdx
+#define __SMLSD __builtin_arm_smlsd
+#define __SMLSDX __builtin_arm_smlsdx
+#define __SMLSLD __builtin_arm_smlsld
+#define __SMLSLDX __builtin_arm_smlsldx
+#define __SEL __builtin_arm_sel
+#define __QADD __builtin_arm_qadd
+#define __QSUB __builtin_arm_qsub
+
+#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
+ ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
+
+#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
+ ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
+
+#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
+
+#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
+
+__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
+{
+ int32_t result;
+
+ __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+#endif /* (__ARM_FEATURE_DSP == 1) */
+/*@} end of group CMSIS_SIMD_intrinsics */
+
+
+#endif /* __CMSIS_ARMCLANG_H */
diff --git a/CMSIS/Core/Include/cmsis_armclang_ltm.h b/CMSIS/Core/Include/cmsis_armclang_ltm.h
new file mode 100644
index 0000000..1e255d5
--- /dev/null
+++ b/CMSIS/Core/Include/cmsis_armclang_ltm.h
@@ -0,0 +1,1928 @@
+/**************************************************************************//**
+ * @file cmsis_armclang_ltm.h
+ * @brief CMSIS compiler armclang (Arm Compiler 6) header file
+ * @version V1.5.3
+ * @date 27. May 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2018-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+/*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */
+
+#ifndef __CMSIS_ARMCLANG_H
+#define __CMSIS_ARMCLANG_H
+
+#pragma clang system_header /* treat file as system include file */
+
+/* CMSIS compiler specific defines */
+#ifndef __ASM
+ #define __ASM __asm
+#endif
+#ifndef __INLINE
+ #define __INLINE __inline
+#endif
+#ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static __inline
+#endif
+#ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
+#endif
+#ifndef __NO_RETURN
+ #define __NO_RETURN __attribute__((__noreturn__))
+#endif
+#ifndef __USED
+ #define __USED __attribute__((used))
+#endif
+#ifndef __WEAK
+ #define __WEAK __attribute__((weak))
+#endif
+#ifndef __PACKED
+ #define __PACKED __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_UNION
+ #define __PACKED_UNION union __attribute__((packed, aligned(1)))
+#endif
+#ifndef __UNALIGNED_UINT32 /* deprecated */
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */
+ struct __attribute__((packed)) T_UINT32 { uint32_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
+#endif
+#ifndef __UNALIGNED_UINT16_WRITE
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
+ __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
+#endif
+#ifndef __UNALIGNED_UINT16_READ
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
+ __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
+#endif
+#ifndef __UNALIGNED_UINT32_WRITE
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
+ __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
+#endif
+#ifndef __UNALIGNED_UINT32_READ
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wpacked"
+/*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */
+ __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
+ #pragma clang diagnostic pop
+ #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
+#endif
+#ifndef __ALIGNED
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+#endif
+#ifndef __RESTRICT
+ #define __RESTRICT __restrict
+#endif
+#ifndef __COMPILER_BARRIER
+ #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
+#endif
+
+/* ######################### Startup and Lowlevel Init ######################## */
+
+#ifndef __PROGRAM_START
+#define __PROGRAM_START __main
+#endif
+
+#ifndef __INITIAL_SP
+#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
+#endif
+
+#ifndef __STACK_LIMIT
+#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base
+#endif
+
+#ifndef __VECTOR_TABLE
+#define __VECTOR_TABLE __Vectors
+#endif
+
+#ifndef __VECTOR_TABLE_ATTRIBUTE
+#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET")))
+#endif
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#ifndef __STACK_SEAL
+#define __STACK_SEAL Image$$STACKSEAL$$ZI$$Base
+#endif
+
+#ifndef __TZ_STACK_SEAL_SIZE
+#define __TZ_STACK_SEAL_SIZE 8U
+#endif
+
+#ifndef __TZ_STACK_SEAL_VALUE
+#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
+#endif
+
+
+__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
+ *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
+}
+#endif
+
+
+/* ########################## Core Instruction Access ######################### */
+/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
+ Access to dedicated instructions
+ @{
+*/
+
+/* Define macros for porting to both thumb1 and thumb2.
+ * For thumb1, use low register (r0-r7), specified by constraint "l"
+ * Otherwise, use general registers, specified by constraint "r" */
+#if defined (__thumb__) && !defined (__thumb2__)
+#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
+#define __CMSIS_GCC_USE_REG(r) "l" (r)
+#else
+#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
+#define __CMSIS_GCC_USE_REG(r) "r" (r)
+#endif
+
+/**
+ \brief No Operation
+ \details No Operation does nothing. This instruction can be used for code alignment purposes.
+ */
+#define __NOP __builtin_arm_nop
+
+/**
+ \brief Wait For Interrupt
+ \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
+ */
+#define __WFI __builtin_arm_wfi
+
+
+/**
+ \brief Wait For Event
+ \details Wait For Event is a hint instruction that permits the processor to enter
+ a low-power state until one of a number of events occurs.
+ */
+#define __WFE __builtin_arm_wfe
+
+
+/**
+ \brief Send Event
+ \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
+ */
+#define __SEV __builtin_arm_sev
+
+
+/**
+ \brief Instruction Synchronization Barrier
+ \details Instruction Synchronization Barrier flushes the pipeline in the processor,
+ so that all instructions following the ISB are fetched from cache or memory,
+ after the instruction has been completed.
+ */
+#define __ISB() __builtin_arm_isb(0xF)
+
+/**
+ \brief Data Synchronization Barrier
+ \details Acts as a special kind of Data Memory Barrier.
+ It completes when all explicit memory accesses before this instruction complete.
+ */
+#define __DSB() __builtin_arm_dsb(0xF)
+
+
+/**
+ \brief Data Memory Barrier
+ \details Ensures the apparent order of the explicit memory operations before
+ and after the instruction, without ensuring their completion.
+ */
+#define __DMB() __builtin_arm_dmb(0xF)
+
+
+/**
+ \brief Reverse byte order (32 bit)
+ \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REV(value) __builtin_bswap32(value)
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REV16(value) __ROR(__REV(value), 16)
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __REVSH(value) (int16_t)__builtin_bswap16(value)
+
+
+/**
+ \brief Rotate Right in unsigned value (32 bit)
+ \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
+ \param [in] op1 Value to rotate
+ \param [in] op2 Number of Bits to rotate
+ \return Rotated value
+ */
+__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
+{
+ op2 %= 32U;
+ if (op2 == 0U)
+ {
+ return op1;
+ }
+ return (op1 >> op2) | (op1 << (32U - op2));
+}
+
+
+/**
+ \brief Breakpoint
+ \details Causes the processor to enter Debug state.
+ Debug tools can use this to investigate system state when the instruction at a particular address is reached.
+ \param [in] value is ignored by the processor.
+ If required, a debugger can use it to store additional information about the breakpoint.
+ */
+#define __BKPT(value) __ASM volatile ("bkpt "#value)
+
+
+/**
+ \brief Reverse bit order of value
+ \details Reverses the bit order of the given value.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+#define __RBIT __builtin_arm_rbit
+
+/**
+ \brief Count leading zeros
+ \details Counts the number of leading zeros of a data value.
+ \param [in] value Value to count the leading zeros
+ \return number of leading zeros in value
+ */
+__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
+{
+ /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
+ __builtin_clz(0) is undefined behaviour, so handle this case specially.
+ This guarantees ARM-compatible results if happening to compile on a non-ARM
+ target, and ensures the compiler doesn't decide to activate any
+ optimisations using the logic "value was passed to __builtin_clz, so it
+ is non-zero".
+ ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a
+ single CLZ instruction.
+ */
+ if (value == 0U)
+ {
+ return 32U;
+ }
+ return __builtin_clz(value);
+}
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+/**
+ \brief LDR Exclusive (8 bit)
+ \details Executes a exclusive LDR instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+#define __LDREXB (uint8_t)__builtin_arm_ldrex
+
+
+/**
+ \brief LDR Exclusive (16 bit)
+ \details Executes a exclusive LDR instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+#define __LDREXH (uint16_t)__builtin_arm_ldrex
+
+
+/**
+ \brief LDR Exclusive (32 bit)
+ \details Executes a exclusive LDR instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+#define __LDREXW (uint32_t)__builtin_arm_ldrex
+
+
+/**
+ \brief STR Exclusive (8 bit)
+ \details Executes a exclusive STR instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STREXB (uint32_t)__builtin_arm_strex
+
+
+/**
+ \brief STR Exclusive (16 bit)
+ \details Executes a exclusive STR instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STREXH (uint32_t)__builtin_arm_strex
+
+
+/**
+ \brief STR Exclusive (32 bit)
+ \details Executes a exclusive STR instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STREXW (uint32_t)__builtin_arm_strex
+
+
+/**
+ \brief Remove the exclusive lock
+ \details Removes the exclusive lock which is created by LDREX.
+ */
+#define __CLREX __builtin_arm_clrex
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+#define __SSAT __builtin_arm_ssat
+
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+#define __USAT __builtin_arm_usat
+
+
+/**
+ \brief Rotate Right with Extend (32 bit)
+ \details Moves each bit of a bitstring right by one bit.
+ The carry input is shifted in at the left end of the bitstring.
+ \param [in] value Value to rotate
+ \return Rotated value
+ */
+__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
+{
+ uint32_t result;
+
+ __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
+ return(result);
+}
+
+
+/**
+ \brief LDRT Unprivileged (8 bit)
+ \details Executes a Unprivileged LDRT instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return ((uint8_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDRT Unprivileged (16 bit)
+ \details Executes a Unprivileged LDRT instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return ((uint16_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDRT Unprivileged (32 bit)
+ \details Executes a Unprivileged LDRT instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return(result);
+}
+
+
+/**
+ \brief STRT Unprivileged (8 bit)
+ \details Executes a Unprivileged STRT instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
+{
+ __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
+}
+
+
+/**
+ \brief STRT Unprivileged (16 bit)
+ \details Executes a Unprivileged STRT instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
+{
+ __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
+}
+
+
+/**
+ \brief STRT Unprivileged (32 bit)
+ \details Executes a Unprivileged STRT instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
+{
+ __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
+}
+
+#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
+{
+ if ((sat >= 1U) && (sat <= 32U))
+ {
+ const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
+ const int32_t min = -1 - max ;
+ if (val > max)
+ {
+ return max;
+ }
+ else if (val < min)
+ {
+ return min;
+ }
+ }
+ return val;
+}
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
+{
+ if (sat <= 31U)
+ {
+ const uint32_t max = ((1U << sat) - 1U);
+ if (val > (int32_t)max)
+ {
+ return max;
+ }
+ else if (val < 0)
+ {
+ return 0U;
+ }
+ }
+ return (uint32_t)val;
+}
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+/**
+ \brief Load-Acquire (8 bit)
+ \details Executes a LDAB instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint8_t) result);
+}
+
+
+/**
+ \brief Load-Acquire (16 bit)
+ \details Executes a LDAH instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint16_t) result);
+}
+
+
+/**
+ \brief Load-Acquire (32 bit)
+ \details Executes a LDA instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return(result);
+}
+
+
+/**
+ \brief Store-Release (8 bit)
+ \details Executes a STLB instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
+{
+ __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Store-Release (16 bit)
+ \details Executes a STLH instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
+{
+ __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Store-Release (32 bit)
+ \details Executes a STL instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
+{
+ __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Load-Acquire Exclusive (8 bit)
+ \details Executes a LDAB exclusive instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+#define __LDAEXB (uint8_t)__builtin_arm_ldaex
+
+
+/**
+ \brief Load-Acquire Exclusive (16 bit)
+ \details Executes a LDAH exclusive instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+#define __LDAEXH (uint16_t)__builtin_arm_ldaex
+
+
+/**
+ \brief Load-Acquire Exclusive (32 bit)
+ \details Executes a LDA exclusive instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+#define __LDAEX (uint32_t)__builtin_arm_ldaex
+
+
+/**
+ \brief Store-Release Exclusive (8 bit)
+ \details Executes a STLB exclusive instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STLEXB (uint32_t)__builtin_arm_stlex
+
+
+/**
+ \brief Store-Release Exclusive (16 bit)
+ \details Executes a STLH exclusive instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STLEXH (uint32_t)__builtin_arm_stlex
+
+
+/**
+ \brief Store-Release Exclusive (32 bit)
+ \details Executes a STL exclusive instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+#define __STLEX (uint32_t)__builtin_arm_stlex
+
+#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
+
+/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
+
+
+/* ########################### Core Function Access ########################### */
+/** \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
+ @{
+ */
+
+/**
+ \brief Enable IRQ Interrupts
+ \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+#ifndef __ARM_COMPAT_H
+__STATIC_FORCEINLINE void __enable_irq(void)
+{
+ __ASM volatile ("cpsie i" : : : "memory");
+}
+#endif
+
+
+/**
+ \brief Disable IRQ Interrupts
+ \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+#ifndef __ARM_COMPAT_H
+__STATIC_FORCEINLINE void __disable_irq(void)
+{
+ __ASM volatile ("cpsid i" : : : "memory");
+}
+#endif
+
+
+/**
+ \brief Get Control Register
+ \details Returns the content of the Control Register.
+ \return Control Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, control" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Control Register (non-secure)
+ \details Returns the content of the non-secure Control Register when in secure mode.
+ \return non-secure Control Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Control Register
+ \details Writes the given value to the Control Register.
+ \param [in] control Control Register value to set
+ */
+__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
+{
+ __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
+ __ISB();
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Control Register (non-secure)
+ \details Writes the given value to the non-secure Control Register when in secure state.
+ \param [in] control Control Register value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
+{
+ __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
+ __ISB();
+}
+#endif
+
+
+/**
+ \brief Get IPSR Register
+ \details Returns the content of the IPSR Register.
+ \return IPSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_IPSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get APSR Register
+ \details Returns the content of the APSR Register.
+ \return APSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_APSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, apsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get xPSR Register
+ \details Returns the content of the xPSR Register.
+ \return xPSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_xPSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get Process Stack Pointer
+ \details Returns the current value of the Process Stack Pointer (PSP).
+ \return PSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PSP(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, psp" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Process Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
+ \return PSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Process Stack Pointer
+ \details Assigns the given value to the Process Stack Pointer (PSP).
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
+{
+ __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Process Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
+{
+ __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
+}
+#endif
+
+
+/**
+ \brief Get Main Stack Pointer
+ \details Returns the current value of the Main Stack Pointer (MSP).
+ \return MSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_MSP(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, msp" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Main Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
+ \return MSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Main Stack Pointer
+ \details Assigns the given value to the Main Stack Pointer (MSP).
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
+{
+ __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Main Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
+{
+ __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
+}
+#endif
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
+ \return SP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Set Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
+ \param [in] topOfStack Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
+{
+ __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
+}
+#endif
+
+
+/**
+ \brief Get Priority Mask
+ \details Returns the current state of the priority mask bit from the Priority Mask Register.
+ \return Priority Mask value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, primask" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Priority Mask (non-secure)
+ \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
+ \return Priority Mask value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Priority Mask
+ \details Assigns the given value to the Priority Mask Register.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
+{
+ __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Priority Mask (non-secure)
+ \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
+{
+ __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
+}
+#endif
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
+/**
+ \brief Enable FIQ
+ \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __enable_fault_irq(void)
+{
+ __ASM volatile ("cpsie f" : : : "memory");
+}
+
+
+/**
+ \brief Disable FIQ
+ \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __disable_fault_irq(void)
+{
+ __ASM volatile ("cpsid f" : : : "memory");
+}
+
+
+/**
+ \brief Get Base Priority
+ \details Returns the current value of the Base Priority register.
+ \return Base Priority register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, basepri" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Base Priority (non-secure)
+ \details Returns the current value of the non-secure Base Priority register when in secure state.
+ \return Base Priority register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Base Priority
+ \details Assigns the given value to the Base Priority register.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Base Priority (non-secure)
+ \details Assigns the given value to the non-secure Base Priority register when in secure state.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
+}
+#endif
+
+
+/**
+ \brief Set Base Priority with condition
+ \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
+ or the new value increases the BASEPRI priority level.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
+}
+
+
+/**
+ \brief Get Fault Mask
+ \details Returns the current value of the Fault Mask register.
+ \return Fault Mask register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Fault Mask (non-secure)
+ \details Returns the current value of the non-secure Fault Mask register when in secure state.
+ \return Fault Mask register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Fault Mask
+ \details Assigns the given value to the Fault Mask register.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
+{
+ __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Fault Mask (non-secure)
+ \details Assigns the given value to the non-secure Fault Mask register when in secure state.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
+{
+ __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
+}
+#endif
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+
+/**
+ \brief Get Process Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always in non-secure
+ mode.
+
+ \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
+ \return PSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, psplim" : "=r" (result) );
+ return result;
+#endif
+}
+
+#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Process Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always in non-secure
+ mode.
+
+ \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
+ \return PSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
+ return result;
+#endif
+}
+#endif
+
+
+/**
+ \brief Set Process Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored in non-secure
+ mode.
+
+ \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
+ \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)ProcStackPtrLimit;
+#else
+ __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Process Stack Pointer (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored in non-secure
+ mode.
+
+ \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
+ \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)ProcStackPtrLimit;
+#else
+ __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
+#endif
+}
+#endif
+
+
+/**
+ \brief Get Main Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always.
+
+ \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
+ \return MSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, msplim" : "=r" (result) );
+ return result;
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Main Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always.
+
+ \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
+ \return MSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
+ return result;
+#endif
+}
+#endif
+
+
+/**
+ \brief Set Main Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored.
+
+ \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
+ \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)MainStackPtrLimit;
+#else
+ __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Main Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored.
+
+ \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
+ \param [in] MainStackPtrLimit Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)MainStackPtrLimit;
+#else
+ __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
+#endif
+}
+#endif
+
+#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
+
+/**
+ \brief Get FPSCR
+ \details Returns the current value of the Floating Point Status/Control register.
+ \return Floating Point Status/Control register value
+ */
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr
+#else
+#define __get_FPSCR() ((uint32_t)0U)
+#endif
+
+/**
+ \brief Set FPSCR
+ \details Assigns the given value to the Floating Point Status/Control register.
+ \param [in] fpscr Floating Point Status/Control value to set
+ */
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+#define __set_FPSCR __builtin_arm_set_fpscr
+#else
+#define __set_FPSCR(x) ((void)(x))
+#endif
+
+
+/*@} end of CMSIS_Core_RegAccFunctions */
+
+
+/* ################### Compiler specific Intrinsics ########################### */
+/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
+ Access to dedicated SIMD instructions
+ @{
+*/
+
+#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
+
+__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+
+__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+
+__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+#define __SSAT16(ARG1,ARG2) \
+({ \
+ int32_t __RES, __ARG1 = (ARG1); \
+ __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
+ __RES; \
+ })
+
+#define __USAT16(ARG1,ARG2) \
+({ \
+ uint32_t __RES, __ARG1 = (ARG1); \
+ __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
+ __RES; \
+ })
+
+__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
+{
+ uint32_t result;
+
+ __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
+{
+ uint32_t result;
+
+ __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
+{
+ int32_t result;
+
+ __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
+{
+ int32_t result;
+
+ __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
+ ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
+
+#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
+ ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
+
+#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
+
+#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
+
+__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
+{
+ int32_t result;
+
+ __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+#endif /* (__ARM_FEATURE_DSP == 1) */
+/*@} end of group CMSIS_SIMD_intrinsics */
+
+
+#endif /* __CMSIS_ARMCLANG_H */
diff --git a/CMSIS/Core/Include/cmsis_compiler.h b/CMSIS/Core/Include/cmsis_compiler.h
new file mode 100644
index 0000000..adbf296
--- /dev/null
+++ b/CMSIS/Core/Include/cmsis_compiler.h
@@ -0,0 +1,283 @@
+/**************************************************************************//**
+ * @file cmsis_compiler.h
+ * @brief CMSIS compiler generic header file
+ * @version V5.1.0
+ * @date 09. October 2018
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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 __CMSIS_COMPILER_H
+#define __CMSIS_COMPILER_H
+
+#include
+
+/*
+ * Arm Compiler 4/5
+ */
+#if defined ( __CC_ARM )
+ #include "cmsis_armcc.h"
+
+
+/*
+ * Arm Compiler 6.6 LTM (armclang)
+ */
+#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
+ #include "cmsis_armclang_ltm.h"
+
+ /*
+ * Arm Compiler above 6.10.1 (armclang)
+ */
+#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
+ #include "cmsis_armclang.h"
+
+
+/*
+ * GNU Compiler
+ */
+#elif defined ( __GNUC__ )
+ #include "cmsis_gcc.h"
+
+
+/*
+ * IAR Compiler
+ */
+#elif defined ( __ICCARM__ )
+ #include
+
+
+/*
+ * TI Arm Compiler
+ */
+#elif defined ( __TI_ARM__ )
+ #include
+
+ #ifndef __ASM
+ #define __ASM __asm
+ #endif
+ #ifndef __INLINE
+ #define __INLINE inline
+ #endif
+ #ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static inline
+ #endif
+ #ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __STATIC_INLINE
+ #endif
+ #ifndef __NO_RETURN
+ #define __NO_RETURN __attribute__((noreturn))
+ #endif
+ #ifndef __USED
+ #define __USED __attribute__((used))
+ #endif
+ #ifndef __WEAK
+ #define __WEAK __attribute__((weak))
+ #endif
+ #ifndef __PACKED
+ #define __PACKED __attribute__((packed))
+ #endif
+ #ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT struct __attribute__((packed))
+ #endif
+ #ifndef __PACKED_UNION
+ #define __PACKED_UNION union __attribute__((packed))
+ #endif
+ #ifndef __UNALIGNED_UINT32 /* deprecated */
+ struct __attribute__((packed)) T_UINT32 { uint32_t v; };
+ #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
+ #endif
+ #ifndef __UNALIGNED_UINT16_WRITE
+ __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
+ #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
+ #endif
+ #ifndef __UNALIGNED_UINT16_READ
+ __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
+ #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
+ #endif
+ #ifndef __UNALIGNED_UINT32_WRITE
+ __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
+ #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
+ #endif
+ #ifndef __UNALIGNED_UINT32_READ
+ __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
+ #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
+ #endif
+ #ifndef __ALIGNED
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+ #endif
+ #ifndef __RESTRICT
+ #define __RESTRICT __restrict
+ #endif
+ #ifndef __COMPILER_BARRIER
+ #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
+ #define __COMPILER_BARRIER() (void)0
+ #endif
+
+
+/*
+ * TASKING Compiler
+ */
+#elif defined ( __TASKING__ )
+ /*
+ * The CMSIS functions have been implemented as intrinsics in the compiler.
+ * Please use "carm -?i" to get an up to date list of all intrinsics,
+ * Including the CMSIS ones.
+ */
+
+ #ifndef __ASM
+ #define __ASM __asm
+ #endif
+ #ifndef __INLINE
+ #define __INLINE inline
+ #endif
+ #ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static inline
+ #endif
+ #ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __STATIC_INLINE
+ #endif
+ #ifndef __NO_RETURN
+ #define __NO_RETURN __attribute__((noreturn))
+ #endif
+ #ifndef __USED
+ #define __USED __attribute__((used))
+ #endif
+ #ifndef __WEAK
+ #define __WEAK __attribute__((weak))
+ #endif
+ #ifndef __PACKED
+ #define __PACKED __packed__
+ #endif
+ #ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT struct __packed__
+ #endif
+ #ifndef __PACKED_UNION
+ #define __PACKED_UNION union __packed__
+ #endif
+ #ifndef __UNALIGNED_UINT32 /* deprecated */
+ struct __packed__ T_UINT32 { uint32_t v; };
+ #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
+ #endif
+ #ifndef __UNALIGNED_UINT16_WRITE
+ __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
+ #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
+ #endif
+ #ifndef __UNALIGNED_UINT16_READ
+ __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
+ #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
+ #endif
+ #ifndef __UNALIGNED_UINT32_WRITE
+ __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
+ #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
+ #endif
+ #ifndef __UNALIGNED_UINT32_READ
+ __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
+ #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
+ #endif
+ #ifndef __ALIGNED
+ #define __ALIGNED(x) __align(x)
+ #endif
+ #ifndef __RESTRICT
+ #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
+ #define __RESTRICT
+ #endif
+ #ifndef __COMPILER_BARRIER
+ #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
+ #define __COMPILER_BARRIER() (void)0
+ #endif
+
+
+/*
+ * COSMIC Compiler
+ */
+#elif defined ( __CSMC__ )
+ #include
+
+ #ifndef __ASM
+ #define __ASM _asm
+ #endif
+ #ifndef __INLINE
+ #define __INLINE inline
+ #endif
+ #ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static inline
+ #endif
+ #ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __STATIC_INLINE
+ #endif
+ #ifndef __NO_RETURN
+ // NO RETURN is automatically detected hence no warning here
+ #define __NO_RETURN
+ #endif
+ #ifndef __USED
+ #warning No compiler specific solution for __USED. __USED is ignored.
+ #define __USED
+ #endif
+ #ifndef __WEAK
+ #define __WEAK __weak
+ #endif
+ #ifndef __PACKED
+ #define __PACKED @packed
+ #endif
+ #ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT @packed struct
+ #endif
+ #ifndef __PACKED_UNION
+ #define __PACKED_UNION @packed union
+ #endif
+ #ifndef __UNALIGNED_UINT32 /* deprecated */
+ @packed struct T_UINT32 { uint32_t v; };
+ #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
+ #endif
+ #ifndef __UNALIGNED_UINT16_WRITE
+ __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
+ #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
+ #endif
+ #ifndef __UNALIGNED_UINT16_READ
+ __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
+ #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
+ #endif
+ #ifndef __UNALIGNED_UINT32_WRITE
+ __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
+ #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
+ #endif
+ #ifndef __UNALIGNED_UINT32_READ
+ __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
+ #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
+ #endif
+ #ifndef __ALIGNED
+ #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
+ #define __ALIGNED(x)
+ #endif
+ #ifndef __RESTRICT
+ #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
+ #define __RESTRICT
+ #endif
+ #ifndef __COMPILER_BARRIER
+ #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
+ #define __COMPILER_BARRIER() (void)0
+ #endif
+
+
+#else
+ #error Unknown compiler.
+#endif
+
+
+#endif /* __CMSIS_COMPILER_H */
+
diff --git a/CMSIS/Core/Include/cmsis_gcc.h b/CMSIS/Core/Include/cmsis_gcc.h
new file mode 100644
index 0000000..67bda4e
--- /dev/null
+++ b/CMSIS/Core/Include/cmsis_gcc.h
@@ -0,0 +1,2211 @@
+/**************************************************************************//**
+ * @file cmsis_gcc.h
+ * @brief CMSIS compiler GCC header file
+ * @version V5.4.1
+ * @date 27. May 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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 __CMSIS_GCC_H
+#define __CMSIS_GCC_H
+
+/* ignore some GCC warnings */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-conversion"
+#pragma GCC diagnostic ignored "-Wconversion"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
+/* Fallback for __has_builtin */
+#ifndef __has_builtin
+ #define __has_builtin(x) (0)
+#endif
+
+/* CMSIS compiler specific defines */
+#ifndef __ASM
+ #define __ASM __asm
+#endif
+#ifndef __INLINE
+ #define __INLINE inline
+#endif
+#ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static inline
+#endif
+#ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
+#endif
+#ifndef __NO_RETURN
+ #define __NO_RETURN __attribute__((__noreturn__))
+#endif
+#ifndef __USED
+ #define __USED __attribute__((used))
+#endif
+#ifndef __WEAK
+ #define __WEAK __attribute__((weak))
+#endif
+#ifndef __PACKED
+ #define __PACKED __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_STRUCT
+ #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
+#endif
+#ifndef __PACKED_UNION
+ #define __PACKED_UNION union __attribute__((packed, aligned(1)))
+#endif
+#ifndef __UNALIGNED_UINT32 /* deprecated */
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpacked"
+ #pragma GCC diagnostic ignored "-Wattributes"
+ struct __attribute__((packed)) T_UINT32 { uint32_t v; };
+ #pragma GCC diagnostic pop
+ #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
+#endif
+#ifndef __UNALIGNED_UINT16_WRITE
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpacked"
+ #pragma GCC diagnostic ignored "-Wattributes"
+ __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
+ #pragma GCC diagnostic pop
+ #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
+#endif
+#ifndef __UNALIGNED_UINT16_READ
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpacked"
+ #pragma GCC diagnostic ignored "-Wattributes"
+ __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
+ #pragma GCC diagnostic pop
+ #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
+#endif
+#ifndef __UNALIGNED_UINT32_WRITE
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpacked"
+ #pragma GCC diagnostic ignored "-Wattributes"
+ __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
+ #pragma GCC diagnostic pop
+ #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
+#endif
+#ifndef __UNALIGNED_UINT32_READ
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wpacked"
+ #pragma GCC diagnostic ignored "-Wattributes"
+ __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
+ #pragma GCC diagnostic pop
+ #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
+#endif
+#ifndef __ALIGNED
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+#endif
+#ifndef __RESTRICT
+ #define __RESTRICT __restrict
+#endif
+#ifndef __COMPILER_BARRIER
+ #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
+#endif
+
+/* ######################### Startup and Lowlevel Init ######################## */
+
+#ifndef __PROGRAM_START
+
+/**
+ \brief Initializes data and bss sections
+ \details This default implementations initialized all data and additional bss
+ sections relying on .copy.table and .zero.table specified properly
+ in the used linker script.
+
+ */
+__STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void)
+{
+ extern void _start(void) __NO_RETURN;
+
+ typedef struct {
+ uint32_t const* src;
+ uint32_t* dest;
+ uint32_t wlen;
+ } __copy_table_t;
+
+ typedef struct {
+ uint32_t* dest;
+ uint32_t wlen;
+ } __zero_table_t;
+
+ extern const __copy_table_t __copy_table_start__;
+ extern const __copy_table_t __copy_table_end__;
+ extern const __zero_table_t __zero_table_start__;
+ extern const __zero_table_t __zero_table_end__;
+
+ for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
+ for(uint32_t i=0u; iwlen; ++i) {
+ pTable->dest[i] = pTable->src[i];
+ }
+ }
+
+ for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
+ for(uint32_t i=0u; iwlen; ++i) {
+ pTable->dest[i] = 0u;
+ }
+ }
+
+ _start();
+}
+
+#define __PROGRAM_START __cmsis_start
+#endif
+
+#ifndef __INITIAL_SP
+#define __INITIAL_SP __StackTop
+#endif
+
+#ifndef __STACK_LIMIT
+#define __STACK_LIMIT __StackLimit
+#endif
+
+#ifndef __VECTOR_TABLE
+#define __VECTOR_TABLE __Vectors
+#endif
+
+#ifndef __VECTOR_TABLE_ATTRIBUTE
+#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors")))
+#endif
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#ifndef __STACK_SEAL
+#define __STACK_SEAL __StackSeal
+#endif
+
+#ifndef __TZ_STACK_SEAL_SIZE
+#define __TZ_STACK_SEAL_SIZE 8U
+#endif
+
+#ifndef __TZ_STACK_SEAL_VALUE
+#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
+#endif
+
+
+__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
+ *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
+}
+#endif
+
+
+/* ########################## Core Instruction Access ######################### */
+/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
+ Access to dedicated instructions
+ @{
+*/
+
+/* Define macros for porting to both thumb1 and thumb2.
+ * For thumb1, use low register (r0-r7), specified by constraint "l"
+ * Otherwise, use general registers, specified by constraint "r" */
+#if defined (__thumb__) && !defined (__thumb2__)
+#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
+#define __CMSIS_GCC_RW_REG(r) "+l" (r)
+#define __CMSIS_GCC_USE_REG(r) "l" (r)
+#else
+#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
+#define __CMSIS_GCC_RW_REG(r) "+r" (r)
+#define __CMSIS_GCC_USE_REG(r) "r" (r)
+#endif
+
+/**
+ \brief No Operation
+ \details No Operation does nothing. This instruction can be used for code alignment purposes.
+ */
+#define __NOP() __ASM volatile ("nop")
+
+/**
+ \brief Wait For Interrupt
+ \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
+ */
+#define __WFI() __ASM volatile ("wfi":::"memory")
+
+
+/**
+ \brief Wait For Event
+ \details Wait For Event is a hint instruction that permits the processor to enter
+ a low-power state until one of a number of events occurs.
+ */
+#define __WFE() __ASM volatile ("wfe":::"memory")
+
+
+/**
+ \brief Send Event
+ \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
+ */
+#define __SEV() __ASM volatile ("sev")
+
+
+/**
+ \brief Instruction Synchronization Barrier
+ \details Instruction Synchronization Barrier flushes the pipeline in the processor,
+ so that all instructions following the ISB are fetched from cache or memory,
+ after the instruction has been completed.
+ */
+__STATIC_FORCEINLINE void __ISB(void)
+{
+ __ASM volatile ("isb 0xF":::"memory");
+}
+
+
+/**
+ \brief Data Synchronization Barrier
+ \details Acts as a special kind of Data Memory Barrier.
+ It completes when all explicit memory accesses before this instruction complete.
+ */
+__STATIC_FORCEINLINE void __DSB(void)
+{
+ __ASM volatile ("dsb 0xF":::"memory");
+}
+
+
+/**
+ \brief Data Memory Barrier
+ \details Ensures the apparent order of the explicit memory operations before
+ and after the instruction, without ensuring their completion.
+ */
+__STATIC_FORCEINLINE void __DMB(void)
+{
+ __ASM volatile ("dmb 0xF":::"memory");
+}
+
+
+/**
+ \brief Reverse byte order (32 bit)
+ \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+__STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
+{
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+ return __builtin_bswap32(value);
+#else
+ uint32_t result;
+
+ __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
+ return result;
+#endif
+}
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
+{
+ uint32_t result;
+
+ __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
+ return result;
+}
+
+
+/**
+ \brief Reverse byte order (16 bit)
+ \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+__STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
+{
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+ return (int16_t)__builtin_bswap16(value);
+#else
+ int16_t result;
+
+ __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
+ return result;
+#endif
+}
+
+
+/**
+ \brief Rotate Right in unsigned value (32 bit)
+ \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
+ \param [in] op1 Value to rotate
+ \param [in] op2 Number of Bits to rotate
+ \return Rotated value
+ */
+__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
+{
+ op2 %= 32U;
+ if (op2 == 0U)
+ {
+ return op1;
+ }
+ return (op1 >> op2) | (op1 << (32U - op2));
+}
+
+
+/**
+ \brief Breakpoint
+ \details Causes the processor to enter Debug state.
+ Debug tools can use this to investigate system state when the instruction at a particular address is reached.
+ \param [in] value is ignored by the processor.
+ If required, a debugger can use it to store additional information about the breakpoint.
+ */
+#define __BKPT(value) __ASM volatile ("bkpt "#value)
+
+
+/**
+ \brief Reverse bit order of value
+ \details Reverses the bit order of the given value.
+ \param [in] value Value to reverse
+ \return Reversed value
+ */
+__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
+{
+ uint32_t result;
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
+ __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
+#else
+ uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
+
+ result = value; /* r will be reversed bits of v; first get LSB of v */
+ for (value >>= 1U; value != 0U; value >>= 1U)
+ {
+ result <<= 1U;
+ result |= value & 1U;
+ s--;
+ }
+ result <<= s; /* shift when v's highest bits are zero */
+#endif
+ return result;
+}
+
+
+/**
+ \brief Count leading zeros
+ \details Counts the number of leading zeros of a data value.
+ \param [in] value Value to count the leading zeros
+ \return number of leading zeros in value
+ */
+__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
+{
+ /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
+ __builtin_clz(0) is undefined behaviour, so handle this case specially.
+ This guarantees ARM-compatible results if happening to compile on a non-ARM
+ target, and ensures the compiler doesn't decide to activate any
+ optimisations using the logic "value was passed to __builtin_clz, so it
+ is non-zero".
+ ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
+ single CLZ instruction.
+ */
+ if (value == 0U)
+ {
+ return 32U;
+ }
+ return __builtin_clz(value);
+}
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+/**
+ \brief LDR Exclusive (8 bit)
+ \details Executes a exclusive LDR instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
+{
+ uint32_t result;
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+ __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
+#else
+ /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
+ accepted by assembler. So has to use following less efficient pattern.
+ */
+ __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
+#endif
+ return ((uint8_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDR Exclusive (16 bit)
+ \details Executes a exclusive LDR instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
+{
+ uint32_t result;
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+ __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
+#else
+ /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
+ accepted by assembler. So has to use following less efficient pattern.
+ */
+ __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
+#endif
+ return ((uint16_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDR Exclusive (32 bit)
+ \details Executes a exclusive LDR instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
+ return(result);
+}
+
+
+/**
+ \brief STR Exclusive (8 bit)
+ \details Executes a exclusive STR instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
+{
+ uint32_t result;
+
+ __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
+ return(result);
+}
+
+
+/**
+ \brief STR Exclusive (16 bit)
+ \details Executes a exclusive STR instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
+{
+ uint32_t result;
+
+ __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
+ return(result);
+}
+
+
+/**
+ \brief STR Exclusive (32 bit)
+ \details Executes a exclusive STR instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
+{
+ uint32_t result;
+
+ __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
+ return(result);
+}
+
+
+/**
+ \brief Remove the exclusive lock
+ \details Removes the exclusive lock which is created by LDREX.
+ */
+__STATIC_FORCEINLINE void __CLREX(void)
+{
+ __ASM volatile ("clrex" ::: "memory");
+}
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] ARG1 Value to be saturated
+ \param [in] ARG2 Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+#define __SSAT(ARG1, ARG2) \
+__extension__ \
+({ \
+ int32_t __RES, __ARG1 = (ARG1); \
+ __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
+ __RES; \
+ })
+
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] ARG1 Value to be saturated
+ \param [in] ARG2 Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+#define __USAT(ARG1, ARG2) \
+__extension__ \
+({ \
+ uint32_t __RES, __ARG1 = (ARG1); \
+ __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
+ __RES; \
+ })
+
+
+/**
+ \brief Rotate Right with Extend (32 bit)
+ \details Moves each bit of a bitstring right by one bit.
+ The carry input is shifted in at the left end of the bitstring.
+ \param [in] value Value to rotate
+ \return Rotated value
+ */
+__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
+{
+ uint32_t result;
+
+ __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
+ return(result);
+}
+
+
+/**
+ \brief LDRT Unprivileged (8 bit)
+ \details Executes a Unprivileged LDRT instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+ __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
+#else
+ /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
+ accepted by assembler. So has to use following less efficient pattern.
+ */
+ __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
+#endif
+ return ((uint8_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDRT Unprivileged (16 bit)
+ \details Executes a Unprivileged LDRT instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+ __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
+#else
+ /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
+ accepted by assembler. So has to use following less efficient pattern.
+ */
+ __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
+#endif
+ return ((uint16_t) result); /* Add explicit type cast here */
+}
+
+
+/**
+ \brief LDRT Unprivileged (32 bit)
+ \details Executes a Unprivileged LDRT instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
+ return(result);
+}
+
+
+/**
+ \brief STRT Unprivileged (8 bit)
+ \details Executes a Unprivileged STRT instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
+{
+ __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
+}
+
+
+/**
+ \brief STRT Unprivileged (16 bit)
+ \details Executes a Unprivileged STRT instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
+{
+ __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
+}
+
+
+/**
+ \brief STRT Unprivileged (32 bit)
+ \details Executes a Unprivileged STRT instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
+{
+ __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
+}
+
+#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
+
+/**
+ \brief Signed Saturate
+ \details Saturates a signed value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (1..32)
+ \return Saturated value
+ */
+__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
+{
+ if ((sat >= 1U) && (sat <= 32U))
+ {
+ const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
+ const int32_t min = -1 - max ;
+ if (val > max)
+ {
+ return max;
+ }
+ else if (val < min)
+ {
+ return min;
+ }
+ }
+ return val;
+}
+
+/**
+ \brief Unsigned Saturate
+ \details Saturates an unsigned value.
+ \param [in] value Value to be saturated
+ \param [in] sat Bit position to saturate to (0..31)
+ \return Saturated value
+ */
+__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
+{
+ if (sat <= 31U)
+ {
+ const uint32_t max = ((1U << sat) - 1U);
+ if (val > (int32_t)max)
+ {
+ return max;
+ }
+ else if (val < 0)
+ {
+ return 0U;
+ }
+ }
+ return (uint32_t)val;
+}
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+/**
+ \brief Load-Acquire (8 bit)
+ \details Executes a LDAB instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint8_t) result);
+}
+
+
+/**
+ \brief Load-Acquire (16 bit)
+ \details Executes a LDAH instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint16_t) result);
+}
+
+
+/**
+ \brief Load-Acquire (32 bit)
+ \details Executes a LDA instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return(result);
+}
+
+
+/**
+ \brief Store-Release (8 bit)
+ \details Executes a STLB instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
+{
+ __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Store-Release (16 bit)
+ \details Executes a STLH instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
+{
+ __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Store-Release (32 bit)
+ \details Executes a STL instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ */
+__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
+{
+ __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+}
+
+
+/**
+ \brief Load-Acquire Exclusive (8 bit)
+ \details Executes a LDAB exclusive instruction for 8 bit value.
+ \param [in] ptr Pointer to data
+ \return value of type uint8_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint8_t) result);
+}
+
+
+/**
+ \brief Load-Acquire Exclusive (16 bit)
+ \details Executes a LDAH exclusive instruction for 16 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint16_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return ((uint16_t) result);
+}
+
+
+/**
+ \brief Load-Acquire Exclusive (32 bit)
+ \details Executes a LDA exclusive instruction for 32 bit values.
+ \param [in] ptr Pointer to data
+ \return value of type uint32_t at (*ptr)
+ */
+__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
+ return(result);
+}
+
+
+/**
+ \brief Store-Release Exclusive (8 bit)
+ \details Executes a STLB exclusive instruction for 8 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+ return(result);
+}
+
+
+/**
+ \brief Store-Release Exclusive (16 bit)
+ \details Executes a STLH exclusive instruction for 16 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+ return(result);
+}
+
+
+/**
+ \brief Store-Release Exclusive (32 bit)
+ \details Executes a STL exclusive instruction for 32 bit values.
+ \param [in] value Value to store
+ \param [in] ptr Pointer to location
+ \return 0 Function succeeded
+ \return 1 Function failed
+ */
+__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
+{
+ uint32_t result;
+
+ __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
+ return(result);
+}
+
+#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
+
+/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
+
+
+/* ########################### Core Function Access ########################### */
+/** \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
+ @{
+ */
+
+/**
+ \brief Enable IRQ Interrupts
+ \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __enable_irq(void)
+{
+ __ASM volatile ("cpsie i" : : : "memory");
+}
+
+
+/**
+ \brief Disable IRQ Interrupts
+ \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __disable_irq(void)
+{
+ __ASM volatile ("cpsid i" : : : "memory");
+}
+
+
+/**
+ \brief Get Control Register
+ \details Returns the content of the Control Register.
+ \return Control Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, control" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Control Register (non-secure)
+ \details Returns the content of the non-secure Control Register when in secure mode.
+ \return non-secure Control Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Control Register
+ \details Writes the given value to the Control Register.
+ \param [in] control Control Register value to set
+ */
+__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
+{
+ __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
+ __ISB();
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Control Register (non-secure)
+ \details Writes the given value to the non-secure Control Register when in secure state.
+ \param [in] control Control Register value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
+{
+ __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
+ __ISB();
+}
+#endif
+
+
+/**
+ \brief Get IPSR Register
+ \details Returns the content of the IPSR Register.
+ \return IPSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_IPSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get APSR Register
+ \details Returns the content of the APSR Register.
+ \return APSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_APSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, apsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get xPSR Register
+ \details Returns the content of the xPSR Register.
+ \return xPSR Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_xPSR(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Get Process Stack Pointer
+ \details Returns the current value of the Process Stack Pointer (PSP).
+ \return PSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PSP(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, psp" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Process Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
+ \return PSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Process Stack Pointer
+ \details Assigns the given value to the Process Stack Pointer (PSP).
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
+{
+ __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Process Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
+ \param [in] topOfProcStack Process Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
+{
+ __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
+}
+#endif
+
+
+/**
+ \brief Get Main Stack Pointer
+ \details Returns the current value of the Main Stack Pointer (MSP).
+ \return MSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_MSP(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, msp" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Main Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
+ \return MSP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Main Stack Pointer
+ \details Assigns the given value to the Main Stack Pointer (MSP).
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
+{
+ __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Main Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
+ \param [in] topOfMainStack Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
+{
+ __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
+}
+#endif
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Stack Pointer (non-secure)
+ \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
+ \return SP Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
+ return(result);
+}
+
+
+/**
+ \brief Set Stack Pointer (non-secure)
+ \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
+ \param [in] topOfStack Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
+{
+ __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
+}
+#endif
+
+
+/**
+ \brief Get Priority Mask
+ \details Returns the current state of the priority mask bit from the Priority Mask Register.
+ \return Priority Mask value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, primask" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Priority Mask (non-secure)
+ \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
+ \return Priority Mask value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Priority Mask
+ \details Assigns the given value to the Priority Mask Register.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
+{
+ __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Priority Mask (non-secure)
+ \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
+ \param [in] priMask Priority Mask
+ */
+__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
+{
+ __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
+}
+#endif
+
+
+#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
+/**
+ \brief Enable FIQ
+ \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __enable_fault_irq(void)
+{
+ __ASM volatile ("cpsie f" : : : "memory");
+}
+
+
+/**
+ \brief Disable FIQ
+ \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
+ Can only be executed in Privileged modes.
+ */
+__STATIC_FORCEINLINE void __disable_fault_irq(void)
+{
+ __ASM volatile ("cpsid f" : : : "memory");
+}
+
+
+/**
+ \brief Get Base Priority
+ \details Returns the current value of the Base Priority register.
+ \return Base Priority register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, basepri" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Base Priority (non-secure)
+ \details Returns the current value of the non-secure Base Priority register when in secure state.
+ \return Base Priority register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Base Priority
+ \details Assigns the given value to the Base Priority register.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Base Priority (non-secure)
+ \details Assigns the given value to the non-secure Base Priority register when in secure state.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
+}
+#endif
+
+
+/**
+ \brief Set Base Priority with condition
+ \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
+ or the new value increases the BASEPRI priority level.
+ \param [in] basePri Base Priority value to set
+ */
+__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
+{
+ __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
+}
+
+
+/**
+ \brief Get Fault Mask
+ \details Returns the current value of the Fault Mask register.
+ \return Fault Mask register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
+ return(result);
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Fault Mask (non-secure)
+ \details Returns the current value of the non-secure Fault Mask register when in secure state.
+ \return Fault Mask register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
+{
+ uint32_t result;
+
+ __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
+ return(result);
+}
+#endif
+
+
+/**
+ \brief Set Fault Mask
+ \details Assigns the given value to the Fault Mask register.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
+{
+ __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Fault Mask (non-secure)
+ \details Assigns the given value to the non-secure Fault Mask register when in secure state.
+ \param [in] faultMask Fault Mask value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
+{
+ __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
+}
+#endif
+
+#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
+ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
+ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
+
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+
+/**
+ \brief Get Process Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always in non-secure
+ mode.
+
+ \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
+ \return PSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, psplim" : "=r" (result) );
+ return result;
+#endif
+}
+
+#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Process Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always.
+
+ \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
+ \return PSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
+ return result;
+#endif
+}
+#endif
+
+
+/**
+ \brief Set Process Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored in non-secure
+ mode.
+
+ \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
+ \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)ProcStackPtrLimit;
+#else
+ __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Process Stack Pointer (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored.
+
+ \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
+ \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)ProcStackPtrLimit;
+#else
+ __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
+#endif
+}
+#endif
+
+
+/**
+ \brief Get Main Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always in non-secure
+ mode.
+
+ \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
+ \return MSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, msplim" : "=r" (result) );
+ return result;
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Get Main Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence zero is returned always.
+
+ \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
+ \return MSPLIM Register value
+ */
+__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ return 0U;
+#else
+ uint32_t result;
+ __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
+ return result;
+#endif
+}
+#endif
+
+
+/**
+ \brief Set Main Stack Pointer Limit
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored in non-secure
+ mode.
+
+ \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
+ \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
+ */
+__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)MainStackPtrLimit;
+#else
+ __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
+#endif
+}
+
+
+#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
+/**
+ \brief Set Main Stack Pointer Limit (non-secure)
+ Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
+ Stack Pointer Limit register hence the write is silently ignored.
+
+ \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
+ \param [in] MainStackPtrLimit Main Stack Pointer value to set
+ */
+__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
+{
+#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)MainStackPtrLimit;
+#else
+ __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
+#endif
+}
+#endif
+
+#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
+
+
+/**
+ \brief Get FPSCR
+ \details Returns the current value of the Floating Point Status/Control register.
+ \return Floating Point Status/Control register value
+ */
+__STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
+{
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+#if __has_builtin(__builtin_arm_get_fpscr)
+// Re-enable using built-in when GCC has been fixed
+// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
+ /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
+ return __builtin_arm_get_fpscr();
+#else
+ uint32_t result;
+
+ __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
+ return(result);
+#endif
+#else
+ return(0U);
+#endif
+}
+
+
+/**
+ \brief Set FPSCR
+ \details Assigns the given value to the Floating Point Status/Control register.
+ \param [in] fpscr Floating Point Status/Control value to set
+ */
+__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
+{
+#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+#if __has_builtin(__builtin_arm_set_fpscr)
+// Re-enable using built-in when GCC has been fixed
+// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
+ /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
+ __builtin_arm_set_fpscr(fpscr);
+#else
+ __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
+#endif
+#else
+ (void)fpscr;
+#endif
+}
+
+
+/*@} end of CMSIS_Core_RegAccFunctions */
+
+
+/* ################### Compiler specific Intrinsics ########################### */
+/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
+ Access to dedicated SIMD instructions
+ @{
+*/
+
+#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
+
+__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+
+__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+
+__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+#define __SSAT16(ARG1, ARG2) \
+__extension__ \
+({ \
+ int32_t __RES, __ARG1 = (ARG1); \
+ __ASM volatile ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
+ __RES; \
+ })
+
+#define __USAT16(ARG1, ARG2) \
+__extension__ \
+({ \
+ uint32_t __RES, __ARG1 = (ARG1); \
+ __ASM volatile ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
+ __RES; \
+ })
+
+__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
+{
+ uint32_t result;
+
+ __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
+{
+ uint32_t result;
+
+ __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate)
+{
+ uint32_t result;
+ if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
+ __ASM volatile ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) );
+ } else {
+ result = __SXTB16(__ROR(op1, rotate)) ;
+ }
+ return result;
+}
+
+__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate)
+{
+ uint32_t result;
+ if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
+ __ASM volatile ("sxtab16 %0, %1, %2, ROR %3" : "=r" (result) : "r" (op1) , "r" (op2) , "i" (rotate));
+ } else {
+ result = __SXTAB16(op1, __ROR(op2, rotate));
+ }
+ return result;
+}
+
+
+__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
+{
+ uint32_t result;
+
+ __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
+{
+ union llreg_u{
+ uint32_t w32[2];
+ uint64_t w64;
+ } llr;
+ llr.w64 = acc;
+
+#ifndef __ARMEB__ /* Little endian */
+ __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
+#else /* Big endian */
+ __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
+#endif
+
+ return(llr.w64);
+}
+
+__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
+{
+ uint32_t result;
+
+ __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
+{
+ int32_t result;
+
+ __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
+{
+ int32_t result;
+
+ __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
+ return(result);
+}
+
+
+#define __PKHBT(ARG1,ARG2,ARG3) \
+__extension__ \
+({ \
+ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
+ __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
+ __RES; \
+ })
+
+#define __PKHTB(ARG1,ARG2,ARG3) \
+__extension__ \
+({ \
+ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
+ if (ARG3 == 0) \
+ __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
+ else \
+ __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
+ __RES; \
+ })
+
+
+__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
+{
+ int32_t result;
+
+ __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
+ return(result);
+}
+
+#endif /* (__ARM_FEATURE_DSP == 1) */
+/*@} end of group CMSIS_SIMD_intrinsics */
+
+
+#pragma GCC diagnostic pop
+
+#endif /* __CMSIS_GCC_H */
diff --git a/CMSIS/Core/Include/cmsis_iccarm.h b/CMSIS/Core/Include/cmsis_iccarm.h
new file mode 100644
index 0000000..65b824b
--- /dev/null
+++ b/CMSIS/Core/Include/cmsis_iccarm.h
@@ -0,0 +1,1002 @@
+/**************************************************************************//**
+ * @file cmsis_iccarm.h
+ * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file
+ * @version V5.3.0
+ * @date 14. April 2021
+ ******************************************************************************/
+
+//------------------------------------------------------------------------------
+//
+// Copyright (c) 2017-2021 IAR Systems
+// Copyright (c) 2017-2021 Arm Limited. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// 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.
+//
+//------------------------------------------------------------------------------
+
+
+#ifndef __CMSIS_ICCARM_H__
+#define __CMSIS_ICCARM_H__
+
+#ifndef __ICCARM__
+ #error This file should only be compiled by ICCARM
+#endif
+
+#pragma system_include
+
+#define __IAR_FT _Pragma("inline=forced") __intrinsic
+
+#if (__VER__ >= 8000000)
+ #define __ICCARM_V8 1
+#else
+ #define __ICCARM_V8 0
+#endif
+
+#ifndef __ALIGNED
+ #if __ICCARM_V8
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+ #elif (__VER__ >= 7080000)
+ /* Needs IAR language extensions */
+ #define __ALIGNED(x) __attribute__((aligned(x)))
+ #else
+ #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
+ #define __ALIGNED(x)
+ #endif
+#endif
+
+
+/* Define compiler macros for CPU architecture, used in CMSIS 5.
+ */
+#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
+/* Macros already defined */
+#else
+ #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
+ #define __ARM_ARCH_8M_MAIN__ 1
+ #elif defined(__ARM8M_BASELINE__)
+ #define __ARM_ARCH_8M_BASE__ 1
+ #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
+ #if __ARM_ARCH == 6
+ #define __ARM_ARCH_6M__ 1
+ #elif __ARM_ARCH == 7
+ #if __ARM_FEATURE_DSP
+ #define __ARM_ARCH_7EM__ 1
+ #else
+ #define __ARM_ARCH_7M__ 1
+ #endif
+ #endif /* __ARM_ARCH */
+ #endif /* __ARM_ARCH_PROFILE == 'M' */
+#endif
+
+/* Alternativ core deduction for older ICCARM's */
+#if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
+ !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
+ #if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
+ #define __ARM_ARCH_6M__ 1
+ #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
+ #define __ARM_ARCH_7M__ 1
+ #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
+ #define __ARM_ARCH_7EM__ 1
+ #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
+ #define __ARM_ARCH_8M_BASE__ 1
+ #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
+ #define __ARM_ARCH_8M_MAIN__ 1
+ #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
+ #define __ARM_ARCH_8M_MAIN__ 1
+ #else
+ #error "Unknown target."
+ #endif
+#endif
+
+
+
+#if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
+ #define __IAR_M0_FAMILY 1
+#elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
+ #define __IAR_M0_FAMILY 1
+#else
+ #define __IAR_M0_FAMILY 0
+#endif
+
+
+#ifndef __ASM
+ #define __ASM __asm
+#endif
+
+#ifndef __COMPILER_BARRIER
+ #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
+#endif
+
+#ifndef __INLINE
+ #define __INLINE inline
+#endif
+
+#ifndef __NO_RETURN
+ #if __ICCARM_V8
+ #define __NO_RETURN __attribute__((__noreturn__))
+ #else
+ #define __NO_RETURN _Pragma("object_attribute=__noreturn")
+ #endif
+#endif
+
+#ifndef __PACKED
+ #if __ICCARM_V8
+ #define __PACKED __attribute__((packed, aligned(1)))
+ #else
+ /* Needs IAR language extensions */
+ #define __PACKED __packed
+ #endif
+#endif
+
+#ifndef __PACKED_STRUCT
+ #if __ICCARM_V8
+ #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
+ #else
+ /* Needs IAR language extensions */
+ #define __PACKED_STRUCT __packed struct
+ #endif
+#endif
+
+#ifndef __PACKED_UNION
+ #if __ICCARM_V8
+ #define __PACKED_UNION union __attribute__((packed, aligned(1)))
+ #else
+ /* Needs IAR language extensions */
+ #define __PACKED_UNION __packed union
+ #endif
+#endif
+
+#ifndef __RESTRICT
+ #if __ICCARM_V8
+ #define __RESTRICT __restrict
+ #else
+ /* Needs IAR language extensions */
+ #define __RESTRICT restrict
+ #endif
+#endif
+
+#ifndef __STATIC_INLINE
+ #define __STATIC_INLINE static inline
+#endif
+
+#ifndef __FORCEINLINE
+ #define __FORCEINLINE _Pragma("inline=forced")
+#endif
+
+#ifndef __STATIC_FORCEINLINE
+ #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
+#endif
+
+#ifndef __UNALIGNED_UINT16_READ
+#pragma language=save
+#pragma language=extended
+__IAR_FT uint16_t __iar_uint16_read(void const *ptr)
+{
+ return *(__packed uint16_t*)(ptr);
+}
+#pragma language=restore
+#define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
+#endif
+
+
+#ifndef __UNALIGNED_UINT16_WRITE
+#pragma language=save
+#pragma language=extended
+__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
+{
+ *(__packed uint16_t*)(ptr) = val;;
+}
+#pragma language=restore
+#define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
+#endif
+
+#ifndef __UNALIGNED_UINT32_READ
+#pragma language=save
+#pragma language=extended
+__IAR_FT uint32_t __iar_uint32_read(void const *ptr)
+{
+ return *(__packed uint32_t*)(ptr);
+}
+#pragma language=restore
+#define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
+#endif
+
+#ifndef __UNALIGNED_UINT32_WRITE
+#pragma language=save
+#pragma language=extended
+__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
+{
+ *(__packed uint32_t*)(ptr) = val;;
+}
+#pragma language=restore
+#define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
+#endif
+
+#ifndef __UNALIGNED_UINT32 /* deprecated */
+#pragma language=save
+#pragma language=extended
+__packed struct __iar_u32 { uint32_t v; };
+#pragma language=restore
+#define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
+#endif
+
+#ifndef __USED
+ #if __ICCARM_V8
+ #define __USED __attribute__((used))
+ #else
+ #define __USED _Pragma("__root")
+ #endif
+#endif
+
+#undef __WEAK /* undo the definition from DLib_Defaults.h */
+#ifndef __WEAK
+ #if __ICCARM_V8
+ #define __WEAK __attribute__((weak))
+ #else
+ #define __WEAK _Pragma("__weak")
+ #endif
+#endif
+
+#ifndef __PROGRAM_START
+#define __PROGRAM_START __iar_program_start
+#endif
+
+#ifndef __INITIAL_SP
+#define __INITIAL_SP CSTACK$$Limit
+#endif
+
+#ifndef __STACK_LIMIT
+#define __STACK_LIMIT CSTACK$$Base
+#endif
+
+#ifndef __VECTOR_TABLE
+#define __VECTOR_TABLE __vector_table
+#endif
+
+#ifndef __VECTOR_TABLE_ATTRIBUTE
+#define __VECTOR_TABLE_ATTRIBUTE @".intvec"
+#endif
+
+#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
+#ifndef __STACK_SEAL
+#define __STACK_SEAL STACKSEAL$$Base
+#endif
+
+#ifndef __TZ_STACK_SEAL_SIZE
+#define __TZ_STACK_SEAL_SIZE 8U
+#endif
+
+#ifndef __TZ_STACK_SEAL_VALUE
+#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
+#endif
+
+__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
+ *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
+}
+#endif
+
+#ifndef __ICCARM_INTRINSICS_VERSION__
+ #define __ICCARM_INTRINSICS_VERSION__ 0
+#endif
+
+#if __ICCARM_INTRINSICS_VERSION__ == 2
+
+ #if defined(__CLZ)
+ #undef __CLZ
+ #endif
+ #if defined(__REVSH)
+ #undef __REVSH
+ #endif
+ #if defined(__RBIT)
+ #undef __RBIT
+ #endif
+ #if defined(__SSAT)
+ #undef __SSAT
+ #endif
+ #if defined(__USAT)
+ #undef __USAT
+ #endif
+
+ #include "iccarm_builtin.h"
+
+ #define __disable_fault_irq __iar_builtin_disable_fiq
+ #define __disable_irq __iar_builtin_disable_interrupt
+ #define __enable_fault_irq __iar_builtin_enable_fiq
+ #define __enable_irq __iar_builtin_enable_interrupt
+ #define __arm_rsr __iar_builtin_rsr
+ #define __arm_wsr __iar_builtin_wsr
+
+
+ #define __get_APSR() (__arm_rsr("APSR"))
+ #define __get_BASEPRI() (__arm_rsr("BASEPRI"))
+ #define __get_CONTROL() (__arm_rsr("CONTROL"))
+ #define __get_FAULTMASK() (__arm_rsr("FAULTMASK"))
+
+ #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
+ #define __get_FPSCR() (__arm_rsr("FPSCR"))
+ #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
+ #else
+ #define __get_FPSCR() ( 0 )
+ #define __set_FPSCR(VALUE) ((void)VALUE)
+ #endif
+
+ #define __get_IPSR() (__arm_rsr("IPSR"))
+ #define __get_MSP() (__arm_rsr("MSP"))
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ #define __get_MSPLIM() (0U)
+ #else
+ #define __get_MSPLIM() (__arm_rsr("MSPLIM"))
+ #endif
+ #define __get_PRIMASK() (__arm_rsr("PRIMASK"))
+ #define __get_PSP() (__arm_rsr("PSP"))
+
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ #define __get_PSPLIM() (0U)
+ #else
+ #define __get_PSPLIM() (__arm_rsr("PSPLIM"))
+ #endif
+
+ #define __get_xPSR() (__arm_rsr("xPSR"))
+
+ #define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE)))
+ #define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE)))
+
+__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
+{
+ __arm_wsr("CONTROL", control);
+ __iar_builtin_ISB();
+}
+
+ #define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE)))
+ #define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE)))
+
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ #define __set_MSPLIM(VALUE) ((void)(VALUE))
+ #else
+ #define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE)))
+ #endif
+ #define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE)))
+ #define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE)))
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ #define __set_PSPLIM(VALUE) ((void)(VALUE))
+ #else
+ #define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE)))
+ #endif
+
+ #define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS"))
+
+__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
+{
+ __arm_wsr("CONTROL_NS", control);
+ __iar_builtin_ISB();
+}
+
+ #define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS"))
+ #define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE)))
+ #define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS"))
+ #define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE)))
+ #define __TZ_get_SP_NS() (__arm_rsr("SP_NS"))
+ #define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE)))
+ #define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS"))
+ #define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE)))
+ #define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS"))
+ #define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE)))
+ #define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS"))
+ #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
+
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ #define __TZ_get_PSPLIM_NS() (0U)
+ #define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE))
+ #else
+ #define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS"))
+ #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE)))
+ #endif
+
+ #define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS"))
+ #define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE)))
+
+ #define __NOP __iar_builtin_no_operation
+
+ #define __CLZ __iar_builtin_CLZ
+ #define __CLREX __iar_builtin_CLREX
+
+ #define __DMB __iar_builtin_DMB
+ #define __DSB __iar_builtin_DSB
+ #define __ISB __iar_builtin_ISB
+
+ #define __LDREXB __iar_builtin_LDREXB
+ #define __LDREXH __iar_builtin_LDREXH
+ #define __LDREXW __iar_builtin_LDREX
+
+ #define __RBIT __iar_builtin_RBIT
+ #define __REV __iar_builtin_REV
+ #define __REV16 __iar_builtin_REV16
+
+ __IAR_FT int16_t __REVSH(int16_t val)
+ {
+ return (int16_t) __iar_builtin_REVSH(val);
+ }
+
+ #define __ROR __iar_builtin_ROR
+ #define __RRX __iar_builtin_RRX
+
+ #define __SEV __iar_builtin_SEV
+
+ #if !__IAR_M0_FAMILY
+ #define __SSAT __iar_builtin_SSAT
+ #endif
+
+ #define __STREXB __iar_builtin_STREXB
+ #define __STREXH __iar_builtin_STREXH
+ #define __STREXW __iar_builtin_STREX
+
+ #if !__IAR_M0_FAMILY
+ #define __USAT __iar_builtin_USAT
+ #endif
+
+ #define __WFE __iar_builtin_WFE
+ #define __WFI __iar_builtin_WFI
+
+ #if __ARM_MEDIA__
+ #define __SADD8 __iar_builtin_SADD8
+ #define __QADD8 __iar_builtin_QADD8
+ #define __SHADD8 __iar_builtin_SHADD8
+ #define __UADD8 __iar_builtin_UADD8
+ #define __UQADD8 __iar_builtin_UQADD8
+ #define __UHADD8 __iar_builtin_UHADD8
+ #define __SSUB8 __iar_builtin_SSUB8
+ #define __QSUB8 __iar_builtin_QSUB8
+ #define __SHSUB8 __iar_builtin_SHSUB8
+ #define __USUB8 __iar_builtin_USUB8
+ #define __UQSUB8 __iar_builtin_UQSUB8
+ #define __UHSUB8 __iar_builtin_UHSUB8
+ #define __SADD16 __iar_builtin_SADD16
+ #define __QADD16 __iar_builtin_QADD16
+ #define __SHADD16 __iar_builtin_SHADD16
+ #define __UADD16 __iar_builtin_UADD16
+ #define __UQADD16 __iar_builtin_UQADD16
+ #define __UHADD16 __iar_builtin_UHADD16
+ #define __SSUB16 __iar_builtin_SSUB16
+ #define __QSUB16 __iar_builtin_QSUB16
+ #define __SHSUB16 __iar_builtin_SHSUB16
+ #define __USUB16 __iar_builtin_USUB16
+ #define __UQSUB16 __iar_builtin_UQSUB16
+ #define __UHSUB16 __iar_builtin_UHSUB16
+ #define __SASX __iar_builtin_SASX
+ #define __QASX __iar_builtin_QASX
+ #define __SHASX __iar_builtin_SHASX
+ #define __UASX __iar_builtin_UASX
+ #define __UQASX __iar_builtin_UQASX
+ #define __UHASX __iar_builtin_UHASX
+ #define __SSAX __iar_builtin_SSAX
+ #define __QSAX __iar_builtin_QSAX
+ #define __SHSAX __iar_builtin_SHSAX
+ #define __USAX __iar_builtin_USAX
+ #define __UQSAX __iar_builtin_UQSAX
+ #define __UHSAX __iar_builtin_UHSAX
+ #define __USAD8 __iar_builtin_USAD8
+ #define __USADA8 __iar_builtin_USADA8
+ #define __SSAT16 __iar_builtin_SSAT16
+ #define __USAT16 __iar_builtin_USAT16
+ #define __UXTB16 __iar_builtin_UXTB16
+ #define __UXTAB16 __iar_builtin_UXTAB16
+ #define __SXTB16 __iar_builtin_SXTB16
+ #define __SXTAB16 __iar_builtin_SXTAB16
+ #define __SMUAD __iar_builtin_SMUAD
+ #define __SMUADX __iar_builtin_SMUADX
+ #define __SMMLA __iar_builtin_SMMLA
+ #define __SMLAD __iar_builtin_SMLAD
+ #define __SMLADX __iar_builtin_SMLADX
+ #define __SMLALD __iar_builtin_SMLALD
+ #define __SMLALDX __iar_builtin_SMLALDX
+ #define __SMUSD __iar_builtin_SMUSD
+ #define __SMUSDX __iar_builtin_SMUSDX
+ #define __SMLSD __iar_builtin_SMLSD
+ #define __SMLSDX __iar_builtin_SMLSDX
+ #define __SMLSLD __iar_builtin_SMLSLD
+ #define __SMLSLDX __iar_builtin_SMLSLDX
+ #define __SEL __iar_builtin_SEL
+ #define __QADD __iar_builtin_QADD
+ #define __QSUB __iar_builtin_QSUB
+ #define __PKHBT __iar_builtin_PKHBT
+ #define __PKHTB __iar_builtin_PKHTB
+ #endif
+
+#else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
+
+ #if __IAR_M0_FAMILY
+ /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
+ #define __CLZ __cmsis_iar_clz_not_active
+ #define __SSAT __cmsis_iar_ssat_not_active
+ #define __USAT __cmsis_iar_usat_not_active
+ #define __RBIT __cmsis_iar_rbit_not_active
+ #define __get_APSR __cmsis_iar_get_APSR_not_active
+ #endif
+
+
+ #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
+ #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
+ #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
+ #endif
+
+ #ifdef __INTRINSICS_INCLUDED
+ #error intrinsics.h is already included previously!
+ #endif
+
+ #include
+
+ #if __IAR_M0_FAMILY
+ /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
+ #undef __CLZ
+ #undef __SSAT
+ #undef __USAT
+ #undef __RBIT
+ #undef __get_APSR
+
+ __STATIC_INLINE uint8_t __CLZ(uint32_t data)
+ {
+ if (data == 0U) { return 32U; }
+
+ uint32_t count = 0U;
+ uint32_t mask = 0x80000000U;
+
+ while ((data & mask) == 0U)
+ {
+ count += 1U;
+ mask = mask >> 1U;
+ }
+ return count;
+ }
+
+ __STATIC_INLINE uint32_t __RBIT(uint32_t v)
+ {
+ uint8_t sc = 31U;
+ uint32_t r = v;
+ for (v >>= 1U; v; v >>= 1U)
+ {
+ r <<= 1U;
+ r |= v & 1U;
+ sc--;
+ }
+ return (r << sc);
+ }
+
+ __STATIC_INLINE uint32_t __get_APSR(void)
+ {
+ uint32_t res;
+ __asm("MRS %0,APSR" : "=r" (res));
+ return res;
+ }
+
+ #endif
+
+ #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
+ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
+ #undef __get_FPSCR
+ #undef __set_FPSCR
+ #define __get_FPSCR() (0)
+ #define __set_FPSCR(VALUE) ((void)VALUE)
+ #endif
+
+ #pragma diag_suppress=Pe940
+ #pragma diag_suppress=Pe177
+
+ #define __enable_irq __enable_interrupt
+ #define __disable_irq __disable_interrupt
+ #define __NOP __no_operation
+
+ #define __get_xPSR __get_PSR
+
+ #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
+
+ __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
+ {
+ return __LDREX((unsigned long *)ptr);
+ }
+
+ __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
+ {
+ return __STREX(value, (unsigned long *)ptr);
+ }
+ #endif
+
+
+ /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
+ #if (__CORTEX_M >= 0x03)
+
+ __IAR_FT uint32_t __RRX(uint32_t value)
+ {
+ uint32_t result;
+ __ASM volatile("RRX %0, %1" : "=r"(result) : "r" (value));
+ return(result);
+ }
+
+ __IAR_FT void __set_BASEPRI_MAX(uint32_t value)
+ {
+ __asm volatile("MSR BASEPRI_MAX,%0"::"r" (value));
+ }
+
+
+ #define __enable_fault_irq __enable_fiq
+ #define __disable_fault_irq __disable_fiq
+
+
+ #endif /* (__CORTEX_M >= 0x03) */
+
+ __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
+ {
+ return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
+ }
+
+ #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+
+ __IAR_FT uint32_t __get_MSPLIM(void)
+ {
+ uint32_t res;
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ res = 0U;
+ #else
+ __asm volatile("MRS %0,MSPLIM" : "=r" (res));
+ #endif
+ return res;
+ }
+
+ __IAR_FT void __set_MSPLIM(uint32_t value)
+ {
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure MSPLIM is RAZ/WI
+ (void)value;
+ #else
+ __asm volatile("MSR MSPLIM,%0" :: "r" (value));
+ #endif
+ }
+
+ __IAR_FT uint32_t __get_PSPLIM(void)
+ {
+ uint32_t res;
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ res = 0U;
+ #else
+ __asm volatile("MRS %0,PSPLIM" : "=r" (res));
+ #endif
+ return res;
+ }
+
+ __IAR_FT void __set_PSPLIM(uint32_t value)
+ {
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)value;
+ #else
+ __asm volatile("MSR PSPLIM,%0" :: "r" (value));
+ #endif
+ }
+
+ __IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,CONTROL_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_CONTROL_NS(uint32_t value)
+ {
+ __asm volatile("MSR CONTROL_NS,%0" :: "r" (value));
+ __iar_builtin_ISB();
+ }
+
+ __IAR_FT uint32_t __TZ_get_PSP_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,PSP_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_PSP_NS(uint32_t value)
+ {
+ __asm volatile("MSR PSP_NS,%0" :: "r" (value));
+ }
+
+ __IAR_FT uint32_t __TZ_get_MSP_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,MSP_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_MSP_NS(uint32_t value)
+ {
+ __asm volatile("MSR MSP_NS,%0" :: "r" (value));
+ }
+
+ __IAR_FT uint32_t __TZ_get_SP_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,SP_NS" : "=r" (res));
+ return res;
+ }
+ __IAR_FT void __TZ_set_SP_NS(uint32_t value)
+ {
+ __asm volatile("MSR SP_NS,%0" :: "r" (value));
+ }
+
+ __IAR_FT uint32_t __TZ_get_PRIMASK_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,PRIMASK_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value)
+ {
+ __asm volatile("MSR PRIMASK_NS,%0" :: "r" (value));
+ }
+
+ __IAR_FT uint32_t __TZ_get_BASEPRI_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,BASEPRI_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value)
+ {
+ __asm volatile("MSR BASEPRI_NS,%0" :: "r" (value));
+ }
+
+ __IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value)
+ {
+ __asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value));
+ }
+
+ __IAR_FT uint32_t __TZ_get_PSPLIM_NS(void)
+ {
+ uint32_t res;
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ res = 0U;
+ #else
+ __asm volatile("MRS %0,PSPLIM_NS" : "=r" (res));
+ #endif
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value)
+ {
+ #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
+ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
+ // without main extensions, the non-secure PSPLIM is RAZ/WI
+ (void)value;
+ #else
+ __asm volatile("MSR PSPLIM_NS,%0" :: "r" (value));
+ #endif
+ }
+
+ __IAR_FT uint32_t __TZ_get_MSPLIM_NS(void)
+ {
+ uint32_t res;
+ __asm volatile("MRS %0,MSPLIM_NS" : "=r" (res));
+ return res;
+ }
+
+ __IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value)
+ {
+ __asm volatile("MSR MSPLIM_NS,%0" :: "r" (value));
+ }
+
+ #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
+
+#endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
+
+#define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
+
+#if __IAR_M0_FAMILY
+ __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
+ {
+ if ((sat >= 1U) && (sat <= 32U))
+ {
+ const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
+ const int32_t min = -1 - max ;
+ if (val > max)
+ {
+ return max;
+ }
+ else if (val < min)
+ {
+ return min;
+ }
+ }
+ return val;
+ }
+
+ __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
+ {
+ if (sat <= 31U)
+ {
+ const uint32_t max = ((1U << sat) - 1U);
+ if (val > (int32_t)max)
+ {
+ return max;
+ }
+ else if (val < 0)
+ {
+ return 0U;
+ }
+ }
+ return (uint32_t)val;
+ }
+#endif
+
+#if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
+
+ __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
+ return ((uint8_t)res);
+ }
+
+ __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
+ return ((uint16_t)res);
+ }
+
+ __IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
+ return res;
+ }
+
+ __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
+ {
+ __ASM volatile ("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
+ }
+
+ __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
+ {
+ __ASM volatile ("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
+ }
+
+ __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
+ {
+ __ASM volatile ("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
+ }
+
+#endif /* (__CORTEX_M >= 0x03) */
+
+#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
+ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
+
+
+ __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
+ return ((uint8_t)res);
+ }
+
+ __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
+ return ((uint16_t)res);
+ }
+
+ __IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
+ return res;
+ }
+
+ __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
+ {
+ __ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
+ }
+
+ __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
+ {
+ __ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
+ }
+
+ __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
+ {
+ __ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
+ }
+
+ __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
+ return ((uint8_t)res);
+ }
+
+ __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
+ return ((uint16_t)res);
+ }
+
+ __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
+ return res;
+ }
+
+ __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
+ return res;
+ }
+
+ __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
+ return res;
+ }
+
+ __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
+ {
+ uint32_t res;
+ __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
+ return res;
+ }
+
+#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
+
+#undef __IAR_FT
+#undef __IAR_M0_FAMILY
+#undef __ICCARM_V8
+
+#pragma diag_default=Pe940
+#pragma diag_default=Pe177
+
+#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
+
+#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
+
+#endif /* __CMSIS_ICCARM_H__ */
diff --git a/CMSIS/Core/Include/cmsis_version.h b/CMSIS/Core/Include/cmsis_version.h
new file mode 100644
index 0000000..8b4765f
--- /dev/null
+++ b/CMSIS/Core/Include/cmsis_version.h
@@ -0,0 +1,39 @@
+/**************************************************************************//**
+ * @file cmsis_version.h
+ * @brief CMSIS Core(M) Version definitions
+ * @version V5.0.5
+ * @date 02. February 2022
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2022 ARM Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef __CMSIS_VERSION_H
+#define __CMSIS_VERSION_H
+
+/* CMSIS Version definitions */
+#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
+#define __CM_CMSIS_VERSION_SUB ( 6U) /*!< [15:0] CMSIS Core(M) sub version */
+#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
+ __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
+#endif
diff --git a/CMSIS/Core/Include/core_cm3.h b/CMSIS/Core/Include/core_cm3.h
new file mode 100644
index 0000000..74fb87e
--- /dev/null
+++ b/CMSIS/Core/Include/core_cm3.h
@@ -0,0 +1,1943 @@
+/**************************************************************************//**
+ * @file core_cm3.h
+ * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File
+ * @version V5.1.2
+ * @date 04. June 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef __CORE_CM3_H_GENERIC
+#define __CORE_CM3_H_GENERIC
+
+#include
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/**
+ \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
+ CMSIS violates the following MISRA-C:2004 rules:
+
+ \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'.
+
+ \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers.
+
+ \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code.
+ */
+
+
+/*******************************************************************************
+ * CMSIS definitions
+ ******************************************************************************/
+/**
+ \ingroup Cortex_M3
+ @{
+ */
+
+#include "cmsis_version.h"
+
+/* CMSIS CM3 definitions */
+#define __CM3_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
+#define __CM3_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
+#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \
+ __CM3_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
+
+#define __CORTEX_M (3U) /*!< Cortex-M Core */
+
+/** __FPU_USED indicates whether an FPU is used or not.
+ This core does not support an FPU at all
+*/
+#define __FPU_USED 0U
+
+#if defined ( __CC_ARM )
+ #if defined __TARGET_FPU_VFP
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
+ #if defined __ARM_FP
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#elif defined ( __GNUC__ )
+ #if defined (__VFP_FP__) && !defined(__SOFTFP__)
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#elif defined ( __ICCARM__ )
+ #if defined __ARMVFP__
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#elif defined ( __TI_ARM__ )
+ #if defined __TI_VFP_SUPPORT__
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#elif defined ( __TASKING__ )
+ #if defined __FPU_VFP__
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#elif defined ( __CSMC__ )
+ #if ( __CSMC__ & 0x400U)
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #endif
+
+#endif
+
+#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_CM3_H_GENERIC */
+
+#ifndef __CMSIS_GENERIC
+
+#ifndef __CORE_CM3_H_DEPENDANT
+#define __CORE_CM3_H_DEPENDANT
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* check device defines and use defaults */
+#if defined __CHECK_DEVICE_DEFINES
+ #ifndef __CM3_REV
+ #define __CM3_REV 0x0200U
+ #warning "__CM3_REV not defined in device header file; using default!"
+ #endif
+
+ #ifndef __MPU_PRESENT
+ #define __MPU_PRESENT 0U
+ #warning "__MPU_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __VTOR_PRESENT
+ #define __VTOR_PRESENT 1U
+ #warning "__VTOR_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __NVIC_PRIO_BITS
+ #define __NVIC_PRIO_BITS 3U
+ #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
+ #endif
+
+ #ifndef __Vendor_SysTickConfig
+ #define __Vendor_SysTickConfig 0U
+ #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
+ #endif
+#endif
+
+/* IO definitions (access restrictions to peripheral registers) */
+/**
+ \defgroup CMSIS_glob_defs CMSIS Global Defines
+
+ IO Type Qualifiers are used
+ \li to specify the access to peripheral variables.
+ \li for automatic generation of peripheral register debug information.
+*/
+#ifdef __cplusplus
+ #define __I volatile /*!< Defines 'read only' permissions */
+#else
+ #define __I volatile const /*!< Defines 'read only' permissions */
+#endif
+#define __O volatile /*!< Defines 'write only' permissions */
+#define __IO volatile /*!< Defines 'read / write' permissions */
+
+/* following defines should be used for structure members */
+#define __IM volatile const /*! Defines 'read only' structure member permissions */
+#define __OM volatile /*! Defines 'write only' structure member permissions */
+#define __IOM volatile /*! Defines 'read / write' structure member permissions */
+
+/*@} end of group Cortex_M3 */
+
+
+
+/*******************************************************************************
+ * Register Abstraction
+ Core Register contain:
+ - Core Register
+ - Core NVIC Register
+ - Core SCB Register
+ - Core SysTick Register
+ - Core Debug Register
+ - Core MPU Register
+ ******************************************************************************/
+/**
+ \defgroup CMSIS_core_register Defines and Type Definitions
+ \brief Type definitions and defines for Cortex-M processor based devices.
+*/
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_CORE Status and Control Registers
+ \brief Core Register type definitions.
+ @{
+ */
+
+/**
+ \brief Union type to access the Application Program Status Register (APSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
+ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
+ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
+ uint32_t C:1; /*!< bit: 29 Carry condition code flag */
+ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
+ uint32_t N:1; /*!< bit: 31 Negative condition code flag */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} APSR_Type;
+
+/* APSR Register Definitions */
+#define APSR_N_Pos 31U /*!< APSR: N Position */
+#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
+
+#define APSR_Z_Pos 30U /*!< APSR: Z Position */
+#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
+
+#define APSR_C_Pos 29U /*!< APSR: C Position */
+#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
+
+#define APSR_V_Pos 28U /*!< APSR: V Position */
+#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
+
+#define APSR_Q_Pos 27U /*!< APSR: Q Position */
+#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */
+
+
+/**
+ \brief Union type to access the Interrupt Program Status Register (IPSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
+ uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} IPSR_Type;
+
+/* IPSR Register Definitions */
+#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
+#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
+
+
+/**
+ \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
+ uint32_t _reserved0:1; /*!< bit: 9 Reserved */
+ uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */
+ uint32_t _reserved1:8; /*!< bit: 16..23 Reserved */
+ uint32_t T:1; /*!< bit: 24 Thumb bit */
+ uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */
+ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
+ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
+ uint32_t C:1; /*!< bit: 29 Carry condition code flag */
+ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
+ uint32_t N:1; /*!< bit: 31 Negative condition code flag */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} xPSR_Type;
+
+/* xPSR Register Definitions */
+#define xPSR_N_Pos 31U /*!< xPSR: N Position */
+#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
+
+#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
+#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
+
+#define xPSR_C_Pos 29U /*!< xPSR: C Position */
+#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
+
+#define xPSR_V_Pos 28U /*!< xPSR: V Position */
+#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
+
+#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
+#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
+
+#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */
+#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */
+
+#define xPSR_T_Pos 24U /*!< xPSR: T Position */
+#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
+
+#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */
+#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */
+
+#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
+#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
+
+
+/**
+ \brief Union type to access the Control Registers (CONTROL).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
+ uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
+ uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} CONTROL_Type;
+
+/* CONTROL Register Definitions */
+#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
+#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
+
+#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */
+#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */
+
+/*@} end of group CMSIS_CORE */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
+ \brief Type definitions for the NVIC Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
+ */
+typedef struct
+{
+ __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
+ uint32_t RESERVED0[24U];
+ __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
+ uint32_t RESERVED1[24U];
+ __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
+ uint32_t RESERVED2[24U];
+ __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
+ uint32_t RESERVED3[24U];
+ __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
+ uint32_t RESERVED4[56U];
+ __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
+ uint32_t RESERVED5[644U];
+ __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
+} NVIC_Type;
+
+/* Software Triggered Interrupt Register Definitions */
+#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */
+#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */
+
+/*@} end of group CMSIS_NVIC */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SCB System Control Block (SCB)
+ \brief Type definitions for the System Control Block Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Control Block (SCB).
+ */
+typedef struct
+{
+ __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
+ __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
+ __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
+ __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
+ __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
+ __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
+ __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
+ __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
+ __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
+ __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
+ __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
+ __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
+ __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
+ __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
+ __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
+ __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
+ __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
+ __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
+ __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
+ uint32_t RESERVED0[5U];
+ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
+} SCB_Type;
+
+/* SCB CPUID Register Definitions */
+#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
+#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
+
+#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
+#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
+
+#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
+#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
+
+#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
+#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
+
+#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
+#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
+
+/* SCB Interrupt Control State Register Definitions */
+#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
+#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
+
+#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
+#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
+
+#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
+#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
+
+#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
+#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
+
+#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
+#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
+
+#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
+#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
+
+#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
+#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
+
+#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
+#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
+
+#define SCB_ICSR_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */
+#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */
+
+#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
+#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
+
+/* SCB Vector Table Offset Register Definitions */
+#if defined (__CM3_REV) && (__CM3_REV < 0x0201U) /* core r2p1 */
+#define SCB_VTOR_TBLBASE_Pos 29U /*!< SCB VTOR: TBLBASE Position */
+#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */
+
+#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */
+#define SCB_VTOR_TBLOFF_Msk (0x3FFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
+#else
+#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */
+#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
+#endif
+
+/* SCB Application Interrupt and Reset Control Register Definitions */
+#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
+#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
+
+#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
+#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
+
+#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
+#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
+
+#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */
+#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
+
+#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
+#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
+
+#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
+#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
+
+#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */
+#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET Mask */
+
+/* SCB System Control Register Definitions */
+#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
+#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
+
+#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
+#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
+
+#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
+#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
+
+/* SCB Configuration Control Register Definitions */
+#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
+#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
+
+#define SCB_CCR_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */
+#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */
+
+#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */
+#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */
+
+#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
+#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
+
+#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */
+#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */
+
+#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */
+#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */
+
+/* SCB System Handler Control and State Register Definitions */
+#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */
+#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
+
+#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */
+#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
+
+#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */
+#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
+
+#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
+#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
+
+#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */
+#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
+
+#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */
+#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
+
+#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */
+#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
+
+#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */
+#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
+
+#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */
+#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
+
+#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */
+#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
+
+#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */
+#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
+
+#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */
+#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
+
+#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */
+#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
+
+#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */
+#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */
+
+/* SCB Configurable Fault Status Register Definitions */
+#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */
+#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */
+
+#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */
+#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */
+
+#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
+#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
+
+/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */
+#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */
+
+#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */
+#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */
+
+#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */
+#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */
+
+#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */
+#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */
+
+#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */
+#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */
+
+/* BusFault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */
+#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */
+
+#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */
+#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */
+
+#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */
+#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */
+
+#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */
+#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */
+
+#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */
+#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */
+
+#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */
+#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */
+
+/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */
+#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */
+
+#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */
+#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */
+
+#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */
+#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */
+
+#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */
+#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */
+
+#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */
+#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */
+
+#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */
+#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */
+
+/* SCB Hard Fault Status Register Definitions */
+#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
+#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
+
+#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */
+#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */
+
+#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */
+#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */
+
+/* SCB Debug Fault Status Register Definitions */
+#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */
+#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */
+
+#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */
+#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */
+
+#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */
+#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */
+
+#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */
+#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */
+
+#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */
+#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */
+
+/*@} end of group CMSIS_SCB */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
+ \brief Type definitions for the System Control and ID Register not in the SCB
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Control and ID Register not in the SCB.
+ */
+typedef struct
+{
+ uint32_t RESERVED0[1U];
+ __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
+#if defined (__CM3_REV) && (__CM3_REV >= 0x200U)
+ __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
+#else
+ uint32_t RESERVED1[1U];
+#endif
+} SCnSCB_Type;
+
+/* Interrupt Controller Type Register Definitions */
+#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */
+#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */
+
+/* Auxiliary Control Register Definitions */
+#if defined (__CM3_REV) && (__CM3_REV >= 0x200U)
+#define SCnSCB_ACTLR_DISOOFP_Pos 9U /*!< ACTLR: DISOOFP Position */
+#define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */
+
+#define SCnSCB_ACTLR_DISFPCA_Pos 8U /*!< ACTLR: DISFPCA Position */
+#define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */
+
+#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */
+#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
+
+#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1U /*!< ACTLR: DISDEFWBUF Position */
+#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */
+
+#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */
+#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */
+#endif
+
+/*@} end of group CMSIS_SCnotSCB */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SysTick System Tick Timer (SysTick)
+ \brief Type definitions for the System Timer Registers.
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Timer (SysTick).
+ */
+typedef struct
+{
+ __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
+ __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
+ __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
+ __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
+} SysTick_Type;
+
+/* SysTick Control / Status Register Definitions */
+#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
+#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
+
+#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
+#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
+
+#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
+#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
+
+#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
+#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
+
+/* SysTick Reload Register Definitions */
+#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
+#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
+
+/* SysTick Current Register Definitions */
+#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
+#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
+
+/* SysTick Calibration Register Definitions */
+#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
+#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
+
+#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
+#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
+
+#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
+#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
+
+/*@} end of group CMSIS_SysTick */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM)
+ \brief Type definitions for the Instrumentation Trace Macrocell (ITM)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM).
+ */
+typedef struct
+{
+ __OM union
+ {
+ __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */
+ __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */
+ __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */
+ } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */
+ uint32_t RESERVED0[864U];
+ __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */
+ uint32_t RESERVED1[15U];
+ __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
+ uint32_t RESERVED2[15U];
+ __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
+ uint32_t RESERVED3[32U];
+ uint32_t RESERVED4[43U];
+ __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
+ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
+ uint32_t RESERVED5[6U];
+ __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */
+ __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */
+ __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */
+ __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */
+ __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */
+ __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */
+ __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */
+ __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */
+ __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */
+ __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */
+ __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */
+ __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */
+} ITM_Type;
+
+/* ITM Trace Privilege Register Definitions */
+#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
+#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
+
+/* ITM Trace Control Register Definitions */
+#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
+#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */
+
+#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */
+#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */
+
+#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */
+#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */
+
+#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */
+#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */
+
+#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */
+#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */
+
+#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */
+#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */
+
+#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */
+#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */
+
+#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */
+#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */
+
+#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
+#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
+
+/* ITM Lock Status Register Definitions */
+#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
+#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
+
+#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */
+#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */
+
+#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */
+#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */
+
+/*@}*/ /* end of group CMSIS_ITM */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT)
+ \brief Type definitions for the Data Watchpoint and Trace (DWT)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Data Watchpoint and Trace Register (DWT).
+ */
+typedef struct
+{
+ __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
+ __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
+ __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */
+ __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */
+ __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */
+ __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */
+ __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */
+ __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */
+ __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */
+ __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */
+ __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */
+ uint32_t RESERVED0[1U];
+ __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */
+ __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */
+ __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */
+ uint32_t RESERVED1[1U];
+ __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */
+ __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */
+ __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */
+ uint32_t RESERVED2[1U];
+ __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */
+ __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */
+ __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */
+} DWT_Type;
+
+/* DWT Control Register Definitions */
+#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */
+#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */
+
+#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */
+#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */
+
+#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */
+#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */
+
+#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */
+#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */
+
+#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */
+#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */
+
+#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */
+#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */
+
+#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */
+#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */
+
+#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */
+#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */
+
+#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */
+#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */
+
+#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */
+#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */
+
+#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */
+#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */
+
+#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */
+#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */
+
+#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */
+#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */
+
+#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */
+#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */
+
+#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */
+#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */
+
+#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */
+#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */
+
+#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */
+#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */
+
+#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */
+#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */
+
+/* DWT CPI Count Register Definitions */
+#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */
+#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */
+
+/* DWT Exception Overhead Count Register Definitions */
+#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */
+#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */
+
+/* DWT Sleep Count Register Definitions */
+#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */
+#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */
+
+/* DWT LSU Count Register Definitions */
+#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */
+#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */
+
+/* DWT Folded-instruction Count Register Definitions */
+#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */
+#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */
+
+/* DWT Comparator Mask Register Definitions */
+#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */
+#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */
+
+/* DWT Comparator Function Register Definitions */
+#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */
+#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */
+
+#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */
+#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */
+
+#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */
+#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */
+
+#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */
+#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */
+
+#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */
+#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */
+
+#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */
+#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */
+
+#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */
+#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */
+
+#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */
+#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */
+
+#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */
+#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */
+
+/*@}*/ /* end of group CMSIS_DWT */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_TPI Trace Port Interface (TPI)
+ \brief Type definitions for the Trace Port Interface (TPI)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Trace Port Interface Register (TPI).
+ */
+typedef struct
+{
+ __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
+ __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
+ uint32_t RESERVED0[2U];
+ __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
+ uint32_t RESERVED1[55U];
+ __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */
+ uint32_t RESERVED2[131U];
+ __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */
+ __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
+ __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
+ uint32_t RESERVED3[759U];
+ __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */
+ __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
+ __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
+ uint32_t RESERVED4[1U];
+ __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */
+ __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */
+ __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */
+ uint32_t RESERVED5[39U];
+ __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */
+ __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */
+ uint32_t RESERVED7[8U];
+ __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */
+ __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */
+} TPI_Type;
+
+/* TPI Asynchronous Clock Prescaler Register Definitions */
+#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */
+#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */
+
+/* TPI Selected Pin Protocol Register Definitions */
+#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */
+#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */
+
+/* TPI Formatter and Flush Status Register Definitions */
+#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */
+#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */
+
+#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */
+#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */
+
+#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */
+#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */
+
+#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */
+#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */
+
+/* TPI Formatter and Flush Control Register Definitions */
+#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */
+#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */
+
+#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */
+#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */
+
+/* TPI TRIGGER Register Definitions */
+#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */
+#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */
+
+/* TPI Integration ETM Data Register Definitions (FIFO0) */
+#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
+#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
+
+#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
+#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
+
+#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
+#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
+
+#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
+#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
+
+#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */
+#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */
+
+#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */
+#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */
+
+#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */
+#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
+
+/* TPI ITATBCTR2 Register Definitions */
+#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */
+#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */
+
+#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */
+#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */
+
+/* TPI Integration ITM Data Register Definitions (FIFO1) */
+#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
+#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
+
+#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
+#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
+
+#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
+#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
+
+#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
+#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
+
+#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */
+#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */
+
+#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */
+#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */
+
+#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */
+#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
+
+/* TPI ITATBCTR0 Register Definitions */
+#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */
+#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */
+
+#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */
+#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */
+
+/* TPI Integration Mode Control Register Definitions */
+#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
+#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
+
+/* TPI DEVID Register Definitions */
+#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
+#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */
+
+#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */
+#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */
+
+#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */
+#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */
+
+#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */
+#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */
+
+#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */
+#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */
+
+#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */
+#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
+
+/* TPI DEVTYPE Register Definitions */
+#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */
+#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
+
+#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */
+#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
+
+/*@}*/ /* end of group CMSIS_TPI */
+
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_MPU Memory Protection Unit (MPU)
+ \brief Type definitions for the Memory Protection Unit (MPU)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Memory Protection Unit (MPU).
+ */
+typedef struct
+{
+ __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
+ __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
+ __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
+ __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
+ __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */
+ __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */
+ __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */
+ __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
+} MPU_Type;
+
+#define MPU_TYPE_RALIASES 4U
+
+/* MPU Type Register Definitions */
+#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
+#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
+
+#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */
+#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
+
+#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */
+#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */
+
+/* MPU Control Register Definitions */
+#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */
+#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
+
+#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */
+#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
+
+#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */
+#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */
+
+/* MPU Region Number Register Definitions */
+#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */
+#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */
+
+/* MPU Region Base Address Register Definitions */
+#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */
+#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
+
+#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */
+#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
+
+#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */
+#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */
+
+/* MPU Region Attribute and Size Register Definitions */
+#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */
+#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
+
+#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */
+#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
+
+#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */
+#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
+
+#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */
+#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
+
+#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */
+#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
+
+#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */
+#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
+
+#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */
+#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
+
+#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */
+#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
+
+#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */
+#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
+
+#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */
+#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
+
+/*@} end of group CMSIS_MPU */
+#endif
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
+ \brief Type definitions for the Core Debug Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the Core Debug Register (CoreDebug).
+ */
+typedef struct
+{
+ __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
+ __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
+ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
+ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
+} CoreDebug_Type;
+
+/* Debug Halting Control and Status Register Definitions */
+#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */
+#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */
+
+#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */
+#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */
+
+#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */
+#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */
+
+#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */
+#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */
+
+#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */
+#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */
+
+#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */
+#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */
+
+#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */
+#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */
+
+#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */
+#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */
+
+#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */
+#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */
+
+#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */
+#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */
+
+#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */
+#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */
+
+#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */
+#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */
+
+/* Debug Core Register Selector Register Definitions */
+#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */
+#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */
+
+#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */
+#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */
+
+/* Debug Exception and Monitor Control Register Definitions */
+#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */
+#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
+
+#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */
+#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */
+
+#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */
+#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */
+
+#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */
+#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */
+
+#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */
+#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */
+
+#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */
+#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */
+
+#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */
+#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */
+
+#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */
+#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */
+
+#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */
+#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */
+
+#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */
+#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */
+
+#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */
+#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */
+
+#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */
+#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */
+
+#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */
+#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */
+
+/*@} end of group CMSIS_CoreDebug */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_core_bitfield Core register bit field macros
+ \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
+ @{
+ */
+
+/**
+ \brief Mask and shift a bit field value for use in a register bit range.
+ \param[in] field Name of the register bit field.
+ \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
+ \return Masked and shifted value.
+*/
+#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
+
+/**
+ \brief Mask and shift a register value to extract a bit filed value.
+ \param[in] field Name of the register bit field.
+ \param[in] value Value of register. This parameter is interpreted as an uint32_t type.
+ \return Masked and shifted bit field value.
+*/
+#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
+
+/*@} end of group CMSIS_core_bitfield */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_core_base Core Definitions
+ \brief Definitions for base addresses, unions, and structures.
+ @{
+ */
+
+/* Memory mapping of Core Hardware */
+#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
+#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
+#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
+#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */
+#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
+#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
+#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
+#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
+
+#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
+#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
+#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
+#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
+#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */
+#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */
+#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
+#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+ #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
+ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
+#endif
+
+/*@} */
+
+
+
+/*******************************************************************************
+ * Hardware Abstraction Layer
+ Core Function Interface contains:
+ - Core NVIC Functions
+ - Core SysTick Functions
+ - Core Debug Functions
+ - Core Register Access Functions
+ ******************************************************************************/
+/**
+ \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
+*/
+
+
+
+/* ########################## NVIC functions #################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_NVICFunctions NVIC Functions
+ \brief Functions that manage interrupts and exceptions via the NVIC.
+ @{
+ */
+
+#ifdef CMSIS_NVIC_VIRTUAL
+ #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
+ #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
+ #endif
+ #include CMSIS_NVIC_VIRTUAL_HEADER_FILE
+#else
+ #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
+ #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
+ #define NVIC_EnableIRQ __NVIC_EnableIRQ
+ #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
+ #define NVIC_DisableIRQ __NVIC_DisableIRQ
+ #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
+ #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
+ #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
+ #define NVIC_GetActive __NVIC_GetActive
+ #define NVIC_SetPriority __NVIC_SetPriority
+ #define NVIC_GetPriority __NVIC_GetPriority
+ #define NVIC_SystemReset __NVIC_SystemReset
+#endif /* CMSIS_NVIC_VIRTUAL */
+
+#ifdef CMSIS_VECTAB_VIRTUAL
+ #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
+ #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
+ #endif
+ #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
+#else
+ #define NVIC_SetVector __NVIC_SetVector
+ #define NVIC_GetVector __NVIC_GetVector
+#endif /* (CMSIS_VECTAB_VIRTUAL) */
+
+#define NVIC_USER_IRQ_OFFSET 16
+
+
+/* The following EXC_RETURN values are saved the LR on exception entry */
+#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
+#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
+#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
+
+
+/**
+ \brief Set Priority Grouping
+ \details Sets the priority grouping field using the required unlock sequence.
+ The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
+ Only values from 0..7 are used.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
+ \param [in] PriorityGroup Priority grouping field.
+ */
+__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
+{
+ uint32_t reg_value;
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+
+ reg_value = SCB->AIRCR; /* read old register configuration */
+ reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
+ reg_value = (reg_value |
+ ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
+ (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */
+ SCB->AIRCR = reg_value;
+}
+
+
+/**
+ \brief Get Priority Grouping
+ \details Reads the priority grouping field from the NVIC Interrupt Controller.
+ \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void)
+{
+ return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
+}
+
+
+/**
+ \brief Enable Interrupt
+ \details Enables a device specific interrupt in the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ __COMPILER_BARRIER();
+ NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ __COMPILER_BARRIER();
+ }
+}
+
+
+/**
+ \brief Get Interrupt Enable status
+ \details Returns a device specific interrupt enable status from the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt is not enabled.
+ \return 1 Interrupt is enabled.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Disable Interrupt
+ \details Disables a device specific interrupt in the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ __DSB();
+ __ISB();
+ }
+}
+
+
+/**
+ \brief Get Pending Interrupt
+ \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt status is not pending.
+ \return 1 Interrupt status is pending.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Set Pending Interrupt
+ \details Sets the pending bit of a device specific interrupt in the NVIC pending register.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ }
+}
+
+
+/**
+ \brief Clear Pending Interrupt
+ \details Clears the pending bit of a device specific interrupt in the NVIC pending register.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ }
+}
+
+
+/**
+ \brief Get Active Interrupt
+ \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt status is not active.
+ \return 1 Interrupt status is active.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Set Interrupt Priority
+ \details Sets the priority of a device specific interrupt or a processor exception.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \param [in] priority Priority to set.
+ \note The priority cannot be set for every processor exception.
+ */
+__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
+ }
+ else
+ {
+ SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
+ }
+}
+
+
+/**
+ \brief Get Interrupt Priority
+ \details Reads the priority of a device specific interrupt or a processor exception.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \return Interrupt Priority.
+ Value is aligned automatically to the implemented priority bits of the microcontroller.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
+{
+
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
+ }
+ else
+ {
+ return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
+ }
+}
+
+
+/**
+ \brief Encode Priority
+ \details Encodes the priority for an interrupt with the given priority group,
+ preemptive priority value, and subpriority value.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
+ \param [in] PriorityGroup Used priority group.
+ \param [in] PreemptPriority Preemptive priority value (starting from 0).
+ \param [in] SubPriority Subpriority value (starting from 0).
+ \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
+ */
+__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
+{
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+ uint32_t PreemptPriorityBits;
+ uint32_t SubPriorityBits;
+
+ PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
+ SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
+
+ return (
+ ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
+ ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
+ );
+}
+
+
+/**
+ \brief Decode Priority
+ \details Decodes an interrupt priority value with a given priority group to
+ preemptive priority value and subpriority value.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
+ \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
+ \param [in] PriorityGroup Used priority group.
+ \param [out] pPreemptPriority Preemptive priority value (starting from 0).
+ \param [out] pSubPriority Subpriority value (starting from 0).
+ */
+__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
+{
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+ uint32_t PreemptPriorityBits;
+ uint32_t SubPriorityBits;
+
+ PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
+ SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
+
+ *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
+ *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
+}
+
+
+/**
+ \brief Set Interrupt Vector
+ \details Sets an interrupt vector in SRAM based interrupt vector table.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ VTOR must been relocated to SRAM before.
+ \param [in] IRQn Interrupt number
+ \param [in] vector Address of interrupt handler function
+ */
+__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
+{
+ uint32_t *vectors = (uint32_t *)SCB->VTOR;
+ vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
+ /* ARM Application Note 321 states that the M3 does not require the architectural barrier */
+}
+
+
+/**
+ \brief Get Interrupt Vector
+ \details Reads an interrupt vector from interrupt vector table.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \return Address of interrupt handler function
+ */
+__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
+{
+ uint32_t *vectors = (uint32_t *)SCB->VTOR;
+ return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
+}
+
+
+/**
+ \brief System Reset
+ \details Initiates a system reset request to reset the MCU.
+ */
+__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
+{
+ __DSB(); /* Ensure all outstanding memory accesses included
+ buffered write are completed before reset */
+ SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
+ (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
+ SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */
+ __DSB(); /* Ensure completion of memory access */
+
+ for(;;) /* wait until reset */
+ {
+ __NOP();
+ }
+}
+
+/*@} end of CMSIS_Core_NVICFunctions */
+
+
+/* ########################## MPU functions #################################### */
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+
+#include "mpu_armv7.h"
+
+#endif
+
+
+/* ########################## FPU functions #################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_FpuFunctions FPU Functions
+ \brief Function that provides FPU type.
+ @{
+ */
+
+/**
+ \brief get FPU type
+ \details returns the FPU type
+ \returns
+ - \b 0: No FPU
+ - \b 1: Single precision FPU
+ - \b 2: Double + Single precision FPU
+ */
+__STATIC_INLINE uint32_t SCB_GetFPUType(void)
+{
+ return 0U; /* No FPU */
+}
+
+
+/*@} end of CMSIS_Core_FpuFunctions */
+
+
+
+/* ################################## SysTick function ############################################ */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
+ \brief Functions that configure the System.
+ @{
+ */
+
+#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
+
+/**
+ \brief System Tick Configuration
+ \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
+ Counter is in free running mode to generate periodic interrupts.
+ \param [in] ticks Number of ticks between two interrupts.
+ \return 0 Function succeeded.
+ \return 1 Function failed.
+ \note When the variable __Vendor_SysTickConfig is set to 1, then the
+ function SysTick_Config is not included. In this case, the file device .h
+ must contain a vendor-specific implementation of this function.
+ */
+__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
+{
+ if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
+ {
+ return (1UL); /* Reload value impossible */
+ }
+
+ SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
+ NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
+ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
+ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
+ SysTick_CTRL_TICKINT_Msk |
+ SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
+ return (0UL); /* Function successful */
+}
+
+#endif
+
+/*@} end of CMSIS_Core_SysTickFunctions */
+
+
+
+/* ##################################### Debug In/Output function ########################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_core_DebugFunctions ITM Functions
+ \brief Functions that access the ITM debug interface.
+ @{
+ */
+
+extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
+#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
+
+
+/**
+ \brief ITM Send Character
+ \details Transmits a character via the ITM channel 0, and
+ \li Just returns when no debugger is connected that has booked the output.
+ \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
+ \param [in] ch Character to transmit.
+ \returns Character to transmit.
+ */
+__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
+{
+ if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
+ ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */
+ {
+ while (ITM->PORT[0U].u32 == 0UL)
+ {
+ __NOP();
+ }
+ ITM->PORT[0U].u8 = (uint8_t)ch;
+ }
+ return (ch);
+}
+
+
+/**
+ \brief ITM Receive Character
+ \details Inputs a character via the external variable \ref ITM_RxBuffer.
+ \return Received character.
+ \return -1 No character pending.
+ */
+__STATIC_INLINE int32_t ITM_ReceiveChar (void)
+{
+ int32_t ch = -1; /* no character available */
+
+ if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY)
+ {
+ ch = ITM_RxBuffer;
+ ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
+ }
+
+ return (ch);
+}
+
+
+/**
+ \brief ITM Check Character
+ \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer.
+ \return 0 No character available.
+ \return 1 Character available.
+ */
+__STATIC_INLINE int32_t ITM_CheckChar (void)
+{
+
+ if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY)
+ {
+ return (0); /* no character available */
+ }
+ else
+ {
+ return (1); /* character available */
+ }
+}
+
+/*@} end of CMSIS_core_DebugFunctions */
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_CM3_H_DEPENDANT */
+
+#endif /* __CMSIS_GENERIC */
diff --git a/CMSIS/Core/Include/core_cm4.h b/CMSIS/Core/Include/core_cm4.h
new file mode 100644
index 0000000..e21cd14
--- /dev/null
+++ b/CMSIS/Core/Include/core_cm4.h
@@ -0,0 +1,2129 @@
+/**************************************************************************//**
+ * @file core_cm4.h
+ * @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File
+ * @version V5.1.2
+ * @date 04. June 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2020 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef __CORE_CM4_H_GENERIC
+#define __CORE_CM4_H_GENERIC
+
+#include
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/**
+ \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
+ CMSIS violates the following MISRA-C:2004 rules:
+
+ \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'.
+
+ \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers.
+
+ \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code.
+ */
+
+
+/*******************************************************************************
+ * CMSIS definitions
+ ******************************************************************************/
+/**
+ \ingroup Cortex_M4
+ @{
+ */
+
+#include "cmsis_version.h"
+
+/* CMSIS CM4 definitions */
+#define __CM4_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
+#define __CM4_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
+#define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \
+ __CM4_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
+
+#define __CORTEX_M (4U) /*!< Cortex-M Core */
+
+/** __FPU_USED indicates whether an FPU is used or not.
+ For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions.
+*/
+#if defined ( __CC_ARM )
+ #if defined __TARGET_FPU_VFP
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
+ #if defined __ARM_FP
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __GNUC__ )
+ #if defined (__VFP_FP__) && !defined(__SOFTFP__)
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __ICCARM__ )
+ #if defined __ARMVFP__
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __TI_ARM__ )
+ #if defined __TI_VFP_SUPPORT__
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __TASKING__ )
+ #if defined __FPU_VFP__
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __CSMC__ )
+ #if ( __CSMC__ & 0x400U)
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#endif
+
+#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_CM4_H_GENERIC */
+
+#ifndef __CMSIS_GENERIC
+
+#ifndef __CORE_CM4_H_DEPENDANT
+#define __CORE_CM4_H_DEPENDANT
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* check device defines and use defaults */
+#if defined __CHECK_DEVICE_DEFINES
+ #ifndef __CM4_REV
+ #define __CM4_REV 0x0000U
+ #warning "__CM4_REV not defined in device header file; using default!"
+ #endif
+
+ #ifndef __FPU_PRESENT
+ #define __FPU_PRESENT 0U
+ #warning "__FPU_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __MPU_PRESENT
+ #define __MPU_PRESENT 0U
+ #warning "__MPU_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __VTOR_PRESENT
+ #define __VTOR_PRESENT 1U
+ #warning "__VTOR_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __NVIC_PRIO_BITS
+ #define __NVIC_PRIO_BITS 3U
+ #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
+ #endif
+
+ #ifndef __Vendor_SysTickConfig
+ #define __Vendor_SysTickConfig 0U
+ #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
+ #endif
+#endif
+
+/* IO definitions (access restrictions to peripheral registers) */
+/**
+ \defgroup CMSIS_glob_defs CMSIS Global Defines
+
+ IO Type Qualifiers are used
+ \li to specify the access to peripheral variables.
+ \li for automatic generation of peripheral register debug information.
+*/
+#ifdef __cplusplus
+ #define __I volatile /*!< Defines 'read only' permissions */
+#else
+ #define __I volatile const /*!< Defines 'read only' permissions */
+#endif
+#define __O volatile /*!< Defines 'write only' permissions */
+#define __IO volatile /*!< Defines 'read / write' permissions */
+
+/* following defines should be used for structure members */
+#define __IM volatile const /*! Defines 'read only' structure member permissions */
+#define __OM volatile /*! Defines 'write only' structure member permissions */
+#define __IOM volatile /*! Defines 'read / write' structure member permissions */
+
+/*@} end of group Cortex_M4 */
+
+
+
+/*******************************************************************************
+ * Register Abstraction
+ Core Register contain:
+ - Core Register
+ - Core NVIC Register
+ - Core SCB Register
+ - Core SysTick Register
+ - Core Debug Register
+ - Core MPU Register
+ - Core FPU Register
+ ******************************************************************************/
+/**
+ \defgroup CMSIS_core_register Defines and Type Definitions
+ \brief Type definitions and defines for Cortex-M processor based devices.
+*/
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_CORE Status and Control Registers
+ \brief Core Register type definitions.
+ @{
+ */
+
+/**
+ \brief Union type to access the Application Program Status Register (APSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
+ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
+ uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
+ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
+ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
+ uint32_t C:1; /*!< bit: 29 Carry condition code flag */
+ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
+ uint32_t N:1; /*!< bit: 31 Negative condition code flag */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} APSR_Type;
+
+/* APSR Register Definitions */
+#define APSR_N_Pos 31U /*!< APSR: N Position */
+#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
+
+#define APSR_Z_Pos 30U /*!< APSR: Z Position */
+#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
+
+#define APSR_C_Pos 29U /*!< APSR: C Position */
+#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
+
+#define APSR_V_Pos 28U /*!< APSR: V Position */
+#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
+
+#define APSR_Q_Pos 27U /*!< APSR: Q Position */
+#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */
+
+#define APSR_GE_Pos 16U /*!< APSR: GE Position */
+#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE Mask */
+
+
+/**
+ \brief Union type to access the Interrupt Program Status Register (IPSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
+ uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} IPSR_Type;
+
+/* IPSR Register Definitions */
+#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
+#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
+
+
+/**
+ \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
+ uint32_t _reserved0:1; /*!< bit: 9 Reserved */
+ uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */
+ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
+ uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
+ uint32_t T:1; /*!< bit: 24 Thumb bit */
+ uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */
+ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
+ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
+ uint32_t C:1; /*!< bit: 29 Carry condition code flag */
+ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
+ uint32_t N:1; /*!< bit: 31 Negative condition code flag */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} xPSR_Type;
+
+/* xPSR Register Definitions */
+#define xPSR_N_Pos 31U /*!< xPSR: N Position */
+#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
+
+#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
+#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
+
+#define xPSR_C_Pos 29U /*!< xPSR: C Position */
+#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
+
+#define xPSR_V_Pos 28U /*!< xPSR: V Position */
+#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
+
+#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
+#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
+
+#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */
+#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */
+
+#define xPSR_T_Pos 24U /*!< xPSR: T Position */
+#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
+
+#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */
+#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */
+
+#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */
+#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */
+
+#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
+#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
+
+
+/**
+ \brief Union type to access the Control Registers (CONTROL).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
+ uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
+ uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
+ uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} CONTROL_Type;
+
+/* CONTROL Register Definitions */
+#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */
+#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */
+
+#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
+#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
+
+#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */
+#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */
+
+/*@} end of group CMSIS_CORE */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
+ \brief Type definitions for the NVIC Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
+ */
+typedef struct
+{
+ __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
+ uint32_t RESERVED0[24U];
+ __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
+ uint32_t RESERVED1[24U];
+ __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
+ uint32_t RESERVED2[24U];
+ __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
+ uint32_t RESERVED3[24U];
+ __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
+ uint32_t RESERVED4[56U];
+ __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
+ uint32_t RESERVED5[644U];
+ __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
+} NVIC_Type;
+
+/* Software Triggered Interrupt Register Definitions */
+#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */
+#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */
+
+/*@} end of group CMSIS_NVIC */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SCB System Control Block (SCB)
+ \brief Type definitions for the System Control Block Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Control Block (SCB).
+ */
+typedef struct
+{
+ __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
+ __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
+ __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
+ __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
+ __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
+ __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
+ __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
+ __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
+ __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
+ __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
+ __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
+ __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
+ __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
+ __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
+ __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
+ __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
+ __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
+ __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
+ __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
+ uint32_t RESERVED0[5U];
+ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
+} SCB_Type;
+
+/* SCB CPUID Register Definitions */
+#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
+#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
+
+#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
+#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
+
+#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
+#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
+
+#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
+#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
+
+#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
+#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
+
+/* SCB Interrupt Control State Register Definitions */
+#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
+#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
+
+#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
+#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
+
+#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
+#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
+
+#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
+#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
+
+#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
+#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
+
+#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
+#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
+
+#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
+#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
+
+#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
+#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
+
+#define SCB_ICSR_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */
+#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */
+
+#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
+#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
+
+/* SCB Vector Table Offset Register Definitions */
+#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */
+#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
+
+/* SCB Application Interrupt and Reset Control Register Definitions */
+#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
+#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
+
+#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
+#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
+
+#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
+#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
+
+#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */
+#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
+
+#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
+#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
+
+#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
+#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
+
+#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */
+#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET Mask */
+
+/* SCB System Control Register Definitions */
+#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
+#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
+
+#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
+#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
+
+#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
+#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
+
+/* SCB Configuration Control Register Definitions */
+#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
+#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
+
+#define SCB_CCR_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */
+#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */
+
+#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */
+#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */
+
+#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
+#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
+
+#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */
+#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */
+
+#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */
+#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */
+
+/* SCB System Handler Control and State Register Definitions */
+#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */
+#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
+
+#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */
+#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
+
+#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */
+#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
+
+#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
+#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
+
+#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */
+#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
+
+#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */
+#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
+
+#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */
+#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
+
+#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */
+#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
+
+#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */
+#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
+
+#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */
+#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
+
+#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */
+#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
+
+#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */
+#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
+
+#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */
+#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
+
+#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */
+#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */
+
+/* SCB Configurable Fault Status Register Definitions */
+#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */
+#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */
+
+#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */
+#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */
+
+#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
+#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
+
+/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */
+#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */
+
+#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */
+#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */
+
+#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */
+#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */
+
+#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */
+#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */
+
+#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */
+#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */
+
+#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */
+#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */
+
+/* BusFault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */
+#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */
+
+#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */
+#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */
+
+#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */
+#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */
+
+#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */
+#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */
+
+#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */
+#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */
+
+#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */
+#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */
+
+#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */
+#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */
+
+/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */
+#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */
+
+#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */
+#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */
+
+#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */
+#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */
+
+#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */
+#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */
+
+#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */
+#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */
+
+#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */
+#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */
+
+/* SCB Hard Fault Status Register Definitions */
+#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
+#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
+
+#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */
+#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */
+
+#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */
+#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */
+
+/* SCB Debug Fault Status Register Definitions */
+#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */
+#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */
+
+#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */
+#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */
+
+#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */
+#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */
+
+#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */
+#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */
+
+#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */
+#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */
+
+/*@} end of group CMSIS_SCB */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
+ \brief Type definitions for the System Control and ID Register not in the SCB
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Control and ID Register not in the SCB.
+ */
+typedef struct
+{
+ uint32_t RESERVED0[1U];
+ __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
+ __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
+} SCnSCB_Type;
+
+/* Interrupt Controller Type Register Definitions */
+#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */
+#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */
+
+/* Auxiliary Control Register Definitions */
+#define SCnSCB_ACTLR_DISOOFP_Pos 9U /*!< ACTLR: DISOOFP Position */
+#define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */
+
+#define SCnSCB_ACTLR_DISFPCA_Pos 8U /*!< ACTLR: DISFPCA Position */
+#define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */
+
+#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */
+#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
+
+#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1U /*!< ACTLR: DISDEFWBUF Position */
+#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */
+
+#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */
+#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */
+
+/*@} end of group CMSIS_SCnotSCB */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SysTick System Tick Timer (SysTick)
+ \brief Type definitions for the System Timer Registers.
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Timer (SysTick).
+ */
+typedef struct
+{
+ __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
+ __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
+ __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
+ __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
+} SysTick_Type;
+
+/* SysTick Control / Status Register Definitions */
+#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
+#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
+
+#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
+#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
+
+#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
+#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
+
+#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
+#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
+
+/* SysTick Reload Register Definitions */
+#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
+#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
+
+/* SysTick Current Register Definitions */
+#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
+#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
+
+/* SysTick Calibration Register Definitions */
+#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
+#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
+
+#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
+#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
+
+#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
+#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
+
+/*@} end of group CMSIS_SysTick */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM)
+ \brief Type definitions for the Instrumentation Trace Macrocell (ITM)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM).
+ */
+typedef struct
+{
+ __OM union
+ {
+ __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */
+ __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */
+ __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */
+ } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */
+ uint32_t RESERVED0[864U];
+ __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */
+ uint32_t RESERVED1[15U];
+ __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
+ uint32_t RESERVED2[15U];
+ __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
+ uint32_t RESERVED3[32U];
+ uint32_t RESERVED4[43U];
+ __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
+ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
+ uint32_t RESERVED5[6U];
+ __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */
+ __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */
+ __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */
+ __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */
+ __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */
+ __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */
+ __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */
+ __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */
+ __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */
+ __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */
+ __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */
+ __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */
+} ITM_Type;
+
+/* ITM Trace Privilege Register Definitions */
+#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
+#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
+
+/* ITM Trace Control Register Definitions */
+#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
+#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */
+
+#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */
+#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */
+
+#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */
+#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */
+
+#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */
+#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */
+
+#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */
+#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */
+
+#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */
+#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */
+
+#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */
+#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */
+
+#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */
+#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */
+
+#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
+#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
+
+/* ITM Lock Status Register Definitions */
+#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
+#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
+
+#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */
+#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */
+
+#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */
+#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */
+
+/*@}*/ /* end of group CMSIS_ITM */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT)
+ \brief Type definitions for the Data Watchpoint and Trace (DWT)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Data Watchpoint and Trace Register (DWT).
+ */
+typedef struct
+{
+ __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
+ __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
+ __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */
+ __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */
+ __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */
+ __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */
+ __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */
+ __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */
+ __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */
+ __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */
+ __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */
+ uint32_t RESERVED0[1U];
+ __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */
+ __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */
+ __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */
+ uint32_t RESERVED1[1U];
+ __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */
+ __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */
+ __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */
+ uint32_t RESERVED2[1U];
+ __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */
+ __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */
+ __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */
+} DWT_Type;
+
+/* DWT Control Register Definitions */
+#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */
+#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */
+
+#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */
+#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */
+
+#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */
+#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */
+
+#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */
+#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */
+
+#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */
+#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */
+
+#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */
+#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */
+
+#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */
+#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */
+
+#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */
+#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */
+
+#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */
+#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */
+
+#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */
+#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */
+
+#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */
+#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */
+
+#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */
+#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */
+
+#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */
+#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */
+
+#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */
+#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */
+
+#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */
+#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */
+
+#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */
+#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */
+
+#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */
+#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */
+
+#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */
+#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */
+
+/* DWT CPI Count Register Definitions */
+#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */
+#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */
+
+/* DWT Exception Overhead Count Register Definitions */
+#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */
+#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */
+
+/* DWT Sleep Count Register Definitions */
+#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */
+#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */
+
+/* DWT LSU Count Register Definitions */
+#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */
+#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */
+
+/* DWT Folded-instruction Count Register Definitions */
+#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */
+#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */
+
+/* DWT Comparator Mask Register Definitions */
+#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */
+#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */
+
+/* DWT Comparator Function Register Definitions */
+#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */
+#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */
+
+#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */
+#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */
+
+#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */
+#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */
+
+#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */
+#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */
+
+#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */
+#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */
+
+#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */
+#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */
+
+#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */
+#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */
+
+#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */
+#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */
+
+#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */
+#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */
+
+/*@}*/ /* end of group CMSIS_DWT */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_TPI Trace Port Interface (TPI)
+ \brief Type definitions for the Trace Port Interface (TPI)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Trace Port Interface Register (TPI).
+ */
+typedef struct
+{
+ __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
+ __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
+ uint32_t RESERVED0[2U];
+ __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
+ uint32_t RESERVED1[55U];
+ __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */
+ uint32_t RESERVED2[131U];
+ __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */
+ __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
+ __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
+ uint32_t RESERVED3[759U];
+ __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */
+ __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
+ __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
+ uint32_t RESERVED4[1U];
+ __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */
+ __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */
+ __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */
+ uint32_t RESERVED5[39U];
+ __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */
+ __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */
+ uint32_t RESERVED7[8U];
+ __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */
+ __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */
+} TPI_Type;
+
+/* TPI Asynchronous Clock Prescaler Register Definitions */
+#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */
+#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */
+
+/* TPI Selected Pin Protocol Register Definitions */
+#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */
+#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */
+
+/* TPI Formatter and Flush Status Register Definitions */
+#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */
+#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */
+
+#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */
+#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */
+
+#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */
+#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */
+
+#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */
+#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */
+
+/* TPI Formatter and Flush Control Register Definitions */
+#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */
+#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */
+
+#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */
+#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */
+
+/* TPI TRIGGER Register Definitions */
+#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */
+#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */
+
+/* TPI Integration ETM Data Register Definitions (FIFO0) */
+#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
+#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
+
+#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
+#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
+
+#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
+#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
+
+#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
+#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
+
+#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */
+#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */
+
+#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */
+#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */
+
+#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */
+#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
+
+/* TPI ITATBCTR2 Register Definitions */
+#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */
+#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */
+
+#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */
+#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */
+
+/* TPI Integration ITM Data Register Definitions (FIFO1) */
+#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
+#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
+
+#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
+#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
+
+#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
+#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
+
+#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
+#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
+
+#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */
+#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */
+
+#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */
+#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */
+
+#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */
+#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
+
+/* TPI ITATBCTR0 Register Definitions */
+#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */
+#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */
+
+#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */
+#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */
+
+/* TPI Integration Mode Control Register Definitions */
+#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
+#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
+
+/* TPI DEVID Register Definitions */
+#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
+#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */
+
+#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */
+#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */
+
+#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */
+#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */
+
+#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */
+#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */
+
+#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */
+#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */
+
+#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */
+#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
+
+/* TPI DEVTYPE Register Definitions */
+#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */
+#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
+
+#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */
+#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
+
+/*@}*/ /* end of group CMSIS_TPI */
+
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_MPU Memory Protection Unit (MPU)
+ \brief Type definitions for the Memory Protection Unit (MPU)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Memory Protection Unit (MPU).
+ */
+typedef struct
+{
+ __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
+ __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
+ __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
+ __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
+ __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */
+ __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */
+ __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */
+ __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
+} MPU_Type;
+
+#define MPU_TYPE_RALIASES 4U
+
+/* MPU Type Register Definitions */
+#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
+#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
+
+#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */
+#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
+
+#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */
+#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */
+
+/* MPU Control Register Definitions */
+#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */
+#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
+
+#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */
+#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
+
+#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */
+#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */
+
+/* MPU Region Number Register Definitions */
+#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */
+#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */
+
+/* MPU Region Base Address Register Definitions */
+#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */
+#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
+
+#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */
+#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
+
+#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */
+#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */
+
+/* MPU Region Attribute and Size Register Definitions */
+#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */
+#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
+
+#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */
+#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
+
+#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */
+#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
+
+#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */
+#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
+
+#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */
+#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
+
+#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */
+#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
+
+#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */
+#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
+
+#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */
+#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
+
+#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */
+#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
+
+#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */
+#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
+
+/*@} end of group CMSIS_MPU */
+#endif /* defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_FPU Floating Point Unit (FPU)
+ \brief Type definitions for the Floating Point Unit (FPU)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Floating Point Unit (FPU).
+ */
+typedef struct
+{
+ uint32_t RESERVED0[1U];
+ __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */
+ __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */
+ __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */
+ __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */
+ __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */
+ __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */
+} FPU_Type;
+
+/* Floating-Point Context Control Register Definitions */
+#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */
+#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */
+
+#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */
+#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */
+
+#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */
+#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */
+
+#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */
+#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */
+
+#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */
+#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */
+
+#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */
+#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */
+
+#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */
+#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */
+
+#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */
+#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */
+
+#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */
+#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */
+
+/* Floating-Point Context Address Register Definitions */
+#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */
+#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */
+
+/* Floating-Point Default Status Control Register Definitions */
+#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */
+#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */
+
+#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */
+#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */
+
+#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */
+#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */
+
+#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */
+#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */
+
+/* Media and FP Feature Register 0 Definitions */
+#define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */
+#define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */
+
+#define FPU_MVFR0_Short_vectors_Pos 24U /*!< MVFR0: Short vectors bits Position */
+#define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */
+
+#define FPU_MVFR0_Square_root_Pos 20U /*!< MVFR0: Square root bits Position */
+#define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */
+
+#define FPU_MVFR0_Divide_Pos 16U /*!< MVFR0: Divide bits Position */
+#define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */
+
+#define FPU_MVFR0_FP_excep_trapping_Pos 12U /*!< MVFR0: FP exception trapping bits Position */
+#define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */
+
+#define FPU_MVFR0_Double_precision_Pos 8U /*!< MVFR0: Double-precision bits Position */
+#define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */
+
+#define FPU_MVFR0_Single_precision_Pos 4U /*!< MVFR0: Single-precision bits Position */
+#define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */
+
+#define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */
+#define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */
+
+/* Media and FP Feature Register 1 Definitions */
+#define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */
+#define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */
+
+#define FPU_MVFR1_FP_HPFP_Pos 24U /*!< MVFR1: FP HPFP bits Position */
+#define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */
+
+#define FPU_MVFR1_D_NaN_mode_Pos 4U /*!< MVFR1: D_NaN mode bits Position */
+#define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */
+
+#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */
+#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */
+
+/* Media and FP Feature Register 2 Definitions */
+
+#define FPU_MVFR2_VFP_Misc_Pos 4U /*!< MVFR2: VFP Misc bits Position */
+#define FPU_MVFR2_VFP_Misc_Msk (0xFUL << FPU_MVFR2_VFP_Misc_Pos) /*!< MVFR2: VFP Misc bits Mask */
+
+/*@} end of group CMSIS_FPU */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
+ \brief Type definitions for the Core Debug Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the Core Debug Register (CoreDebug).
+ */
+typedef struct
+{
+ __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
+ __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
+ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
+ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
+} CoreDebug_Type;
+
+/* Debug Halting Control and Status Register Definitions */
+#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */
+#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */
+
+#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */
+#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */
+
+#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */
+#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */
+
+#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */
+#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */
+
+#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */
+#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */
+
+#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */
+#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */
+
+#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */
+#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */
+
+#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */
+#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */
+
+#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */
+#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */
+
+#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */
+#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */
+
+#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */
+#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */
+
+#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */
+#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */
+
+/* Debug Core Register Selector Register Definitions */
+#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */
+#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */
+
+#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */
+#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */
+
+/* Debug Exception and Monitor Control Register Definitions */
+#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */
+#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
+
+#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */
+#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */
+
+#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */
+#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */
+
+#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */
+#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */
+
+#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */
+#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */
+
+#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */
+#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */
+
+#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */
+#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */
+
+#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */
+#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */
+
+#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */
+#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */
+
+#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */
+#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */
+
+#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */
+#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */
+
+#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */
+#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */
+
+#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */
+#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */
+
+/*@} end of group CMSIS_CoreDebug */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_core_bitfield Core register bit field macros
+ \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
+ @{
+ */
+
+/**
+ \brief Mask and shift a bit field value for use in a register bit range.
+ \param[in] field Name of the register bit field.
+ \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
+ \return Masked and shifted value.
+*/
+#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
+
+/**
+ \brief Mask and shift a register value to extract a bit filed value.
+ \param[in] field Name of the register bit field.
+ \param[in] value Value of register. This parameter is interpreted as an uint32_t type.
+ \return Masked and shifted bit field value.
+*/
+#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
+
+/*@} end of group CMSIS_core_bitfield */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_core_base Core Definitions
+ \brief Definitions for base addresses, unions, and structures.
+ @{
+ */
+
+/* Memory mapping of Core Hardware */
+#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
+#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
+#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
+#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */
+#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
+#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
+#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
+#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
+
+#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
+#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
+#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
+#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
+#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */
+#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */
+#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
+#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+ #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
+ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
+#endif
+
+#define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */
+#define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */
+
+/*@} */
+
+
+
+/*******************************************************************************
+ * Hardware Abstraction Layer
+ Core Function Interface contains:
+ - Core NVIC Functions
+ - Core SysTick Functions
+ - Core Debug Functions
+ - Core Register Access Functions
+ ******************************************************************************/
+/**
+ \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
+*/
+
+
+
+/* ########################## NVIC functions #################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_NVICFunctions NVIC Functions
+ \brief Functions that manage interrupts and exceptions via the NVIC.
+ @{
+ */
+
+#ifdef CMSIS_NVIC_VIRTUAL
+ #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
+ #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
+ #endif
+ #include CMSIS_NVIC_VIRTUAL_HEADER_FILE
+#else
+ #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
+ #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
+ #define NVIC_EnableIRQ __NVIC_EnableIRQ
+ #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
+ #define NVIC_DisableIRQ __NVIC_DisableIRQ
+ #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
+ #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
+ #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
+ #define NVIC_GetActive __NVIC_GetActive
+ #define NVIC_SetPriority __NVIC_SetPriority
+ #define NVIC_GetPriority __NVIC_GetPriority
+ #define NVIC_SystemReset __NVIC_SystemReset
+#endif /* CMSIS_NVIC_VIRTUAL */
+
+#ifdef CMSIS_VECTAB_VIRTUAL
+ #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
+ #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
+ #endif
+ #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
+#else
+ #define NVIC_SetVector __NVIC_SetVector
+ #define NVIC_GetVector __NVIC_GetVector
+#endif /* (CMSIS_VECTAB_VIRTUAL) */
+
+#define NVIC_USER_IRQ_OFFSET 16
+
+
+/* The following EXC_RETURN values are saved the LR on exception entry */
+#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
+#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
+#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
+#define EXC_RETURN_HANDLER_FPU (0xFFFFFFE1UL) /* return to Handler mode, uses MSP after return, restore floating-point state */
+#define EXC_RETURN_THREAD_MSP_FPU (0xFFFFFFE9UL) /* return to Thread mode, uses MSP after return, restore floating-point state */
+#define EXC_RETURN_THREAD_PSP_FPU (0xFFFFFFEDUL) /* return to Thread mode, uses PSP after return, restore floating-point state */
+
+
+/**
+ \brief Set Priority Grouping
+ \details Sets the priority grouping field using the required unlock sequence.
+ The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
+ Only values from 0..7 are used.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
+ \param [in] PriorityGroup Priority grouping field.
+ */
+__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
+{
+ uint32_t reg_value;
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+
+ reg_value = SCB->AIRCR; /* read old register configuration */
+ reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
+ reg_value = (reg_value |
+ ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
+ (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */
+ SCB->AIRCR = reg_value;
+}
+
+
+/**
+ \brief Get Priority Grouping
+ \details Reads the priority grouping field from the NVIC Interrupt Controller.
+ \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void)
+{
+ return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
+}
+
+
+/**
+ \brief Enable Interrupt
+ \details Enables a device specific interrupt in the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ __COMPILER_BARRIER();
+ NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ __COMPILER_BARRIER();
+ }
+}
+
+
+/**
+ \brief Get Interrupt Enable status
+ \details Returns a device specific interrupt enable status from the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt is not enabled.
+ \return 1 Interrupt is enabled.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Disable Interrupt
+ \details Disables a device specific interrupt in the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ __DSB();
+ __ISB();
+ }
+}
+
+
+/**
+ \brief Get Pending Interrupt
+ \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt status is not pending.
+ \return 1 Interrupt status is pending.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Set Pending Interrupt
+ \details Sets the pending bit of a device specific interrupt in the NVIC pending register.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ }
+}
+
+
+/**
+ \brief Clear Pending Interrupt
+ \details Clears the pending bit of a device specific interrupt in the NVIC pending register.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ }
+}
+
+
+/**
+ \brief Get Active Interrupt
+ \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt status is not active.
+ \return 1 Interrupt status is active.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Set Interrupt Priority
+ \details Sets the priority of a device specific interrupt or a processor exception.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \param [in] priority Priority to set.
+ \note The priority cannot be set for every processor exception.
+ */
+__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
+ }
+ else
+ {
+ SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
+ }
+}
+
+
+/**
+ \brief Get Interrupt Priority
+ \details Reads the priority of a device specific interrupt or a processor exception.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \return Interrupt Priority.
+ Value is aligned automatically to the implemented priority bits of the microcontroller.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
+{
+
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
+ }
+ else
+ {
+ return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
+ }
+}
+
+
+/**
+ \brief Encode Priority
+ \details Encodes the priority for an interrupt with the given priority group,
+ preemptive priority value, and subpriority value.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
+ \param [in] PriorityGroup Used priority group.
+ \param [in] PreemptPriority Preemptive priority value (starting from 0).
+ \param [in] SubPriority Subpriority value (starting from 0).
+ \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
+ */
+__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
+{
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+ uint32_t PreemptPriorityBits;
+ uint32_t SubPriorityBits;
+
+ PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
+ SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
+
+ return (
+ ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
+ ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
+ );
+}
+
+
+/**
+ \brief Decode Priority
+ \details Decodes an interrupt priority value with a given priority group to
+ preemptive priority value and subpriority value.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
+ \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
+ \param [in] PriorityGroup Used priority group.
+ \param [out] pPreemptPriority Preemptive priority value (starting from 0).
+ \param [out] pSubPriority Subpriority value (starting from 0).
+ */
+__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
+{
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+ uint32_t PreemptPriorityBits;
+ uint32_t SubPriorityBits;
+
+ PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
+ SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
+
+ *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
+ *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
+}
+
+
+/**
+ \brief Set Interrupt Vector
+ \details Sets an interrupt vector in SRAM based interrupt vector table.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ VTOR must been relocated to SRAM before.
+ \param [in] IRQn Interrupt number
+ \param [in] vector Address of interrupt handler function
+ */
+__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
+{
+ uint32_t *vectors = (uint32_t *)SCB->VTOR;
+ vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
+ /* ARM Application Note 321 states that the M4 does not require the architectural barrier */
+}
+
+
+/**
+ \brief Get Interrupt Vector
+ \details Reads an interrupt vector from interrupt vector table.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \return Address of interrupt handler function
+ */
+__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
+{
+ uint32_t *vectors = (uint32_t *)SCB->VTOR;
+ return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
+}
+
+
+/**
+ \brief System Reset
+ \details Initiates a system reset request to reset the MCU.
+ */
+__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
+{
+ __DSB(); /* Ensure all outstanding memory accesses included
+ buffered write are completed before reset */
+ SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
+ (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
+ SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */
+ __DSB(); /* Ensure completion of memory access */
+
+ for(;;) /* wait until reset */
+ {
+ __NOP();
+ }
+}
+
+/*@} end of CMSIS_Core_NVICFunctions */
+
+
+/* ########################## MPU functions #################################### */
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+
+#include "mpu_armv7.h"
+
+#endif
+
+
+/* ########################## FPU functions #################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_FpuFunctions FPU Functions
+ \brief Function that provides FPU type.
+ @{
+ */
+
+/**
+ \brief get FPU type
+ \details returns the FPU type
+ \returns
+ - \b 0: No FPU
+ - \b 1: Single precision FPU
+ - \b 2: Double + Single precision FPU
+ */
+__STATIC_INLINE uint32_t SCB_GetFPUType(void)
+{
+ uint32_t mvfr0;
+
+ mvfr0 = FPU->MVFR0;
+ if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U)
+ {
+ return 1U; /* Single precision FPU */
+ }
+ else
+ {
+ return 0U; /* No FPU */
+ }
+}
+
+
+/*@} end of CMSIS_Core_FpuFunctions */
+
+
+
+/* ################################## SysTick function ############################################ */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
+ \brief Functions that configure the System.
+ @{
+ */
+
+#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
+
+/**
+ \brief System Tick Configuration
+ \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
+ Counter is in free running mode to generate periodic interrupts.
+ \param [in] ticks Number of ticks between two interrupts.
+ \return 0 Function succeeded.
+ \return 1 Function failed.
+ \note When the variable __Vendor_SysTickConfig is set to 1, then the
+ function SysTick_Config is not included. In this case, the file device .h
+ must contain a vendor-specific implementation of this function.
+ */
+__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
+{
+ if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
+ {
+ return (1UL); /* Reload value impossible */
+ }
+
+ SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
+ NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
+ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
+ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
+ SysTick_CTRL_TICKINT_Msk |
+ SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
+ return (0UL); /* Function successful */
+}
+
+#endif
+
+/*@} end of CMSIS_Core_SysTickFunctions */
+
+
+
+/* ##################################### Debug In/Output function ########################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_core_DebugFunctions ITM Functions
+ \brief Functions that access the ITM debug interface.
+ @{
+ */
+
+extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
+#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
+
+
+/**
+ \brief ITM Send Character
+ \details Transmits a character via the ITM channel 0, and
+ \li Just returns when no debugger is connected that has booked the output.
+ \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
+ \param [in] ch Character to transmit.
+ \returns Character to transmit.
+ */
+__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
+{
+ if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
+ ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */
+ {
+ while (ITM->PORT[0U].u32 == 0UL)
+ {
+ __NOP();
+ }
+ ITM->PORT[0U].u8 = (uint8_t)ch;
+ }
+ return (ch);
+}
+
+
+/**
+ \brief ITM Receive Character
+ \details Inputs a character via the external variable \ref ITM_RxBuffer.
+ \return Received character.
+ \return -1 No character pending.
+ */
+__STATIC_INLINE int32_t ITM_ReceiveChar (void)
+{
+ int32_t ch = -1; /* no character available */
+
+ if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY)
+ {
+ ch = ITM_RxBuffer;
+ ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
+ }
+
+ return (ch);
+}
+
+
+/**
+ \brief ITM Check Character
+ \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer.
+ \return 0 No character available.
+ \return 1 Character available.
+ */
+__STATIC_INLINE int32_t ITM_CheckChar (void)
+{
+
+ if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY)
+ {
+ return (0); /* no character available */
+ }
+ else
+ {
+ return (1); /* character available */
+ }
+}
+
+/*@} end of CMSIS_core_DebugFunctions */
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_CM4_H_DEPENDANT */
+
+#endif /* __CMSIS_GENERIC */
diff --git a/CMSIS/Core/Include/core_cm7.h b/CMSIS/Core/Include/core_cm7.h
new file mode 100644
index 0000000..010506e
--- /dev/null
+++ b/CMSIS/Core/Include/core_cm7.h
@@ -0,0 +1,2366 @@
+/**************************************************************************//**
+ * @file core_cm7.h
+ * @brief CMSIS Cortex-M7 Core Peripheral Access Layer Header File
+ * @version V5.1.6
+ * @date 04. June 2021
+ ******************************************************************************/
+/*
+ * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef __CORE_CM7_H_GENERIC
+#define __CORE_CM7_H_GENERIC
+
+#include
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/**
+ \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
+ CMSIS violates the following MISRA-C:2004 rules:
+
+ \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'.
+
+ \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers.
+
+ \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code.
+ */
+
+
+/*******************************************************************************
+ * CMSIS definitions
+ ******************************************************************************/
+/**
+ \ingroup Cortex_M7
+ @{
+ */
+
+#include "cmsis_version.h"
+
+/* CMSIS CM7 definitions */
+#define __CM7_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
+#define __CM7_CMSIS_VERSION_SUB ( __CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
+#define __CM7_CMSIS_VERSION ((__CM7_CMSIS_VERSION_MAIN << 16U) | \
+ __CM7_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
+
+#define __CORTEX_M (7U) /*!< Cortex-M Core */
+
+/** __FPU_USED indicates whether an FPU is used or not.
+ For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions.
+*/
+#if defined ( __CC_ARM )
+ #if defined __TARGET_FPU_VFP
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
+ #if defined __ARM_FP
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __GNUC__ )
+ #if defined (__VFP_FP__) && !defined(__SOFTFP__)
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __ICCARM__ )
+ #if defined __ARMVFP__
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __TI_ARM__ )
+ #if defined __TI_VFP_SUPPORT__
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __TASKING__ )
+ #if defined __FPU_VFP__
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#elif defined ( __CSMC__ )
+ #if ( __CSMC__ & 0x400U)
+ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
+ #define __FPU_USED 1U
+ #else
+ #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+ #define __FPU_USED 0U
+ #endif
+ #else
+ #define __FPU_USED 0U
+ #endif
+
+#endif
+
+#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_CM7_H_GENERIC */
+
+#ifndef __CMSIS_GENERIC
+
+#ifndef __CORE_CM7_H_DEPENDANT
+#define __CORE_CM7_H_DEPENDANT
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* check device defines and use defaults */
+#if defined __CHECK_DEVICE_DEFINES
+ #ifndef __CM7_REV
+ #define __CM7_REV 0x0000U
+ #warning "__CM7_REV not defined in device header file; using default!"
+ #endif
+
+ #ifndef __FPU_PRESENT
+ #define __FPU_PRESENT 0U
+ #warning "__FPU_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __MPU_PRESENT
+ #define __MPU_PRESENT 0U
+ #warning "__MPU_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __ICACHE_PRESENT
+ #define __ICACHE_PRESENT 0U
+ #warning "__ICACHE_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __DCACHE_PRESENT
+ #define __DCACHE_PRESENT 0U
+ #warning "__DCACHE_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __DTCM_PRESENT
+ #define __DTCM_PRESENT 0U
+ #warning "__DTCM_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __VTOR_PRESENT
+ #define __VTOR_PRESENT 1U
+ #warning "__VTOR_PRESENT not defined in device header file; using default!"
+ #endif
+
+ #ifndef __NVIC_PRIO_BITS
+ #define __NVIC_PRIO_BITS 3U
+ #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
+ #endif
+
+ #ifndef __Vendor_SysTickConfig
+ #define __Vendor_SysTickConfig 0U
+ #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
+ #endif
+#endif
+
+/* IO definitions (access restrictions to peripheral registers) */
+/**
+ \defgroup CMSIS_glob_defs CMSIS Global Defines
+
+ IO Type Qualifiers are used
+ \li to specify the access to peripheral variables.
+ \li for automatic generation of peripheral register debug information.
+*/
+#ifdef __cplusplus
+ #define __I volatile /*!< Defines 'read only' permissions */
+#else
+ #define __I volatile const /*!< Defines 'read only' permissions */
+#endif
+#define __O volatile /*!< Defines 'write only' permissions */
+#define __IO volatile /*!< Defines 'read / write' permissions */
+
+/* following defines should be used for structure members */
+#define __IM volatile const /*! Defines 'read only' structure member permissions */
+#define __OM volatile /*! Defines 'write only' structure member permissions */
+#define __IOM volatile /*! Defines 'read / write' structure member permissions */
+
+/*@} end of group Cortex_M7 */
+
+
+
+/*******************************************************************************
+ * Register Abstraction
+ Core Register contain:
+ - Core Register
+ - Core NVIC Register
+ - Core SCB Register
+ - Core SysTick Register
+ - Core Debug Register
+ - Core MPU Register
+ - Core FPU Register
+ ******************************************************************************/
+/**
+ \defgroup CMSIS_core_register Defines and Type Definitions
+ \brief Type definitions and defines for Cortex-M processor based devices.
+*/
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_CORE Status and Control Registers
+ \brief Core Register type definitions.
+ @{
+ */
+
+/**
+ \brief Union type to access the Application Program Status Register (APSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
+ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
+ uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
+ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
+ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
+ uint32_t C:1; /*!< bit: 29 Carry condition code flag */
+ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
+ uint32_t N:1; /*!< bit: 31 Negative condition code flag */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} APSR_Type;
+
+/* APSR Register Definitions */
+#define APSR_N_Pos 31U /*!< APSR: N Position */
+#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
+
+#define APSR_Z_Pos 30U /*!< APSR: Z Position */
+#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
+
+#define APSR_C_Pos 29U /*!< APSR: C Position */
+#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
+
+#define APSR_V_Pos 28U /*!< APSR: V Position */
+#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
+
+#define APSR_Q_Pos 27U /*!< APSR: Q Position */
+#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */
+
+#define APSR_GE_Pos 16U /*!< APSR: GE Position */
+#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE Mask */
+
+
+/**
+ \brief Union type to access the Interrupt Program Status Register (IPSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
+ uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} IPSR_Type;
+
+/* IPSR Register Definitions */
+#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
+#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
+
+
+/**
+ \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
+ uint32_t _reserved0:1; /*!< bit: 9 Reserved */
+ uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */
+ uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
+ uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
+ uint32_t T:1; /*!< bit: 24 Thumb bit */
+ uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */
+ uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
+ uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
+ uint32_t C:1; /*!< bit: 29 Carry condition code flag */
+ uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
+ uint32_t N:1; /*!< bit: 31 Negative condition code flag */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} xPSR_Type;
+
+/* xPSR Register Definitions */
+#define xPSR_N_Pos 31U /*!< xPSR: N Position */
+#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
+
+#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
+#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
+
+#define xPSR_C_Pos 29U /*!< xPSR: C Position */
+#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
+
+#define xPSR_V_Pos 28U /*!< xPSR: V Position */
+#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
+
+#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
+#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
+
+#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */
+#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */
+
+#define xPSR_T_Pos 24U /*!< xPSR: T Position */
+#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
+
+#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */
+#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */
+
+#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */
+#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */
+
+#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
+#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
+
+
+/**
+ \brief Union type to access the Control Registers (CONTROL).
+ */
+typedef union
+{
+ struct
+ {
+ uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
+ uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
+ uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
+ uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
+ } b; /*!< Structure used for bit access */
+ uint32_t w; /*!< Type used for word access */
+} CONTROL_Type;
+
+/* CONTROL Register Definitions */
+#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */
+#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */
+
+#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
+#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
+
+#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */
+#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */
+
+/*@} end of group CMSIS_CORE */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
+ \brief Type definitions for the NVIC Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
+ */
+typedef struct
+{
+ __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
+ uint32_t RESERVED0[24U];
+ __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
+ uint32_t RESERVED1[24U];
+ __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
+ uint32_t RESERVED2[24U];
+ __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
+ uint32_t RESERVED3[24U];
+ __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
+ uint32_t RESERVED4[56U];
+ __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
+ uint32_t RESERVED5[644U];
+ __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
+} NVIC_Type;
+
+/* Software Triggered Interrupt Register Definitions */
+#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */
+#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */
+
+/*@} end of group CMSIS_NVIC */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SCB System Control Block (SCB)
+ \brief Type definitions for the System Control Block Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Control Block (SCB).
+ */
+typedef struct
+{
+ __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
+ __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
+ __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
+ __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
+ __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
+ __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
+ __IOM uint8_t SHPR[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
+ __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
+ __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
+ __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
+ __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
+ __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
+ __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
+ __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
+ __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
+ __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
+ __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
+ __IM uint32_t ID_MFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
+ __IM uint32_t ID_ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
+ uint32_t RESERVED0[1U];
+ __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */
+ __IM uint32_t CTR; /*!< Offset: 0x07C (R/ ) Cache Type register */
+ __IM uint32_t CCSIDR; /*!< Offset: 0x080 (R/ ) Cache Size ID Register */
+ __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */
+ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
+ uint32_t RESERVED3[93U];
+ __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */
+ uint32_t RESERVED4[15U];
+ __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */
+ __IM uint32_t MVFR1; /*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 */
+ __IM uint32_t MVFR2; /*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 2 */
+ uint32_t RESERVED5[1U];
+ __OM uint32_t ICIALLU; /*!< Offset: 0x250 ( /W) I-Cache Invalidate All to PoU */
+ uint32_t RESERVED6[1U];
+ __OM uint32_t ICIMVAU; /*!< Offset: 0x258 ( /W) I-Cache Invalidate by MVA to PoU */
+ __OM uint32_t DCIMVAC; /*!< Offset: 0x25C ( /W) D-Cache Invalidate by MVA to PoC */
+ __OM uint32_t DCISW; /*!< Offset: 0x260 ( /W) D-Cache Invalidate by Set-way */
+ __OM uint32_t DCCMVAU; /*!< Offset: 0x264 ( /W) D-Cache Clean by MVA to PoU */
+ __OM uint32_t DCCMVAC; /*!< Offset: 0x268 ( /W) D-Cache Clean by MVA to PoC */
+ __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */
+ __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */
+ __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */
+ __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */
+ uint32_t RESERVED7[5U];
+ __IOM uint32_t ITCMCR; /*!< Offset: 0x290 (R/W) Instruction Tightly-Coupled Memory Control Register */
+ __IOM uint32_t DTCMCR; /*!< Offset: 0x294 (R/W) Data Tightly-Coupled Memory Control Registers */
+ __IOM uint32_t AHBPCR; /*!< Offset: 0x298 (R/W) AHBP Control Register */
+ __IOM uint32_t CACR; /*!< Offset: 0x29C (R/W) L1 Cache Control Register */
+ __IOM uint32_t AHBSCR; /*!< Offset: 0x2A0 (R/W) AHB Slave Control Register */
+ uint32_t RESERVED8[1U];
+ __IOM uint32_t ABFSR; /*!< Offset: 0x2A8 (R/W) Auxiliary Bus Fault Status Register */
+} SCB_Type;
+
+/* SCB CPUID Register Definitions */
+#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
+#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
+
+#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
+#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
+
+#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
+#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
+
+#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
+#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
+
+#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
+#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
+
+/* SCB Interrupt Control State Register Definitions */
+#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
+#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
+
+#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
+#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
+
+#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
+#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
+
+#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
+#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
+
+#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
+#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
+
+#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
+#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
+
+#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
+#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
+
+#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
+#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
+
+#define SCB_ICSR_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */
+#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */
+
+#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
+#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
+
+/* SCB Vector Table Offset Register Definitions */
+#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */
+#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
+
+/* SCB Application Interrupt and Reset Control Register Definitions */
+#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
+#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
+
+#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
+#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
+
+#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
+#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
+
+#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */
+#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
+
+#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
+#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
+
+#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
+#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
+
+#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */
+#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET Mask */
+
+/* SCB System Control Register Definitions */
+#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
+#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
+
+#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
+#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
+
+#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
+#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
+
+/* SCB Configuration Control Register Definitions */
+#define SCB_CCR_BP_Pos 18U /*!< SCB CCR: Branch prediction enable bit Position */
+#define SCB_CCR_BP_Msk (1UL << SCB_CCR_BP_Pos) /*!< SCB CCR: Branch prediction enable bit Mask */
+
+#define SCB_CCR_IC_Pos 17U /*!< SCB CCR: Instruction cache enable bit Position */
+#define SCB_CCR_IC_Msk (1UL << SCB_CCR_IC_Pos) /*!< SCB CCR: Instruction cache enable bit Mask */
+
+#define SCB_CCR_DC_Pos 16U /*!< SCB CCR: Cache enable bit Position */
+#define SCB_CCR_DC_Msk (1UL << SCB_CCR_DC_Pos) /*!< SCB CCR: Cache enable bit Mask */
+
+#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
+#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
+
+#define SCB_CCR_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */
+#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */
+
+#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */
+#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */
+
+#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
+#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
+
+#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */
+#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */
+
+#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */
+#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */
+
+/* SCB System Handler Control and State Register Definitions */
+#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */
+#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
+
+#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */
+#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
+
+#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */
+#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
+
+#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
+#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
+
+#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */
+#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
+
+#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */
+#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
+
+#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */
+#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
+
+#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */
+#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
+
+#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */
+#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
+
+#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */
+#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
+
+#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */
+#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
+
+#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */
+#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
+
+#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */
+#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
+
+#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */
+#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */
+
+/* SCB Configurable Fault Status Register Definitions */
+#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */
+#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */
+
+#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */
+#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */
+
+#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
+#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
+
+/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */
+#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */
+
+#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */
+#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */
+
+#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */
+#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */
+
+#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */
+#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */
+
+#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */
+#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */
+
+#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */
+#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */
+
+/* BusFault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */
+#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */
+
+#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */
+#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */
+
+#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */
+#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */
+
+#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */
+#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */
+
+#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */
+#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */
+
+#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */
+#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */
+
+#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */
+#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */
+
+/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */
+#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */
+#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */
+
+#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */
+#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */
+
+#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */
+#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */
+
+#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */
+#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */
+
+#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */
+#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */
+
+#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */
+#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */
+
+/* SCB Hard Fault Status Register Definitions */
+#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
+#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
+
+#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */
+#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */
+
+#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */
+#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */
+
+/* SCB Debug Fault Status Register Definitions */
+#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */
+#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */
+
+#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */
+#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */
+
+#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */
+#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */
+
+#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */
+#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */
+
+#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */
+#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */
+
+/* SCB Cache Level ID Register Definitions */
+#define SCB_CLIDR_LOUU_Pos 27U /*!< SCB CLIDR: LoUU Position */
+#define SCB_CLIDR_LOUU_Msk (7UL << SCB_CLIDR_LOUU_Pos) /*!< SCB CLIDR: LoUU Mask */
+
+#define SCB_CLIDR_LOC_Pos 24U /*!< SCB CLIDR: LoC Position */
+#define SCB_CLIDR_LOC_Msk (7UL << SCB_CLIDR_LOC_Pos) /*!< SCB CLIDR: LoC Mask */
+
+/* SCB Cache Type Register Definitions */
+#define SCB_CTR_FORMAT_Pos 29U /*!< SCB CTR: Format Position */
+#define SCB_CTR_FORMAT_Msk (7UL << SCB_CTR_FORMAT_Pos) /*!< SCB CTR: Format Mask */
+
+#define SCB_CTR_CWG_Pos 24U /*!< SCB CTR: CWG Position */
+#define SCB_CTR_CWG_Msk (0xFUL << SCB_CTR_CWG_Pos) /*!< SCB CTR: CWG Mask */
+
+#define SCB_CTR_ERG_Pos 20U /*!< SCB CTR: ERG Position */
+#define SCB_CTR_ERG_Msk (0xFUL << SCB_CTR_ERG_Pos) /*!< SCB CTR: ERG Mask */
+
+#define SCB_CTR_DMINLINE_Pos 16U /*!< SCB CTR: DminLine Position */
+#define SCB_CTR_DMINLINE_Msk (0xFUL << SCB_CTR_DMINLINE_Pos) /*!< SCB CTR: DminLine Mask */
+
+#define SCB_CTR_IMINLINE_Pos 0U /*!< SCB CTR: ImInLine Position */
+#define SCB_CTR_IMINLINE_Msk (0xFUL /*<< SCB_CTR_IMINLINE_Pos*/) /*!< SCB CTR: ImInLine Mask */
+
+/* SCB Cache Size ID Register Definitions */
+#define SCB_CCSIDR_WT_Pos 31U /*!< SCB CCSIDR: WT Position */
+#define SCB_CCSIDR_WT_Msk (1UL << SCB_CCSIDR_WT_Pos) /*!< SCB CCSIDR: WT Mask */
+
+#define SCB_CCSIDR_WB_Pos 30U /*!< SCB CCSIDR: WB Position */
+#define SCB_CCSIDR_WB_Msk (1UL << SCB_CCSIDR_WB_Pos) /*!< SCB CCSIDR: WB Mask */
+
+#define SCB_CCSIDR_RA_Pos 29U /*!< SCB CCSIDR: RA Position */
+#define SCB_CCSIDR_RA_Msk (1UL << SCB_CCSIDR_RA_Pos) /*!< SCB CCSIDR: RA Mask */
+
+#define SCB_CCSIDR_WA_Pos 28U /*!< SCB CCSIDR: WA Position */
+#define SCB_CCSIDR_WA_Msk (1UL << SCB_CCSIDR_WA_Pos) /*!< SCB CCSIDR: WA Mask */
+
+#define SCB_CCSIDR_NUMSETS_Pos 13U /*!< SCB CCSIDR: NumSets Position */
+#define SCB_CCSIDR_NUMSETS_Msk (0x7FFFUL << SCB_CCSIDR_NUMSETS_Pos) /*!< SCB CCSIDR: NumSets Mask */
+
+#define SCB_CCSIDR_ASSOCIATIVITY_Pos 3U /*!< SCB CCSIDR: Associativity Position */
+#define SCB_CCSIDR_ASSOCIATIVITY_Msk (0x3FFUL << SCB_CCSIDR_ASSOCIATIVITY_Pos) /*!< SCB CCSIDR: Associativity Mask */
+
+#define SCB_CCSIDR_LINESIZE_Pos 0U /*!< SCB CCSIDR: LineSize Position */
+#define SCB_CCSIDR_LINESIZE_Msk (7UL /*<< SCB_CCSIDR_LINESIZE_Pos*/) /*!< SCB CCSIDR: LineSize Mask */
+
+/* SCB Cache Size Selection Register Definitions */
+#define SCB_CSSELR_LEVEL_Pos 1U /*!< SCB CSSELR: Level Position */
+#define SCB_CSSELR_LEVEL_Msk (7UL << SCB_CSSELR_LEVEL_Pos) /*!< SCB CSSELR: Level Mask */
+
+#define SCB_CSSELR_IND_Pos 0U /*!< SCB CSSELR: InD Position */
+#define SCB_CSSELR_IND_Msk (1UL /*<< SCB_CSSELR_IND_Pos*/) /*!< SCB CSSELR: InD Mask */
+
+/* SCB Software Triggered Interrupt Register Definitions */
+#define SCB_STIR_INTID_Pos 0U /*!< SCB STIR: INTID Position */
+#define SCB_STIR_INTID_Msk (0x1FFUL /*<< SCB_STIR_INTID_Pos*/) /*!< SCB STIR: INTID Mask */
+
+/* SCB D-Cache Invalidate by Set-way Register Definitions */
+#define SCB_DCISW_WAY_Pos 30U /*!< SCB DCISW: Way Position */
+#define SCB_DCISW_WAY_Msk (3UL << SCB_DCISW_WAY_Pos) /*!< SCB DCISW: Way Mask */
+
+#define SCB_DCISW_SET_Pos 5U /*!< SCB DCISW: Set Position */
+#define SCB_DCISW_SET_Msk (0x1FFUL << SCB_DCISW_SET_Pos) /*!< SCB DCISW: Set Mask */
+
+/* SCB D-Cache Clean by Set-way Register Definitions */
+#define SCB_DCCSW_WAY_Pos 30U /*!< SCB DCCSW: Way Position */
+#define SCB_DCCSW_WAY_Msk (3UL << SCB_DCCSW_WAY_Pos) /*!< SCB DCCSW: Way Mask */
+
+#define SCB_DCCSW_SET_Pos 5U /*!< SCB DCCSW: Set Position */
+#define SCB_DCCSW_SET_Msk (0x1FFUL << SCB_DCCSW_SET_Pos) /*!< SCB DCCSW: Set Mask */
+
+/* SCB D-Cache Clean and Invalidate by Set-way Register Definitions */
+#define SCB_DCCISW_WAY_Pos 30U /*!< SCB DCCISW: Way Position */
+#define SCB_DCCISW_WAY_Msk (3UL << SCB_DCCISW_WAY_Pos) /*!< SCB DCCISW: Way Mask */
+
+#define SCB_DCCISW_SET_Pos 5U /*!< SCB DCCISW: Set Position */
+#define SCB_DCCISW_SET_Msk (0x1FFUL << SCB_DCCISW_SET_Pos) /*!< SCB DCCISW: Set Mask */
+
+/* Instruction Tightly-Coupled Memory Control Register Definitions */
+#define SCB_ITCMCR_SZ_Pos 3U /*!< SCB ITCMCR: SZ Position */
+#define SCB_ITCMCR_SZ_Msk (0xFUL << SCB_ITCMCR_SZ_Pos) /*!< SCB ITCMCR: SZ Mask */
+
+#define SCB_ITCMCR_RETEN_Pos 2U /*!< SCB ITCMCR: RETEN Position */
+#define SCB_ITCMCR_RETEN_Msk (1UL << SCB_ITCMCR_RETEN_Pos) /*!< SCB ITCMCR: RETEN Mask */
+
+#define SCB_ITCMCR_RMW_Pos 1U /*!< SCB ITCMCR: RMW Position */
+#define SCB_ITCMCR_RMW_Msk (1UL << SCB_ITCMCR_RMW_Pos) /*!< SCB ITCMCR: RMW Mask */
+
+#define SCB_ITCMCR_EN_Pos 0U /*!< SCB ITCMCR: EN Position */
+#define SCB_ITCMCR_EN_Msk (1UL /*<< SCB_ITCMCR_EN_Pos*/) /*!< SCB ITCMCR: EN Mask */
+
+/* Data Tightly-Coupled Memory Control Register Definitions */
+#define SCB_DTCMCR_SZ_Pos 3U /*!< SCB DTCMCR: SZ Position */
+#define SCB_DTCMCR_SZ_Msk (0xFUL << SCB_DTCMCR_SZ_Pos) /*!< SCB DTCMCR: SZ Mask */
+
+#define SCB_DTCMCR_RETEN_Pos 2U /*!< SCB DTCMCR: RETEN Position */
+#define SCB_DTCMCR_RETEN_Msk (1UL << SCB_DTCMCR_RETEN_Pos) /*!< SCB DTCMCR: RETEN Mask */
+
+#define SCB_DTCMCR_RMW_Pos 1U /*!< SCB DTCMCR: RMW Position */
+#define SCB_DTCMCR_RMW_Msk (1UL << SCB_DTCMCR_RMW_Pos) /*!< SCB DTCMCR: RMW Mask */
+
+#define SCB_DTCMCR_EN_Pos 0U /*!< SCB DTCMCR: EN Position */
+#define SCB_DTCMCR_EN_Msk (1UL /*<< SCB_DTCMCR_EN_Pos*/) /*!< SCB DTCMCR: EN Mask */
+
+/* AHBP Control Register Definitions */
+#define SCB_AHBPCR_SZ_Pos 1U /*!< SCB AHBPCR: SZ Position */
+#define SCB_AHBPCR_SZ_Msk (7UL << SCB_AHBPCR_SZ_Pos) /*!< SCB AHBPCR: SZ Mask */
+
+#define SCB_AHBPCR_EN_Pos 0U /*!< SCB AHBPCR: EN Position */
+#define SCB_AHBPCR_EN_Msk (1UL /*<< SCB_AHBPCR_EN_Pos*/) /*!< SCB AHBPCR: EN Mask */
+
+/* L1 Cache Control Register Definitions */
+#define SCB_CACR_FORCEWT_Pos 2U /*!< SCB CACR: FORCEWT Position */
+#define SCB_CACR_FORCEWT_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: FORCEWT Mask */
+
+#define SCB_CACR_ECCEN_Pos 1U /*!< \deprecated SCB CACR: ECCEN Position */
+#define SCB_CACR_ECCEN_Msk (1UL << SCB_CACR_ECCEN_Pos) /*!< \deprecated SCB CACR: ECCEN Mask */
+
+#define SCB_CACR_ECCDIS_Pos 1U /*!< SCB CACR: ECCDIS Position */
+#define SCB_CACR_ECCDIS_Msk (1UL << SCB_CACR_ECCDIS_Pos) /*!< SCB CACR: ECCDIS Mask */
+
+#define SCB_CACR_SIWT_Pos 0U /*!< SCB CACR: SIWT Position */
+#define SCB_CACR_SIWT_Msk (1UL /*<< SCB_CACR_SIWT_Pos*/) /*!< SCB CACR: SIWT Mask */
+
+/* AHBS Control Register Definitions */
+#define SCB_AHBSCR_INITCOUNT_Pos 11U /*!< SCB AHBSCR: INITCOUNT Position */
+#define SCB_AHBSCR_INITCOUNT_Msk (0x1FUL << SCB_AHBSCR_INITCOUNT_Pos) /*!< SCB AHBSCR: INITCOUNT Mask */
+
+#define SCB_AHBSCR_TPRI_Pos 2U /*!< SCB AHBSCR: TPRI Position */
+#define SCB_AHBSCR_TPRI_Msk (0x1FFUL << SCB_AHBSCR_TPRI_Pos) /*!< SCB AHBSCR: TPRI Mask */
+
+#define SCB_AHBSCR_CTL_Pos 0U /*!< SCB AHBSCR: CTL Position*/
+#define SCB_AHBSCR_CTL_Msk (3UL /*<< SCB_AHBSCR_CTL_Pos*/) /*!< SCB AHBSCR: CTL Mask */
+
+/* Auxiliary Bus Fault Status Register Definitions */
+#define SCB_ABFSR_AXIMTYPE_Pos 8U /*!< SCB ABFSR: AXIMTYPE Position*/
+#define SCB_ABFSR_AXIMTYPE_Msk (3UL << SCB_ABFSR_AXIMTYPE_Pos) /*!< SCB ABFSR: AXIMTYPE Mask */
+
+#define SCB_ABFSR_EPPB_Pos 4U /*!< SCB ABFSR: EPPB Position*/
+#define SCB_ABFSR_EPPB_Msk (1UL << SCB_ABFSR_EPPB_Pos) /*!< SCB ABFSR: EPPB Mask */
+
+#define SCB_ABFSR_AXIM_Pos 3U /*!< SCB ABFSR: AXIM Position*/
+#define SCB_ABFSR_AXIM_Msk (1UL << SCB_ABFSR_AXIM_Pos) /*!< SCB ABFSR: AXIM Mask */
+
+#define SCB_ABFSR_AHBP_Pos 2U /*!< SCB ABFSR: AHBP Position*/
+#define SCB_ABFSR_AHBP_Msk (1UL << SCB_ABFSR_AHBP_Pos) /*!< SCB ABFSR: AHBP Mask */
+
+#define SCB_ABFSR_DTCM_Pos 1U /*!< SCB ABFSR: DTCM Position*/
+#define SCB_ABFSR_DTCM_Msk (1UL << SCB_ABFSR_DTCM_Pos) /*!< SCB ABFSR: DTCM Mask */
+
+#define SCB_ABFSR_ITCM_Pos 0U /*!< SCB ABFSR: ITCM Position*/
+#define SCB_ABFSR_ITCM_Msk (1UL /*<< SCB_ABFSR_ITCM_Pos*/) /*!< SCB ABFSR: ITCM Mask */
+
+/*@} end of group CMSIS_SCB */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
+ \brief Type definitions for the System Control and ID Register not in the SCB
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Control and ID Register not in the SCB.
+ */
+typedef struct
+{
+ uint32_t RESERVED0[1U];
+ __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
+ __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
+} SCnSCB_Type;
+
+/* Interrupt Controller Type Register Definitions */
+#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */
+#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */
+
+/* Auxiliary Control Register Definitions */
+#define SCnSCB_ACTLR_DISDYNADD_Pos 26U /*!< ACTLR: DISDYNADD Position */
+#define SCnSCB_ACTLR_DISDYNADD_Msk (1UL << SCnSCB_ACTLR_DISDYNADD_Pos) /*!< ACTLR: DISDYNADD Mask */
+
+#define SCnSCB_ACTLR_DISISSCH1_Pos 21U /*!< ACTLR: DISISSCH1 Position */
+#define SCnSCB_ACTLR_DISISSCH1_Msk (0x1FUL << SCnSCB_ACTLR_DISISSCH1_Pos) /*!< ACTLR: DISISSCH1 Mask */
+
+#define SCnSCB_ACTLR_DISDI_Pos 16U /*!< ACTLR: DISDI Position */
+#define SCnSCB_ACTLR_DISDI_Msk (0x1FUL << SCnSCB_ACTLR_DISDI_Pos) /*!< ACTLR: DISDI Mask */
+
+#define SCnSCB_ACTLR_DISCRITAXIRUR_Pos 15U /*!< ACTLR: DISCRITAXIRUR Position */
+#define SCnSCB_ACTLR_DISCRITAXIRUR_Msk (1UL << SCnSCB_ACTLR_DISCRITAXIRUR_Pos) /*!< ACTLR: DISCRITAXIRUR Mask */
+
+#define SCnSCB_ACTLR_DISBTACALLOC_Pos 14U /*!< ACTLR: DISBTACALLOC Position */
+#define SCnSCB_ACTLR_DISBTACALLOC_Msk (1UL << SCnSCB_ACTLR_DISBTACALLOC_Pos) /*!< ACTLR: DISBTACALLOC Mask */
+
+#define SCnSCB_ACTLR_DISBTACREAD_Pos 13U /*!< ACTLR: DISBTACREAD Position */
+#define SCnSCB_ACTLR_DISBTACREAD_Msk (1UL << SCnSCB_ACTLR_DISBTACREAD_Pos) /*!< ACTLR: DISBTACREAD Mask */
+
+#define SCnSCB_ACTLR_DISITMATBFLUSH_Pos 12U /*!< ACTLR: DISITMATBFLUSH Position */
+#define SCnSCB_ACTLR_DISITMATBFLUSH_Msk (1UL << SCnSCB_ACTLR_DISITMATBFLUSH_Pos) /*!< ACTLR: DISITMATBFLUSH Mask */
+
+#define SCnSCB_ACTLR_DISRAMODE_Pos 11U /*!< ACTLR: DISRAMODE Position */
+#define SCnSCB_ACTLR_DISRAMODE_Msk (1UL << SCnSCB_ACTLR_DISRAMODE_Pos) /*!< ACTLR: DISRAMODE Mask */
+
+#define SCnSCB_ACTLR_FPEXCODIS_Pos 10U /*!< ACTLR: FPEXCODIS Position */
+#define SCnSCB_ACTLR_FPEXCODIS_Msk (1UL << SCnSCB_ACTLR_FPEXCODIS_Pos) /*!< ACTLR: FPEXCODIS Mask */
+
+#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */
+#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
+
+#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */
+#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */
+
+/*@} end of group CMSIS_SCnotSCB */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_SysTick System Tick Timer (SysTick)
+ \brief Type definitions for the System Timer Registers.
+ @{
+ */
+
+/**
+ \brief Structure type to access the System Timer (SysTick).
+ */
+typedef struct
+{
+ __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
+ __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
+ __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
+ __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
+} SysTick_Type;
+
+/* SysTick Control / Status Register Definitions */
+#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
+#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
+
+#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
+#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
+
+#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
+#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
+
+#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
+#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
+
+/* SysTick Reload Register Definitions */
+#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
+#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
+
+/* SysTick Current Register Definitions */
+#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
+#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
+
+/* SysTick Calibration Register Definitions */
+#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
+#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
+
+#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
+#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
+
+#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
+#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
+
+/*@} end of group CMSIS_SysTick */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM)
+ \brief Type definitions for the Instrumentation Trace Macrocell (ITM)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM).
+ */
+typedef struct
+{
+ __OM union
+ {
+ __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */
+ __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */
+ __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */
+ } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */
+ uint32_t RESERVED0[864U];
+ __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */
+ uint32_t RESERVED1[15U];
+ __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
+ uint32_t RESERVED2[15U];
+ __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
+ uint32_t RESERVED3[32U];
+ uint32_t RESERVED4[43U];
+ __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
+ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
+ uint32_t RESERVED5[6U];
+ __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */
+ __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */
+ __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */
+ __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */
+ __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */
+ __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */
+ __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */
+ __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */
+ __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */
+ __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */
+ __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */
+ __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */
+} ITM_Type;
+
+/* ITM Trace Privilege Register Definitions */
+#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
+#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
+
+/* ITM Trace Control Register Definitions */
+#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
+#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */
+
+#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */
+#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */
+
+#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */
+#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */
+
+#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */
+#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */
+
+#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */
+#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */
+
+#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */
+#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */
+
+#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */
+#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */
+
+#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */
+#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */
+
+#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
+#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
+
+/* ITM Lock Status Register Definitions */
+#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
+#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
+
+#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */
+#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */
+
+#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */
+#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */
+
+/*@}*/ /* end of group CMSIS_ITM */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT)
+ \brief Type definitions for the Data Watchpoint and Trace (DWT)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Data Watchpoint and Trace Register (DWT).
+ */
+typedef struct
+{
+ __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
+ __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
+ __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */
+ __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */
+ __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */
+ __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */
+ __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */
+ __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */
+ __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */
+ __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */
+ __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */
+ uint32_t RESERVED0[1U];
+ __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */
+ __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */
+ __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */
+ uint32_t RESERVED1[1U];
+ __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */
+ __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */
+ __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */
+ uint32_t RESERVED2[1U];
+ __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */
+ __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */
+ __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */
+ uint32_t RESERVED3[981U];
+ __OM uint32_t LAR; /*!< Offset: 0xFB0 ( W) Lock Access Register */
+ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R ) Lock Status Register */
+} DWT_Type;
+
+/* DWT Control Register Definitions */
+#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */
+#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */
+
+#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */
+#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */
+
+#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */
+#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */
+
+#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */
+#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */
+
+#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */
+#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */
+
+#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */
+#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */
+
+#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */
+#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */
+
+#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */
+#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */
+
+#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */
+#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */
+
+#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */
+#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */
+
+#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */
+#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */
+
+#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */
+#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */
+
+#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */
+#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */
+
+#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */
+#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */
+
+#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */
+#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */
+
+#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */
+#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */
+
+#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */
+#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */
+
+#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */
+#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */
+
+/* DWT CPI Count Register Definitions */
+#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */
+#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */
+
+/* DWT Exception Overhead Count Register Definitions */
+#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */
+#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */
+
+/* DWT Sleep Count Register Definitions */
+#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */
+#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */
+
+/* DWT LSU Count Register Definitions */
+#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */
+#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */
+
+/* DWT Folded-instruction Count Register Definitions */
+#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */
+#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */
+
+/* DWT Comparator Mask Register Definitions */
+#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */
+#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */
+
+/* DWT Comparator Function Register Definitions */
+#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */
+#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */
+
+#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */
+#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */
+
+#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */
+#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */
+
+#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */
+#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */
+
+#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */
+#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */
+
+#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */
+#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */
+
+#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */
+#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */
+
+#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */
+#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */
+
+#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */
+#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */
+
+/*@}*/ /* end of group CMSIS_DWT */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_TPI Trace Port Interface (TPI)
+ \brief Type definitions for the Trace Port Interface (TPI)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Trace Port Interface Register (TPI).
+ */
+typedef struct
+{
+ __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
+ __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
+ uint32_t RESERVED0[2U];
+ __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
+ uint32_t RESERVED1[55U];
+ __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */
+ uint32_t RESERVED2[131U];
+ __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */
+ __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
+ __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
+ uint32_t RESERVED3[759U];
+ __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */
+ __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
+ __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
+ uint32_t RESERVED4[1U];
+ __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */
+ __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */
+ __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */
+ uint32_t RESERVED5[39U];
+ __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */
+ __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */
+ uint32_t RESERVED7[8U];
+ __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */
+ __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */
+} TPI_Type;
+
+/* TPI Asynchronous Clock Prescaler Register Definitions */
+#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */
+#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */
+
+/* TPI Selected Pin Protocol Register Definitions */
+#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */
+#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */
+
+/* TPI Formatter and Flush Status Register Definitions */
+#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */
+#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */
+
+#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */
+#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */
+
+#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */
+#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */
+
+#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */
+#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */
+
+/* TPI Formatter and Flush Control Register Definitions */
+#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */
+#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */
+
+#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */
+#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */
+
+/* TPI TRIGGER Register Definitions */
+#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */
+#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */
+
+/* TPI Integration ETM Data Register Definitions (FIFO0) */
+#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
+#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
+
+#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
+#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
+
+#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
+#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
+
+#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
+#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
+
+#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */
+#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */
+
+#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */
+#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */
+
+#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */
+#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
+
+/* TPI ITATBCTR2 Register Definitions */
+#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */
+#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */
+
+#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */
+#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */
+
+/* TPI Integration ITM Data Register Definitions (FIFO1) */
+#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
+#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
+
+#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
+#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
+
+#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
+#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
+
+#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
+#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
+
+#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */
+#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */
+
+#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */
+#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */
+
+#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */
+#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
+
+/* TPI ITATBCTR0 Register Definitions */
+#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */
+#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */
+
+#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */
+#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */
+
+/* TPI Integration Mode Control Register Definitions */
+#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
+#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
+
+/* TPI DEVID Register Definitions */
+#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
+#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */
+
+#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */
+#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */
+
+#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */
+#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */
+
+#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */
+#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */
+
+#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */
+#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */
+
+#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */
+#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
+
+/* TPI DEVTYPE Register Definitions */
+#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */
+#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
+
+#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */
+#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
+
+/*@}*/ /* end of group CMSIS_TPI */
+
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_MPU Memory Protection Unit (MPU)
+ \brief Type definitions for the Memory Protection Unit (MPU)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Memory Protection Unit (MPU).
+ */
+typedef struct
+{
+ __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
+ __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
+ __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
+ __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
+ __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */
+ __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */
+ __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */
+ __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */
+ __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
+} MPU_Type;
+
+#define MPU_TYPE_RALIASES 4U
+
+/* MPU Type Register Definitions */
+#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
+#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
+
+#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */
+#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
+
+#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */
+#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */
+
+/* MPU Control Register Definitions */
+#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */
+#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
+
+#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */
+#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
+
+#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */
+#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */
+
+/* MPU Region Number Register Definitions */
+#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */
+#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */
+
+/* MPU Region Base Address Register Definitions */
+#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */
+#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
+
+#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */
+#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
+
+#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */
+#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */
+
+/* MPU Region Attribute and Size Register Definitions */
+#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */
+#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
+
+#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */
+#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
+
+#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */
+#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
+
+#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */
+#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
+
+#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */
+#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
+
+#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */
+#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
+
+#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */
+#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
+
+#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */
+#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
+
+#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */
+#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
+
+#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */
+#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
+
+/*@} end of group CMSIS_MPU */
+#endif /* defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_FPU Floating Point Unit (FPU)
+ \brief Type definitions for the Floating Point Unit (FPU)
+ @{
+ */
+
+/**
+ \brief Structure type to access the Floating Point Unit (FPU).
+ */
+typedef struct
+{
+ uint32_t RESERVED0[1U];
+ __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */
+ __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */
+ __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */
+ __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */
+ __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */
+ __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */
+} FPU_Type;
+
+/* Floating-Point Context Control Register Definitions */
+#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */
+#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */
+
+#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */
+#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */
+
+#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */
+#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */
+
+#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */
+#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */
+
+#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */
+#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */
+
+#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */
+#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */
+
+#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */
+#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */
+
+#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */
+#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */
+
+#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */
+#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */
+
+/* Floating-Point Context Address Register Definitions */
+#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */
+#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */
+
+/* Floating-Point Default Status Control Register Definitions */
+#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */
+#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */
+
+#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */
+#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */
+
+#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */
+#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */
+
+#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */
+#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */
+
+/* Media and FP Feature Register 0 Definitions */
+#define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */
+#define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */
+
+#define FPU_MVFR0_Short_vectors_Pos 24U /*!< MVFR0: Short vectors bits Position */
+#define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */
+
+#define FPU_MVFR0_Square_root_Pos 20U /*!< MVFR0: Square root bits Position */
+#define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */
+
+#define FPU_MVFR0_Divide_Pos 16U /*!< MVFR0: Divide bits Position */
+#define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */
+
+#define FPU_MVFR0_FP_excep_trapping_Pos 12U /*!< MVFR0: FP exception trapping bits Position */
+#define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */
+
+#define FPU_MVFR0_Double_precision_Pos 8U /*!< MVFR0: Double-precision bits Position */
+#define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */
+
+#define FPU_MVFR0_Single_precision_Pos 4U /*!< MVFR0: Single-precision bits Position */
+#define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */
+
+#define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */
+#define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */
+
+/* Media and FP Feature Register 1 Definitions */
+#define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */
+#define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */
+
+#define FPU_MVFR1_FP_HPFP_Pos 24U /*!< MVFR1: FP HPFP bits Position */
+#define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */
+
+#define FPU_MVFR1_D_NaN_mode_Pos 4U /*!< MVFR1: D_NaN mode bits Position */
+#define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */
+
+#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */
+#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */
+
+/* Media and FP Feature Register 2 Definitions */
+
+#define FPU_MVFR2_VFP_Misc_Pos 4U /*!< MVFR2: VFP Misc bits Position */
+#define FPU_MVFR2_VFP_Misc_Msk (0xFUL << FPU_MVFR2_VFP_Misc_Pos) /*!< MVFR2: VFP Misc bits Mask */
+
+/*@} end of group CMSIS_FPU */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
+ \brief Type definitions for the Core Debug Registers
+ @{
+ */
+
+/**
+ \brief Structure type to access the Core Debug Register (CoreDebug).
+ */
+typedef struct
+{
+ __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
+ __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
+ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
+ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
+} CoreDebug_Type;
+
+/* Debug Halting Control and Status Register Definitions */
+#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */
+#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */
+
+#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */
+#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */
+
+#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */
+#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */
+
+#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */
+#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */
+
+#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */
+#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */
+
+#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */
+#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */
+
+#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */
+#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */
+
+#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */
+#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */
+
+#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */
+#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */
+
+#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */
+#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */
+
+#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */
+#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */
+
+#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */
+#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */
+
+/* Debug Core Register Selector Register Definitions */
+#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */
+#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */
+
+#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */
+#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */
+
+/* Debug Exception and Monitor Control Register Definitions */
+#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */
+#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
+
+#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */
+#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */
+
+#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */
+#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */
+
+#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */
+#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */
+
+#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */
+#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */
+
+#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */
+#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */
+
+#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */
+#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */
+
+#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */
+#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */
+
+#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */
+#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */
+
+#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */
+#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */
+
+#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */
+#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */
+
+#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */
+#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */
+
+#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */
+#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */
+
+/*@} end of group CMSIS_CoreDebug */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_core_bitfield Core register bit field macros
+ \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
+ @{
+ */
+
+/**
+ \brief Mask and shift a bit field value for use in a register bit range.
+ \param[in] field Name of the register bit field.
+ \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
+ \return Masked and shifted value.
+*/
+#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
+
+/**
+ \brief Mask and shift a register value to extract a bit filed value.
+ \param[in] field Name of the register bit field.
+ \param[in] value Value of register. This parameter is interpreted as an uint32_t type.
+ \return Masked and shifted bit field value.
+*/
+#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
+
+/*@} end of group CMSIS_core_bitfield */
+
+
+/**
+ \ingroup CMSIS_core_register
+ \defgroup CMSIS_core_base Core Definitions
+ \brief Definitions for base addresses, unions, and structures.
+ @{
+ */
+
+/* Memory mapping of Core Hardware */
+#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
+#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
+#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
+#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */
+#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
+#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
+#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
+#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
+
+#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
+#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
+#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
+#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
+#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */
+#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */
+#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
+#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+ #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
+ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
+#endif
+
+#define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */
+#define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */
+
+/*@} */
+
+
+
+/*******************************************************************************
+ * Hardware Abstraction Layer
+ Core Function Interface contains:
+ - Core NVIC Functions
+ - Core SysTick Functions
+ - Core Debug Functions
+ - Core Register Access Functions
+ ******************************************************************************/
+/**
+ \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
+*/
+
+
+
+/* ########################## NVIC functions #################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_NVICFunctions NVIC Functions
+ \brief Functions that manage interrupts and exceptions via the NVIC.
+ @{
+ */
+
+#ifdef CMSIS_NVIC_VIRTUAL
+ #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
+ #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
+ #endif
+ #include CMSIS_NVIC_VIRTUAL_HEADER_FILE
+#else
+ #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
+ #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
+ #define NVIC_EnableIRQ __NVIC_EnableIRQ
+ #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
+ #define NVIC_DisableIRQ __NVIC_DisableIRQ
+ #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
+ #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
+ #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
+ #define NVIC_GetActive __NVIC_GetActive
+ #define NVIC_SetPriority __NVIC_SetPriority
+ #define NVIC_GetPriority __NVIC_GetPriority
+ #define NVIC_SystemReset __NVIC_SystemReset
+#endif /* CMSIS_NVIC_VIRTUAL */
+
+#ifdef CMSIS_VECTAB_VIRTUAL
+ #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
+ #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
+ #endif
+ #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
+#else
+ #define NVIC_SetVector __NVIC_SetVector
+ #define NVIC_GetVector __NVIC_GetVector
+#endif /* (CMSIS_VECTAB_VIRTUAL) */
+
+#define NVIC_USER_IRQ_OFFSET 16
+
+
+/* The following EXC_RETURN values are saved the LR on exception entry */
+#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
+#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
+#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
+#define EXC_RETURN_HANDLER_FPU (0xFFFFFFE1UL) /* return to Handler mode, uses MSP after return, restore floating-point state */
+#define EXC_RETURN_THREAD_MSP_FPU (0xFFFFFFE9UL) /* return to Thread mode, uses MSP after return, restore floating-point state */
+#define EXC_RETURN_THREAD_PSP_FPU (0xFFFFFFEDUL) /* return to Thread mode, uses PSP after return, restore floating-point state */
+
+
+/**
+ \brief Set Priority Grouping
+ \details Sets the priority grouping field using the required unlock sequence.
+ The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
+ Only values from 0..7 are used.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
+ \param [in] PriorityGroup Priority grouping field.
+ */
+__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
+{
+ uint32_t reg_value;
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+
+ reg_value = SCB->AIRCR; /* read old register configuration */
+ reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
+ reg_value = (reg_value |
+ ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
+ (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */
+ SCB->AIRCR = reg_value;
+}
+
+
+/**
+ \brief Get Priority Grouping
+ \details Reads the priority grouping field from the NVIC Interrupt Controller.
+ \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void)
+{
+ return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
+}
+
+
+/**
+ \brief Enable Interrupt
+ \details Enables a device specific interrupt in the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ __COMPILER_BARRIER();
+ NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ __COMPILER_BARRIER();
+ }
+}
+
+
+/**
+ \brief Get Interrupt Enable status
+ \details Returns a device specific interrupt enable status from the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt is not enabled.
+ \return 1 Interrupt is enabled.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Disable Interrupt
+ \details Disables a device specific interrupt in the NVIC interrupt controller.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ __DSB();
+ __ISB();
+ }
+}
+
+
+/**
+ \brief Get Pending Interrupt
+ \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt status is not pending.
+ \return 1 Interrupt status is pending.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Set Pending Interrupt
+ \details Sets the pending bit of a device specific interrupt in the NVIC pending register.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ }
+}
+
+
+/**
+ \brief Clear Pending Interrupt
+ \details Clears the pending bit of a device specific interrupt in the NVIC pending register.
+ \param [in] IRQn Device specific interrupt number.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
+ }
+}
+
+
+/**
+ \brief Get Active Interrupt
+ \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt.
+ \param [in] IRQn Device specific interrupt number.
+ \return 0 Interrupt status is not active.
+ \return 1 Interrupt status is active.
+ \note IRQn must not be negative.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
+ }
+ else
+ {
+ return(0U);
+ }
+}
+
+
+/**
+ \brief Set Interrupt Priority
+ \details Sets the priority of a device specific interrupt or a processor exception.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \param [in] priority Priority to set.
+ \note The priority cannot be set for every processor exception.
+ */
+__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
+{
+ if ((int32_t)(IRQn) >= 0)
+ {
+ NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
+ }
+ else
+ {
+ SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
+ }
+}
+
+
+/**
+ \brief Get Interrupt Priority
+ \details Reads the priority of a device specific interrupt or a processor exception.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \return Interrupt Priority.
+ Value is aligned automatically to the implemented priority bits of the microcontroller.
+ */
+__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
+{
+
+ if ((int32_t)(IRQn) >= 0)
+ {
+ return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
+ }
+ else
+ {
+ return(((uint32_t)SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
+ }
+}
+
+
+/**
+ \brief Encode Priority
+ \details Encodes the priority for an interrupt with the given priority group,
+ preemptive priority value, and subpriority value.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
+ \param [in] PriorityGroup Used priority group.
+ \param [in] PreemptPriority Preemptive priority value (starting from 0).
+ \param [in] SubPriority Subpriority value (starting from 0).
+ \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
+ */
+__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
+{
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+ uint32_t PreemptPriorityBits;
+ uint32_t SubPriorityBits;
+
+ PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
+ SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
+
+ return (
+ ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
+ ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
+ );
+}
+
+
+/**
+ \brief Decode Priority
+ \details Decodes an interrupt priority value with a given priority group to
+ preemptive priority value and subpriority value.
+ In case of a conflict between priority grouping and available
+ priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
+ \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
+ \param [in] PriorityGroup Used priority group.
+ \param [out] pPreemptPriority Preemptive priority value (starting from 0).
+ \param [out] pSubPriority Subpriority value (starting from 0).
+ */
+__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
+{
+ uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
+ uint32_t PreemptPriorityBits;
+ uint32_t SubPriorityBits;
+
+ PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
+ SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
+
+ *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
+ *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
+}
+
+
+/**
+ \brief Set Interrupt Vector
+ \details Sets an interrupt vector in SRAM based interrupt vector table.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ VTOR must been relocated to SRAM before.
+ \param [in] IRQn Interrupt number
+ \param [in] vector Address of interrupt handler function
+ */
+__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
+{
+ uint32_t *vectors = (uint32_t *)SCB->VTOR;
+ vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
+ __DSB();
+}
+
+
+/**
+ \brief Get Interrupt Vector
+ \details Reads an interrupt vector from interrupt vector table.
+ The interrupt number can be positive to specify a device specific interrupt,
+ or negative to specify a processor exception.
+ \param [in] IRQn Interrupt number.
+ \return Address of interrupt handler function
+ */
+__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
+{
+ uint32_t *vectors = (uint32_t *)SCB->VTOR;
+ return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
+}
+
+
+/**
+ \brief System Reset
+ \details Initiates a system reset request to reset the MCU.
+ */
+__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
+{
+ __DSB(); /* Ensure all outstanding memory accesses included
+ buffered write are completed before reset */
+ SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
+ (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
+ SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */
+ __DSB(); /* Ensure completion of memory access */
+
+ for(;;) /* wait until reset */
+ {
+ __NOP();
+ }
+}
+
+/*@} end of CMSIS_Core_NVICFunctions */
+
+
+/* ########################## MPU functions #################################### */
+
+#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
+
+#include "mpu_armv7.h"
+
+#endif
+
+
+/* ########################## FPU functions #################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_FpuFunctions FPU Functions
+ \brief Function that provides FPU type.
+ @{
+ */
+
+/**
+ \brief get FPU type
+ \details returns the FPU type
+ \returns
+ - \b 0: No FPU
+ - \b 1: Single precision FPU
+ - \b 2: Double + Single precision FPU
+ */
+__STATIC_INLINE uint32_t SCB_GetFPUType(void)
+{
+ uint32_t mvfr0;
+
+ mvfr0 = SCB->MVFR0;
+ if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x220U)
+ {
+ return 2U; /* Double + Single precision FPU */
+ }
+ else if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U)
+ {
+ return 1U; /* Single precision FPU */
+ }
+ else
+ {
+ return 0U; /* No FPU */
+ }
+}
+
+/*@} end of CMSIS_Core_FpuFunctions */
+
+
+/* ########################## Cache functions #################################### */
+
+#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \
+ (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)))
+#include "cachel1_armv7.h"
+#endif
+
+
+/* ################################## SysTick function ############################################ */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
+ \brief Functions that configure the System.
+ @{
+ */
+
+#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
+
+/**
+ \brief System Tick Configuration
+ \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
+ Counter is in free running mode to generate periodic interrupts.
+ \param [in] ticks Number of ticks between two interrupts.
+ \return 0 Function succeeded.
+ \return 1 Function failed.
+ \note When the variable __Vendor_SysTickConfig is set to 1, then the
+ function SysTick_Config is not included. In this case, the file device .h
+ must contain a vendor-specific implementation of this function.
+ */
+__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
+{
+ if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
+ {
+ return (1UL); /* Reload value impossible */
+ }
+
+ SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
+ NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
+ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
+ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
+ SysTick_CTRL_TICKINT_Msk |
+ SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
+ return (0UL); /* Function successful */
+}
+
+#endif
+
+/*@} end of CMSIS_Core_SysTickFunctions */
+
+
+
+/* ##################################### Debug In/Output function ########################################### */
+/**
+ \ingroup CMSIS_Core_FunctionInterface
+ \defgroup CMSIS_core_DebugFunctions ITM Functions
+ \brief Functions that access the ITM debug interface.
+ @{
+ */
+
+extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
+#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
+
+
+/**
+ \brief ITM Send Character
+ \details Transmits a character via the ITM channel 0, and
+ \li Just returns when no debugger is connected that has booked the output.
+ \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
+ \param [in] ch Character to transmit.
+ \returns Character to transmit.
+ */
+__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
+{
+ if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
+ ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */
+ {
+ while (ITM->PORT[0U].u32 == 0UL)
+ {
+ __NOP();
+ }
+ ITM->PORT[0U].u8 = (uint8_t)ch;
+ }
+ return (ch);
+}
+
+
+/**
+ \brief ITM Receive Character
+ \details Inputs a character via the external variable \ref ITM_RxBuffer.
+ \return Received character.
+ \return -1 No character pending.
+ */
+__STATIC_INLINE int32_t ITM_ReceiveChar (void)
+{
+ int32_t ch = -1; /* no character available */
+
+ if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY)
+ {
+ ch = ITM_RxBuffer;
+ ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
+ }
+
+ return (ch);
+}
+
+
+/**
+ \brief ITM Check Character
+ \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer.
+ \return 0 No character available.
+ \return 1 Character available.
+ */
+__STATIC_INLINE int32_t ITM_CheckChar (void)
+{
+
+ if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY)
+ {
+ return (0); /* no character available */
+ }
+ else
+ {
+ return (1); /* character available */
+ }
+}
+
+/*@} end of CMSIS_core_DebugFunctions */
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_CM7_H_DEPENDANT */
+
+#endif /* __CMSIS_GENERIC */
diff --git a/CMSIS/Core/Include/mpu_armv7.h b/CMSIS/Core/Include/mpu_armv7.h
new file mode 100644
index 0000000..d9eedf8
--- /dev/null
+++ b/CMSIS/Core/Include/mpu_armv7.h
@@ -0,0 +1,275 @@
+/******************************************************************************
+ * @file mpu_armv7.h
+ * @brief CMSIS MPU API for Armv7-M MPU
+ * @version V5.1.2
+ * @date 25. May 2020
+ ******************************************************************************/
+/*
+ * Copyright (c) 2017-2020 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef ARM_MPU_ARMV7_H
+#define ARM_MPU_ARMV7_H
+
+#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes
+#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes
+#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes
+#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes
+#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes
+#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte
+#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes
+#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes
+#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes
+#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes
+#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes
+#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes
+#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes
+#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes
+#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes
+#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte
+#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes
+#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes
+#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes
+#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes
+#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes
+#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes
+#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes
+#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes
+#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes
+#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte
+#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes
+#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes
+
+#define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access
+#define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only
+#define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only
+#define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access
+#define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only
+#define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access
+
+/** MPU Region Base Address Register Value
+*
+* \param Region The region to be configured, number 0 to 15.
+* \param BaseAddress The base address for the region.
+*/
+#define ARM_MPU_RBAR(Region, BaseAddress) \
+ (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
+ ((Region) & MPU_RBAR_REGION_Msk) | \
+ (MPU_RBAR_VALID_Msk))
+
+/**
+* MPU Memory Access Attributes
+*
+* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
+* \param IsShareable Region is shareable between multiple bus masters.
+* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
+* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
+*/
+#define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \
+ ((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
+ (((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
+ (((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
+ (((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk))
+
+/**
+* MPU Region Attribute and Size Register Value
+*
+* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
+* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
+* \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_.
+* \param SubRegionDisable Sub-region disable field.
+* \param Size Region size of the region to be configured, for example 4K, 8K.
+*/
+#define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \
+ ((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
+ (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
+ (((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \
+ (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \
+ (((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \
+ (((MPU_RASR_ENABLE_Msk))))
+
+/**
+* MPU Region Attribute and Size Register Value
+*
+* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
+* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
+* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
+* \param IsShareable Region is shareable between multiple bus masters.
+* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
+* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
+* \param SubRegionDisable Sub-region disable field.
+* \param Size Region size of the region to be configured, for example 4K, 8K.
+*/
+#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
+ ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size)
+
+/**
+* MPU Memory Access Attribute for strongly ordered memory.
+* - TEX: 000b
+* - Shareable
+* - Non-cacheable
+* - Non-bufferable
+*/
+#define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U)
+
+/**
+* MPU Memory Access Attribute for device memory.
+* - TEX: 000b (if shareable) or 010b (if non-shareable)
+* - Shareable or non-shareable
+* - Non-cacheable
+* - Bufferable (if shareable) or non-bufferable (if non-shareable)
+*
+* \param IsShareable Configures the device memory as shareable or non-shareable.
+*/
+#define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U))
+
+/**
+* MPU Memory Access Attribute for normal memory.
+* - TEX: 1BBb (reflecting outer cacheability rules)
+* - Shareable or non-shareable
+* - Cacheable or non-cacheable (reflecting inner cacheability rules)
+* - Bufferable or non-bufferable (reflecting inner cacheability rules)
+*
+* \param OuterCp Configures the outer cache policy.
+* \param InnerCp Configures the inner cache policy.
+* \param IsShareable Configures the memory as shareable or non-shareable.
+*/
+#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) >> 1U), ((InnerCp) & 1U))
+
+/**
+* MPU Memory Access Attribute non-cacheable policy.
+*/
+#define ARM_MPU_CACHEP_NOCACHE 0U
+
+/**
+* MPU Memory Access Attribute write-back, write and read allocate policy.
+*/
+#define ARM_MPU_CACHEP_WB_WRA 1U
+
+/**
+* MPU Memory Access Attribute write-through, no write allocate policy.
+*/
+#define ARM_MPU_CACHEP_WT_NWA 2U
+
+/**
+* MPU Memory Access Attribute write-back, no write allocate policy.
+*/
+#define ARM_MPU_CACHEP_WB_NWA 3U
+
+
+/**
+* Struct for a single MPU Region
+*/
+typedef struct {
+ uint32_t RBAR; //!< The region base address register value (RBAR)
+ uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
+} ARM_MPU_Region_t;
+
+/** Enable the MPU.
+* \param MPU_Control Default access permissions for unconfigured regions.
+*/
+__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
+{
+ __DMB();
+ MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
+#ifdef SCB_SHCSR_MEMFAULTENA_Msk
+ SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
+#endif
+ __DSB();
+ __ISB();
+}
+
+/** Disable the MPU.
+*/
+__STATIC_INLINE void ARM_MPU_Disable(void)
+{
+ __DMB();
+#ifdef SCB_SHCSR_MEMFAULTENA_Msk
+ SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
+#endif
+ MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
+ __DSB();
+ __ISB();
+}
+
+/** Clear and disable the given MPU region.
+* \param rnr Region number to be cleared.
+*/
+__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
+{
+ MPU->RNR = rnr;
+ MPU->RASR = 0U;
+}
+
+/** Configure an MPU region.
+* \param rbar Value for RBAR register.
+* \param rasr Value for RASR register.
+*/
+__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
+{
+ MPU->RBAR = rbar;
+ MPU->RASR = rasr;
+}
+
+/** Configure the given MPU region.
+* \param rnr Region number to be configured.
+* \param rbar Value for RBAR register.
+* \param rasr Value for RASR register.
+*/
+__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
+{
+ MPU->RNR = rnr;
+ MPU->RBAR = rbar;
+ MPU->RASR = rasr;
+}
+
+/** Memcpy with strictly ordered memory access, e.g. used by code in ARM_MPU_Load().
+* \param dst Destination data is copied to.
+* \param src Source data is copied from.
+* \param len Amount of data words to be copied.
+*/
+__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
+{
+ uint32_t i;
+ for (i = 0U; i < len; ++i)
+ {
+ dst[i] = src[i];
+ }
+}
+
+/** Load the given number of MPU regions from a table.
+* \param table Pointer to the MPU configuration table.
+* \param cnt Amount of regions to be configured.
+*/
+__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
+{
+ const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
+ while (cnt > MPU_TYPE_RALIASES) {
+ ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
+ table += MPU_TYPE_RALIASES;
+ cnt -= MPU_TYPE_RALIASES;
+ }
+ ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
+}
+
+#endif
diff --git a/CMSIS/Core/Include/tz_context.h b/CMSIS/Core/Include/tz_context.h
new file mode 100644
index 0000000..0d09749
--- /dev/null
+++ b/CMSIS/Core/Include/tz_context.h
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * @file tz_context.h
+ * @brief Context Management for Armv8-M TrustZone
+ * @version V1.0.1
+ * @date 10. January 2018
+ ******************************************************************************/
+/*
+ * Copyright (c) 2017-2018 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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
+ *
+ * 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.
+ */
+
+#if defined ( __ICCARM__ )
+ #pragma system_include /* treat file as system include file for MISRA check */
+#elif defined (__clang__)
+ #pragma clang system_header /* treat file as system include file */
+#endif
+
+#ifndef TZ_CONTEXT_H
+#define TZ_CONTEXT_H
+
+#include
+
+#ifndef TZ_MODULEID_T
+#define TZ_MODULEID_T
+/// \details Data type that identifies secure software modules called by a process.
+typedef uint32_t TZ_ModuleId_t;
+#endif
+
+/// \details TZ Memory ID identifies an allocated memory slot.
+typedef uint32_t TZ_MemoryId_t;
+
+/// Initialize secure context memory system
+/// \return execution status (1: success, 0: error)
+uint32_t TZ_InitContextSystem_S (void);
+
+/// Allocate context memory for calling secure software modules in TrustZone
+/// \param[in] module identifies software modules called from non-secure mode
+/// \return value != 0 id TrustZone memory slot identifier
+/// \return value 0 no memory available or internal error
+TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module);
+
+/// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
+/// \param[in] id TrustZone memory slot identifier
+/// \return execution status (1: success, 0: error)
+uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id);
+
+/// Load secure context (called on RTOS thread context switch)
+/// \param[in] id TrustZone memory slot identifier
+/// \return execution status (1: success, 0: error)
+uint32_t TZ_LoadContext_S (TZ_MemoryId_t id);
+
+/// Store secure context (called on RTOS thread context switch)
+/// \param[in] id TrustZone memory slot identifier
+/// \return execution status (1: success, 0: error)
+uint32_t TZ_StoreContext_S (TZ_MemoryId_t id);
+
+#endif // TZ_CONTEXT_H
diff --git a/CMSIS/LICENSE.txt b/CMSIS/LICENSE.txt
new file mode 100644
index 0000000..8dada3e
--- /dev/null
+++ b/CMSIS/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ 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.
diff --git a/GD32F20x_Demo_Suites_V2.2.1/.project b/GD32F20x_Demo_Suites_V2.2.1/.project
deleted file mode 100644
index dd47011..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/.project
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
- GD32F20x_Demo_Suites_V2.2.1
-
-
-
-
-
-
-
-
diff --git a/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/gd32f20x.bin
deleted file mode 100755
index 2d7dc7c..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/udp_send b/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/01_GPIO_Runing_Led/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/gd32f20x.bin
deleted file mode 100755
index 10a9023..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/udp_send b/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/02_GPIO_KeyBoard_Polling_mode/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/gd32f20x.bin
deleted file mode 100755
index cb84408..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/udp_send b/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/03_EXTI_KeyBoard_Interrupt_mode/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/gd32f20x.bin
deleted file mode 100755
index d14f0eb..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/udp_send b/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/04_USART_Printf/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/gd32f20x.bin
deleted file mode 100755
index 091da22..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/udp_send b/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/05_USART_Echo_Interrupt_mode/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/gd32f20x.bin
deleted file mode 100755
index 97991dd..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/udp_send b/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/06_USART_DMA/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/gd32f20x.bin
deleted file mode 100755
index 4fef932..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/udp_send b/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/07_ADC_Temperature_Vrefint/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/gd32f20x.bin
deleted file mode 100755
index 526253d..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/udp_send b/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/08_ADC0_ADC1_Follow_up_mode/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/gd32f20x.bin
deleted file mode 100755
index e3ed255..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/udp_send b/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/09_ADC0_ADC1_Regular_Parallel_mode/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/gd32f20x.bin
deleted file mode 100755
index 003b786..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/udp_send b/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/10_DAC_Output_Voltage_Value/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/gd32f20x.bin
deleted file mode 100755
index 2804274..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/udp_send b/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/11_I2C_EEPROM/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/gd32f20x.bin
deleted file mode 100755
index 8fe48c9..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/udp_send b/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/12_SPI_QSPI_Flash/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/gd32f20x.bin
deleted file mode 100755
index 96231c6..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/udp_send b/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/13_EXMC_NandFlash/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/gd32f20x.bin
deleted file mode 100755
index b6cefb4..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/udp_send b/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/14_TRNG_Get_Random/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/15_CAU/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/15_CAU/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/15_CAU/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/15_CAU/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/15_CAU/gd32f20x.bin
deleted file mode 100755
index c77f1bb..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/15_CAU/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/15_CAU/udp_send b/GD32F20x_Demo_Suites_V2.2.1/15_CAU/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/15_CAU/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/16_HAU/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/16_HAU/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/16_HAU/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/16_HAU/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/16_HAU/gd32f20x.bin
deleted file mode 100755
index 9f1699f..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/16_HAU/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/16_HAU/udp_send b/GD32F20x_Demo_Suites_V2.2.1/16_HAU/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/16_HAU/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/gd32f20x.bin
deleted file mode 100755
index 5456cba..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/udp_send b/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/17_Tamper_Detection/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/gd32f20x.bin
deleted file mode 100755
index c66d436..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/udp_send b/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/18_SDIO_SDCardTest/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/gd32f20x.bin
deleted file mode 100755
index 2ed4bbb..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/udp_send b/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/19_CAN_Network/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/gd32f20x.bin
deleted file mode 100755
index ff4e0f3..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/udp_send b/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/20_RCU_Clock_Out/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/gd32f20x.bin
deleted file mode 100755
index f173b97..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/udp_send b/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/21_PMU_sleep_wakeup/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/gd32f20x.bin
deleted file mode 100755
index 0217e29..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/udp_send b/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/22_RTC_Calendar/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/gd32f20x.bin
deleted file mode 100755
index 13af8fa..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/udp_send b/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/23_TIMER_Breath_LED/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/gd32f20x.bin
deleted file mode 100755
index 5d4195f..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/udp_send b/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/24_TLI_without_GUI/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/25_ENET/do-tftp.sh b/GD32F20x_Demo_Suites_V2.2.1/25_ENET/do-tftp.sh
deleted file mode 120000
index e97b899..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/25_ENET/do-tftp.sh
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/do-tftp.sh
\ No newline at end of file
diff --git a/GD32F20x_Demo_Suites_V2.2.1/25_ENET/gd32f20x.bin b/GD32F20x_Demo_Suites_V2.2.1/25_ENET/gd32f20x.bin
deleted file mode 100755
index 927801d..0000000
Binary files a/GD32F20x_Demo_Suites_V2.2.1/25_ENET/gd32f20x.bin and /dev/null differ
diff --git a/GD32F20x_Demo_Suites_V2.2.1/25_ENET/udp_send b/GD32F20x_Demo_Suites_V2.2.1/25_ENET/udp_send
deleted file mode 120000
index c363ace..0000000
--- a/GD32F20x_Demo_Suites_V2.2.1/25_ENET/udp_send
+++ /dev/null
@@ -1 +0,0 @@
-../../udp_send/Release/udp_send
\ No newline at end of file
diff --git a/README.md b/README.md
index 047463f..0199357 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
![GitHub](https://img.shields.io/github/license/vanvught/GD32207C-EVAL-board-Bootloader-TFTP)
-[![C++ Standard](https://img.shields.io/badge/C%2B%2B-11-blue.svg)](https://img.shields.io/badge/C%2B%2B-11%-blue.svg)
+[![C++ Standard](https://img.shields.io/badge/C%2B%2B-20-blue.svg)](https://img.shields.io/badge/C%2B%2B-11%-blue.svg)
![GitHub issues](https://img.shields.io/github/issues-raw/vanvught/GD32207C-EVAL-board-Bootloader-TFTP)
![GitHub contributors](https://img.shields.io/github/contributors/vanvught/GD32207C-EVAL-board-Bootloader-TFTP)
![GitHub Sponsors](https://img.shields.io/github/sponsors/vanvught)
@@ -9,61 +9,6 @@
# GD32F207VC Bootloader TFTP
-This bootloader will install your application by means of the TFTP protocol. There is no need to change your application code.
-Per default DHCP is used for obtaining the ip-address.
-
-The bootloader is active during reset of the board:
-
-* Or when the `User Key` is pressed. Which is defined in file `lib-gd32/include/board/gd32f207c_eval.h`.
-
- #define KEY3_PINx GPIO_PIN_14
- #define KEY3_GPIOx GPIOB
- #define KEY3_RCU_GPIOx RCU_GPIOB
-
- #define KEY_BOOTLOADER_TFTP_GPIO_PINx KEY3_PINx
- #define KEY_BOOTLOADER_TFTP_GPIOx KEY3_GPIOx
- #define KEY_BOOTLOADER_TFTP_RCU_GPIOx KEY3_RCU_GPIOx
-
-* Or when `bkp_data_read(BKP_DATA_1) == 0xA5A5`. This is set in your application by means of human readable UDP messages. See for more information: [https://www.gd32-dmx.org/bootloader.html](https://www.gd32-dmx.org/bootloader.html). There is also a sample Java UI application available for working with the UDP messages: [https://github.com/vanvught/GD32F-Firmware-Update-UI](https://github.com/vanvught/GD32F-Firmware-Update-UI)
-
-Otherwise the bootloader will directly jump to you application. With the snippet:
-
- // 8. Call the reset handler
- const uint32_t* reset_p = (uint32_t *)(FLASH_BASE + OFFSET_UIMAGE + 4);
- asm volatile ("bx %0;" : : "r"(*reset_p));
-
-The bootloader can be installed with the tools supplied by GigaDevice -> [http://www.gd32mcu.com/en/download/7?kw=GD32F2](http://www.gd32mcu.com/en/download/7?kw=GD32F2)
-
-The limitation for the firmware file to be uploaded is given by the RAM available. For example, the MCU on GD32207C-EVAL is the [GD32F207VCT6](https://www.gigadevice.com/microcontroller/gd32f207vct6/). With the 128K RAM we have the firmware file size limit of 106K.
-
-There are 2 places for this configuration:
-
-File: `gd32f207vc_flash.ld`
-
- __heap_size = DEFINED(__heap_size) ? __heap_size : 107K;
- __stack_size = DEFINED(__stack_size) ? __stack_size : 1K;
-
-File: `spiflashinstall.h`
-
- # elif defined (BOARD_GD32F207C_EVAL)
- # define OFFSET_UIMAGE 0x007000 // 28K
- # define FIRMWARE_MAX_SIZE (106 * 1024) // 106K
-
-The 1K difference is needed for other `new` (`malloc`) within the bootloader.
-
-The change to be made in your application is in the file `gd32f207vc_flash.ld`.
-
- MEMORY
- {
- FLASH (rx) : ORIGIN = 0x08007000, LENGTH = 106K
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
- }
-
-The `FLASH ORIGIN` must match the `OFFSET_UIMAGE` from the bootloader file `spiflashinstall.h`
-
-The direcroty `GD32F20x_Demo_Suites_V2.2.1` contains the `gd32f20x.bin` for each demo. There is also the shell script `do-tftp.sh` included.
-Usage: `do-tftp.sh `
-
-A ready to compile `GD32F20x_Demo_Suites_V2.2.1` can be found here -> [https://github.com/vanvught/GD32207C-EVAL-board](https://github.com/vanvught/GD32207C-EVAL-board)
+See for more information: [https://www.gd32-dmx.org/bootloader.html](https://www.gd32-dmx.org/bootloader.html).
The code for the bootloader is a fork from [https://github.com/vanvught/rpidmx512](https://github.com/vanvught/rpidmx512). In order to reduce the memory footprint, some functions are not available.
\ No newline at end of file
diff --git a/bootloader-tftp/.cproject b/bootloader-tftp/.cproject
index 4bbb07f..44efa18 100644
--- a/bootloader-tftp/.cproject
+++ b/bootloader-tftp/.cproject
@@ -5,7 +5,7 @@
-
+
@@ -16,21 +16,85 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -38,25 +102,16 @@
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
@@ -64,25 +119,22 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
+
@@ -90,14 +142,41 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -124,18 +203,24 @@
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/bootloader-tftp/.settings/language.settings.xml b/bootloader-tftp/.settings/language.settings.xml
index 2e81177..a149a73 100644
--- a/bootloader-tftp/.settings/language.settings.xml
+++ b/bootloader-tftp/.settings/language.settings.xml
@@ -2,10 +2,10 @@
+
-
diff --git a/bootloader-tftp/Makefile.GD32 b/bootloader-tftp/Makefile.GD32
index 500b196..7e7a2d6 100644
--- a/bootloader-tftp/Makefile.GD32
+++ b/bootloader-tftp/Makefile.GD32
@@ -6,9 +6,9 @@ DEFINES+=DISABLE_PRINTF_FLOAT
DEFINES+=ENABLE_TFTP_SERVER
DEFINES+=CONFIG_REMOTECONFIG_MINIMUM
-DEFINES+=UDP_MAX_PORTS_ALLOWED=2
+DEFINES+=UDP_MAX_PORTS_ALLOWED=3
-#DEFINES+=ENET_LINK_CHECK_REG_POLL
+DEFINES+=ENET_RXBUF_NUM=2 ENET_TXBUF_NUM=1
DEFINES+=CONFIG_STORE_USE_ROM
diff --git a/bootloader-tftp/firmware/main.cpp b/bootloader-tftp/firmware/main.cpp
index 6ae8cc6..ae03bd7 100644
--- a/bootloader-tftp/firmware/main.cpp
+++ b/bootloader-tftp/firmware/main.cpp
@@ -2,7 +2,7 @@
* @file main.cpp
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@gd32-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,12 +29,10 @@
#include "hardware.h"
#include "network.h"
#include "networkconst.h"
-#include "storenetwork.h"
#include "display.h"
#include "remoteconfig.h"
#include "remoteconfigparams.h"
-#include "storeremoteconfig.h"
#include "firmwareversion.h"
#include "software_version.h"
@@ -49,71 +47,76 @@ void Hardware::RebootHandler() {
}
int main(void) {
- rcu_periph_clock_enable(KEY_BOOTLOADER_TFTP_RCU_GPIOx);
-#if !defined (GD32F4XX)
- rcu_periph_clock_enable(RCU_AF);
- rcu_periph_clock_enable(KEY_BOOTLOADER_TFTP_RCU_GPIOx);
- gpio_init(KEY_BOOTLOADER_TFTP_GPIOx, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, KEY_BOOTLOADER_TFTP_GPIO_PINx);
-#else
+ rcu_periph_clock_enable(KEY_BOOTLOADER_TFTP_RCU_GPIOx);
+#if defined (GD32F4XX) || defined (GD32H7XX)
rcu_periph_clock_enable(RCU_PMU);
+# if defined (GD32F4XX)
pmu_backup_ldo_config(PMU_BLDOON_ON);
+# endif
rcu_periph_clock_enable(RCU_BKPSRAM);
pmu_backup_write_enable();
- gpio_af_set(KEY_BOOTLOADER_TFTP_GPIOx, GPIO_AF_0, KEY_BOOTLOADER_TFTP_GPIO_PINx);
- gpio_mode_set(KEY_BOOTLOADER_TFTP_GPIOx, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY_BOOTLOADER_TFTP_GPIO_PINx);
+ gpio_mode_set(KEY_BOOTLOADER_TFTP_GPIOx, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY_BOOTLOADER_TFTP_GPIO_PINx);
+#else
+ rcu_periph_clock_enable(RCU_AF);
+ rcu_periph_clock_enable(KEY_BOOTLOADER_TFTP_RCU_GPIOx);
+ if constexpr (KEY_BOOTLOADER_TFTP_GPIOx == GPIOA) {
+ if constexpr ((KEY_BOOTLOADER_TFTP_GPIO_PINx == GPIO_PIN_13) || (KEY_BOOTLOADER_TFTP_GPIO_PINx == GPIO_PIN_14)) {
+ gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
+ }
+ }
+ gpio_init(KEY_BOOTLOADER_TFTP_GPIOx, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, KEY_BOOTLOADER_TFTP_GPIO_PINx);
#endif
- if ((bkp_data_read(BKP_DATA_1) != 0xA5A5) && (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx))) {
- // https://developer.arm.com/documentation/ka001423/1-0
- //1. Disable interrupt response.
- __disable_irq();
- //2. Disable all enabled interrupts in NVIC.
- memset((uint32_t *)NVIC->ICER, 0xFF, sizeof(NVIC->ICER));
- /* 3. Disable all enabled peripherals which might generate interrupt requests.
- * Clear all pending interrupt flags in those peripherals.
- * This part is device-dependent, and you can write it by referring to device datasheet.
- */
-
- /* Clear all pending interrupt requests in NVIC. */
- memset((uint32_t *)NVIC->ICPR, 0xFF, sizeof(NVIC->ICPR));
- // 4. Disable SysTick and clear its exception pending bit.
- SysTick->CTRL = 0;
- SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;
- // 5. Load the vector table address of user application code in to VTOR.
- SCB->VTOR = FLASH_BASE + OFFSET_UIMAGE;
- // 6. Use the MSP as the current SP.
- // Set the MSP with the value from the vector table used by the application.
- __set_MSP( ((unsigned int *)(SCB->VTOR))[0] );
- // In thread mode, enable privileged access and use the MSP as the current SP.
- __set_CONTROL( 0 );
- // 7. Enable interrupts.
- __enable_irq();
- // 8. Call the reset handler
- const uint32_t* reset_p = (uint32_t *)(FLASH_BASE + OFFSET_UIMAGE + 4);
- asm volatile ("bx %0;" : : "r"(*reset_p));
- }
+ const auto isNotRemote = (bkp_data_read(BKP_DATA_1) != 0xA5A5);
+ const auto isNotKey = (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx));
+
+ if (isNotRemote && isNotKey) {
+ // https://developer.arm.com/documentation/ka001423/1-0
+ //1. Disable interrupt response.
+ __disable_irq();
+ //2. Disable all enabled interrupts in NVIC.
+ memset((uint32_t *)NVIC->ICER, 0xFF, sizeof(NVIC->ICER));
+ /* 3. Disable all enabled peripherals which might generate interrupt requests.
+ * Clear all pending interrupt flags in those peripherals.
+ * This part is device-dependent, and you can write it by referring to device datasheet.
+ */
+
+ /* Clear all pending interrupt requests in NVIC. */
+ memset((uint32_t *)NVIC->ICPR, 0xFF, sizeof(NVIC->ICPR));
+ // 4. Disable SysTick and clear its exception pending bit.
+ SysTick->CTRL = 0;
+ SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;
+ // 5. Load the vector table address of user application code in to VTOR.
+ SCB->VTOR = FLASH_BASE + OFFSET_UIMAGE;
+ // 6. Use the MSP as the current SP.
+ // Set the MSP with the value from the vector table used by the application.
+ __set_MSP( ((unsigned int *)(SCB->VTOR))[0] );
+ // In thread mode, enable privileged access and use the MSP as the current SP.
+ __set_CONTROL( 0 );
+ // 7. Enable interrupts.
+ __enable_irq();
+ // 8. Call the reset handler
+ const uint32_t* reset_p = (uint32_t *)(FLASH_BASE + OFFSET_UIMAGE + 4);
+ asm volatile ("bx %0;" : : "r"(*reset_p));
+ }
Hardware hw;
Display display(4);
ConfigStore configStore;
- StoreNetwork storeNetwork;
- Network nw(&storeNetwork);
+ Network nw;
FirmwareVersion fw(SOFTWARE_VERSION, __DATE__, __TIME__);
FlashCodeInstall flashCodeInstall;
+ printf("Remote=%c, Key=%c\n", isNotRemote ? 'N' : 'Y', isNotKey ? 'N' : 'Y');
fw.Print("Bootloader TFTP Server");
- nw.Print();
hw.SetMode(hardware::ledblink::Mode::OFF_ON);
RemoteConfig remoteConfig(remoteconfig::Node::BOOTLOADER_TFTP, remoteconfig::Output::CONFIG);
- StoreRemoteConfig storeRemoteConfig;
- RemoteConfigParams remoteConfigParams(&storeRemoteConfig);
-
- if (remoteConfigParams.Load()) {
- remoteConfigParams.Set(&remoteConfig);
- }
+ RemoteConfigParams remoteConfigParams;
+ remoteConfigParams.Load();
+ remoteConfigParams.Set(&remoteConfig);
remoteConfig.SetEnableReboot(true);
diff --git a/bootloader-tftp/include/software_version.h b/bootloader-tftp/include/software_version.h
index 8c65b31..c515236 100644
--- a/bootloader-tftp/include/software_version.h
+++ b/bootloader-tftp/include/software_version.h
@@ -2,7 +2,7 @@
* @file software_version.h
*
*/
-/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,6 @@
#ifndef SOFTWARE_VERSION_H_
#define SOFTWARE_VERSION_H_
-constexpr char SOFTWARE_VERSION[] = "2.0";
+constexpr char SOFTWARE_VERSION[] = "2.1";
#endif /* SOFTWARE_VERSION_H_ */
diff --git a/bootloader-tftp/lib/networkdisplay.cpp b/bootloader-tftp/lib/networkdisplay.cpp
index 4c78934..c5021de 100644
--- a/bootloader-tftp/lib/networkdisplay.cpp
+++ b/bootloader-tftp/lib/networkdisplay.cpp
@@ -2,7 +2,7 @@
* @file networkdisplay.cpp
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -25,31 +25,36 @@
#include
-#include "network.h"
-
#include "display.h"
-#include "display7segment.h"
-namespace network {
+#include "network.h"
+#include "net/protocol/dhcp.h"
+
+namespace net {
static constexpr auto LINE_IP = 2U;
void display_emac_config() {
- Display::Get()->ClearEndOfLine();
- Display::Get()->Printf(LINE_IP, "Ethernet config");
+ Display::Get()->ClearLine(LINE_IP);
+ Display::Get()->PutString("Ethernet config");
}
void display_emac_start() {
- Display::Get()->ClearEndOfLine();
- Display::Get()->Printf(LINE_IP, "Ethernet start");
+ Display::Get()->ClearLine(LINE_IP);
+ Display::Get()->PutString("Ethernet start");
}
void display_emac_status(const bool isLinkUp) {
- Display::Get()->ClearEndOfLine();
- Display::Get()->Printf(LINE_IP, "Ethernet Link %s", isLinkUp ? "UP" : "DOWN");
+ Display::Get()->ClearLine(LINE_IP);
+ Display::Get()->PutString("Ethernet Link ");
+ if (isLinkUp) {
+ Display::Get()->PutString("UP");
+ } else {
+ Display::Get()->PutString("DOWN");
+ }
}
void display_ip() {
- Display::Get()->ClearEndOfLine();
+ Display::Get()->ClearLine(LINE_IP);
Display::Get()->Printf(LINE_IP, "" IPSTR "/%d %c", IP2STR(Network::Get()->GetIp()), Network::Get()->GetNetmaskCIDR(), Network::Get()->GetAddressingMode());
}
@@ -64,31 +69,27 @@ void display_hostname() {
}
void display_emac_shutdown() {
- Display::Get()->ClearEndOfLine();
+ Display::Get()->ClearLine(LINE_IP);
Display::Get()->PutString("Ethernet shutdown");
}
-void display_dhcp_status(network::dhcp::ClientStatus nStatus) {
+void display_dhcp_status(net::dhcp::State state) {
Display::Get()->ClearLine(LINE_IP);
- switch (nStatus) {
- case network::dhcp::ClientStatus::IDLE:
+ switch (state) {
+ case net::dhcp::State::STATE_OFF:
break;
- case network::dhcp::ClientStatus::RENEW:
+ case net::dhcp::State::STATE_RENEWING:
Display::Get()->PutString("DHCP renewing");
- Display::Get()->Status(Display7SegmentMessage::INFO_DHCP);
break;
- case network::dhcp::ClientStatus::GOT_IP:
+ case net::dhcp::State::STATE_BOUND:
Display::Get()->PutString("Got IP");
- Display::Get()->Status(Display7SegmentMessage::INFO_NONE);
break;
- case network::dhcp::ClientStatus::RETRYING:
- Display::Get()->PutString("DHCP retrying");
- Display::Get()->Status(Display7SegmentMessage::INFO_DHCP);
+ case net::dhcp::State::STATE_REQUESTING:
+ Display::Get()->PutString("DHCP requesting");
break;
- case network::dhcp::ClientStatus::FAILED:
+ case net::dhcp::State::STATE_BACKING_OFF:
Display::Get()->PutString("DHCP Error");
- Display::Get()->Status(Display7SegmentMessage::ERROR_DHCP);
break;
default:
break;
diff --git a/firmware-template-gd32/Board.mk b/firmware-template-gd32/Board.mk
new file mode 100644
index 0000000..bc44a93
--- /dev/null
+++ b/firmware-template-gd32/Board.mk
@@ -0,0 +1,108 @@
+$(info "Board.mk")
+
+ifndef BOARD
+ $(error BOARD is not set)
+endif
+
+ifndef DEFINES
+ DEFINES=
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F103RC)
+ MCU=GD32F103RC
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+ DEFINES+=-DNO_EMAC
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F107RC)
+ MCU=GD32F107RC
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F207RG)
+ MCU=GD32F207RG
+ DEFINES+=-DCONFIG_STORE_USE_SPI
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F207VC_2)
+ MCU=GD32F207VC
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+ BITBANGING595=1
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F207VC_4)
+ MCU=GD32F207VC
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+ BITBANGING595=1
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F303RC)
+ MCU=GD32F303RC
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+ DEFINES+=-DNO_EMAC
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F407RE)
+ MCU=GD32F407RE
+ DEFINES+=-DCONFIG_STORE_USE_SPI
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F450VE)
+ MCU=GD32F450VE
+ DEFINES+=-DCONFIG_STORE_USE_RAM
+ BITBANGING595=1
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F450VI)
+ MCU=GD32F450VI
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_16X4U_PIXEL)
+ MCU=GD32F450VI
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F470VG)
+ MCU=GD32F470VG
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F207C_EVAL)
+ MCU=GD32F207VC
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32F470Z_EVAL)
+ MCU=GD32F470ZK
+ DEFINES+=-DCONFIG_STORE_USE_RAM
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_GD32H759I_EVAL)
+ MCU=GD32H759IM
+ DEFINES+=-DCONFIG_STORE_USE_ROM
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_BW_OPIDMX4)
+ BOARD_DMX=4
+ DEFINES+=-DCONFIG_STORE_USE_SPI
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_DMX3)
+ BOARD_DMX=3
+ DEFINES+=-DCONFIG_STORE_USE_SPI
+endif
+
+ifeq ($(strip $(BOARD)),BOARD_DMX4)
+ DEFINES+=-DCONFIG_STORE_USE_SPI
+ BOARD_DMX=4
+endif
+
+ifdef BOARD_DMX
+ ifeq ($(MCU),GD32F207RG)
+ else ifeq ($(MCU),GD32F407RE)
+ else
+ $(error MCU is not support for BOARD_DMX)
+ endif
+endif
+
+ifndef MCU
+ $(error BOARD is not configured)
+endif
\ No newline at end of file
diff --git a/firmware-template-gd32/Includes.mk b/firmware-template-gd32/Includes.mk
index d13b7f0..71aadc0 100644
--- a/firmware-template-gd32/Includes.mk
+++ b/firmware-template-gd32/Includes.mk
@@ -1,8 +1,69 @@
-INCLUDES:= -I./include -I../include -I../lib-hal/include -I../lib-debug/include
-INCLUDES+=$(addprefix -I,$(EXTRA_INCLUDES))
+$(info "Includes.mk")
+
+INCLUDES:=-I./include -I../include
INCLUDES+=-I../firmware-template-gd32/include
INCLUDES+=-I../firmware-template-gd32/template
+INCLUDES+=-I../CMSIS/Core/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/${FAMILY_UC}_standard_peripheral/Include
-INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS/GD/${FAMILY_UC}/Include
-INCLUDES+=-I../lib-gd32/include
\ No newline at end of file
+INCLUDES+=-I../lib-gd32/include
+INCLUDES+=$(addprefix -I,$(EXTRA_INCLUDES))
+
+ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
+ USB_HOST=1
+endif
+ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
+ USB_HOST=1
+endif
+
+ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
+ USB_HOST_MSC=1
+endif
+ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
+ USB_HOST_MSC=1
+endif
+
+ifdef USB_HOST
+ INCLUDES+=-I../lib-gd32/device/usb
+ INCLUDES+=-I../lib-hal/device/usb/host/gd32
+endif
+
+ifeq ($(findstring gd32f20x,$(FAMILY)), gd32f20x)
+ ifdef USB_HOST
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/driver/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/host/core/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/ustd/common
+ ifdef USB_HOST_MSC
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/host/class/msc/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/ustd/class/msc
+ endif
+ endif
+endif
+
+ifeq ($(findstring gd32f4xx,$(FAMILY)), gd32f4xx)
+ ifdef USB_HOST
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/driver/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/host/core/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/ustd/common
+ ifdef USB_HOST_MSC
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/host/class/msc/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/ustd/class/msc
+ endif
+ endif
+endif
+
+ifeq ($(findstring gd32h7xx,$(FAMILY)), gd32h7xx)
+ ifdef USB_HOST
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32H7xx_usbhs_library/driver/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32H7xx_usbhs_library/host/core/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32H7xx_usbhs_library/ustd/common
+ ifdef USB_HOST_MSC
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32H7xx_usbhs_library/host/class/msc/Include
+ INCLUDES+=-I../lib-gd32/${FAMILY}/GD32H7xx_usbhs_library/ustd/class/msc
+ endif
+ endif
+endif
+
+ifdef USB_HOST_MSC
+ INCLUDES+=-I../lib-hal/ff14b/source
+endif
\ No newline at end of file
diff --git a/firmware-template-gd32/Mcu.mk b/firmware-template-gd32/Mcu.mk
new file mode 100644
index 0000000..46058e8
--- /dev/null
+++ b/firmware-template-gd32/Mcu.mk
@@ -0,0 +1,139 @@
+$(info "Mcu.mk")
+
+ifndef MCU
+ $(error MCU is not set)
+endif
+
+$(info $$MCU [${MCU}])
+
+# Extract upper and lower case versions of MCU name
+MCU_UC=$(shell echo $(MCU) | rev | cut -c3- | rev )
+MCU_LC=$(shell echo $(MCU_UC) | tr A-Z a-z )
+
+$(info $$MCU [${MCU}])
+$(info $$MCU_LC [${MCU_LC}])
+$(info $$MCU_UC [${MCU_UC}])
+
+# Set LINKER, FAMILY, and LINE based on MCU
+
+ifeq ($(strip $(MCU)),GD32F103RC)
+ LINKER=$(FIRMWARE_DIR)gd32f103rc_flash.ld
+ FAMILY=gd32f10x
+ LINE=gd32f10x_hd
+endif
+
+ifeq ($(strip $(MCU)),GD32F107RC)
+ LINKER=$(FIRMWARE_DIR)gd32f107rc_flash.ld
+ FAMILY=gd32f10x
+ LINE=gd32f10x_cl
+endif
+
+ifeq ($(strip $(MCU)),GD32F207VC)
+ LINKER=$(FIRMWARE_DIR)gd32f207vc_flash.ld
+ FAMILY=gd32f20x
+ LINE=gd32f20x_cl
+endif
+
+ifeq ($(strip $(MCU)),GD32F207RG)
+ LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld
+ FAMILY=gd32f20x
+ LINE=gd32f20x_cl
+endif
+
+ifeq ($(strip $(MCU)),GD32F303RC)
+ LINKER=$(FIRMWARE_DIR)gd32f303rc_flash.ld
+ FAMILY=gd32f30x
+ LINE=gd32f30x_hd
+endif
+
+ifeq ($(strip $(MCU)),GD32F407RE)
+ LINKER=$(FIRMWARE_DIR)gd32f407re_flash.ld
+ FAMILY=gd32f4xx
+ LINE=gd32f407
+endif
+
+ifeq ($(strip $(MCU)),GD32F450VE)
+ LINKER=$(FIRMWARE_DIR)gd32f450ve_flash.ld
+ FAMILY=gd32f4xx
+ LINE=gd32f450
+endif
+
+ifeq ($(strip $(MCU)),GD32F450VI)
+ LINKER=$(FIRMWARE_DIR)gd32f450vi_flash.ld
+ FAMILY=gd32f4xx
+ LINE=gd32f450
+endif
+
+ifeq ($(strip $(MCU)),GD32F470VG)
+ LINKER=$(FIRMWARE_DIR)gd32f470vg_flash.ld
+ FAMILY=gd32f4xx
+ LINE=gd32f470
+endif
+
+ifeq ($(strip $(MCU)),GD32F470ZK)
+ LINKER=$(FIRMWARE_DIR)gd32f470zk_flash.ld
+ FAMILY=gd32f4xx
+ LINE=gd32f470
+endif
+
+ifeq ($(strip $(MCU)),GD32H759IM)
+ LINKER=$(FIRMWARE_DIR)gd32h7xx_xM_flash.ld
+ FAMILY=gd32h7xx
+ LINE=gd32h759
+endif
+
+ifndef LINKER
+ $(error MCU is not configured)
+endif
+
+# Common ARM options for Cortex-M3
+ARMOPS_CM3=-mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+
+# Common ARM options for Cortex-M4
+ARMOPS_CM4=-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant
+
+# Common ARM options for Cortex-M7
+ARMOPS_CM7=-mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -fsingle-precision-constant
+
+# CMSIS options for FPU present
+CMSISOPS_FPU_PRESENT = -D__FPU_PRESENT=1 -DARM_MATH_CM4
+
+# Common CMSIS options
+CMSISOPS=-D__Vendor_SysTickConfig=0
+
+# Set ARM options and CMSIS options based on FAMILY
+
+ifeq ($(FAMILY),gd32f10x)
+ ARMOPS=$(ARMOPS_CM3)
+endif
+
+ifeq ($(FAMILY),gd32f20x)
+ ARMOPS=$(ARMOPS_CM3)
+endif
+
+ifeq ($(FAMILY),gd32f30x)
+ ARMOPS=$(ARMOPS_CM4)
+ CMSISOPS+=$(CMSISOPS_FPU_PRESENT)
+endif
+
+ifeq ($(FAMILY),gd32f4xx)
+ ARMOPS=$(ARMOPS_CM4)
+ CMSISOPS+=$(CMSISOPS_FPU_PRESENT)
+endif
+
+ifeq ($(FAMILY),gd32h7xx)
+ ARMOPS=$(ARMOPS_CM7)
+ CMSISOPS+=-D__FPU_PRESENT=1 -DARM_MATH_CM7
+endif
+
+FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)
+FAMILY_UCA=$(shell echo $(FAMILY) | tr a-z A-Z)
+LINE_UC=$(shell echo $(LINE) | tr a-z A-Z)
+
+
+$(info $$FAMILY [${FAMILY}])
+$(info $$FAMILY_UC [${FAMILY_UC}])
+$(info $$FAMILY_UCA [${FAMILY_UCA}])
+
+$(info $$LINE [${LINE}])
+$(info $$LINE_UC [${LINE_UC}])
\ No newline at end of file
diff --git a/firmware-template-gd32/Rules.mk b/firmware-template-gd32/Rules.mk
index 8e4ef00..67b7dad 100644
--- a/firmware-template-gd32/Rules.mk
+++ b/firmware-template-gd32/Rules.mk
@@ -1,3 +1,5 @@
+$(info "Rules.mk")
+
PREFIX ?= arm-none-eabi-
CC = $(PREFIX)gcc
@@ -6,40 +8,26 @@ AS = $(CC)
LD = $(PREFIX)ld
AR = $(PREFIX)ar
-FAMILY?=gd32f20x
BOARD?=BOARD_GD32F207C_EVAL
+ENET_PHY?=DP83848
-FAMILY:=$(shell echo $(FAMILY) | tr A-Z a-z)
-FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)
-
-$(info $$FAMILY [${FAMILY}])
-$(info $$FAMILY_UC [${FAMILY_UC}])
-
-# Output
-TARGET=$(FAMILY).bin
+TARGET=gd32f207.bin
LIST=$(FAMILY).list
MAP=$(FAMILY).map
+SIZE=$(FAMILY).size
BUILD=build_gd32/
-# Input
-SOURCE=./
FIRMWARE_DIR=./../firmware-template-gd32/
-ifeq ($(strip $(BOARD)),BOARD_GD32F207C_EVAL)
- LINKER=$(FIRMWARE_DIR)gd32f207vc_flash.ld
-else
- LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld
-endif
-
-include ../firmware-template/libs.mk
-LIBS+=c++ c gd32
-
-$(info [${LIBS}])
-
DEFINES:=$(addprefix -D,$(DEFINES))
-DEFINES+=-DCONFIG_STORE_USE_ROM
+include ../firmware-template-gd32/Board.mk
+include ../firmware-template-gd32/Mcu.mk
+include ../firmware-template/libs.mk
include ../firmware-template-gd32/Includes.mk
+include ../firmware-template-gd32/Validate.mk
+
+LIBS+=gd32 clib
# The variable for the libraries include directory
LIBINCDIRS:=$(addprefix -I../lib-,$(LIBS))
@@ -49,33 +37,32 @@ LIBINCDIRS+=$(addsuffix /include, $(LIBINCDIRS))
LIBGD32=$(addprefix -L../lib-,$(LIBS))
LIBGD32:=$(addsuffix /lib_gd32, $(LIBGD32))
-# The variable for the ld -l flag
+# The variable for the ld -l flag
LDLIBS:=$(addprefix -l,$(LIBS))
-# The variables for the dependency check
+# The variables for the dependency check
LIBDEP=$(addprefix ../lib-,$(LIBS))
-$(info $$LIBDEP [${LIBDEP}])
-
-COPS=-DBARE_METAL -DGD32 -DGD32F20X_CL -D$(BOARD)
-COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES)
-COPS+=$(LIBINCDIRS)
-COPS+=-Os -mcpu=cortex-m3 -mthumb
-COPS+=-nostartfiles -ffreestanding -nostdlib
+COPS=-DGD32 -D$(FAMILY_UCA) -D$(LINE_UC) -D$(MCU) -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
+COPS+=$(strip $(DEFINES) $(MAKE_FLAGS) $(INCLUDES) $(LIBINCDIRS))
+COPS+=$(strip $(ARMOPS) $(CMSISOPS))
+COPS+=-Os -nostartfiles -ffreestanding -nostdlib
COPS+=-fstack-usage
-COPS+=-Wstack-usage=1024
COPS+=-ffunction-sections -fdata-sections
+COPS+=-Wall -Werror -Wpedantic -Wextra -Wunused -Wsign-conversion -Wconversion -Wduplicated-cond -Wlogical-op
-CPPOPS=-std=c++11
+CPPOPS=-std=c++20
CPPOPS+=-Wnon-virtual-dtor -Woverloaded-virtual -Wnull-dereference -fno-rtti -fno-exceptions -fno-unwind-tables
-#CPPOPS+=-Wuseless-cast -Wold-style-cast
+CPPOPS+=-Wuseless-cast -Wold-style-cast
CPPOPS+=-fno-threadsafe-statics
-LDOPS=--gc-sections --print-gc-sections
+LDOPS=--gc-sections --print-gc-sections --print-memory-usage
PLATFORM_LIBGCC+= -L $(shell dirname `$(CC) $(COPS) -print-libgcc-file-name`)
+PLATFORM_LIBC+= -L $(shell dirname `$(CC) $(COPS) --print-file-name=libc.a`)
$(info $$PLATFORM_LIBGCC [${PLATFORM_LIBGCC}])
+$(info $$PLATFORM_LIBC [${PLATFORM_LIBC}])
C_OBJECTS=$(foreach sdir,$(SRCDIR),$(patsubst $(sdir)/%.c,$(BUILD)$(sdir)/%.o,$(wildcard $(sdir)/*.c)))
C_OBJECTS+=$(foreach sdir,$(SRCDIR),$(patsubst $(sdir)/%.cpp,$(BUILD)$(sdir)/%.o,$(wildcard $(sdir)/*.cpp)))
@@ -86,19 +73,18 @@ BUILD_DIRS:=$(addprefix $(BUILD),$(SRCDIR))
OBJECTS:=$(ASM_OBJECTS) $(C_OBJECTS)
define compile-objects
-$(BUILD)$1/%.o: $(SOURCE)$1/%.cpp
- $(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
+$(BUILD)$1/%.o: $1/%.cpp
+ $(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
-$(BUILD)$1/%.o: $(SOURCE)$1/%.c
+$(BUILD)$1/%.o: $1/%.c
$(CC) $(COPS) -c $$< -o $$@
-
-$(BUILD)$1/%.o: $(SOURCE)$1/%.S
+
+$(BUILD)$1/%.o: $1/%.S
$(CC) $(COPS) -D__ASSEMBLY__ -c $$< -o $$@
endef
-
all : builddirs prerequisites $(TARGET)
-
+
.PHONY: clean builddirs
builddirs:
@@ -121,22 +107,27 @@ clean: $(LIBDEP)
lisdep: $(LIBDEP)
$(LIBDEP):
- $(MAKE) -f Makefile.GD32 $(MAKECMDGOALS) 'FAMILY=${FAMILY}' 'BOARD=${BOARD}' 'MAKE_FLAGS=$(DEFINES)' -C $@
+ $(MAKE) -f Makefile.GD32 $(MAKECMDGOALS) 'FAMILY=${FAMILY}' 'BOARD=${BOARD}' 'ENET_PHY=${ENET_PHY}' 'MAKE_FLAGS=$(DEFINES)' -C $@
-# Build uImage
+#
+# Build bin
+#
$(BUILD_DIRS) :
mkdir -p $(BUILD_DIRS)
-$(BUILD)startup_$(FAMILY)_cl.o : $(FIRMWARE_DIR)/startup_$(FAMILY)_cl.S
- $(AS) $(COPS) -D__ASSEMBLY__ -c $(FIRMWARE_DIR)/startup_$(FAMILY)_cl.S -o $(BUILD)startup_$(FAMILY)_cl.o
-
-$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(FAMILY)_cl.o $(OBJECTS) $(LIBDEP)
- $(LD) $(BUILD)startup_$(FAMILY)_cl.o $(OBJECTS) -Map $(MAP) -T $(LINKER) $(LDOPS) -o $(BUILD)main.elf $(LIBGD32) $(LDLIBS) $(PLATFORM_LIBGCC) -lgcc
+$(BUILD)startup_$(LINE).o : $(FIRMWARE_DIR)/startup_$(LINE).S
+ $(AS) $(COPS) -D__ASSEMBLY__ -c $(FIRMWARE_DIR)/startup_$(LINE).S -o $(BUILD)startup_$(LINE).o
+
+$(BUILD)hardfault_handler.o : $(FIRMWARE_DIR)/hardfault_handler.c
+ $(CC) $(COPS) -c $(FIRMWARE_DIR)/hardfault_handler.c -o $(BUILD)hardfault_handler.o
+
+$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(LINE).o $(BUILD)hardfault_handler.o $(OBJECTS) $(LIBDEP)
+ $(LD) $(BUILD)startup_$(LINE).o $(BUILD)hardfault_handler.o $(OBJECTS) -Map $(MAP) -T $(LINKER) $(LDOPS) -o $(BUILD)main.elf $(LIBGD32) $(LDLIBS) $(PLATFORM_LIBGCC) -lgcc
$(PREFIX)objdump -D $(BUILD)main.elf | $(PREFIX)c++filt > $(LIST)
$(PREFIX)size -A -x $(BUILD)main.elf
-$(TARGET) : $(BUILD)main.elf
- $(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET)
-
-$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
\ No newline at end of file
+$(TARGET) : $(BUILD)main.elf
+ $(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET) --remove-section=.tcmsram* --remove-section=.sram1* --remove-section=.sram2* --remove-section=.ramadd* --remove-section=.bkpsram*
+
+$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
diff --git a/firmware-template-gd32/Validate.mk b/firmware-template-gd32/Validate.mk
new file mode 100644
index 0000000..9531da3
--- /dev/null
+++ b/firmware-template-gd32/Validate.mk
@@ -0,0 +1,33 @@
+$(info "Validate.mk")
+$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
+$(info $$DEFINES [${DEFINES}])
+
+FLAGS:=$(MAKE_FLAGS)
+ifeq ($(FLAGS),)
+ FLAGS:=$(DEFINES)
+endif
+
+ifneq (,$(findstring OUTPUT_DMX_SEND,$(FLAGS))$(findstring CONFIG_RDM,$(FLAGS))$(findstring RDM_CONTROLLER,$(FLAGS))$(findstring LTC,$(FLAGS)))
+ TIMER6_HAVE_IRQ_HANDLER=1
+ ifneq (,$(findstring CONFIG_TIMER6_HAVE_NO_IRQ_HANDLER,$(MAKE_FLAGS)))
+ $(error CONFIG_TIMER6_HAVE_NO_IRQ_HANDLER is set)
+ endif
+endif
+
+ifndef TIMER6_HAVE_IRQ_HANDLER
+ DEFINES+=-DCONFIG_TIMER6_HAVE_NO_IRQ_HANDLER
+endif
+
+ifneq ($(findstring USE_FREE_RTOS,$(FLAGS)),USE_FREE_RTOS)
+ DEFINES+=-DCONFIG_HAL_USE_SYSTICK
+else
+ DEFINES+=-DCONFIG_HAL_USE_SYSTICK # Temporarily need to fix TIMER10
+endif
+
+ifeq ($(findstring ENABLE_TFTP_SERVER,$(FLAGS)),ENABLE_TFTP_SERVER)
+ ifneq ($(findstring CONFIG_HAL_USE_SYSTICK,$(FLAGS)),CONFIG_HAL_USE_SYSTICK)
+ DEFINES+=-DCONFIG_HAL_USE_SYSTICK
+ endif
+endif
+
+$(info $$DEFINES [${DEFINES}])
diff --git a/firmware-template-gd32/calculate_unused_ram.sh b/firmware-template-gd32/calculate_unused_ram.sh
deleted file mode 100755
index c00d2a8..0000000
--- a/firmware-template-gd32/calculate_unused_ram.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-
-if [ $# -lt 2 ]; then
- echo "Usage: $0 "
- exit 1
-fi
-
-size_file="$1"
-linker_script="$2"
-
-used_stack=$(grep ".stack" "$size_file" | awk '{print $2}')
-used_heap=$(grep ".heap" "$size_file" | awk '{print $2}')
-used_data=$(grep '.data' "$size_file" | tail -n 1 | awk '{print $2}')
-used_bss=$(grep ".bss" "$size_file" | awk '{print $2}')
-
-total_ram=$(grep "RAM (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
-unused_ram=$(( $(echo $total_ram) - $(echo $used_stack) - $(echo $used_heap) - $(echo $used_data) - $(echo $used_bss) ))
-
-cat $1
-echo "Available RAM: $total_ram bytes"
-echo "Unused RAM: $unused_ram bytes"
\ No newline at end of file
diff --git a/firmware-template-gd32/gd32f207vc_flash.ld b/firmware-template-gd32/gd32f207vc_flash.ld
index 35f53d5..6e0a581 100644
--- a/firmware-template-gd32/gd32f207vc_flash.ld
+++ b/firmware-template-gd32/gd32f207vc_flash.ld
@@ -8,7 +8,7 @@ ENTRY(Reset_Handler)
SECTIONS
{
- __heap_size = DEFINED(__heap_size) ? __heap_size : 1K;
+ __heap_size = DEFINED(__heap_size) ? __heap_size : 2K;
__stack_size = DEFINED(__stack_size) ? __stack_size : 2K;
.vectors :
@@ -23,8 +23,8 @@ SECTIONS
.text :
{
. = ALIGN(4);
- *(.text.unlikely*)
- *(.text.hot*)
+ *(.text.unlikely*)
+ *(.text.hot*)
*(.text)
*(.text*)
*(.glue_7)
@@ -35,7 +35,7 @@ SECTIONS
. = ALIGN(4);
_etext = .;
} >FLASH
-
+
.rodata :
{
. = ALIGN(4);
@@ -43,14 +43,14 @@ SECTIONS
*(.rodata*)
. = ALIGN(4);
} >FLASH
-
+
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
-
+
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
@@ -58,7 +58,7 @@ SECTIONS
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
-
+
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
@@ -74,16 +74,7 @@ SECTIONS
. = __stack_size;
PROVIDE( _sp = . );
. = ALIGN(4);
- } >RAM AT>RAM
-
- .heap :
- {
- . = ALIGN(4);
- heap_low = .;
- . = . + __heap_size;
- heap_top = .;
- . = ALIGN(4);
- } >RAM AT>RAM
+ } >RAM
_sidata = LOADADDR(.data);
.data :
@@ -95,6 +86,16 @@ SECTIONS
. = ALIGN(4);
_edata = .;
} >RAM AT> FLASH
+
+ .ram :
+ {
+ . = ALIGN(4);
+ _snetwork = .;
+ *(.network*)
+ . = ALIGN(4);
+ _enetwork = .;
+ . = ALIGN(4);
+ } >RAM
. = ALIGN(4);
.bss :
@@ -109,9 +110,18 @@ SECTIONS
__bss_end__ = _ebss;
} >RAM
- . = ALIGN(8);
+ . = ALIGN(8);
PROVIDE ( end = _ebss );
PROVIDE ( _end = _ebss );
+
+ .heap :
+ {
+ . = ALIGN(4);
+ heap_low = .;
+ . = . + __heap_size;
+ heap_top = .;
+ . = ALIGN(4);
+ } >RAM
/DISCARD/ :
{
@@ -121,5 +131,4 @@ SECTIONS
}
}
- /* input sections */
-GROUP(libgcc.a libc.a)
\ No newline at end of file
+GROUP(libgcc.a)
diff --git a/firmware-template-gd32/hardfault_handler.c b/firmware-template-gd32/hardfault_handler.c
new file mode 100644
index 0000000..039d1f9
--- /dev/null
+++ b/firmware-template-gd32/hardfault_handler.c
@@ -0,0 +1,77 @@
+/*
+ * hardfault_handler.c
+ */
+/**
+ * Using Cortex-M3/M4/M7 Fault Exceptions
+ * MDK Tutorial
+ * AN209, Summer 2017, V 5.0
+ */
+
+#include
+
+#include "gd32.h"
+
+void HardFault_Handler() {
+ __asm volatile(
+ "TST LR, #4\n"
+ "ITE EQ\n"
+ "MRSEQ R0, MSP\n"
+ "MRSNE R0, PSP\n"
+ "MOV R1, LR\n"
+ "B hardfault_handler\n"
+ );
+}
+
+void hardfault_handler(unsigned long *hardfault_args, unsigned int lr_value) {
+ unsigned long stacked_r0;
+ unsigned long stacked_r1;
+ unsigned long stacked_r2;
+ unsigned long stacked_r3;
+ unsigned long stacked_r12;
+ unsigned long stacked_lr;
+ unsigned long stacked_pc;
+ unsigned long stacked_psr;
+ unsigned long cfsr;
+ unsigned long bus_fault_address;
+ unsigned long memmanage_fault_address;
+
+ bus_fault_address = SCB->BFAR;
+ memmanage_fault_address = SCB->MMFAR;
+ cfsr = SCB->CFSR;
+
+ stacked_r0 = ((unsigned long) hardfault_args[0]);
+ stacked_r1 = ((unsigned long) hardfault_args[1]);
+ stacked_r2 = ((unsigned long) hardfault_args[2]);
+ stacked_r3 = ((unsigned long) hardfault_args[3]);
+ stacked_r12 = ((unsigned long) hardfault_args[4]);
+ stacked_lr = ((unsigned long) hardfault_args[5]);
+ stacked_pc = ((unsigned long) hardfault_args[6]);
+ stacked_psr = ((unsigned long) hardfault_args[7]);
+
+ printf("[HardFault]\n");
+ printf("- Stack frame:\n");
+ printf(" R0 = %x\n", (unsigned int) stacked_r0);
+ printf(" R1 = %x\n", (unsigned int) stacked_r1);
+ printf(" R2 = %x\n", (unsigned int) stacked_r2);
+ printf(" R3 = %x\n", (unsigned int) stacked_r3);
+ printf(" R12 = %x\n", (unsigned int) stacked_r12);
+ printf(" LR = %x\n", (unsigned int) stacked_lr);
+ printf(" PC = %x\n", (unsigned int) stacked_pc);
+ printf(" PSR = %x\n", (unsigned int) stacked_psr);
+ printf("- FSR/FAR:\n");
+ printf(" CFSR = %x\n", (unsigned int) cfsr);
+ printf(" HFSR = %x\n", (unsigned int) SCB->HFSR);
+ printf(" DFSR = %x\n", (unsigned int) SCB->DFSR);
+ printf(" AFSR = %x\n", (unsigned int) SCB->AFSR);
+ if (cfsr & 0x0080) {
+ printf(" MMFAR = %x\n", (unsigned int) memmanage_fault_address);
+ }
+ if (cfsr & 0x8000) {
+ printf(" BFAR = %x\n", (unsigned int) bus_fault_address);
+ }
+ printf("- Misc\n");
+ printf(" LR/EXC_RETURN= %x\n", lr_value);
+
+ while (1)
+ ;
+}
diff --git a/firmware-template-gd32/lib/Rules.mk b/firmware-template-gd32/lib/Rules.mk
index 0b32a1a..3f2b9a2 100644
--- a/firmware-template-gd32/lib/Rules.mk
+++ b/firmware-template-gd32/lib/Rules.mk
@@ -1,3 +1,6 @@
+$(info "lib/Rules.mk")
+$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
+
PREFIX ?= arm-none-eabi-
CC = $(PREFIX)gcc
@@ -6,39 +9,37 @@ AS = $(CC)
LD = $(PREFIX)ld
AR = $(PREFIX)ar
-FAMILY?=gd32f20x
BOARD?=BOARD_GD32F207C_EVAL
+ENET_PHY?=DP83848
-FAMILY:=$(shell echo $(FAMILY) | tr A-Z a-z)
-FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)
+$(info $$BOARD [${BOARD}])
+$(info $$ENET_PHY [${ENET_PHY}])
-$(info $$FAMILY [${FAMILY}])
-$(info $$FAMILY_UC [${FAMILY_UC}])
+SRCDIR=src src/gd32 $(EXTRA_SRCDIR)
-SRCDIR = src src/gd32 $(EXTRA_SRCDIR)
+DEFINES:=$(addprefix -D,$(DEFINES))
+DEFINES+=-D_TIME_STAMP_YEAR_=$(shell date +"%Y") -D_TIME_STAMP_MONTH_=$(shell date +"%-m") -D_TIME_STAMP_DAY_=$(shell date +"%-d")
+include ../firmware-template-gd32/Board.mk
+include ../firmware-template-gd32/Mcu.mk
include ../firmware-template-gd32/Includes.mk
+include ../firmware-template-gd32/Validate.mk
-DEFINES:=$(addprefix -D,$(DEFINES))
-DEFINES+=-D_TIME_STAMP_YEAR_=$(shell date +"%Y") -D_TIME_STAMP_MONTH_=$(shell date +"%-m") -D_TIME_STAMP_DAY_=$(shell date +"%-d")
-DEFINES+=-DCONFIG_STORE_USE_ROM
+INCLUDES+=-I../lib-configstore/include -I../lib-display/include -I../lib-flashcode/include -I../lib-hal/include -I../lib-network/include
-COPS=-DBARE_METAL -DGD32 -DGD32F20X_CL -D$(BOARD)
-COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES)
-COPS+=-Os -mcpu=cortex-m3 -mthumb
-COPS+=-nostartfiles -ffreestanding -nostdlib
+COPS=-DGD32 -D$(FAMILY_UCA) -D$(LINE_UC) -D$(MCU) -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
+COPS+=$(strip $(DEFINES)) $(MAKE_FLAGS) $(INCLUDES)
+COPS+=$(strip $(ARMOPS) $(CMSISOPS))
+COPS+=-Os -nostartfiles -ffreestanding -nostdlib
COPS+=-fstack-usage
-COPS+=-Wstack-usage=1024
COPS+=-ffunction-sections -fdata-sections
+COPS+=-Wall -Werror -Wpedantic -Wextra -Wunused -Wsign-conversion -Wconversion -Wduplicated-cond -Wlogical-op
-CPPOPS=-std=c++11
+CPPOPS=-std=c++20
CPPOPS+=-Wnon-virtual-dtor -Woverloaded-virtual -Wnull-dereference -fno-rtti -fno-exceptions -fno-unwind-tables
-#CPPOPS+=-Wuseless-cast -Wold-style-cast
+CPPOPS+=-Wuseless-cast -Wold-style-cast
CPPOPS+=-fno-threadsafe-statics
-CURR_DIR:=$(notdir $(patsubst %/,%,$(CURDIR)))
-LIB_NAME:=$(patsubst lib-%,%,$(CURR_DIR))
-
BUILD=build_gd32/
BUILD_DIRS:=$(addprefix build_gd32/,$(SRCDIR))
$(info $$BUILD_DIRS [${BUILD_DIRS}])
@@ -47,22 +48,31 @@ C_OBJECTS=$(foreach sdir,$(SRCDIR),$(patsubst $(sdir)/%.c,$(BUILD)$(sdir)/%.o,$(
CPP_OBJECTS=$(foreach sdir,$(SRCDIR),$(patsubst $(sdir)/%.cpp,$(BUILD)$(sdir)/%.o,$(wildcard $(sdir)/*.cpp)))
ASM_OBJECTS=$(foreach sdir,$(SRCDIR),$(patsubst $(sdir)/%.S,$(BUILD)$(sdir)/%.o,$(wildcard $(sdir)/*.S)))
-OBJECTS:=$(ASM_OBJECTS) $(C_OBJECTS) $(CPP_OBJECTS)
+EXTRA_C_OBJECTS=$(patsubst %.c,$(BUILD)%.o,$(EXTRA_C_SOURCE_FILES))
+EXTRA_C_DIRECTORIES=$(shell dirname $(EXTRA_C_SOURCE_FILES))
+EXTRA_BUILD_DIRS:=$(addsuffix $(EXTRA_C_DIRECTORIES), $(BUILD))
-TARGET=lib_gd32/lib$(LIB_NAME).a
-$(info $$TARGET [${TARGET}])
+OBJECTS:=$(strip $(ASM_OBJECTS) $(C_OBJECTS) $(CPP_OBJECTS) $(EXTRA_C_OBJECTS))
-LIST = lib.list
+CURR_DIR:=$(notdir $(patsubst %/,%,$(CURDIR)))
+LIB_NAME:=$(patsubst lib-%,%,$(CURR_DIR))
+TARGET=lib_gd32/lib$(LIB_NAME).a
+
+$(info $$DEFINES [${DEFINES}])
+$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
+$(info $$OBJECTS [${OBJECTS}])
+$(info $$TARGET [${TARGET}])
define compile-objects
+$(info $1)
$(BUILD)$1/%.o: $1/%.c
$(CC) $(COPS) -c $$< -o $$@
$(BUILD)$1/%.o: $1/%.cpp
- $(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
+ $(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
$(BUILD)$1/%.o: $1/%.S
- $(CC) $(COPS) -D__ASSEMBLY__ -c $$< -o $$@
+ $(CC) $(COPS) -D__ASSEMBLY__ -c $$< -o $$@
endef
all : builddirs $(TARGET)
@@ -71,18 +81,22 @@ all : builddirs $(TARGET)
builddirs:
mkdir -p $(BUILD_DIRS)
+ mkdir -p $(EXTRA_BUILD_DIRS)
mkdir -p lib_gd32
clean:
rm -rf build_gd32
rm -rf lib_gd32
+$(BUILD)%.o: %.c
+ $(CC) $(COPS) -c $< -o $@
+
$(BUILD_DIRS) :
mkdir -p $(BUILD_DIRS)
mkdir -p lib_gd32
$(TARGET): Makefile.GD32 $(OBJECTS)
$(AR) -r $(TARGET) $(OBJECTS)
- $(PREFIX)objdump -d $(TARGET) | $(PREFIX)c++filt > lib_gd32/$(LIST)
+ $(PREFIX)objdump -d $(TARGET) | $(PREFIX)c++filt > lib_gd32/lib.list
$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
\ No newline at end of file
diff --git a/firmware-template-gd32/startup_gd32f20x_cl.S b/firmware-template-gd32/startup_gd32f20x_cl.S
index 0e78b9e..fd84383 100644
--- a/firmware-template-gd32/startup_gd32f20x_cl.S
+++ b/firmware-template-gd32/startup_gd32f20x_cl.S
@@ -1,3 +1,28 @@
+/**
+ * @file startup_gd32f20x_cl.S
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
.syntax unified
.cpu cortex-m3
.fpu softvfp
@@ -5,55 +30,64 @@
.global Default_Handler
-.word _sidata
+/* Necessary symbols defined in linker script to initialize data */
.word _sdata
+.word _sidata
.word _edata
.word _sbss
.word _ebss
-.section .text.Reset_Handler
+.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
- movs r1, #0
- b DataInit
-
+/* Copy .data section from FLASH to RAM */
CopyData:
- ldr r3, =_sidata
- ldr r3, [r3, r1]
- str r3, [r0, r1]
- adds r1, r1, #4
-
-DataInit:
- ldr r0, =_sdata
- ldr r3, =_edata
- adds r2, r0, r1
- cmp r2, r3
- bcc CopyData
- ldr r2, =_sbss
- b Zerobss
-FillZerobss:
- movs r3, #0
- str r3, [r2], #4
-
-Zerobss:
- ldr r3, = _ebss
- cmp r2, r3
- bcc FillZerobss
- #if defined (DEBUG_STACK)
- bl stack_debug_init
- #endif
+ ldr r1, =_sdata /* Load the start address of .data section (RAM) into r1 */
+ ldr r2, =_sidata /* Load the start address of .data section (FLASH) into r2 */
+ ldr r3, =_edata /* Load the end address of .data section (RAM) into r3 */
+ subs r3, r3, r1 /* Calculate the size of .data section by subtracting start from end */
+ beq ZeroBSS /* If size is zero, jump to ZeroBSS */
+CopyDataLoop:
+ ldrb r4, [r2], #1 /* Load a byte from Flash (source), post-increment r2 by 1 */
+ strb r4, [r1], #1 /* Store the byte to RAM (destination), post-increment r1 by 1 */
+ subs r3, r3, #1 /* Decrement the remaining byte count by 1 */
+ bgt CopyDataLoop /* If there are still bytes left, continue looping */
+/* Initialize .bss section to zero */
+ZeroBSS:
+ ldr r2, =_sbss /* Load the start address of the .bss section */
+ ldr r3, =_ebss /* Load the end address of the .bss section */
+ sub r3, r3, r2 /* Calculate bytes count (r3 = (end - start) */
+ mov r4, #0 /* Load zero into r4 */
+ZeroBSSLoop:
+ str r4, [r2], #4 /* Store zero to memory location, increment address */
+ subs r3, r3, #4 /* Subtract 4 bytes from the remaining byte count */
+ bgt ZeroBSSLoop /* If there are still bytes left, continue looping */
+/* Call stack_debug_init function if in debug mode */
+#if defined (DEBUG_STACK)
+ bl stack_debug_init /* Branch to stack_debug_init if DEBUG_STACK is defined */
+#endif
+/* Call SystemInit function to perform system-specific initialization */
bl SystemInit
+/* Call static constructors to initialize global objects */
+ bl __libc_init_array
+/* Call the main function to start the application */
bl main
+/* Return from main (in case main returns) */
bx lr
+/* NOP to align the code (optional) */
+ nop /* No operation; used for code alignment and readability */
+
.size Reset_Handler, .-Reset_Handler
.section .text.Default_Handler,"ax",%progbits
+
Default_Handler:
Infinite_Loop:
b Infinite_Loop
- .size Default_Handler, .-Default_Handler
+
+.size Default_Handler, .-Default_Handler
.section .vectors,"a",%progbits
.global __gVectors
@@ -75,7 +109,6 @@ __gVectors:
.word 0 /* Reserved */
.word PendSV_Handler /* 14:PendSV Handler */
.word SysTick_Handler /* 15:SysTick Handler */
-
/* External Interrupts */
.word WWDGT_IRQHandler /*16,Window Watchdog Timer*/
.word LVD_IRQHandler /*17,LVD through EXTI Line detect */
@@ -170,6 +203,12 @@ __gVectors:
.size __gVectors, . - __gVectors
+/*******************************************************************************
+* Provide weak aliases for each Exception handler to the Default_Handler.
+* As they are weak aliases, any function with the same name will override
+* this definition.
+*******************************************************************************/
+
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
diff --git a/include/cstring b/include/cstring
index 998d93d..b32bea0 100644
--- a/include/cstring
+++ b/include/cstring
@@ -2,7 +2,7 @@
* @file cstring
*
*/
-/* Copyright (C) 2021 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +26,37 @@
#ifndef CSTRING_
#define CSTRING_
-#ifdef __cplusplus
-# include
-#endif
+#include
+
+// Get rid of those macros defined in in lieu of real functions.
+#undef memcmp
+#undef memcpy
+#undef memmove
+#undef memset
+#undef strchr
+#undef strcmp
+#undef strcpy
+#undef strerror
+#undef strlen
+#undef strncmp
+#undef strncpy
+#undef strstr
+#undef strtok
+
+namespace std {
+using ::memcmp;
+using ::memcpy;
+using ::memmove;
+using ::memset;
+using ::strcmp;
+using ::strcpy;
+using ::strerror;
+using ::strlen;
+using ::strncmp;
+using ::strncpy;
+using ::strtok;
+using ::strchr;
+using ::strstr;
+}
#endif /* CSTRING_ */
diff --git a/include/dirent.h b/include/dirent.h
index 70e0160..772c3b9 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -2,7 +2,7 @@
* @file dirent.h
*
*/
-/* Copyright (C) 2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2020-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,7 @@
#include
-#if !defined (_FATFS)
+#if !defined (FF_DEFINED)
typedef void *DIR;
#endif
diff --git a/include/stdio.h b/include/stdio.h
index 364bf88..86e4741 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -2,7 +2,7 @@
* @file stdio.h
*
*/
-/* Copyright (C) 2017-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,10 +28,29 @@
#include
#include
-
-#define EOF -1
-
-typedef void *FILE;
+#include
+
+#define EOF (-1)
+
+typedef struct __sFILE {
+ void *udata;
+#define __SLBF 0x0001 /* line buffered */
+#define __SNBF 0x0002 /* unbuffered */
+#define __SRD 0x0004 /* OK to read */
+#define __SWR 0x0008 /* OK to write */
+ /* RD and WR are never simultaneously asserted */
+#define __SRW 0x0010 /* open for reading & writing */
+#define __SEOF 0x0020 /* found EOF */
+#define __SERR 0x0040 /* found error */
+ uint8_t flags;
+} FILE;
+
+#if defined(CONFIG_POSIX_ENABLE_STDIN)
+#error Not supported
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+#endif
#ifndef SEEK_SET
#define SEEK_SET 0 /* set file offset to offset */
@@ -49,36 +68,40 @@ typedef void *FILE;
extern "C" {
#endif
-extern int puts(const char *s);
-extern int putchar(int c);
+int puts(const char *s);
+int putchar(int c);
+
+int fileno(FILE *stream);
-extern FILE *fopen(const char *path, const char *mode);
-extern int fclose(FILE *stream);
+FILE *fopen(const char *path, const char *mode);
+int fclose(FILE *stream);
-extern int fgetc(FILE *stream);
+int fgetc(FILE *stream);
+int fputc(int c, FILE *stream);
-extern char *fgets(char *s, int size, FILE *stream);
-extern int fputs(const char *s, FILE *stream);
+char *fgets(char *s, int size, FILE *stream);
+int fputs(const char *s, FILE *stream);
-extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
-extern size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
-extern int fseek(FILE *stream, long offset, int whence);
+int fseek(FILE *stream, long offset, int whence);
-extern long ftell(FILE *stream);
+long ftell(FILE *stream);
-extern void clearerr(FILE *stream);
-extern int ferror(FILE *stream);
+void clearerr(FILE *stream);
+int ferror(FILE *stream);
+int feof(FILE *stream);
-extern int printf(const char *format, ...);
+int printf(const char *format, ...);
-extern int sprintf(char *str, const char *format, ...);
-extern int snprintf(char *str, size_t size, const char *format, ...);
+int sprintf(char *str, const char *format, ...);
+int snprintf(char *str, size_t size, const char *format, ...);
-extern int vprintf(const char *format, va_list ap);
-extern int vsnprintf(char *str, size_t size, const char *format, va_list);
+int vprintf(const char *format, va_list ap);
+int vsnprintf(char *str, size_t size, const char *format, va_list);
-extern void perror(const char *s);
+void perror(const char *s);
#ifdef __cplusplus
}
diff --git a/include/string.h b/include/string.h
index fdbdbb4..9763a14 100644
--- a/include/string.h
+++ b/include/string.h
@@ -35,6 +35,7 @@ extern "C" {
extern char *strerror(int errnum);
extern char *strtok(char *str, const char *delim);
+extern char *strstr(const char *string, const char *substring);
inline int memcmp(const void *s1, const void *s2, size_t n) {
unsigned char u1, u2;
@@ -193,6 +194,20 @@ inline char *strcat(char *s1, const char *s2) {
return s1;
}
+inline char *strchr(const char *p, int ch) {
+ char c = (char) ch;
+
+ for (;; ++p) {
+ if (*p == c) {
+ return (char *)p;
+ }
+ if (*p == '\0') {
+ return NULL;
+ }
+ }
+ /* NOTREACHED */
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/include/time.h b/include/time.h
index d77b3b6..bee8d35 100644
--- a/include/time.h
+++ b/include/time.h
@@ -2,7 +2,7 @@
* @file time.h
*
*/
-/* Copyright (C) 2017-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -61,6 +61,7 @@ extern "C" {
extern time_t time(time_t *t);
extern time_t mktime(struct tm *tm);
+extern struct tm *gmtime(const time_t *timep);
extern struct tm *localtime(const time_t *timep);
extern char *asctime(const struct tm *tm);
diff --git a/lib-c++/.cproject b/lib-c++/.cproject
deleted file mode 100644
index 3021b34..0000000
--- a/lib-c++/.cproject
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib-c++/.settings/language.settings.xml b/lib-c++/.settings/language.settings.xml
deleted file mode 100644
index 10c666a..0000000
--- a/lib-c++/.settings/language.settings.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib-c++/Makefile.GD32 b/lib-c++/Makefile.GD32
deleted file mode 100644
index ff29a8d..0000000
--- a/lib-c++/Makefile.GD32
+++ /dev/null
@@ -1,2 +0,0 @@
-
-include ../firmware-template-gd32/lib/Rules.mk
\ No newline at end of file
diff --git a/lib-c++/README.md b/lib-c++/README.md
deleted file mode 100644
index f2e0374..0000000
--- a/lib-c++/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-## C++ library
-
-[http://www.orangepi-dmx.org](http://www.orangepi-dmx.org)
-
diff --git a/lib-c/.cproject b/lib-c/.cproject
deleted file mode 100644
index 949c7f2..0000000
--- a/lib-c/.cproject
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib-c/.settings/org.eclipse.cdt.core.prefs b/lib-c/.settings/org.eclipse.cdt.core.prefs
deleted file mode 100644
index c8ec5df..0000000
--- a/lib-c/.settings/org.eclipse.cdt.core.prefs
+++ /dev/null
@@ -1,6 +0,0 @@
-doxygen/doxygen_new_line_after_brief=true
-doxygen/doxygen_use_brief_tag=false
-doxygen/doxygen_use_javadoc_tags=true
-doxygen/doxygen_use_pre_tag=false
-doxygen/doxygen_use_structural_commands=false
-eclipse.preferences.version=1
diff --git a/lib-c/.settings/org.eclipse.core.resources.prefs b/lib-c/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 99f26c0..0000000
--- a/lib-c/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
diff --git a/lib-c/Makefile.GD32 b/lib-c/Makefile.GD32
deleted file mode 100644
index b54ecb2..0000000
--- a/lib-c/Makefile.GD32
+++ /dev/null
@@ -1,3 +0,0 @@
-#DEFINES=MEM_DEBUG
-
-include ../firmware-template-gd32/lib/Rules.mk
\ No newline at end of file
diff --git a/lib-clib/.cproject b/lib-clib/.cproject
new file mode 100644
index 0000000..fb8c641
--- /dev/null
+++ b/lib-clib/.cproject
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib-c++/.project b/lib-clib/.project
similarity index 97%
rename from lib-c++/.project
rename to lib-clib/.project
index cabc78a..47d0f02 100644
--- a/lib-c++/.project
+++ b/lib-clib/.project
@@ -1,6 +1,6 @@
- lib-c++
+ lib-clib
diff --git a/lib-clib/.settings/language.settings.xml b/lib-clib/.settings/language.settings.xml
new file mode 100755
index 0000000..9f1cbad
--- /dev/null
+++ b/lib-clib/.settings/language.settings.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib-c++/.settings/org.eclipse.core.resources.prefs b/lib-clib/.settings/org.eclipse.core.resources.prefs
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c++/.settings/org.eclipse.core.resources.prefs
rename to lib-clib/.settings/org.eclipse.core.resources.prefs
diff --git a/lib-clib/Makefile.GD32 b/lib-clib/Makefile.GD32
new file mode 100644
index 0000000..0502e1a
--- /dev/null
+++ b/lib-clib/Makefile.GD32
@@ -0,0 +1,25 @@
+DEFINES=NDEBUG
+
+EXTRA_INCLUDES=
+
+EXTRA_SRCDIR=
+
+ifneq ($(MAKE_FLAGS),)
+ ifeq ($(findstring CONFIG_ENET_ENABLE_PTP,$(MAKE_FLAGS)), CONFIG_ENET_ENABLE_PTP)
+ EXTRA_SRCDIR+=src/gd32/time_ptp
+ else
+ ifeq ($(findstring CONFIG_TIME_USE_TIMER,$(MAKE_FLAGS)), CONFIG_TIME_USE_TIMER)
+ EXTRA_SRCDIR+=src/gd32/time_timer
+ else
+ EXTRA_SRCDIR+=src/gd32/time_systick
+ endif
+ endif
+else
+ EXTRA_SRCDIR+=src/gd32/time_systick
+
+ EXTRA_SRCDIR+=src/gd32/time_timer
+ DEFINES+=CONFIG_TIME_USE_TIMER
+endif
+
+include Rules.mk
+include ../firmware-template-gd32/lib/Rules.mk
\ No newline at end of file
diff --git a/lib-clib/Rules.mk b/lib-clib/Rules.mk
new file mode 100755
index 0000000..821b5db
--- /dev/null
+++ b/lib-clib/Rules.mk
@@ -0,0 +1,2 @@
+
+EXTRA_SRCDIR+=src/c++
\ No newline at end of file
diff --git a/lib-clib/src/abort.c b/lib-clib/src/abort.c
new file mode 100755
index 0000000..7680b69
--- /dev/null
+++ b/lib-clib/src/abort.c
@@ -0,0 +1,15 @@
+/*
+ * abort.c
+ */
+
+
+#ifdef NDEBUG
+# undef NDEBUG
+#endif
+
+#include
+
+void abort(void) {
+ assert(0);
+ for(;;);
+}
diff --git a/lib-c/src/asctime.c b/lib-clib/src/asctime.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/asctime.c
rename to lib-clib/src/asctime.c
diff --git a/lib-clib/src/c++/cxa_atexit.cpp b/lib-clib/src/c++/cxa_atexit.cpp
new file mode 100755
index 0000000..cae8031
--- /dev/null
+++ b/lib-clib/src/c++/cxa_atexit.cpp
@@ -0,0 +1,26 @@
+/*
+ * cxa_atexit.cpp
+ */
+
+#include
+
+typedef void (*exitfunc_t)();
+
+static exitfunc_t atexit_funcs[32];
+static size_t atexit_count = 0;
+
+extern "C" int __cxa_atexit(exitfunc_t func, [[maybe_unused]] void *arg, [[maybe_unused]] void *dso_handle) {
+ if (atexit_count >= sizeof(atexit_funcs) / sizeof(atexit_funcs[0]))
+ return -1;
+
+ atexit_funcs[atexit_count++] = func;
+ return 0; // Success
+}
+
+extern "C" void __call_atexit_funcs() {
+ for (size_t i = atexit_count; i > 0; --i) {
+ exitfunc_t func = atexit_funcs[i - 1];
+ if (func)
+ func();
+ }
+}
diff --git a/lib-c++/src/delete.cpp b/lib-clib/src/c++/delete.cpp
old mode 100644
new mode 100755
similarity index 78%
rename from lib-c++/src/delete.cpp
rename to lib-clib/src/c++/delete.cpp
index 4f5019c..72c4aa9
--- a/lib-c++/src/delete.cpp
+++ b/lib-clib/src/c++/delete.cpp
@@ -2,7 +2,7 @@
* @file delete.cpp
*
*/
-/* Copyright (C) 2017-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,8 @@
* THE SOFTWARE.
*/
-#include
+#include
+#include
void operator delete(void *p) {
free(p);
@@ -32,3 +33,15 @@ void operator delete(void *p) {
void operator delete[](void *p) {
free(p);
}
+
+/*
+ * C++14 and above
+ */
+
+void operator delete(void *p, [[maybe_unused]] std::size_t size) noexcept {
+ free(p);
+}
+
+void operator delete[](void *p, [[maybe_unused]]std::size_t size) noexcept {
+ free(p);
+}
diff --git a/lib-clib/src/c++/dso_handle.cpp b/lib-clib/src/c++/dso_handle.cpp
new file mode 100755
index 0000000..2b06c2e
--- /dev/null
+++ b/lib-clib/src/c++/dso_handle.cpp
@@ -0,0 +1,33 @@
+/**
+ * @file dso_handle.cpp
+ *
+ */
+/* Copyright (C) 2023 by Arjan van Vught mailto:info@info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+//extern "C" int __aeabi_atexit(void *object, void (*destructor)(void *), void *dso_handle) {
+// static_cast(object);
+// static_cast(destructor);
+// static_cast(dso_handle);
+// return 0;
+//}
+
+void *__dso_handle = nullptr;
diff --git a/lib-clib/src/c++/impure_prt.cpp b/lib-clib/src/c++/impure_prt.cpp
new file mode 100755
index 0000000..98bc95e
--- /dev/null
+++ b/lib-clib/src/c++/impure_prt.cpp
@@ -0,0 +1,11 @@
+/*
+ * impure_prt.cpp
+ */
+
+typedef struct _reent {
+ int _errno; // Placeholder for the actual contents of _reent
+} _reent;
+
+// Define the global _impure_ptr. Normally points to reentrant data.
+static struct _reent _reent_data = {0};
+struct _reent *_impure_ptr = &_reent_data;
diff --git a/lib-c++/src/new.cpp b/lib-clib/src/c++/new.cpp
old mode 100644
new mode 100755
similarity index 92%
rename from lib-c++/src/new.cpp
rename to lib-clib/src/c++/new.cpp
index 6cf0eb0..64b61cc
--- a/lib-c++/src/new.cpp
+++ b/lib-clib/src/c++/new.cpp
@@ -2,7 +2,7 @@
* @file new.cpp
*
*/
-/* Copyright (C) 2017-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,7 @@
* THE SOFTWARE.
*/
-#include
+#include
void *operator new(unsigned size) {
return malloc(size);
diff --git a/lib-c++/src/purecall.cpp b/lib-clib/src/c++/purecall.cpp
old mode 100644
new mode 100755
similarity index 94%
rename from lib-c++/src/purecall.cpp
rename to lib-clib/src/c++/purecall.cpp
index b6c1dcb..d4ff1c3
--- a/lib-c++/src/purecall.cpp
+++ b/lib-clib/src/c++/purecall.cpp
@@ -2,7 +2,7 @@
* @file purecall.cpp
*
*/
-/* Copyright (C) 2017-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/lib-network/src/net/ntp_internal.h b/lib-clib/src/errno.c
old mode 100644
new mode 100755
similarity index 83%
rename from lib-network/src/net/ntp_internal.h
rename to lib-clib/src/errno.c
index 328dafa..d316613
--- a/lib-network/src/net/ntp_internal.h
+++ b/lib-clib/src/errno.c
@@ -1,8 +1,8 @@
/**
- * @file ntp_internal.h
+ * @file errno.c
*
*/
-/* Copyright (C) 2019-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,11 +23,4 @@
* THE SOFTWARE.
*/
-#ifndef NTP_INTERNAL_H_
-#define NTP_INTERNAL_H_
-
-enum {
- NTP_PORT_SERVER = 123
-};
-
-#endif /* NTP_INTERNAL_H_ */
+int errno = 0;
diff --git a/lib-c/src/assert.c b/lib-clib/src/gd32/assert.c
similarity index 100%
rename from lib-c/src/assert.c
rename to lib-clib/src/gd32/assert.c
diff --git a/lib-clib/src/gd32/malloc.h b/lib-clib/src/gd32/malloc.h
new file mode 100755
index 0000000..7a4109a
--- /dev/null
+++ b/lib-clib/src/gd32/malloc.h
@@ -0,0 +1,31 @@
+/**
+ * @file malloc.h
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef GD32_MALLOC_H_
+#define GD32_MALLOC_H_
+
+static struct block_bucket s_block_bucket[] __attribute__((aligned(4))) = {{0x10, 0}, {0x20, 0}, {0x40, 0}, {0x60, 0}, {0x80,0}, {0x100,0}, {0x140,0}, {0x180,0}, {0x200,0}, {0x300,0}, {0x400,0}, {0x500,0}, {0,0}};
+
+#endif /* GD32_MALLOC_H_ */
diff --git a/lib-clib/src/gd32/time_ptp/time.cpp b/lib-clib/src/gd32/time_ptp/time.cpp
new file mode 100644
index 0000000..a418f74
--- /dev/null
+++ b/lib-clib/src/gd32/time_ptp/time.cpp
@@ -0,0 +1,99 @@
+/**
+ * @file time.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma GCC push_options
+#pragma GCC optimize ("O2")
+
+#include
+#include
+#include
+#include
+
+#include "gd32.h"
+#include "gd32_ptp.h"
+
+#if defined (GD32H7XX)
+# define enet_ptp_timestamp_function_config(x) enet_ptp_timestamp_function_config(ENETx, x)
+# define enet_ptp_timestamp_update_config(x,y,z) enet_ptp_timestamp_update_config(ENETx, x, y, z)
+# define enet_ptp_system_time_get(x) enet_ptp_system_time_get(ENETx, x)
+#endif
+
+extern "C" {
+/*
+ * number of seconds and microseconds since the Epoch,
+ * 1970-01-01 00:00:00 +0000 (UTC).
+ */
+
+int gettimeofday(struct timeval *tv, [[maybe_unused]] struct timezone *tz) {
+ assert(tv != 0);
+
+ enet_ptp_systime_struct systime;
+ enet_ptp_system_time_get(&systime);
+
+ tv->tv_sec = systime.second;
+
+#if !defined (GD32F4XX)
+ const auto nNanoSecond = systime.nanosecond;
+#else
+ const auto nNanoSecond = gd32::ptp_subsecond_2_nanosecond(systime.subsecond);
+#endif
+
+ tv->tv_usec = nNanoSecond / 1000U;
+
+ return 0;
+}
+
+int settimeofday(const struct timeval *tv, [[maybe_unused]] const struct timezone *tz) {
+ assert(tv != 0);
+
+ const uint32_t nSign = ENET_PTP_ADD_TO_TIME;
+ const uint32_t nSecond = tv->tv_sec;
+ const uint32_t nNanoSecond = tv->tv_usec * 1000U;
+ const auto nSubSecond = gd32::ptp_nanosecond_2_subsecond(nNanoSecond);
+
+ enet_ptp_timestamp_update_config(nSign, nSecond, nSubSecond);
+
+ if (SUCCESS == enet_ptp_timestamp_function_config(ENET_PTP_SYSTIME_INIT)) {
+ return 0;
+ }
+
+ return -1;
+}
+
+/*
+ * time() returns the time as the number of seconds since the Epoch,
+ 1970-01-01 00:00:00 +0000 (UTC).
+ */
+time_t time(time_t *__timer) {
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+
+ if (__timer != nullptr) {
+ *__timer = tv.tv_sec;
+ }
+
+ return tv.tv_sec;
+}
+}
diff --git a/lib-c/src/gd32/time.c b/lib-clib/src/gd32/time_systick/time.cpp
old mode 100755
new mode 100644
similarity index 54%
rename from lib-c/src/gd32/time.c
rename to lib-clib/src/gd32/time_systick/time.cpp
index b754cc2..024803b
--- a/lib-c/src/gd32/time.c
+++ b/lib-clib/src/gd32/time_systick/time.cpp
@@ -2,7 +2,7 @@
* @file time.c
*
*/
-/* Copyright (C) 2021 by Arjan van Vught mailto:info@gd32-dmx.nl
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,50 +23,67 @@
* THE SOFTWARE.
*/
-#include
-#include
-#include
-#include
+#pragma GCC push_options
+#pragma GCC optimize ("O2")
-extern volatile uint32_t s_nSysTickMillis;
+#include
+#include
+#include
+#include
-static uint32_t set_timer = 0;
-static uint64_t s_micros = 0;
+extern volatile uint32_t gv_nSysTickMillis;
-#define MICROS_SECONDS 1000000
+static uint32_t nPreviousSysTickMillis;
+static struct timeval s_tv;
+extern "C" {
/*
* number of seconds and microseconds since the Epoch,
* 1970-01-01 00:00:00 +0000 (UTC).
*/
-int gettimeofday(struct timeval *tv, __attribute__((unused)) struct timezone *tz) {
+int gettimeofday(struct timeval *tv, __attribute__((unused)) struct timezone *tz) {
assert(tv != 0);
- const uint32_t timer = s_nSysTickMillis; // Millis timer
+ const auto nCurrentSysTickMillis = gv_nSysTickMillis;
- uint32_t timer_elapsed;
+ uint32_t nMillisElapsed;
- if (set_timer >= timer) {
- timer_elapsed = set_timer - timer;
+ if (nCurrentSysTickMillis >= nPreviousSysTickMillis) {
+ nMillisElapsed = nCurrentSysTickMillis - nPreviousSysTickMillis;
} else {
- timer_elapsed = timer - set_timer;
+ nMillisElapsed = (UINT32_MAX - nPreviousSysTickMillis) + nCurrentSysTickMillis + 1;
}
- set_timer = timer;
- s_micros += (timer_elapsed * 1000);
+ nPreviousSysTickMillis = nCurrentSysTickMillis;
+
+ const auto nSeconds = nMillisElapsed / 1000U;
+ const auto nMicroSeconds = (nMillisElapsed % 1000U) * 1000U;
- tv->tv_sec = (time_t)(s_micros / MICROS_SECONDS);
- tv->tv_usec = (suseconds_t) (s_micros - ((uint64_t) tv->tv_sec * MICROS_SECONDS));
+ s_tv.tv_sec += static_cast(nSeconds);
+ s_tv.tv_usec += static_cast(nMicroSeconds);
+
+ if (s_tv.tv_usec >= 1000000) {
+ s_tv.tv_sec++;
+ s_tv.tv_usec -= 1000000;
+ }
+
+ tv->tv_sec = s_tv.tv_sec;
+ tv->tv_usec = s_tv.tv_usec;
return 0;
}
-int settimeofday(const struct timeval *tv, __attribute__((unused)) const struct timezone *tz) {
+int settimeofday(const struct timeval *tv, __attribute__((unused)) const struct timezone *tz) {
assert(tv != 0);
- set_timer = s_nSysTickMillis;
- s_micros = ((uint64_t) tv->tv_sec * MICROS_SECONDS) + (uint64_t) tv->tv_usec;
+ struct timeval g;
+ gettimeofday(&g, nullptr);
+
+ nPreviousSysTickMillis = gv_nSysTickMillis;
+
+ s_tv.tv_sec = tv->tv_sec;
+ s_tv.tv_usec = tv->tv_usec;
return 0;
}
@@ -77,11 +94,12 @@ int settimeofday(const struct timeval *tv, __attribute__((unused)) const struct
*/
time_t time(time_t *__timer) {
struct timeval tv;
- gettimeofday(&tv, 0);
+ gettimeofday(&tv, nullptr);
- if (__timer != NULL) {
+ if (__timer != nullptr) {
*__timer = tv.tv_sec;
}
return tv.tv_sec;
}
+}
diff --git a/lib-clib/src/gd32/time_timer/time.cpp b/lib-clib/src/gd32/time_timer/time.cpp
new file mode 100644
index 0000000..8782a95
--- /dev/null
+++ b/lib-clib/src/gd32/time_timer/time.cpp
@@ -0,0 +1,157 @@
+/**
+ * @file time.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma GCC push_options
+#pragma GCC optimize ("O2")
+
+#include
+#include
+#include
+#include
+
+#include "gd32.h"
+
+#if defined(GD32H7XX)
+# define TIMERx TIMER16
+# define RCU_TIMERx RCU_TIMER16
+# define TIMERx_IRQn TIMER16_IRQn
+#else
+# define TIMERx TIMER7
+# define RCU_TIMERx RCU_TIMER7
+# if defined (GD32F10X) || defined (GD32F30X)
+# define TIMERx_IRQn TIMER7_IRQn
+# else
+# define TIMERx_IRQn TIMER7_UP_TIMER12_IRQn
+# endif
+#endif
+
+extern struct HwTimersSeconds g_Seconds;
+
+extern "C" {
+#if !defined (CONFIG_ENET_ENABLE_PTP)
+# if defined (CONFIG_TIME_USE_TIMER)
+# if defined(GD32H7XX)
+void TIMER16_IRQHandler() {
+# elif defined (GD32F10X) || defined (GD32F30X)
+void TIMER7_IRQHandler() {
+# else
+void TIMER7_UP_TIMER12_IRQHandler() {
+# endif
+ const auto nIntFlag = TIMER_INTF(TIMERx);
+
+ if ((nIntFlag & TIMER_INT_FLAG_UP) == TIMER_INT_FLAG_UP) {
+ g_Seconds.nTimeval++;
+ }
+
+ TIMER_INTF(TIMERx) = static_cast(~nIntFlag);
+}
+# endif
+#endif
+}
+
+#if defined(GD32H7XX)
+void timer16_config() {
+#else
+void timer7_config() {
+#endif
+ g_Seconds.nTimeval = 0;
+
+ rcu_periph_clock_enable(RCU_TIMERx);
+ timer_deinit(TIMERx);
+
+ timer_parameter_struct timer_initpara;
+ timer_struct_para_init(&timer_initpara);
+
+ timer_initpara.prescaler = TIMER_PSC_10KHZ;
+ timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
+ timer_initpara.counterdirection = TIMER_COUNTER_UP;
+ timer_initpara.period = (10000 - 1); // 1 second
+ timer_init(TIMERx, &timer_initpara);
+
+ timer_interrupt_flag_clear(TIMERx, ~0);
+
+ timer_interrupt_enable(TIMERx, TIMER_INT_UP);
+
+ NVIC_SetPriority(TIMERx_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); // Lowest priority
+ NVIC_EnableIRQ(TIMERx_IRQn);
+
+ timer_enable(TIMERx);
+}
+
+extern "C" {
+/*
+ * number of seconds and microseconds since the Epoch,
+ * 1970-01-01 00:00:00 +0000 (UTC).
+ */
+
+int gettimeofday(struct timeval *tv, __attribute__((unused)) struct timezone *tz) {
+ assert(tv != 0);
+
+#if __CORTEX_M == 7
+ __DMB();
+#endif
+
+ tv->tv_sec = g_Seconds.nTimeval;
+ tv->tv_usec = TIMER_CNT(TIMERx) * 100U;
+
+#if __CORTEX_M == 7
+ __ISB();
+#endif
+
+ return 0;
+}
+
+int settimeofday(const struct timeval *tv, __attribute__((unused)) const struct timezone *tz) {
+ assert(tv != 0);
+
+ // Disable the timer interrupt to prevent it from triggering while we adjust the counter
+ TIMER_DMAINTEN(TIMERx) &= static_cast(~TIMER_INT_UP);
+ TIMER_CTL0(TIMERx) &= static_cast(~TIMER_CTL0_CEN);
+
+ g_Seconds.nTimeval = tv->tv_sec;
+ TIMER_CNT(TIMERx) = (tv->tv_usec / 100U) % 10000;
+
+ TIMER_INTF(TIMERx) = static_cast(~0);
+ TIMER_DMAINTEN(TIMERx) |= TIMER_INT_UP;
+ TIMER_CTL0(TIMERx) |= TIMER_CTL0_CEN;
+
+ return 0;
+}
+
+/*
+ * time() returns the time as the number of seconds since the Epoch,
+ 1970-01-01 00:00:00 +0000 (UTC).
+ */
+time_t time(time_t *__timer) {
+ struct timeval tv;
+ gettimeofday(&tv, nullptr);
+
+ if (__timer != nullptr) {
+ *__timer = tv.tv_sec;
+ }
+
+ return tv.tv_sec;
+}
+}
diff --git a/lib-clib/src/gd32/uuid.cpp b/lib-clib/src/gd32/uuid.cpp
new file mode 100644
index 0000000..89f9772
--- /dev/null
+++ b/lib-clib/src/gd32/uuid.cpp
@@ -0,0 +1,58 @@
+/**
+ * @file uuid.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of thnDmxDataDirecte Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+#include
+
+#include "gd32.h"
+
+namespace hal {
+typedef union pcast32 {
+ uuid_t uuid;
+ uint32_t u32[4];
+} _pcast32;
+
+void uuid_init(uuid_t out) {
+ _pcast32 cast;
+
+#if defined (GD32H7XX)
+ cast.u32[0] = REG32(0x1FF0F7E8);
+ cast.u32[1] = REG32(0x1FF0F7EC);
+ cast.u32[2] = REG32(0x1FF0F7F0);
+#elif defined (GD32F4XX)
+ cast.u32[0] = REG32(0x1FFF7A10);
+ cast.u32[1] = REG32(0x1FFF7A14);
+ cast.u32[2] = REG32(0x1FFF7A18);
+#else
+ cast.u32[0] = REG32(0x1FFFF7E8);
+ cast.u32[1] = REG32(0x1FFFF7EC);
+ cast.u32[2] = REG32(0x1FFFF7F0);
+#endif
+ cast.u32[3] = cast.u32[0] + cast.u32[1] + cast.u32[2];
+
+ memcpy(out, cast.uuid, sizeof(uuid_t));
+}
+} // namespace hal
diff --git a/lib-c/src/inet_aton.c b/lib-clib/src/inet_aton.c
old mode 100644
new mode 100755
similarity index 94%
rename from lib-c/src/inet_aton.c
rename to lib-clib/src/inet_aton.c
index 52dbfc3..cc83bb5
--- a/lib-c/src/inet_aton.c
+++ b/lib-clib/src/inet_aton.c
@@ -25,13 +25,14 @@
#include
#include
+#include
typedef union pcast32 {
uint32_t u32;
uint8_t u8[4];
} _pcast32;
-int inet_aton(const char *cp, uint32_t *ip_address) {
+int inet_aton(const char *cp, struct in_addr *ip_address) {
const char *b = cp;
int i, j, k;
_pcast32 cast32;
@@ -79,7 +80,7 @@ int inet_aton(const char *cp, uint32_t *ip_address) {
cast32.u8[i] = (uint8_t)k;
if (ip_address != 0) {
- *ip_address = cast32.u32;
+ ip_address->s_addr = cast32.u32;
}
return 1;
diff --git a/lib-clib/src/init.c b/lib-clib/src/init.c
new file mode 100755
index 0000000..647ec7d
--- /dev/null
+++ b/lib-clib/src/init.c
@@ -0,0 +1,23 @@
+/*
+ * init.c
+ */
+
+#include "stddef.h"
+
+extern void (*__preinit_array_start []) (void) __attribute__((weak));
+extern void (*__preinit_array_end []) (void) __attribute__((weak));
+extern void (*__init_array_start []) (void) __attribute__((weak));
+extern void (*__init_array_end []) (void) __attribute__((weak));
+
+void __libc_init_array(void) {
+ size_t count;
+ size_t i;
+
+ count = (size_t)(__preinit_array_end - __preinit_array_start);
+ for (i = 0; i < count; i++)
+ __preinit_array_start[i] ();
+
+ count = (size_t)(__init_array_end - __init_array_start);
+ for (i = 0; i < count; i++)
+ __init_array_start[i] ();
+}
diff --git a/lib-clib/src/log.c b/lib-clib/src/log.c
new file mode 100755
index 0000000..b8ee6f0
--- /dev/null
+++ b/lib-clib/src/log.c
@@ -0,0 +1,80 @@
+/**
+ * @file log.c
+ *
+ */
+/*
+ * Based on http://www.flipcode.com/archives/Fast_log_Function.shtml
+ * and https://stackoverflow.com/questions/9411823/fast-log2float-x-implementation-c
+ *
+ * Reference https://www.doc.ic.ac.uk/~eedwards/compsys/float/nan.html
+ * and http://steve.hollasch.net/cgindex/coding/ieeefloat.html
+ */
+/* Copyright (C) 2017-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+
+typedef union {
+ float number;
+ int32_t bits;
+} float2bits;
+
+/* Natural log of 2 */
+#ifndef _M_LN2
+#define _M_LN2 0.693147180559945309417f
+#endif
+
+/**
+ * On success, the function return the base 2 logarithm of x.
+ * maximum error ±0.00493976
+ *
+ * If x is 1, the result is +0.
+ * If x is 0, the result is -infinity
+ * If x is negative a NaN (not a number) is returned.
+ */
+float log2f(float x) {
+ float2bits m;
+
+ m.number = x;
+
+ if (x == 0) {
+ m.bits = (int32_t) 0xFF800000; // -inf
+ return m.number;
+ } else if (x == 1) {
+ return (float) 0;
+ } else if (x < 0) {
+ m.bits = (int32_t) 0x7F800001; // nan
+ return m.number;
+ }
+
+ register float log2 = (float)(((m.bits >> 23) & 0x00FF) - 128);
+
+ m.bits &= ~(255 << 23);
+ m.bits += (127 << 23);
+
+ log2 += ((-0.34484843f) * m.number + 2.02466578f) * m.number - 0.67487759f;
+
+ return log2;
+}
+
+float logf(float v) {
+ return log2f(v) * _M_LN2;
+}
diff --git a/lib-c/src/malloc.c b/lib-clib/src/malloc.c
old mode 100644
new mode 100755
similarity index 90%
rename from lib-c/src/malloc.c
rename to lib-clib/src/malloc.c
index e6af3cb..5867677
--- a/lib-c/src/malloc.c
+++ b/lib-clib/src/malloc.c
@@ -8,7 +8,7 @@
* Copyright (C) 2014-2016 R. Stange
* https://github.com/rsta2/circle/blob/master/lib/alloc.cpp
*/
-/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,15 +32,18 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-arith" // FIXME ignored "-Wpointer-arith"
#pragma GCC diagnostic ignored "-Wpedantic" // FIXME ignored "-Wpedantic"
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include
#include
#include
-#ifdef MEM_DEBUG
+#ifdef DEBUG_HEAP
#include
#endif
+extern void console_error(const char *);
+
extern unsigned char heap_low; /* Defined by the linker */
extern unsigned char heap_top; /* Defined by the linker */
@@ -58,14 +61,20 @@ struct block_header {
struct block_bucket {
unsigned int size;
-#ifdef MEM_DEBUG
+#ifdef DEBUG_HEAP
unsigned int count;
unsigned int max_count;
#endif
struct block_header *free_list;
};
-static struct block_bucket s_block_bucket[] __attribute__((aligned(4))) = {{0x10, 0}, {0x20, 0}, {0x40, 0}, {0x60, 0}, {0x80,0}, {0x100,0}, {0x140,0}, {0x180,0}, {0x200,0}, {0x300,0}, {0x400,0}, {0x500,0}, {0,0}};
+#if defined (H3)
+# include "h3/malloc.h"
+#elif defined (GD32)
+# include "gd32/malloc.h"
+#else
+# include "rpi/malloc.h"
+#endif
size_t get_allocated(void *p) {
if (p == 0) {
@@ -83,9 +92,6 @@ size_t get_allocated(void *p) {
}
void *malloc(size_t size) {
-#ifdef MEM_DEBUG
- printf("malloc: %u\n", size);
-#endif
struct block_bucket *bucket;
struct block_header *header;
@@ -96,7 +102,7 @@ void *malloc(size_t size) {
for (bucket = s_block_bucket; bucket->size > 0; bucket++) {
if (size <= bucket->size) {
size = bucket->size;
-#ifdef MEM_DEBUG
+#ifdef DEBUG_HEAP
if (++bucket->count > bucket->max_count) {
bucket->max_count = bucket->count;
}
@@ -120,9 +126,7 @@ void *malloc(size_t size) {
assert(((unsigned)next & (unsigned)3) == 0);
if (next > block_limit) {
-#ifdef MEM_DEBUG
- printf("malloc: next > block_limit\n");
-#endif
+ console_error("next > block_limit\n");
return NULL;
} else {
next_block = next;
@@ -133,8 +137,8 @@ void *malloc(size_t size) {
}
header->next = 0;
-#ifdef MEM_DEBUG
- printf("malloc: pBlockHeader=%p, size=%d, data=%p\n", header, (int) size, (void *)header->data);
+#ifdef DEBUG_HEAP
+ printf("malloc: pBlockHeader = %p, size = %d\n", header, (int) size);
#endif
assert(((unsigned)header->data & (unsigned)3) == 0);
@@ -150,7 +154,7 @@ void free(void *p) {
struct block_header *header = (struct block_header *) ((void *) p - sizeof(struct block_header));
-#ifdef MEM_DEBUG
+#ifdef DEBUG_HEAP
printf("free: pBlockHeader = %p, pBlock = %p\n", header, p);
#endif
@@ -164,7 +168,7 @@ void free(void *p) {
header->next = bucket->free_list;
bucket->free_list = header;
-#ifdef MEM_DEBUG
+#ifdef DEBUG_HEAP
bucket->count--;
#endif
break;
@@ -258,8 +262,8 @@ void *realloc(void *ptr, size_t size) {
return newblk;
}
-void mem_info(void) {
-#ifdef MEM_DEBUG
+void debug_heap(void) {
+#ifdef DEBUG_HEAP
struct block_bucket *pBucket;
struct block_header *pBlockHeader;
printf("s_pNextBlock = %p\n", next_block);
diff --git a/lib-clib/src/memchr.c b/lib-clib/src/memchr.c
new file mode 100755
index 0000000..ca055d2
--- /dev/null
+++ b/lib-clib/src/memchr.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include
+
+void* memchr(const void *src, int c, size_t len) {
+ const unsigned char *s = src;
+
+ while (len--) {
+ if (*s == (unsigned char) c)
+ return (void*) s;
+ s++;
+ }
+
+ return NULL;
+}
diff --git a/lib-clib/src/memcmp.c b/lib-clib/src/memcmp.c
new file mode 100755
index 0000000..7b1a185
--- /dev/null
+++ b/lib-clib/src/memcmp.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include
+
+int memcmp(const void *s1, const void *s2, size_t len)
+{
+ const unsigned char *s = s1;
+ const unsigned char *d = s2;
+ unsigned char sc;
+ unsigned char dc;
+
+ while (len--) {
+ sc = *s++;
+ dc = *d++;
+ if (sc - dc)
+ return (sc - dc);
+ }
+
+ return 0;
+}
diff --git a/lib-c/src/memcpy.c b/lib-clib/src/memcpy.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/memcpy.c
rename to lib-clib/src/memcpy.c
diff --git a/lib-c/src/memmove.c b/lib-clib/src/memmove.c
similarity index 100%
rename from lib-c/src/memmove.c
rename to lib-clib/src/memmove.c
diff --git a/lib-c/src/memset.c b/lib-clib/src/memset.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/memset.c
rename to lib-clib/src/memset.c
diff --git a/lib-clib/src/perror.c b/lib-clib/src/perror.c
new file mode 100755
index 0000000..dd443b8
--- /dev/null
+++ b/lib-clib/src/perror.c
@@ -0,0 +1,105 @@
+/**
+ * @file perror.c
+ *
+ */
+/* Copyright (C) 2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+
+extern void console_error(const char *);
+extern int console_putc(int);
+extern int console_puts(const char *);
+
+/*
+errno -l | cut -f3- -d ' ' | sort -V -u | awk '$0="\""$0"\","'
+*/
+
+const char * const sys_errlist[] = {
+ "OK",
+ "Operation not permitted",
+ "No such file or directory",
+ "No such process",
+ "Interrupted system call",
+ "Input/output error",
+ "No such device or address",
+ "Argument list too long",
+ "Exec format error",
+ "Bad file descriptor",
+ "No child processes",
+ "Resource temporarily unavailable",
+ "Cannot allocate memory",
+ "Permission denied",
+ "Bad address",
+ "Block device required",
+ "Device or resource busy",
+ "File exists",
+ "Invalid cross-device link",
+ "No such device",
+ "Not a directory",
+ "Is a directory",
+ "Invalid argument",
+ "Too many open files in system",
+ "Too many open files",
+ "Inappropriate ioctl for device",
+ "Text file busy",
+ "File too large",
+ "No space left on device",
+ "Illegal seek",
+ "Read-only file system",
+ "Too many links",
+ "Broken pipe",
+ "Numerical argument out of domain",
+ "Numerical result out of range",
+ "Resource deadlock avoided",
+ "File name too long",
+ "No locks available",
+ "Function not implemented",
+ "Directory not empty",
+ "Bad message"
+};
+
+char *strerror(int errnum) {
+ if (errnum <= ELAST) {
+ return (char *)sys_errlist[errnum];
+ }
+
+ return (char *)sys_errlist[EBADMSG];
+}
+
+void perror(const char *s) {
+ const char *ptr = NULL;
+
+ if (errno >= 0 && errno < ELAST) {
+ ptr = sys_errlist[errno];
+ } else {
+ ptr = sys_errlist[EBADMSG];
+ }
+
+ if (s && *s) {
+ console_error(s);
+ console_puts(": ");
+ }
+
+ console_error(ptr);
+ console_putc('\n');
+}
diff --git a/lib-c/src/printf.c b/lib-clib/src/printf.c
old mode 100644
new mode 100755
similarity index 92%
rename from lib-c/src/printf.c
rename to lib-clib/src/printf.c
index 24b240b..0ba6756
--- a/lib-c/src/printf.c
+++ b/lib-clib/src/printf.c
@@ -2,7 +2,7 @@
* @file printf.c
*
*/
-/* Copyright (C) 2016-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2016-2023 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,6 @@
#include
#include
#include
-#include
extern int console_putc(int);
@@ -53,7 +52,7 @@ enum {
static char *outptr = NULL;
-inline static void _xputch(struct context *ctx, int c) {
+inline static void _xputch(struct context *ctx, const int c) {
ctx->total++;
if (outptr != NULL) {
@@ -78,7 +77,7 @@ static int _pow10(int n) {
return r;
}
-static int _itostr(int x, /*@out@*/char *s, int d) {
+static int _itostr(int x, char *s, int d) {
char buffer[64];
char *p = buffer + (sizeof(buffer) / sizeof(buffer[0])) - 1;
char *o = p;
@@ -123,7 +122,7 @@ static int _itostr(int x, /*@out@*/char *s, int d) {
return i + 1;
}
-static void _round_float(/*@out@*/char *dest, int *size) {
+static void _round_float(char *dest, int *size) {
int i = *size - 1;
char *q = (char *) dest + i;
bool round_int = false;
@@ -175,7 +174,7 @@ static void _round_float(/*@out@*/char *dest, int *size) {
#endif
static void _format_hex(struct context *ctx, unsigned int arg) {
- char buffer[64] __attribute__((aligned(4)));
+ char buffer[64];
char *p = buffer + (sizeof(buffer) / sizeof(buffer[0])) - 1;
char *o = p;
char alpha;
@@ -227,7 +226,7 @@ static void _format_hex(struct context *ctx, unsigned int arg) {
}
}
-static void _format_int(struct context *ctx, uint64_t arg) {
+static void _format_int(struct context *ctx, unsigned long int arg) {
char buffer[64];
char *p = buffer + (sizeof(buffer) / sizeof(buffer[0])) - 1;
char *o = p;
@@ -281,7 +280,7 @@ static void _format_int(struct context *ctx, uint64_t arg) {
#if !defined (DISABLE_PRINTF_FLOAT)
static void _format_float(struct context *ctx, float f) {
- char buffer[64] __attribute__((aligned(4)));
+ char buffer[64];
char *dest = (char *) buffer;
int ipart;
int precision;
@@ -366,8 +365,8 @@ static int _vprintf(const int size, const char *fmt, va_list va) {
#if !defined (DISABLE_PRINTF_FLOAT)
float f;
#endif
- int64_t l;
- uint64_t lu;
+ long int l;
+ unsigned long int lu;
const char *s;
ctx.total = 0;
@@ -433,12 +432,12 @@ static int _vprintf(const int size, const char *fmt, va_list va) {
/*@fallthrough@*/
/* no break */
case 'i':
- l = ((ctx.flag & FLAG_LONG) != 0) ? va_arg(va, int64_t) : (int64_t) va_arg(va, int32_t);
+ l = ((ctx.flag & FLAG_LONG) != 0) ? va_arg(va, long int) : (long int) va_arg(va, int);
if (l < 0) {
ctx.flag |= FLAG_NEGATIVE;
l = -l;
}
- _format_int(&ctx, (uint64_t) l);
+ _format_int(&ctx, (unsigned long int) l);
break;
#if !defined (DISABLE_PRINTF_FLOAT)
case 'f':
@@ -447,14 +446,14 @@ static int _vprintf(const int size, const char *fmt, va_list va) {
break;
#endif
case 'p':
- _format_pointer(&ctx, va_arg(va, uint32_t));
+ _format_pointer(&ctx, va_arg(va, unsigned int));
break;
case 's':
s = va_arg(va, const char *);
_format_string(&ctx, s);
break;
case 'u':
- lu = ((ctx.flag & FLAG_LONG) != 0) ? va_arg(va, uint64_t) : va_arg(va,uint32_t);
+ lu = ((ctx.flag & FLAG_LONG) != 0) ? va_arg(va, unsigned long int) : va_arg(va, unsigned int);
_format_int(&ctx, lu);
break;
case 'X':
@@ -462,7 +461,7 @@ static int _vprintf(const int size, const char *fmt, va_list va) {
/*@fallthrough@*/
/* no break */
case 'x':
- _format_hex(&ctx, va_arg(va, uint32_t));
+ _format_hex(&ctx, va_arg(va, unsigned int));
break;
default:
_xputch(&ctx, (int) *fmt);
diff --git a/lib-c/src/putchar.c b/lib-clib/src/putchar.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/putchar.c
rename to lib-clib/src/putchar.c
diff --git a/lib-c/src/puts.c b/lib-clib/src/puts.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/puts.c
rename to lib-clib/src/puts.c
diff --git a/lib-c/src/random.c b/lib-clib/src/random.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/random.c
rename to lib-clib/src/random.c
diff --git a/lib-clib/src/strchr.c b/lib-clib/src/strchr.c
new file mode 100755
index 0000000..750a42d
--- /dev/null
+++ b/lib-clib/src/strchr.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include
+
+/*
+ * strchr --
+ *
+ * PUBLIC: #ifndef HAVE_STRCHR
+ * PUBLIC: char *strchr __P((const char *, int));
+ * PUBLIC: #endif
+ */
+char *strchr(const char *p, int ch)
+{
+ char c;
+
+ c = (char) ch;
+ for (;; ++p) {
+ if (*p == c)
+ return ((char *)p);
+ if (*p == '\0')
+ return (NULL);
+ }
+ /* NOTREACHED */
+}
diff --git a/lib-network/src/net/tftp_internal.h b/lib-clib/src/strlen.c
old mode 100644
new mode 100755
similarity index 82%
rename from lib-network/src/net/tftp_internal.h
rename to lib-clib/src/strlen.c
index 13c9f05..a0eb47f
--- a/lib-network/src/net/tftp_internal.h
+++ b/lib-clib/src/strlen.c
@@ -1,8 +1,8 @@
/**
- * @file tftp_internal.h
+ * @file strlen.c
*
*/
-/* Copyright (C) 2019-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,11 +23,15 @@
* THE SOFTWARE.
*/
-#ifndef TFTP_INTERNAL_H_
-#define TFTP_INTERNAL_H_
-enum {
- TFTP_PORT_SERVER = 69
-};
+#include
-#endif /* TFTP_INTERNAL_H_ */
+size_t strlen(const char *s) {
+ const char *p = s;
+
+ while (*s != (char) 0) {
+ ++s;
+ }
+
+ return (size_t) (s - p);
+}
diff --git a/lib-clib/src/strncmp.c b/lib-clib/src/strncmp.c
new file mode 100755
index 0000000..77d962a
--- /dev/null
+++ b/lib-clib/src/strncmp.c
@@ -0,0 +1,51 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Portions copyright (c) 2018, Arm Limited and Contributors.
+ * All rights reserved.
+ */
+
+#include
+
+int strncmp(const char *s1, const char *s2, size_t n) {
+
+ if (n == 0)
+ return (0);
+ do {
+ if (*s1 != *s2++)
+ return (*(const unsigned char*) s1
+ - *(const unsigned char*) (s2 - 1));
+ if (*s1++ == '\0')
+ break;
+ } while (--n != 0);
+ return (0);
+}
diff --git a/lib-clib/src/strstr.c b/lib-clib/src/strstr.c
new file mode 100755
index 0000000..29d74bb
--- /dev/null
+++ b/lib-clib/src/strstr.c
@@ -0,0 +1,71 @@
+/*
+ * strstr.c --
+ *
+ * Source code for the "strstr" library routine.
+ *
+ * Copyright (c) 1988-1993 The Regents of the University of California.
+ * Copyright (c) 1994 Sun Microsystems, Inc.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: strstr.c,v 1.1.1.3 2003/03/06 00:09:04 landonf Exp $
+ */
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * strstr --
+ *
+ * Locate the first instance of a substring in a string.
+ *
+ * Results:
+ * If string contains substring, the return value is the
+ * location of the first matching instance of substring
+ * in string. If string doesn't contain substring, the
+ * return value is 0. Matching is done on an exact
+ * character-for-character basis with no wildcards or special
+ * characters.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#include
+
+char *strstr(const char *string, const char *substring) {
+ /* First scan quickly through the two strings looking for a
+ * single-character match. When it's found, then compare the
+ * rest of the substring.
+ */
+
+ const char *b = substring;
+
+ if (*b == 0) {
+ return (char *)string;
+ }
+
+ for (; *string != 0; string += 1) {
+ if (*string != *b) {
+ continue;
+ }
+
+ const char *a = string;
+
+ while (1) {
+ if (*b == 0) {
+ return (char *)string;
+ }
+
+ if (*a++ != *b++) {
+ break;
+ }
+ }
+
+ b = substring;
+ }
+
+ return NULL;
+}
diff --git a/lib-c/src/strtok.c b/lib-clib/src/strtok.c
old mode 100644
new mode 100755
similarity index 100%
rename from lib-c/src/strtok.c
rename to lib-clib/src/strtok.c
diff --git a/lib-clib/src/strtoul.c b/lib-clib/src/strtoul.c
new file mode 100755
index 0000000..2581ed1
--- /dev/null
+++ b/lib-clib/src/strtoul.c
@@ -0,0 +1,118 @@
+#pragma GCC push_options
+#pragma GCC diagnostic ignored "-Wsign-conversion"
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include
+#include
+#include
+#include
+
+static int isspace(int c) {
+ return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' ' ? 1 : 0);
+}
+
+/*
+ * Convert a string to an unsigned long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long strtoul(const char *nptr, char **endptr, int base)
+{
+ const char *s;
+ unsigned long acc;
+ char c;
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (isspace((unsigned char)c));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X') &&
+ ((s[1] >= '0' && s[1] <= '9') ||
+ (s[1] >= 'A' && s[1] <= 'F') ||
+ (s[1] >= 'a' && s[1] <= 'f'))) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+ acc = any = 0;
+
+ cutoff = ULONG_MAX / base;
+ cutlim = ULONG_MAX % base;
+ for ( ; ; c = *s++) {
+ if (c >= '0' && c <= '9')
+ c -= '0';
+ else if (c >= 'A' && c <= 'Z')
+ c -= 'A' - 10;
+ else if (c >= 'a' && c <= 'z')
+ c -= 'a' - 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ any = -1;
+ else {
+ any = 1;
+ acc *= base;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = ULONG_MAX;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != NULL)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}
diff --git a/lib-c/src/time.c b/lib-clib/src/time.cpp
old mode 100644
new mode 100755
similarity index 54%
rename from lib-c/src/time.c
rename to lib-clib/src/time.cpp
index 0f08b95..86fe621
--- a/lib-c/src/time.c
+++ b/lib-clib/src/time.cpp
@@ -1,8 +1,8 @@
/**
- * @file time.c
+ * @file time.cpp
*
*/
-/* Copyright (C) 2016-2019 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2016-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,12 +23,19 @@
* THE SOFTWARE.
*/
-#include
+#include
+
+#include
+#include
#include
-static const int days_of_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+namespace global {
+int32_t *gp_nUtcOffset;
+} // namespace global
+
+static constexpr int days_of_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-static int isleapyear(int year) {
+static int isleapyear(const int year) {
if (year % 100 == 0) {
return year % 400 == 0;
}
@@ -36,7 +43,7 @@ static int isleapyear(int year) {
return year % 4 == 0;
}
-static int getdaysofmonth(int month, int year) {
+static int getdaysofmonth(const int month, const int year) {
if ((month == 1) && isleapyear(year)) {
return 29;
}
@@ -46,106 +53,120 @@ static int getdaysofmonth(int month, int year) {
static struct tm Tm;
+extern "C" {
+
struct tm *localtime(const time_t *pTime) {
- int nYear;
- int nMonth;
+ if (pTime == nullptr) {
+ return nullptr;
+ }
+
+ auto nTime = *pTime + *global::gp_nUtcOffset;
+ return gmtime(&nTime);
+}
- if (pTime == 0) {
- return NULL;
+struct tm *gmtime(const time_t *pTime) {
+ if (pTime == nullptr) {
+ return nullptr;
}
- time_t Time = *pTime;
+ auto nTime = *pTime;
- Tm.tm_sec = Time % 60;
- Time /= 60;
- Tm.tm_min = Time % 60;
- Time /= 60;
- Tm.tm_hour = Time % 24;
- Time /= 24;
+ Tm.tm_sec = nTime % 60;
+ nTime /= 60;
+ Tm.tm_min = nTime % 60;
+ nTime /= 60;
+ Tm.tm_hour = nTime % 24;
+ nTime /= 24;
- Tm.tm_wday = (Time + 4) % 7;
+ Tm.tm_wday = (nTime + 4) % 7;
+
+ int nYear = 1970;
- nYear = 1970;
while (1) {
- int nDaysOfYear = isleapyear(nYear) ? 366 : 365;
- if (Time < nDaysOfYear) {
+ const time_t nDaysOfYear = isleapyear(nYear) ? 366 : 365;
+ if (nTime < nDaysOfYear) {
break;
}
- Time -= nDaysOfYear;
+ nTime -= nDaysOfYear;
nYear++;
}
Tm.tm_year = nYear - 1900;
- Tm.tm_yday = Time;
+ Tm.tm_yday = nTime;
+
+ int nMonth = 0;
- nMonth = 0;
while (1) {
- int nDaysOfMonth = getdaysofmonth(nMonth, nYear);
- if (Time < nDaysOfMonth) {
+ const time_t nDaysOfMonth = getdaysofmonth(nMonth, nYear);
+ if (nTime < nDaysOfMonth) {
break;
}
- Time -= nDaysOfMonth;
+ nTime -= nDaysOfMonth;
nMonth++;
}
Tm.tm_mon = nMonth;
- Tm.tm_mday = Time + 1;
+ Tm.tm_mday = nTime + 1;
return &Tm;
}
time_t mktime(struct tm *pTm) {
- int year, month;
- time_t result = 0;
+ time_t nResult = 0;
- if (pTm == NULL) {
- return (time_t) -1;
+ if (pTm == nullptr) {
+ return -1;
}
if (pTm->tm_year < 70 || pTm->tm_year > 139) {
- return (time_t) -1;
+ return -1;
}
- for (year = 1970; year < 1900 + pTm->tm_year; year++) {
- result += isleapyear(year) ? 366 : 365;
+ int nYear;
+
+ for (nYear = 1970; nYear < 1900 + pTm->tm_year; nYear++) {
+ nResult += isleapyear(nYear) ? 366 : 365;
}
if (pTm->tm_mon < 0 || pTm->tm_mon > 11) {
- return (time_t) -1;
+ return -1;
}
- for (month = 0; month < pTm->tm_mon; month++) {
- result += getdaysofmonth(month, pTm->tm_year);
+ int nMonth;
+
+ for (nMonth = 0; nMonth < pTm->tm_mon; nMonth++) {
+ nResult += getdaysofmonth(nMonth, pTm->tm_year);
}
if (pTm->tm_mday < 1 || pTm->tm_mday > getdaysofmonth(pTm->tm_mon, pTm->tm_year)) {
- return (time_t) -1;
+ return -1;
}
- result += pTm->tm_mday - 1;
- result *= 24;
+ nResult += pTm->tm_mday - 1;
+ nResult *= 24;
if (pTm->tm_hour < 0 || pTm->tm_hour > 23) {
- return (time_t) -1;
+ return -1;
}
- result += pTm->tm_hour;
- result *= 60;
+ nResult += pTm->tm_hour;
+ nResult *= 60;
if (pTm->tm_min < 0 || pTm->tm_min > 59) {
- return (time_t) -1;
+ return -1;
}
- result += pTm->tm_min;
- result *= 60;
+ nResult += pTm->tm_min;
+ nResult *= 60;
if (pTm->tm_sec < 0 || pTm->tm_sec > 59) {
- return (time_t) -1;
+ return -1;
}
- result += pTm->tm_sec;
+ nResult += pTm->tm_sec;
- return result;
+ return nResult;
+}
}
diff --git a/lib-configstore/src/storenetwork.cpp b/lib-clib/src/uuid_internal.h
similarity index 75%
rename from lib-configstore/src/storenetwork.cpp
rename to lib-clib/src/uuid_internal.h
index 0ed3c4a..1a4530d 100755
--- a/lib-configstore/src/storenetwork.cpp
+++ b/lib-clib/src/uuid_internal.h
@@ -1,8 +1,8 @@
/**
- * @file storenetwork.cpp
+ * @file uuid_internal.h
*
*/
-/* Copyright (C) 2018-2021 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2016-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,19 +23,17 @@
* THE SOFTWARE.
*/
-#include
+#ifndef UUID_INTERNAL_H_
+#define UUID_INTERNAL_H_
-#include "storenetwork.h"
-#include "debug.h"
+#include
-StoreNetwork *StoreNetwork::s_pThis = nullptr;
+struct uuid {
+ uint32_t time_low;
+ uint16_t time_mid;
+ uint16_t time_hi_and_version;
+ uint16_t clock_seq;
+ uint8_t node[6];
+};
-StoreNetwork::StoreNetwork() {
- DEBUG_ENTRY
-
- assert(s_pThis == nullptr);
- s_pThis = this;
-
- DEBUG_PRINTF("%p", reinterpret_cast(s_pThis));
- DEBUG_EXIT
-}
+#endif /* UUID_INTERNAL_H_ */
diff --git a/lib-clib/src/uuid_parse.c b/lib-clib/src/uuid_parse.c
new file mode 100755
index 0000000..462b96a
--- /dev/null
+++ b/lib-clib/src/uuid_parse.c
@@ -0,0 +1,171 @@
+/**
+ * @file uuid_parse.c
+ *
+ */
+/**
+ * This code is inspired by:
+ * http://code.metager.de/source/xref/linux/utils/util-linux/libuuid/src/
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+/* Copyright (C) 2016-2021 by Arjan van Vught mailto:info@orangepi-dmx.nl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "uuid_internal.h"
+
+static uint32_t hex_uint32(const char *s) {
+ uint32_t ret = 0;
+ uint8_t nibble;
+
+ while (*s != '\0') {
+ char d = *s;
+
+ if (isxdigit((int) d) == 0) {
+ break;
+ }
+
+ nibble = d > '9' ? (uint8_t)((uint8_t)( d | 0x20) - 'a' + 10) : (uint8_t) (d - '0');
+ ret = (ret << 4) | nibble;
+ s++;
+ }
+
+ return ret;
+}
+
+static void uuid_pack(const struct uuid *uu, uuid_t ptr) {
+ uint32_t tmp;
+ unsigned char *out = ptr;
+
+ assert(uu != NULL);
+
+ tmp = uu->time_low;
+ out[3] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[2] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[1] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[0] = (unsigned char) tmp;
+
+ tmp = uu->time_mid;
+ out[5] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[4] = (unsigned char) tmp;
+
+ tmp = uu->time_hi_and_version;
+ out[7] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[6] = (unsigned char) tmp;
+
+ tmp = uu->clock_seq;
+ out[9] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[8] = (unsigned char) tmp;
+
+ memcpy(out + 10, uu->node, 6);
+}
+
+int uuid_parse(const char *in, uuid_t uu) {
+ struct uuid uuid;
+ int i;
+ const char *cp;
+ char buf[3];
+
+ assert(in != NULL);
+
+ if (strlen(in) != 36) {
+ return -1;
+ }
+
+ for (i = 0, cp = in; i <= 36; i++, cp++) {
+
+ if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
+ if (*cp == '-') {
+ continue;
+ } else {
+ return -1;
+ }
+ }
+
+ if (i == 36) {
+ if (*cp == 0) {
+ continue;
+ }
+ }
+
+ if (!isxdigit(*cp)) {
+ return -1;
+ }
+ }
+
+ uuid.time_low = hex_uint32(in);
+ uuid.time_mid = (uint16_t)(hex_uint32(in + 9));
+ uuid.time_hi_and_version = (uint16_t)(hex_uint32(in + 14));
+ uuid.clock_seq = (uint16_t)(hex_uint32(in + 19));
+
+ cp = in + 24;
+ buf[2] = 0;
+
+ for (i = 0; i < 6; i++) {
+ buf[0] = *cp++;
+ buf[1] = *cp++;
+ uuid.node[i] = (uint8_t)(hex_uint32(buf));
+ }
+
+ uuid_pack(&uuid, uu);
+
+ return 0;
+}
diff --git a/lib-clib/src/uuid_unparse.c b/lib-clib/src/uuid_unparse.c
new file mode 100755
index 0000000..5c01249
--- /dev/null
+++ b/lib-clib/src/uuid_unparse.c
@@ -0,0 +1,133 @@
+/**
+ * @file uuid_unparse.c
+ *
+ */
+/**
+ * This code is inspired by:
+ * http://code.metager.de/source/xref/linux/utils/util-linux/libuuid/src/
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+/* Copyright (C) 2016-2021 by Arjan van Vught mailto:info@orangepi-dmx.nl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "uuid_internal.h"
+
+#ifndef ALIGNED
+ #define ALIGNED __attribute__ ((aligned (4)))
+#endif
+
+static const char *fmt_lower ALIGNED = "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
+static const char *fmt_upper ALIGNED = "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X";
+
+#ifdef UUID_UNPARSE_DEFAULT_UPPER
+#define FMT_DEFAULT fmt_upper
+#else
+#define FMT_DEFAULT fmt_lower
+#endif
+
+static void uuid_unpack(const uuid_t in, struct uuid *uu) {
+ const uint8_t *ptr = in;
+ uint32_t tmp;
+
+ assert(uu != NULL);
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_low = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_mid = (uint16_t)(tmp);
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_hi_and_version = (uint16_t)(tmp);
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->clock_seq = (uint16_t)(tmp);
+
+ memcpy(uu->node, ptr, 6);
+}
+
+static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt) {
+ struct uuid uuid;
+
+ assert(out != NULL);
+ assert(fmt != NULL);
+
+ uuid_unpack(uu, &uuid);
+
+ sprintf(out, fmt, uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
+ uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, uuid.node[0],
+ uuid.node[1], uuid.node[2], uuid.node[3], uuid.node[4],
+ uuid.node[5]);
+}
+
+void uuid_unparse_lower(const uuid_t uu, char *out) {
+ uuid_unparse_x(uu, out, fmt_lower);
+}
+
+void uuid_unparse_upper(const uuid_t uu, char *out) {
+ uuid_unparse_x(uu, out, fmt_upper);
+}
+
+void uuid_unparse(const uuid_t uu, char *out) {
+ uuid_unparse_x(uu, out, FMT_DEFAULT);
+}
diff --git a/lib-configstore/.cproject b/lib-configstore/.cproject
index 7535ba0..933f4c5 100755
--- a/lib-configstore/.cproject
+++ b/lib-configstore/.cproject
@@ -29,15 +29,12 @@
-
-
-
@@ -54,13 +51,10 @@
-
-
-
@@ -85,10 +79,8 @@
-
-
@@ -131,13 +123,10 @@
-
-
-
@@ -155,14 +144,11 @@
-
-
-
@@ -187,10 +173,8 @@
-
-
@@ -218,13 +202,10 @@
-
-
-
diff --git a/lib-configstore/.settings/language.settings.xml b/lib-configstore/.settings/language.settings.xml
index 78f74bf..53c4b5e 100755
--- a/lib-configstore/.settings/language.settings.xml
+++ b/lib-configstore/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -14,10 +14,13 @@
+
+
+
+
-
-
+
diff --git a/lib-configstore/Makefile.GD32 b/lib-configstore/Makefile.GD32
index feb2b55..643fe9b 100644
--- a/lib-configstore/Makefile.GD32
+++ b/lib-configstore/Makefile.GD32
@@ -1,11 +1,13 @@
DEFINES =NDEBUG
ifneq ($(MAKE_FLAGS),)
+ ifneq (,$(findstring CONFIG_STORE_USE_RAM,$(MAKE_FLAGS)))
+ EXTRA_SRCDIR+=device/ram/gd32
+ endif
else
DEFINES+=CONFIG_STORE_USE_RAM
+ EXTRA_SRCDIR=device/ram/gd32
endif
-EXTRA_SRCDIR=device/ram/gd32
-
include Rules.mk
include ../firmware-template-gd32/lib/Rules.mk
diff --git a/lib-configstore/Rules.mk b/lib-configstore/Rules.mk
old mode 100644
new mode 100755
index 31498ee..af70068
--- a/lib-configstore/Rules.mk
+++ b/lib-configstore/Rules.mk
@@ -1,7 +1,6 @@
$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
-EXTRA_INCLUDES =../lib-flashcode/include ../lib-flash/include
-EXTRA_INCLUDES+=../lib-hal/include ../lib-properties/include ../lib-lightset/include ../lib-network/include
+EXTRA_INCLUDES+=../lib-properties/include
ifneq ($(MAKE_FLAGS),)
ifneq (,$(findstring CONFIG_STORE_USE_FILE,$(MAKE_FLAGS)))
@@ -23,153 +22,10 @@ ifneq ($(MAKE_FLAGS),)
ifneq (,$(findstring CONFIG_STORE_USE_SPI,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=device/spi
endif
-
- RDM=
-
- ifneq (,$(findstring ESP8266,$(MAKE_FLAGS)))
- EXTRA_SRCDIR+=src/network
- EXTRA_INCLUDES+=../lib-network/include
- # Remote config is not used with ESP8266
- EXTRA_INCLUDES+=../lib-remoteconfig/include
- endif
-
- ifeq (,$(findstring NO_EMAC,$(MAKE_FLAGS)))
- EXTRA_SRCDIR+=src/network
- EXTRA_INCLUDES+=../lib-network/include
- EXTRA_INCLUDES+=../lib-remoteconfig/include
- endif
-
- ifeq ($(findstring DISPLAY_UDF,$(MAKE_FLAGS)), DISPLAY_UDF)
- EXTRA_SRCDIR+=src/displayudf
- EXTRA_INCLUDES+=../lib-displayudf/include
- endif
-
- ifeq ($(findstring NODE_ARTNET,$(MAKE_FLAGS)), NODE_ARTNET)
- EXTRA_SRCDIR+=src/artnet
- EXTRA_INCLUDES+=../lib-artnet/include
- EXTRA_SRCDIR+=src/rdm
- RDM=1
- EXTRA_INCLUDES+=../lib-rdm/include ../lib-rdmsensor/include ../lib-rdmsubdevice/include
- ifeq ($(findstring ARTNET_VERSION=4,$(MAKE_FLAGS)), ARTNET_VERSION=4)
- EXTRA_INCLUDES+=../lib-e131/include
- endif
- endif
-
- ifeq ($(findstring NODE_E131,$(MAKE_FLAGS)), NODE_E131)
- EXTRA_SRCDIR+=src/e131
- EXTRA_INCLUDES+=../lib-e131/include
- endif
-
- ifeq ($(findstring NODE_LTC_SMPTE,$(MAKE_FLAGS)), NODE_LTC_SMPTE)
- EXTRA_SRCDIR+=src/ltc
- EXTRA_INCLUDES+=../lib-ltc/include ../lib-tcnet/include
- EXTRA_INCLUDES+=../lib-gps/include
- EXTRA_INCLUDES+=../lib-rgbpanel/include
- EXTRA_INCLUDES+=../lib-ws28xx/include
- endif
-
- ifeq ($(findstring NODE_NODE,$(MAKE_FLAGS)), NODE_NODE)
- EXTRA_SRCDIR+=src/node
- EXTRA_INCLUDES+=../lib-node/include
- EXTRA_INCLUDES+=../lib-artnet/include ../lib-rdmdiscovery/include
- EXTRA_INCLUDES+=../lib-e131/include
- endif
-
- ifeq ($(findstring NODE_OSC_CLIENT,$(MAKE_FLAGS)), NODE_OSC_CLIENT)
- EXTRA_SRCDIR+=src/oscclient
- EXTRA_INCLUDES+=../lib-oscclient/include
- endif
-
- ifeq ($(findstring OUTPUT_DMX_SEND,$(MAKE_FLAGS)),OUTPUT_DMX_SEND)
- EXTRA_SRCDIR+=src/dmx
- EXTRA_INCLUDES+=../lib-dmx/include
- endif
-
- ifeq ($(findstring OUTPUT_DMX_PIXEL,$(MAKE_FLAGS)), OUTPUT_DMX_PIXEL)
- EXTRA_SRCDIR+=src/pixel
- EXTRA_INCLUDES+=../lib-ws28xxdmx/include ../lib-ws28xx/include
- endif
-
- ifeq ($(findstring OUTPUT_DMX_SHOWFILE,$(MAKE_FLAGS)), OUTPUT_DMX_SHOWFILE)
- EXTRA_SRCDIR+=src/showfile
- EXTRA_INCLUDES+=../lib-showfile/include
- endif
-
- ifeq ($(findstring OUTPUT_DMX_SERIAL,$(MAKE_FLAGS)), OUTPUT_DMX_SERIAL)
- EXTRA_SRCDIR+=src/dmxserial
- EXTRA_INCLUDES+=../lib-dmxserial/include
- endif
-
- ifeq ($(findstring OUTPUT_DMX_STEPPER,$(MAKE_FLAGS)), OUTPUT_DMX_STEPPER)
- EXTRA_SRCDIR+=src/stepper
- EXTRA_INCLUDES+=../lib-l6470dmx/include ../lib-l6470/include
- endif
-
- ifeq ($(findstring OUTPUT_DMX_TLC59711,$(MAKE_FLAGS)), OUTPUT_DMX_TLC59711)
- EXTRA_SRCDIR+=src/tlc59711
- EXTRA_INCLUDES+=../lib-tlc59711dmx/include ../lib-tlc59711/include
- endif
-
- ifeq ($(findstring RDM_CONTROLLER,$(MAKE_FLAGS)), RDM_CONTROLLER)
- ifdef RDM
- else
- EXTRA_SRCDIR+=src/rdm
- RDM=1
- endif
- endif
-
- ifeq ($(findstring RDM_RESPONDER,$(MAKE_FLAGS)), RDM_RESPONDER)
- ifdef RDM
- else
- EXTRA_SRCDIR+=src/rdm
- RDM=1
- endif
- EXTRA_INCLUDES+=../lib-rdmresponder/include
- endif
-
- ifeq ($(findstring NODE_RDMNET_LLRP_ONLY,$(MAKE_FLAGS)), NODE_RDMNET_LLRP_ONLY)
- ifdef RDM
- else
- EXTRA_SRCDIR+=src/rdm
- RDM=1
- endif
- EXTRA_INCLUDES+=../lib-rdm/include ../lib-rdmsensor/include ../lib-rdmsubdevice/include
- endif
-
- ifeq ($(findstring WIDGET_HAVE_FLASHROM,$(MAKE_FLAGS)), WIDGET_HAVE_FLASHROM)
- EXTRA_SRCDIR+=src/widget
- EXTRA_INCLUDES+=../lib-widget/include
- endif
else
- EXTRA_SRCDIR+=src/artnet
- EXTRA_INCLUDES+=../lib-artnet/include
- EXTRA_SRCDIR+=src/e131
- EXTRA_INCLUDES+=../lib-e131/include
- EXTRA_SRCDIR+=src/node
- EXTRA_INCLUDES+=../lib-node/include ../lib-rdmdiscovery/include
- EXTRA_SRCDIR+=src/ltc
- EXTRA_INCLUDES+=../lib-ltc/include ../lib-tcnet/include
- EXTRA_INCLUDES+=../lib-gps/include
- EXTRA_INCLUDES+=../lib-rgbpanel/include
- EXTRA_INCLUDES+=../lib-ws28xx/include
- EXTRA_SRCDIR+=src/rdm
- EXTRA_INCLUDES+=../lib-rdm/include ../lib-rdmsensor/include ../lib-rdmsubdevice/include
- EXTRA_SRCDIR+=src/stepper
- EXTRA_INCLUDES+=../lib-l6470dmx/include ../lib-l6470/include
- EXTRA_INCLUDES+=../lib-tlc59711dmx/include ../lib-tlc59711/include
-
- DEFINES+=ARTNET_VERSION=4
- DEFINES+=LIGHTSET_PORTS=4
- DEFINES+=CONFIG_PIXELDMX_MAX_PORTS=8
- DEFINES+=CONFIG_DDPDISPLAY_MAX_PORTS=8
+ EXTRA_SRCDIR+=device/file
+ EXTRA_SRCDIR+=device/i2c
+ EXTRA_SRCDIR+=device/ram
+ EXTRA_SRCDIR+=device/rom
+ EXTRA_SRCDIR+=device/spi
endif
-
-EXTRA_INCLUDES+=../lib-displayudf/include ../lib-display/include
-EXTRA_INCLUDES+=../lib-dmxsend/include
-EXTRA_INCLUDES+=../lib-dmxmonitor/include
-EXTRA_INCLUDES+=../lib-dmxreceiver/include ../lib-dmx/include
-EXTRA_INCLUDES+=../lib-oscserver/include
-EXTRA_INCLUDES+=../lib-rdm/include ../lib-rdmsensor/include ../lib-rdmsubdevice/include
-EXTRA_INCLUDES+=../lib-spiflashinstall/include
-EXTRA_INCLUDES+=../lib-device/include
-EXTRA_INCLUDES+=../lib-midi/include
\ No newline at end of file
diff --git a/lib-configstore/device/rom/storedevice.cpp b/lib-configstore/device/rom/storedevice.cpp
old mode 100644
new mode 100755
index d9be65d..f06bad4
--- a/lib-configstore/device/rom/storedevice.cpp
+++ b/lib-configstore/device/rom/storedevice.cpp
@@ -26,8 +26,7 @@
#include
#include
-#include "storedevice.h"
-
+#include "configstoredevice.h"
#include "flashcode.h"
#include "debug.h"
diff --git a/lib-configstore/device/spi/storedevice.cpp b/lib-configstore/device/spi/storedevice.cpp
old mode 100644
new mode 100755
index 4f3cb7f..1c77549
--- a/lib-configstore/device/spi/storedevice.cpp
+++ b/lib-configstore/device/spi/storedevice.cpp
@@ -2,7 +2,7 @@
* @file storedevice.cpp
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +26,9 @@
#include
#include
-#include "storedevice.h"
+#include "configstoredevice.h"
#include "spi/spi_flash.h"
+
#include "debug.h"
StoreDevice::StoreDevice() {
@@ -36,11 +37,11 @@ StoreDevice::StoreDevice() {
if (spi_flash_probe(0, 0, 0) < 0) {
DEBUG_PUTS("No SPI flash chip");
} else {
- printf("StoreDevice: Detected %s with sector size %u total %u bytes [%u kB]\n",
+ printf("StoreDevice: %s sector size %u total %u bytes [%u kB]\n",
spi_flash_get_name(),
- spi_flash_get_sector_size(),
- spi_flash_get_size(),
- spi_flash_get_size() / 1024U);
+ static_cast(spi_flash_get_sector_size()),
+ static_cast(spi_flash_get_size()),
+ static_cast(spi_flash_get_size() / 1024U));
m_IsDetected = true;
}
diff --git a/lib-configstore/include/configstore.h b/lib-configstore/include/configstore.h
old mode 100755
new mode 100644
index 73b23ae..bb69861
--- a/lib-configstore/include/configstore.h
+++ b/lib-configstore/include/configstore.h
@@ -2,7 +2,7 @@
* @file configstore.h
*
*/
-/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,8 +27,14 @@
#define CONFIGSTORE_H_
#include
+#include
+#include
-#include "storedevice.h"
+#include "configstoredevice.h"
+
+#include "utc.h"
+
+#include "debug.h"
namespace configstore {
enum class Store {
@@ -58,13 +64,13 @@ enum class Store {
GPS,
RGBPANEL,
NODE,
+ PCA9685,
LAST
};
enum class State {
IDLE, CHANGED, CHANGED_WAITING, ERASING, ERASED, ERASED_WAITING, WRITING
};
-
} // namespace configstore
class ConfigStore: StoreDevice {
@@ -75,18 +81,19 @@ class ConfigStore: StoreDevice {
;
}
- bool HaveFlashChip() const {
- return s_bHaveFlashChip;
- }
-
void Update(configstore::Store store, uint32_t nOffset, const void *pData, uint32_t nDataLength, uint32_t nSetList = 0, uint32_t nOffsetSetList = 0);
void Update(configstore::Store store, const void *pData, uint32_t nDataLength) {
Update(store, 0, pData, nDataLength);
}
- void Copy(const configstore::Store store, void *pData, uint32_t nDataLength, uint32_t nOffset = 0);
+ void Copy(const configstore::Store store, void *pData, uint32_t nDataLength, uint32_t nOffset = 0, const bool doUpdate = true);
void ResetSetList(configstore::Store store);
+ void ResetSetListAll() {
+ for (uint32_t i = 0; i < static_cast(configstore::Store::LAST); i++) {
+ ResetSetList(static_cast(i));
+ }
+ }
bool Flash();
@@ -94,6 +101,53 @@ class ConfigStore: StoreDevice {
void Delay();
+ /*
+ * Environment
+ */
+
+ bool SetEnvUtcOffset(const int8_t nHours, const uint8_t nMinutes) {
+ int32_t nUtcOffset;
+
+ DEBUG_PRINTF("nHours=%d, nMinutes =%u", nHours, nMinutes);
+
+ if (hal::utc_validate(nHours, nMinutes, nUtcOffset)) {
+ auto *p = reinterpret_cast(&s_SpiFlashData[FlashStore::SIGNATURE_SIZE]);
+
+ if (p->nUtcOffset != nUtcOffset) {
+ p->nUtcOffset = nUtcOffset;
+ s_State = configstore::State::CHANGED;
+ }
+
+ DEBUG_EXIT
+ return true;
+ }
+
+ DEBUG_EXIT
+ return false;
+ }
+
+ void GetEnvUtcOffset(int8_t& nHours, uint8_t& nMinutes) {
+ const auto *p = reinterpret_cast(&s_SpiFlashData[FlashStore::SIGNATURE_SIZE]);
+
+ DEBUG_PRINTF("p->nUtcOffset=%d", p->nUtcOffset);
+
+ assert((p->nUtcOffset / 3600) <= INT8_MAX);
+ assert((p->nUtcOffset / 3600) >= INT8_MIN);
+
+ nHours = static_cast(p->nUtcOffset / 3600);
+
+ if (nHours > 0) {
+ nMinutes = static_cast(static_cast(p->nUtcOffset - (nHours * 3600)) / 60U);
+ } else {
+ nMinutes = static_cast(static_cast((nHours * 3600) - p->nUtcOffset) / 60U);
+ }
+ }
+
+ int32_t GetEnvUtcOffset() const {
+ const auto *p = reinterpret_cast(&s_SpiFlashData[FlashStore::SIGNATURE_SIZE]);
+ return p->nUtcOffset;
+ }
+
static ConfigStore *Get() {
return s_pThis;
}
@@ -102,10 +156,20 @@ class ConfigStore: StoreDevice {
uint32_t GetStoreOffset(configstore::Store tStore);
private:
+ struct Env {
+ int32_t nUtcOffset;
+ uint8_t filler[12];
+ };
+
struct FlashStore {
- static constexpr auto SIZE = 4096U;
+ static constexpr uint32_t SIGNATURE_SIZE = 16;
+ static constexpr uint32_t ENV_SIZE = 16;
+ static constexpr uint32_t OFFSET_STORES = SIGNATURE_SIZE + ENV_SIZE;
+ static constexpr uint32_t SIZE = 4096;
};
+ static_assert(sizeof(struct Env) == FlashStore::ENV_SIZE, "");
+
static bool s_bHaveFlashChip;
static configstore::State s_State;
diff --git a/lib-configstore/include/storedevice.h b/lib-configstore/include/configstoredevice.h
similarity index 100%
rename from lib-configstore/include/storedevice.h
rename to lib-configstore/include/configstoredevice.h
diff --git a/lib-configstore/include/envparams.h b/lib-configstore/include/envparams.h
new file mode 100755
index 0000000..6333389
--- /dev/null
+++ b/lib-configstore/include/envparams.h
@@ -0,0 +1,48 @@
+/**
+ * @file envparams.h
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef ENVPARAMS_H_
+#define ENVPARAMS_H_
+
+#include
+
+class EnvParams {
+public:
+ EnvParams();
+
+ void LoadAndSet();
+ void LoadAndSet(const char *pBuffer, uint32_t nLength);
+
+ void Builder(char *pBuffer, uint32_t nLength, uint32_t& nSize);
+
+public:
+ static void staticCallbackFunction(void *p, const char *s);
+
+private:
+ void Dump();
+ void callbackFunction(const char *s);
+};
+
+#endif /* ENVPARAMS_H_ */
diff --git a/lib-display/src/display_timeout.cpp b/lib-configstore/include/envparamsconst.h
old mode 100644
new mode 100755
similarity index 79%
rename from lib-display/src/display_timeout.cpp
rename to lib-configstore/include/envparamsconst.h
index 5b403dd..dcc2ea2
--- a/lib-display/src/display_timeout.cpp
+++ b/lib-configstore/include/envparamsconst.h
@@ -1,8 +1,8 @@
/**
- * @file display_timeout.cpp
+ * @file envparamsconst.h
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,9 +23,13 @@
* THE SOFTWARE.
*/
-namespace display {
-namespace timeout {
-void __attribute__((weak)) gpio_init() {}
-bool __attribute__((weak)) gpio_renew() { return false;}
-} // namespace timeout
-} // namespace display
+#ifndef ENVPARAMSCONST_H_
+#define ENVPARAMSCONST_H_
+
+struct EnvParamsConst {
+ static const char FILE_NAME[];
+
+ static const char UTC_OFFSET[];
+};
+
+#endif /* ENVPARAMSCONST_H_ */
diff --git a/lib-configstore/include/storenetwork.h b/lib-configstore/include/storenetwork.h
deleted file mode 100755
index 427c05b..0000000
--- a/lib-configstore/include/storenetwork.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * @file storenetwork.h
- *
- */
-/* Copyright (C) 2018-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef STORENETWORK_H_
-#define STORENETWORK_H_
-
-#include
-
-#include "network.h"
-#include "networkparams.h"
-#include "configstore.h"
-
-class StoreNetwork final: public NetworkParamsStore, public NetworkStore {
-public:
- StoreNetwork();
-
- void Update(const struct networkparams::Params *pNetworkParams) override {
- ConfigStore::Get()->Update(configstore::Store::NETWORK, pNetworkParams, sizeof(struct networkparams::Params));
- }
-
- void Copy(struct networkparams::Params *pNetworkParams) override {
- ConfigStore::Get()->Copy(configstore::Store::NETWORK, pNetworkParams, sizeof(struct networkparams::Params));
- }
-
- void SaveIp(uint32_t nIp) override {
- ConfigStore::Get()->Update(configstore::Store::NETWORK, __builtin_offsetof(struct networkparams::Params, nLocalIp), &nIp, sizeof(uint32_t), networkparams::Mask::IP_ADDRESS);
- }
-
- void SaveNetMask(uint32_t nNetMask) override {
- ConfigStore::Get()->Update(configstore::Store::NETWORK, __builtin_offsetof(struct networkparams::Params, nNetmask), &nNetMask, sizeof(uint32_t), networkparams::Mask::NET_MASK);
- }
-
- void SaveGatewayIp(uint32_t nGatewayIp) override {
- ConfigStore::Get()->Update(configstore::Store::NETWORK, __builtin_offsetof(struct networkparams::Params, nGatewayIp), &nGatewayIp, sizeof(uint32_t), networkparams::Mask::DEFAULT_GATEWAY);
- }
-
- void SaveHostName(const char *pHostName, uint32_t nLength) override {
- nLength = std::min(nLength,static_cast(network::HOSTNAME_SIZE));
- ConfigStore::Get()->Update(configstore::Store::NETWORK, __builtin_offsetof(struct networkparams::Params, aHostName), pHostName, nLength, networkparams::Mask::HOSTNAME);
- }
-
- void SaveDhcp(bool bIsDhcpUsed) override {
- ConfigStore::Get()->Update(configstore::Store::NETWORK, __builtin_offsetof(struct networkparams::Params, bIsDhcpUsed), &bIsDhcpUsed, sizeof(bool), networkparams::Mask::DHCP);
- }
-
- static StoreNetwork *Get() {
- return s_pThis;
- }
-
-private:
- static StoreNetwork *s_pThis;
-};
-
-#endif /* STORENETWORK_H_ */
diff --git a/lib-configstore/include/storeremoteconfig.h b/lib-configstore/include/storeremoteconfig.h
deleted file mode 100755
index 46360d4..0000000
--- a/lib-configstore/include/storeremoteconfig.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * @file storeremoteconfig.h
- *
- */
-/* Copyright (C) 2019-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef STOREREMOTECONFIG_H_
-#define STOREREMOTECONFIG_H_
-
-#include "remoteconfigparams.h"
-
-#include "configstore.h"
-
-class StoreRemoteConfig final: public RemoteConfigParamsStore {
-public:
- StoreRemoteConfig();
-
- void Update(const struct TRemoteConfigParams *pRemoteConfigParams) override {
- ConfigStore::Get()->Update(configstore::Store::RCONFIG, pRemoteConfigParams, sizeof(struct TRemoteConfigParams));
- }
-
- void Copy(struct TRemoteConfigParams *pRemoteConfigParams) override {
- ConfigStore::Get()->Copy(configstore::Store::RCONFIG, pRemoteConfigParams, sizeof(struct TRemoteConfigParams));
- }
-
- static StoreRemoteConfig *Get() {
- return s_pThis;
- }
-
-private:
- static StoreRemoteConfig *s_pThis;
-};
-
-#endif /* STOREREMOTECONFIG_H_ */
diff --git a/lib-configstore/include/storetcnet.h b/lib-configstore/include/storetcnet.h
deleted file mode 100755
index 093f77f..0000000
--- a/lib-configstore/include/storetcnet.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * @file storetcnet.h
- *
- */
-/* Copyright (C) 2019-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef STORETCNET_H_
-#define STORETCNET_H_
-
-#include "tcnetparams.h"
-
-#include "spiflashstore.h"
-
-class StoreTCNet final: public TCNetParamsStore {
-public:
- StoreTCNet();
-
- void Update(const struct tcnetparams::Params *pTCNetParams) override {
- SpiFlashStore::Get()->Update(spiflashstore::Store::TCNET, pTCNetParams, sizeof(struct tcnetparams::Params));
- }
-
- void Copy(struct tcnetparams::Params *pTCNetParams) override {
- SpiFlashStore::Get()->Copy(spiflashstore::Store::TCNET, pTCNetParams, sizeof(struct tcnetparams::Params));
- }
-
- static StoreTCNet *Get() {
- return s_pThis;
- }
-
-private:
- static StoreTCNet *s_pThis;
-};
-
-#endif /* STORETCNET_H_ */
diff --git a/lib-configstore/include/storewidget.h b/lib-configstore/include/storewidget.h
deleted file mode 100755
index d27820f..0000000
--- a/lib-configstore/include/storewidget.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * @file storewidget.h
- *
- */
-/* Copyright (C) 2019-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef STOREWIDGET_H_
-#define STOREWIDGET_H_
-
-#include "widgetparams.h"
-#include "widgetstore.h"
-
-#include "spiflashstore.h"
-
-class StoreWidget final: public WidgetParamsStore, public WidgetStore {
-public:
- StoreWidget();
-
- void Update(const struct TWidgetParams* pWidgetParams) {
- SpiFlashStore::Get()->Update(spiflashstore::Store::WIDGET, pWidgetParams, sizeof(struct TWidgetParams));
- }
-
- void Copy(struct TWidgetParams* pWidgetParams) {
- SpiFlashStore::Get()->Copy(spiflashstore::Store::WIDGET, pWidgetParams, sizeof(struct TWidgetParams));
- }
-
- void UpdateBreakTime(uint8_t nBreakTime) {
- SpiFlashStore::Get()->Update(spiflashstore::Store::WIDGET, __builtin_offsetof(struct TWidgetParams, nBreakTime), &nBreakTime, sizeof(uint8_t), WidgetParamsMask::BREAK_TIME);
- }
-
- void UpdateMabTime(uint8_t nMabTime) {
- SpiFlashStore::Get()->Update(spiflashstore::Store::WIDGET, __builtin_offsetof(struct TWidgetParams, nMabTime), &nMabTime, sizeof(uint8_t), WidgetParamsMask::MAB_TIME);
- }
-
- void UpdateRefreshRate(uint8_t nRefreshRate) {
- SpiFlashStore::Get()->Update(spiflashstore::Store::WIDGET, __builtin_offsetof(struct TWidgetParams, nRefreshRate), &nRefreshRate, sizeof(uint8_t), WidgetParamsMask::REFRESH_RATE);
- }
-
- static StoreWidget* Get() {
- return s_pThis;
- }
-
-private:
- static StoreWidget *s_pThis;
-};
-
-#endif /* STOREWIDGET_H_ */
diff --git a/lib-configstore/src/configstore.cpp b/lib-configstore/src/configstore.cpp
old mode 100644
new mode 100755
index 5e325d4..4b6bbf2
--- a/lib-configstore/src/configstore.cpp
+++ b/lib-configstore/src/configstore.cpp
@@ -2,7 +2,7 @@
* @file configstore.cpp
*
*/
-/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,13 +36,16 @@
#include "debug.h"
+namespace global {
+extern int32_t *gp_nUtcOffset;
+} // namespace global
+
using namespace configstore;
static constexpr uint8_t s_aSignature[] = {'A', 'v', 'V', 0x01};
-static constexpr auto OFFSET_STORES = ((((sizeof(s_aSignature) + 15) / 16) * 16) + 16); // +16 is reserved for future use
-static constexpr uint32_t s_aStorSize[static_cast(Store::LAST)] = {96, 32, 64, 64, 32, 32, 480, 64, 32, 96, 48, 32, 944, 48, 64, 32, 96, 32, 1024, 32, 32, 64, 96, 32, 32, 320};
+static constexpr uint32_t s_aStorSize[static_cast(Store::LAST)] = {96, 32, 64, 64, 32, 32, 480, 64, 32, 96, 48, 32, 944, 48, 64, 32, 96, 32, 1024, 32, 32, 64, 96, 32, 32, 320, 32};
#ifndef NDEBUG
-static constexpr char s_aStoreName[static_cast(Store::LAST)][16] = {"Network", "DMX", "Pixel", "LTC", "MIDI", "LTC ETC", "OSC Server", "TLC59711", "USB Pro", "RDM Device", "RConfig", "TCNet", "OSC Client", "Display", "LTC Display", "Monitor", "SparkFun", "Slush", "Motors", "Show", "Serial", "RDM Sensors", "RDM SubDevices", "GPS", "RGB Panel", "Node"};
+static constexpr char s_aStoreName[static_cast(Store::LAST)][16] = {"Network", "DMX", "Pixel", "LTC", "MIDI", "LTC ETC", "OSC Server", "TLC59711", "USB Pro", "RDM Device", "RConfig", "TCNet", "OSC Client", "Display", "LTC Display", "Monitor", "SparkFun", "Slush", "Motors", "Show", "Serial", "RDM Sensors", "RDM SubDevices", "GPS", "RGB Panel", "Node", "PCA9685"};
#endif
bool ConfigStore::s_bHaveFlashChip;
@@ -57,9 +60,13 @@ ConfigStore *ConfigStore::s_pThis;
ConfigStore::ConfigStore() {
DEBUG_ENTRY
+ static_assert(sizeof(s_aSignature) <= FlashStore::SIGNATURE_SIZE);
+
assert(s_pThis == nullptr);
s_pThis = this;
+ global::gp_nUtcOffset = reinterpret_cast(&s_SpiFlashData[FlashStore::SIGNATURE_SIZE]);
+
s_bHaveFlashChip = StoreDevice::IsDetected();
assert(FlashStore::SIZE <= StoreDevice::GetSize());
@@ -94,20 +101,32 @@ ConfigStore::ConfigStore() {
if (!bSignatureOK) {
DEBUG_PUTS("No signature");
- memset(&s_SpiFlashData[OFFSET_STORES], 0, FlashStore::SIZE - OFFSET_STORES);
+ memset(&s_SpiFlashData[FlashStore::SIGNATURE_SIZE], 0, FlashStore::SIZE - FlashStore::SIGNATURE_SIZE);
s_State = State::CHANGED;
}
- s_nSpiFlashStoreSize = OFFSET_STORES;
+ s_nSpiFlashStoreSize = FlashStore::OFFSET_STORES;
for (uint32_t j = 0; j < static_cast(Store::LAST); j++) {
s_nSpiFlashStoreSize += s_aStorSize[j];
}
- DEBUG_PRINTF("OFFSET_STORES=%d, m_nSpiFlashStoreSize=%d", static_cast(OFFSET_STORES), s_nSpiFlashStoreSize);
+ DEBUG_PRINTF("FlashStore::OFFSET_STORES=%d, m_nSpiFlashStoreSize=%d", static_cast(FlashStore::OFFSET_STORES), s_nSpiFlashStoreSize);
assert(s_nSpiFlashStoreSize <= FlashStore::SIZE);
+ for (uint32_t nStore = 0; nStore < static_cast(Store::LAST); nStore++) {
+ auto *pSet = reinterpret_cast((&s_SpiFlashData[GetStoreOffset(static_cast(nStore))]));
+ if (*pSet == UINT32_MAX) {
+ *pSet = 0;
+ }
+ }
+
+ auto *p = reinterpret_cast(&s_SpiFlashData[FlashStore::SIGNATURE_SIZE]);
+ if (p->nUtcOffset == -1) {
+ p->nUtcOffset = 0;
+ }
+
DEBUG_PUTS("");
debug_dump(s_SpiFlashData, FlashStore::SIZE);
@@ -117,7 +136,7 @@ ConfigStore::ConfigStore() {
uint32_t ConfigStore::GetStoreOffset(Store store) {
assert(store < Store::LAST);
- uint32_t nOffset = OFFSET_STORES;
+ uint32_t nOffset = FlashStore::OFFSET_STORES;
for (uint32_t i = 0; i < static_cast(store); i++) {
nOffset += s_aStorSize[i];
@@ -171,9 +190,8 @@ void ConfigStore::Update(Store store, uint32_t nOffset, const void *pData, uint3
pSrc++;
}
- if ((0 != nOffset) && (bIsChanged) && (nSetList != 0)) {
- auto *pSet = reinterpret_cast((&s_SpiFlashData[GetStoreOffset(store)] + nOffsetSetList));
-
+ if (bIsChanged){
+ auto *pSet = reinterpret_cast((&s_SpiFlashData[GetStoreOffset(store)] + nOffsetSetList));
*pSet |= nSetList;
}
@@ -181,12 +199,13 @@ void ConfigStore::Update(Store store, uint32_t nOffset, const void *pData, uint3
s_State = State::CHANGED;
}
+ debug_dump(&s_SpiFlashData[GetStoreOffset(store)] + nOffsetSetList, 8);
DEBUG_EXIT
}
-void ConfigStore::Copy(const Store store, void *pData, uint32_t nDataLength, uint32_t nOffset) {
+void ConfigStore::Copy(const Store store, void *pData, uint32_t nDataLength, uint32_t nOffset, const bool doUpdate) {
DEBUG_ENTRY
- DEBUG_PRINTF("[%s]:%u pData=%p, nDataLength=%u, nOffset=%u", s_aStoreName[static_cast(store)], static_cast(store), pData, nDataLength, nOffset);
+ DEBUG_PRINTF("[%s]:%u pData=%p, nDataLength=%u, nOffset=%u, doUpdate=%u", s_aStoreName[static_cast(store)], static_cast(store), pData, nDataLength, nOffset, doUpdate);
assert(store < Store::LAST);
assert(pData != nullptr);
@@ -210,7 +229,9 @@ void ConfigStore::Copy(const Store store, void *pData, uint32_t nDataLength, uin
return;
}
- Update(store, pData, nDataLength);
+ if (doUpdate) {
+ Update(store, pData, nDataLength);
+ }
DEBUG_EXIT
}
@@ -293,8 +314,8 @@ void ConfigStore::Dump() {
Hardware::Get()->WatchdogStop();
}
- debug_dump(s_SpiFlashData, OFFSET_STORES);
- printf("\n");
+ debug_dump(s_SpiFlashData, FlashStore::OFFSET_STORES);
+ puts("");
for (uint32_t j = 0; j < static_cast(Store::LAST); j++) {
printf("Store [%s]:%d\n", s_aStoreName[j], j);
@@ -302,7 +323,7 @@ void ConfigStore::Dump() {
auto *p = &s_SpiFlashData[GetStoreOffset(static_cast(j))];
debug_dump(p, static_cast(s_aStorSize[j]));
- printf("\n");
+ puts("");
}
if (IsWatchDog) {
diff --git a/lib-configstore/src/envparams.cpp b/lib-configstore/src/envparams.cpp
new file mode 100755
index 0000000..cead222
--- /dev/null
+++ b/lib-configstore/src/envparams.cpp
@@ -0,0 +1,132 @@
+/**
+ * @file envparams.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if !defined(__clang__) // Needed for compiling on MacOS
+# pragma GCC push_options
+# pragma GCC optimize ("Os")
+#endif
+
+#include
+#include
+#include
+
+#include "envparams.h"
+#include "envparamsconst.h"
+
+#include "readconfigfile.h"
+#include "sscan.h"
+
+#include "propertiesbuilder.h"
+
+#include "configstore.h"
+
+#include "debug.h"
+
+EnvParams::EnvParams() {
+ DEBUG_ENTRY
+
+ DEBUG_EXIT
+}
+
+void EnvParams::LoadAndSet() {
+ DEBUG_ENTRY
+
+ assert(ConfigStore::Get() != nullptr);
+
+#if !defined(DISABLE_FS)
+ ReadConfigFile configfile(EnvParams::staticCallbackFunction, this);
+ configfile.Read(EnvParamsConst::FILE_NAME);
+#endif
+
+#ifndef NDEBUG
+ Dump();
+#endif
+
+ DEBUG_EXIT
+}
+
+void EnvParams::LoadAndSet(const char *pBuffer, uint32_t nLength) {
+ DEBUG_ENTRY
+
+ assert(ConfigStore::Get() != nullptr);
+
+ assert(pBuffer != nullptr);
+ assert(nLength != 0);
+
+ ReadConfigFile config(EnvParams::staticCallbackFunction, this);
+ config.Read(pBuffer, nLength);
+
+#ifndef NDEBUG
+ Dump();
+#endif
+ DEBUG_EXIT
+}
+
+void EnvParams::callbackFunction(const char *pLine) {
+ assert(pLine != nullptr);
+
+ int8_t nHours;
+ uint8_t nMinutes;
+
+ if (Sscan::UtcOffset(pLine, EnvParamsConst::UTC_OFFSET, nHours, nMinutes) == Sscan::OK) {
+ ConfigStore::Get()->SetEnvUtcOffset(nHours, nMinutes);
+ return;
+ }
+}
+
+void EnvParams::staticCallbackFunction(void *p, const char *s) {
+ assert(p != nullptr);
+ assert(s != nullptr);
+
+ (static_cast(p))->callbackFunction(s);
+}
+
+void EnvParams::Builder(char *pBuffer, uint32_t nLength, uint32_t& nSize) {
+ DEBUG_ENTRY
+
+ assert(pBuffer != nullptr);
+
+ PropertiesBuilder builder(EnvParamsConst::FILE_NAME, pBuffer, nLength);
+
+ int8_t nHours;
+ uint8_t nMinutes;
+ ConfigStore::Get()->GetEnvUtcOffset(nHours, nMinutes);
+ builder.AddUtcOffset(EnvParamsConst::UTC_OFFSET, nHours, nMinutes);
+
+ nSize = builder.GetSize();
+
+ DEBUG_PRINTF("nSize=%d", nSize);
+ DEBUG_EXIT
+}
+
+void EnvParams::Dump() {
+ printf("%s::%s \'%s\':\n", __FILE__, __FUNCTION__, EnvParamsConst::FILE_NAME);
+
+ puts("UTC Offset");
+ int8_t nHours;
+ uint8_t nMinutes;
+ ConfigStore::Get()->GetEnvUtcOffset(nHours, nMinutes);
+ printf(" %s=%.2d:%.2u [%d]\n", EnvParamsConst::UTC_OFFSET, nHours, nMinutes, ConfigStore::Get()->GetEnvUtcOffset());
+}
diff --git a/lib-configstore/src/envparamsconst.cpp b/lib-configstore/src/envparamsconst.cpp
new file mode 100755
index 0000000..3788070
--- /dev/null
+++ b/lib-configstore/src/envparamsconst.cpp
@@ -0,0 +1,30 @@
+/**
+ * @file envparamsconst.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "envparamsconst.h"
+
+const char EnvParamsConst::FILE_NAME[] = "env.txt";
+
+const char EnvParamsConst::UTC_OFFSET[] = "utc_offset";
diff --git a/lib-configstore/src/platform_configstore.h b/lib-configstore/src/platform_configstore.h
old mode 100644
new mode 100755
diff --git a/lib-debug/.cproject b/lib-debug/.cproject
deleted file mode 100755
index e20034b..0000000
--- a/lib-debug/.cproject
+++ /dev/null
@@ -1,239 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib-debug/.project b/lib-debug/.project
deleted file mode 100755
index e661d6a..0000000
--- a/lib-debug/.project
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
- lib-debug
-
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.core.ccnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
diff --git a/lib-debug/.settings/language.settings.xml b/lib-debug/.settings/language.settings.xml
deleted file mode 100755
index 3bc3d7e..0000000
--- a/lib-debug/.settings/language.settings.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib-debug/.settings/org.eclipse.cdt.core.prefs b/lib-debug/.settings/org.eclipse.cdt.core.prefs
deleted file mode 100644
index c8ec5df..0000000
--- a/lib-debug/.settings/org.eclipse.cdt.core.prefs
+++ /dev/null
@@ -1,6 +0,0 @@
-doxygen/doxygen_new_line_after_brief=true
-doxygen/doxygen_use_brief_tag=false
-doxygen/doxygen_use_javadoc_tags=true
-doxygen/doxygen_use_pre_tag=false
-doxygen/doxygen_use_structural_commands=false
-eclipse.preferences.version=1
diff --git a/lib-debug/.settings/org.eclipse.core.resources.prefs b/lib-debug/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 99f26c0..0000000
--- a/lib-debug/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
diff --git a/lib-debug/Makefile.GD32 b/lib-debug/Makefile.GD32
deleted file mode 100644
index e62a508..0000000
--- a/lib-debug/Makefile.GD32
+++ /dev/null
@@ -1,3 +0,0 @@
-EXTRA_SRCDIR=
-
-include ../firmware-template-gd32/lib/Rules.mk
\ No newline at end of file
diff --git a/lib-debug/src/debug.cpp b/lib-debug/src/debug.cpp
deleted file mode 100644
index e69de29..0000000
diff --git a/lib-display/.settings/language.settings.xml b/lib-display/.settings/language.settings.xml
index 4aa88d1..08576d4 100644
--- a/lib-display/.settings/language.settings.xml
+++ b/lib-display/.settings/language.settings.xml
@@ -1,14 +1,11 @@
-
+
+
-
-
-
-
-
+
diff --git a/lib-display/Makefile.GD32 b/lib-display/Makefile.GD32
index 1ce9f25..a1ffa83 100644
--- a/lib-display/Makefile.GD32
+++ b/lib-display/Makefile.GD32
@@ -1,6 +1,6 @@
DEFINES=NDEBUG
-EXTRA_INCLUDES=../lib-hal/include
+EXTRA_INCLUDES=
include Rules.mk
include ../firmware-template-gd32/lib/Rules.mk
diff --git a/lib-display/include/display.h b/lib-display/include/display.h
index c8d9215..ab4d374 100644
--- a/lib-display/include/display.h
+++ b/lib-display/include/display.h
@@ -2,7 +2,7 @@
* @file display.h
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,17 +26,14 @@
#ifndef DISPLAY_H_
#define DISPLAY_H_
-#include "display7segment.h"
+#include
+
#include "console.h"
namespace display {
struct Defaults {
- static constexpr auto SEEP_TIMEOUT = 5;
+ static constexpr uint32_t SEEP_TIMEOUT = 5;
};
-namespace timeout {
-void gpio_init();
-bool gpio_renew();
-} // namespace timeout
} // namespace display
#if !defined (CONFIG_DISPLAY_USE_CUSTOM)
diff --git a/lib-display/include/display7segment.h b/lib-display/include/display7segment.h
deleted file mode 100644
index cbc545b..0000000
--- a/lib-display/include/display7segment.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * @file display7segment.h
- *
- */
-/* Copyright (C) 2019-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef DISPLAY7SEGMENT_H_
-#define DISPLAY7SEGMENT_H_
-
-#include
-
-namespace display7segment {
-static constexpr uint8_t CH_0 = 0x3F; // 0b00111111
-static constexpr uint8_t CH_1 = 0x06; // 0b00000110
-static constexpr uint8_t CH_2 = 0x5B; // 0b01011011
-static constexpr uint8_t CH_3 = 0x4F; // 0b01001111
-static constexpr uint8_t CH_4 = 0x66; // 0b01100110
-static constexpr uint8_t CH_5 = 0x6D; // 0b01101101
-static constexpr uint8_t CH_6 = 0x7D; // 0b01111101
-static constexpr uint8_t CH_7 = 0x07; // 0b00000111
-static constexpr uint8_t CH_8 = 0x7F; // 0b01111111
-static constexpr uint8_t CH_9 = 0x6F; // 0b01101111
-static constexpr uint8_t CH_A = 0x77; // 0b01110111
-static constexpr uint8_t CH_B = 0x7C; // 0b01111100
-static constexpr uint8_t CH_C = 0x39; // 0b00111001
-static constexpr uint8_t CH_D = 0x5E; // 0b01011110
-static constexpr uint8_t CH_E = 0x79; // 0b01111001
-static constexpr uint8_t CH_F = 0x71; // 0b01110001
-static constexpr uint8_t CH_P = 0x73; // 0b01110011
-static constexpr uint8_t CH_MIN = 0x40; // 0b01000000
-static constexpr uint8_t CH_DP = 0x80; // 0b10000000
-static constexpr uint8_t CH_BLANK = 0x00; // 0b00000000
-
-static constexpr uint16_t Msg(uint8_t nDigitRight, uint8_t nDigitLeft) {
- return static_cast((nDigitLeft << 8) | nDigitRight);
-}
-} // namespace display7segment
-
-enum class Display7SegmentMessage {
- // Generic Digits
- GENERIC_0 = display7segment::Msg(display7segment::CH_0, display7segment::CH_BLANK),
- GENERIC_1 = display7segment::Msg(display7segment::CH_1, display7segment::CH_BLANK),
- GENERIC_2 = display7segment::Msg(display7segment::CH_2, display7segment::CH_BLANK),
- GENERIC_3 = display7segment::Msg(display7segment::CH_3, display7segment::CH_BLANK),
- GENERIC_4 = display7segment::Msg(display7segment::CH_4, display7segment::CH_BLANK),
- GENERIC_5 = display7segment::Msg(display7segment::CH_5, display7segment::CH_BLANK),
- GENERIC_6 = display7segment::Msg(display7segment::CH_6, display7segment::CH_BLANK),
- GENERIC_7 = display7segment::Msg(display7segment::CH_7, display7segment::CH_BLANK),
- GENERIC_8 = display7segment::Msg(display7segment::CH_8, display7segment::CH_BLANK),
- GENERIC_9 = display7segment::Msg(display7segment::CH_9, display7segment::CH_BLANK),
- // Startup messages
- INFO_STARTUP = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_0),
- INFO_NETWORK_INIT = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_1),
- INFO_DHCP = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_2),
- INFO_IP = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_3),
- INFO_NTP = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_4),
- INFO_SPARKFUN = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_5),
- INFO_CPLD = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_6),
- INFO_MDNS_CONFIG = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_7),
- INFO_RDMNET_CONFIG = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_8),
- //
- INFO_NETWORK_SHUTDOWN = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_9),
- //
- INFO_NODE_PARMAMS = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_4),
- INFO_BRIDGE_PARMAMS = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_4),
- INFO_OSCCLIENT_PARMAMS = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_4),
- //
- INFO_RDM_RUN = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_5),
- INFO_NODE_START = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_6),
- INFO_BRIDGE_START = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_6),
- INFO_OSCCLIENT_START = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_6),
- INFO_RDMNET_START = display7segment::Msg(display7segment::CH_BLANK, display7segment::CH_6),
- //
- INFO_NONE = display7segment::Msg(display7segment::CH_DP, display7segment::CH_DP),
- INFO_NODE_STARTED = display7segment::Msg(display7segment::CH_DP, display7segment::CH_DP),
- INFO_BRIDGE_STARTED = display7segment::Msg(display7segment::CH_DP, display7segment::CH_DP),
- INFO_OSCCLIENT_STARTED = display7segment::Msg(display7segment::CH_DP, display7segment::CH_DP),
- INFO_RDMNET_STARTED = display7segment::Msg(display7segment::CH_DP, display7segment::CH_DP),
- // SPI Flash messages
- INFO_SPI_NONE = display7segment::Msg(display7segment::CH_C, display7segment::CH_MIN),
- INFO_SPI_CHECK = display7segment::Msg(display7segment::CH_C, display7segment::CH_0),
- INFO_SPI_ERASE = display7segment::Msg(display7segment::CH_C, display7segment::CH_1),
- INFO_SPI_WRITING = display7segment::Msg(display7segment::CH_C, display7segment::CH_2),
- INFO_SPI_NODIFF = display7segment::Msg(display7segment::CH_C, display7segment::CH_3),
- INFO_SPI_DONE = display7segment::Msg(display7segment::CH_C, display7segment::CH_C),
- INFO_SPI_UPDATE = display7segment::Msg(display7segment::CH_C, display7segment::CH_F),
- // Firmware TFTP messages
- INFO_TFTP_ON = display7segment::Msg(display7segment::CH_F, display7segment::CH_MIN),
- INFO_TFTP_STARTED = display7segment::Msg(display7segment::CH_F, display7segment::CH_1),
- INFO_TFTP_ENDED = display7segment::Msg(display7segment::CH_F, display7segment::CH_2),
- INFO_TFTP_OFF = display7segment::Msg(display7segment::CH_F, display7segment::CH_DP),
- // Informational / Warning messages
- INFO_REBOOTING = display7segment::Msg(display7segment::CH_MIN, display7segment::CH_MIN),
- INFO_DATALOSS = display7segment::Msg(display7segment::CH_D, display7segment::CH_MIN),
- // Error messages
- ERROR_DHCP = display7segment::Msg(display7segment::CH_E, display7segment::CH_2),
- ERROR_NTP = display7segment::Msg(display7segment::CH_E, display7segment::CH_4),
- ERROR_SPARKFUN = display7segment::Msg(display7segment::CH_E, display7segment::CH_5),
- ERROR_MCP23S017 = display7segment::Msg(display7segment::CH_E, display7segment::CH_8),
- ERROR_SI5351A = display7segment::Msg(display7segment::CH_E, display7segment::CH_9),
- ERROR_NEXTION = display7segment::Msg(display7segment::CH_E, display7segment::CH_A),
- ERROR_SPI = display7segment::Msg(display7segment::CH_E, display7segment::CH_C),
- ERROR_FATAL = display7segment::Msg(display7segment::CH_E, display7segment::CH_E),
- ERROR_TFTP = display7segment::Msg(display7segment::CH_E, display7segment::CH_F),
- // LTC messages
- LTC_WAITING = display7segment::Msg(display7segment::CH_DP, display7segment::CH_DP),
- LTC_FILM = display7segment::Msg(display7segment::CH_2, display7segment::CH_4),
- LTC_EBU = display7segment::Msg(display7segment::CH_2, display7segment::CH_5),
- LTC_DF = display7segment::Msg(display7segment::CH_2, display7segment::CH_9),
- LTC_SMPTE = display7segment::Msg(display7segment::CH_3, display7segment::CH_0),
- // OSC Client messages
- INFO_OSCCLIENT_PING_PONG = display7segment::Msg(display7segment::CH_P, display7segment::CH_P),
- ERROR_OSCCLIENT_PING_PONG = display7segment::Msg(display7segment::CH_P, display7segment::CH_E),
- // Apple MIDI - rtpMIDI messages
- // TODO Apple MIDI - rtpMIDI messages
- // Show File player
- INFO_PLAYER_IDLE = display7segment::Msg(display7segment::CH_P, display7segment::CH_0),
- INFO_PLAYER_RUNNING = display7segment::Msg(display7segment::CH_P, display7segment::CH_1),
- INFO_PLAYER_RUNNING_LOOP = display7segment::Msg(display7segment::CH_P, display7segment::CH_2),
- INFO_PLAYER_STOPPED = display7segment::Msg(display7segment::CH_P, display7segment::CH_3),
- INFO_PLAYER_STOPPED_LOOP = display7segment::Msg(display7segment::CH_P, display7segment::CH_4),
- INFO_PLAYER_ENDED = display7segment::Msg(display7segment::CH_P, display7segment::CH_9),
- ERROR_PLAYER = display7segment::Msg(display7segment::CH_P, display7segment::CH_E)
-};
-
-#endif /* DISPLAY7SEGMENT_H_ */
diff --git a/lib-display/include/displayset.h b/lib-display/include/displayset.h
index 52ac2dd..ee7cbb2 100644
--- a/lib-display/include/displayset.h
+++ b/lib-display/include/displayset.h
@@ -39,7 +39,7 @@ static constexpr uint32_t BLINK_ON = (1U << 1);
class DisplaySet {
public:
- virtual ~DisplaySet() {}
+ virtual ~DisplaySet() = default;
uint32_t GetColumns() const {
return m_nCols;
@@ -66,9 +66,9 @@ class DisplaySet {
virtual void SetCursorPos(uint32_t nCol, uint32_t nRow)= 0;
virtual void SetCursor(uint32_t)= 0;
- virtual void SetSleep(__attribute__((unused)) bool bSleep) {}
- virtual void SetContrast(__attribute__((unused)) uint8_t nContrast) {}
- virtual void SetFlipVertically(__attribute__((unused)) bool doFlipVertically) {}
+ virtual void SetSleep([[maybe_unused]] bool bSleep) {}
+ virtual void SetContrast([[maybe_unused]] uint8_t nContrast) {}
+ virtual void SetFlipVertically([[maybe_unused]] bool doFlipVertically) {}
virtual void PrintInfo() {}
diff --git a/lib-display/include/i2c/display.h b/lib-display/include/i2c/display.h
index 56ba79d..24f7671 100644
--- a/lib-display/include/i2c/display.h
+++ b/lib-display/include/i2c/display.h
@@ -2,7 +2,7 @@
* @file display.h
*
*/
-/* Copyright (C) 2017-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -36,11 +36,14 @@
#include
#include "displayset.h"
-#include "display7segment.h"
-#include "hal_i2c.h"
#include "hardware.h"
+#include "hal_i2c.h"
+#if defined (DISPLAYTIMEOUT_GPIO)
+# include "hal_gpio.h"
+#endif
+
namespace display {
enum class Type {
PCF8574T_1602, PCF8574T_2004, SSD1306, SSD1311, UNKNOWN
@@ -182,9 +185,8 @@ class Display {
Write(nRows, pText);
}
- void TextStatus(const char *pText, Display7SegmentMessage message, uint32_t nConsoleColor = UINT32_MAX) {
+ void TextStatus(const char *pText, uint32_t nConsoleColor) {
TextStatus(pText);
- Status(message);
if (nConsoleColor == UINT32_MAX) {
return;
@@ -193,11 +195,6 @@ class Display {
console_status(nConsoleColor, pText);
}
- void TextStatus(const char *pText, uint32_t nValue7Segment, bool bHex = false) {
- TextStatus(pText);
- Status(nValue7Segment, bHex);
- }
-
void SetCursor(uint32_t nMode) {
if (m_LcdDisplay == nullptr) {
return;
@@ -274,28 +271,6 @@ class Display {
return m_LcdDisplay->GetRows();
}
- void Status(Display7SegmentMessage nData) {
- if (m_bHave7Segment) {
- m_I2C.WriteRegister(display::segment7::MCP23017_GPIOA, static_cast(~static_cast(nData)));
- }
- }
-
- void Status(uint32_t nValue, bool bHex) {
- if (m_bHave7Segment) {
- uint16_t nData;
-
- if (!bHex) {
- nData = GetData(nValue / 10);
- nData = static_cast(nData | GetData(nValue % 10) << 8U);
- } else {
- nData = GetData(nValue & 0x0F);
- nData = static_cast(nData | GetData((nValue >> 4) & 0x0F) << 8U);
- }
-
- m_I2C.WriteRegister(display::segment7::MCP23017_GPIOA, static_cast(~nData));
- }
- }
-
void Progress() {
static constexpr char SYMBOLS[] = { '/' , '-', '\\' , '|' };
static uint32_t nSymbolsIndex;
@@ -336,9 +311,11 @@ class Display {
SetSleep(true);
}
} else {
- if (__builtin_expect((display::timeout::gpio_renew()), 0)) {
+#if defined (DISPLAYTIMEOUT_GPIO)
+ if (__builtin_expect(((FUNC_PREFIX(gpio_lev(DISPLAYTIMEOUT_GPIO)) == LOW)), 0)) {
SetSleep(false);
}
+#endif
}
}
@@ -349,82 +326,19 @@ class Display {
private:
void Detect(display::Type tDisplayType);
void Detect(uint32_t nRows);
- void Detect7Segment() {
- m_bHave7Segment = m_I2C.IsConnected();
-
- if (m_bHave7Segment) {
- m_I2C.WriteRegister(display::segment7::MCP23017_IODIRA, static_cast(0x0000)); // All output
- Status(Display7SegmentMessage::INFO_STARTUP);
- }
- }
-
- uint16_t GetData(const uint32_t nHexValue) const {
- switch (nHexValue) {
- case 0:
- return display7segment::CH_0;
- break;
- case 1:
- return display7segment::CH_1;
- break;
- case 2:
- return display7segment::CH_2;
- break;
- case 3:
- return display7segment::CH_3;
- break;
- case 4:
- return display7segment::CH_4;
- break;
- case 5:
- return display7segment::CH_5;
- break;
- case 6:
- return display7segment::CH_6;
- break;
- case 7:
- return display7segment::CH_7;
- break;
- case 8:
- return display7segment::CH_8;
- break;
- case 9:
- return display7segment::CH_9;
- break;
- case 0xa:
- return display7segment::CH_A;
- break;
- case 0xb:
- return display7segment::CH_B;
- break;
- case 0xc:
- return display7segment::CH_C;
- break;
- case 0xd:
- return display7segment::CH_D;
- break;
- case 0xe:
- return display7segment::CH_E;
- break;
- case 0xf:
- return display7segment::CH_F;
- break;
- default:
- break;
- }
-
- return display7segment::CH_BLANK;
- }
private:
display::Type m_tType { display::Type::UNKNOWN };
uint32_t m_nMillis { 0 };
HAL_I2C m_I2C;
- bool m_bIsSleep { false };
- bool m_bHave7Segment { false };
uint32_t m_nSleepTimeout { 1000 * 60 * display::Defaults::SEEP_TIMEOUT };
-
uint8_t m_nContrast { 0x7F };
+
+ bool m_bIsSleep { false };
bool m_bIsFlippedVertically { false };
+#if defined (CONFIG_DISPLAY_HAVE_7SEGMENT)
+ bool m_bHave7Segment { false };
+#endif
DisplaySet *m_LcdDisplay { nullptr };
static Display *s_pThis;
diff --git a/lib-display/include/i2c/ssd1311.h b/lib-display/include/i2c/ssd1311.h
index 667f124..d3d50e4 100644
--- a/lib-display/include/i2c/ssd1311.h
+++ b/lib-display/include/i2c/ssd1311.h
@@ -34,7 +34,7 @@
class Ssd1311 final: public DisplaySet {
public:
Ssd1311 ();
- ~Ssd1311 () override {}
+ ~Ssd1311 () override = default;
bool Start() override;
diff --git a/lib-display/include/spi/config.h b/lib-display/include/spi/config.h
index 5cfe272..1cccce6 100755
--- a/lib-display/include/spi/config.h
+++ b/lib-display/include/spi/config.h
@@ -2,7 +2,7 @@
* @file config.h
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,33 +26,35 @@
#ifndef CONFIG_H
#define CONFIG_H
+#include
+
namespace config {
#if defined (SPI_LCD_240X240)
-static constexpr auto WIDTH = 240U;
-static constexpr auto HEIGHT = 240U;
+static constexpr uint32_t WIDTH = 240;
+static constexpr uint32_t HEIGHT = 240;
#elif defined (SPI_LCD_240X320)
-static constexpr auto WIDTH = 240U;
-static constexpr auto HEIGHT = 320U;
+static constexpr uint32_t WIDTH = 240;
+static constexpr uint32_t HEIGHT = 320;
#else
# error lib-display spi config
#endif
} // namespace config
#if defined (H3)
-# define SPI_LCD_RST_PIN GPIO_EXT_7 // GPIO6
-# define SPI_LCD_DC_PIN GPIO_EXT_26 // GPIO10
-# define SPI_LCD_BL_PIN GPIO_EXT_22 // GPIO2
-# if defined(SPI_LCD_HAVE_CS_PIN)
-# define SPI_LCD_CS_PIN GPIO_EXT_24 // GPIO13 / SPI CS0
+# define SPI_LCD_RST_GPIO GPIO_EXT_7 // GPIO6
+# define SPI_LCD_DC_GPIO GPIO_EXT_26 // GPIO10
+# define SPI_LCD_BL_GPIO GPIO_EXT_22 // GPIO2
+# if defined(SPI_LCD_HAVE_CS_GPIO)
+# define SPI_LCD_CS_GPIO GPIO_EXT_24 // GPIO13 / SPI CS0
# endif
-#elif defined (GD32) //See board file
+#elif defined (GD32) //See board file
#else
# include "bcm2835.h"
-# define SPI_LCD_RST_PIN RPI_V2_GPIO_P1_07 // GPIO4
-# define SPI_LCD_DC_PIN RPI_V2_GPIO_P1_31 // GPIO6
-# define SPI_LCD_BL_PIN RPI_V2_GPIO_P1_29 // GPIO5
-# if defined(SPI_LCD_HAVE_CS_PIN)
-# define SPI_LCD_CS_PIN RPI_V2_GPIO_P1_24 // GPIO8 / SPI CS0
+# define SPI_LCD_RST_GPIO RPI_V2_GPIO_P1_07 // GPIO4
+# define SPI_LCD_DC_GPIO RPI_V2_GPIO_P1_31 // GPIO6
+# define SPI_LCD_BL_GPIO RPI_V2_GPIO_P1_29 // GPIO5
+# if defined(SPI_LCD_HAVE_CS_GPIO)
+# define SPI_LCD_CS_GPIO RPI_V2_GPIO_P1_24 // GPIO8 / SPI CS0
# endif
#endif
diff --git a/lib-display/include/spi/display.h b/lib-display/include/spi/display.h
index 6ecee92..0db5ee3 100644
--- a/lib-display/include/spi/display.h
+++ b/lib-display/include/spi/display.h
@@ -2,7 +2,7 @@
* @file display.h
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,6 +41,10 @@
# include "spi/st7789.h"
#endif
+#if defined (DISPLAYTIMEOUT_GPIO)
+# include "hal_gpio.h"
+#endif
+
#include "hardware.h"
class Display {
@@ -101,10 +105,6 @@ class Display {
m_bClearEndOfLine = true;
}
- void Status(__attribute__((unused)) Display7SegmentMessage nValue) { }
-
- void Status(__attribute__((unused)) uint8_t nValue, __attribute__((unused)) bool bHex) {}
-
void Text(const char *pData, uint32_t nLength) {
if (nLength > m_nCols) {
nLength = m_nCols;
@@ -158,9 +158,8 @@ class Display {
Write(m_nRows, pText);
}
- void TextStatus(const char *pText, Display7SegmentMessage message, uint32_t nConsoleColor = UINT32_MAX) {
+ void TextStatus(const char *pText, uint32_t nConsoleColor) {
TextStatus(pText);
- Status(message);
if (nConsoleColor == UINT32_MAX) {
return;
@@ -169,11 +168,6 @@ class Display {
console_status(nConsoleColor, pText);
}
- void TextStatus(const char *pText, uint8_t nValue7Segment, bool bHex = false) {
- TextStatus(pText);
- Status(nValue7Segment, bHex);
- }
-
void Progress() {
static constexpr char SYMBOLS[] = { '/' , '-', '\\' , '|' };
static uint32_t nSymbolsIndex;
@@ -242,9 +236,11 @@ class Display {
SetSleep(true);
}
} else {
- if (__builtin_expect((display::timeout::gpio_renew()), 0)) {
+#if defined (DISPLAYTIMEOUT_GPIO)
+ if (__builtin_expect(((FUNC_PREFIX(gpio_lev(DISPLAYTIMEOUT_GPIO)) == LOW)), 0)) {
SetSleep(false);
}
+#endif
}
}
diff --git a/lib-display/include/spi/ili9341.h b/lib-display/include/spi/ili9341.h
index fe72a20..ea0eccc 100644
--- a/lib-display/include/spi/ili9341.h
+++ b/lib-display/include/spi/ili9341.h
@@ -2,7 +2,7 @@
* @file ili9341.h
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,25 +32,25 @@
namespace ili9341 {
namespace cmd {
-static constexpr uint8_t NOP = 0x00;
-static constexpr uint8_t SWRESET = 0x01;
-static constexpr uint8_t RDDID = 0x04;
-static constexpr uint8_t RDDST = 0x09;
-static constexpr uint8_t SLPIN = 0x10;
-static constexpr uint8_t SLPOUT = 0x11;
-static constexpr uint8_t PTLON = 0x12;
-static constexpr uint8_t NORON = 0x13;
-static constexpr uint8_t INVOFF = 0x20;
-static constexpr uint8_t INVON = 0x21;
-static constexpr uint8_t DISPOFF = 0x28;
-static constexpr uint8_t DISPON = 0x29;
-static constexpr uint8_t CASET = 0x2A;
-static constexpr uint8_t RASET = 0x2B;
-static constexpr uint8_t RAMWR = 0x2C;
-static constexpr uint8_t RAMRD = 0x2E;
-static constexpr uint8_t PTLAR = 0x30;
-static constexpr uint8_t MADCTL = 0x36;
-static constexpr uint8_t PIXFMT = 0x3A;
+static constexpr uint8_t NOP = 0x00;
+static constexpr uint8_t SWRESET = 0x01;
+static constexpr uint8_t RDDID = 0x04;
+static constexpr uint8_t RDDST = 0x09;
+static constexpr uint8_t SLPIN = 0x10;
+static constexpr uint8_t SLPOUT = 0x11;
+static constexpr uint8_t PTLON = 0x12;
+static constexpr uint8_t NORON = 0x13;
+static constexpr uint8_t INVOFF = 0x20;
+static constexpr uint8_t INVON = 0x21;
+static constexpr uint8_t DISPOFF = 0x28;
+static constexpr uint8_t DISPON = 0x29;
+static constexpr uint8_t CASET = 0x2A;
+static constexpr uint8_t RASET = 0x2B;
+static constexpr uint8_t RAMWR = 0x2C;
+static constexpr uint8_t RAMRD = 0x2E;
+static constexpr uint8_t PTLAR = 0x30;
+static constexpr uint8_t MADCTL = 0x36;
+static constexpr uint8_t PIXFMT = 0x3A;
} // namespace cmd
namespace data {
/**
@@ -59,27 +59,26 @@ namespace data {
* param: MY MX MV ML RGB MH - -
*
*/
-static constexpr uint8_t MADCTL_MY = 0x80; ///< Page Address Order ('0': Top to Bottom, '1': the opposite)
-static constexpr uint8_t MADCTL_MX = 0x40; ///< Column Address Order ('0': Left to Right, '1': the opposite)
-static constexpr uint8_t MADCTL_MV = 0x20; ///< Page/Column Order ('0' = Normal Mode, '1' = Reverse Mode)
-static constexpr uint8_t MADCTL_ML = 0x10; ///< Line Address Order ('0' = LCD Refresh Top to Bottom, '1' = the opposite)
-static constexpr uint8_t MADCTL_RGB = 0x00; ///< Red-Green-Blue pixel order
-static constexpr uint8_t MADCTL_BGR = 0x08; ///< Blue-Green-Red pixel order
+static constexpr uint8_t MADCTL_MY = 0x80; ///< Page Address Order ('0': Top to Bottom, '1': the opposite)
+static constexpr uint8_t MADCTL_MX = 0x40; ///< Column Address Order ('0': Left to Right, '1': the opposite)
+static constexpr uint8_t MADCTL_MV = 0x20; ///< Page/Column Order ('0' = Normal Mode, '1' = Reverse Mode)
+static constexpr uint8_t MADCTL_ML = 0x10; ///< Line Address Order ('0' = LCD Refresh Top to Bottom, '1' = the opposite)
+static constexpr uint8_t MADCTL_RGB = 0x00; ///< Red-Green-Blue pixel order
+static constexpr uint8_t MADCTL_BGR = 0x08; ///< Blue-Green-Red pixel order
} // namespace data
-//TODO Need to sort here
namespace colour {
-static constexpr uint16_t BLACK = 0x0000;
-static constexpr uint16_t WHITE = 0xFFFF;
-static constexpr uint16_t RED = 0xF800;
-static constexpr uint16_t GREEN = 0x07E0;
-static constexpr uint16_t BLUE = 0x001F;
-static constexpr uint16_t DARKBLUE = 0X01CF;
-static constexpr uint16_t CYAN = 0x07FF;
-static constexpr uint16_t MAGENTA = 0xF81F;
-static constexpr uint16_t YELLOW = 0xFFE0;
-static constexpr uint16_t ORANGE = 0xFC00;
-static constexpr uint16_t GRAY = 0X8430;
+static constexpr uint16_t BLACK = 0x0000;
+static constexpr uint16_t BLUE = 0x001F;
+static constexpr uint16_t CYAN = 0x07FF;
+static constexpr uint16_t DARKBLUE = 0X01CF;
+static constexpr uint16_t GRAY = 0X8430;
+static constexpr uint16_t GREEN = 0x07E0;
+static constexpr uint16_t MAGENTA = 0xF81F;
+static constexpr uint16_t ORANGE = 0xFC00;
+static constexpr uint16_t RED = 0xF800;
+static constexpr uint16_t WHITE = 0xFFFF;
+static constexpr uint16_t YELLOW = 0xFFE0;
} // namespace colour
} // namespace ili9341
diff --git a/lib-display/include/spi/spi_lcd.h b/lib-display/include/spi/spi_lcd.h
index b15481a..9e37914 100644
--- a/lib-display/include/spi/spi_lcd.h
+++ b/lib-display/include/spi/spi_lcd.h
@@ -38,31 +38,31 @@ inline static void ms_delay(const uint32_t ms) {
}
inline static void CS_Set() {
-#if defined(SPI_LCD_HAVE_CS_PIN)
- FUNC_PREFIX(gpio_set(SPI_LCD_CS_PIN));
+#if defined(SPI_LCD_HAVE_CS_GPIO)
+ FUNC_PREFIX(gpio_set(SPI_LCD_CS_GPIO));
#endif
}
inline static void CS_Clear() {
-#if defined(SPI_LCD_HAVE_CS_PIN)
- FUNC_PREFIX(gpio_clr(SPI_LCD_CS_PIN));
+#if defined(SPI_LCD_HAVE_CS_GPIO)
+ FUNC_PREFIX(gpio_clr(SPI_LCD_CS_GPIO));
#endif
}
inline static void DC_Set() {
- FUNC_PREFIX(gpio_set(SPI_LCD_DC_PIN));
+ FUNC_PREFIX(gpio_set(SPI_LCD_DC_GPIO));
}
inline static void DC_Clear() {
- FUNC_PREFIX(gpio_clr(SPI_LCD_DC_PIN));
+ FUNC_PREFIX(gpio_clr(SPI_LCD_DC_GPIO));
}
inline static void HW_Reset() {
-#if defined (SPI_LCD_RST_PIN)
+#if defined (SPI_LCD_RST_GPIO)
ms_delay(200);
- FUNC_PREFIX(gpio_clr(SPI_LCD_RST_PIN));
+ FUNC_PREFIX(gpio_clr(SPI_LCD_RST_GPIO));
ms_delay(200);
- FUNC_PREFIX(gpio_set(SPI_LCD_RST_PIN));
+ FUNC_PREFIX(gpio_set(SPI_LCD_RST_GPIO));
ms_delay(200);
#endif
}
diff --git a/lib-display/include/spi/st77xx.h b/lib-display/include/spi/st77xx.h
index 0371d4a..af61b9b 100644
--- a/lib-display/include/spi/st77xx.h
+++ b/lib-display/include/spi/st77xx.h
@@ -2,7 +2,7 @@
* @file st77xx.h
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,27 +34,27 @@
namespace st77xx {
namespace cmd {
-static constexpr uint8_t NOP = 0x00;
-static constexpr uint8_t SWRESET = 0x01;
-static constexpr uint8_t RDDID = 0x04;
-static constexpr uint8_t RDDST = 0x09;
-static constexpr uint8_t SLPIN = 0x10;
-static constexpr uint8_t SLPOUT = 0x11;
-static constexpr uint8_t PTLON = 0x12;
-static constexpr uint8_t NORON = 0x13;
-static constexpr uint8_t INVOFF = 0x20;
-static constexpr uint8_t INVON = 0x21;
-static constexpr uint8_t DISPOFF = 0x28;
-static constexpr uint8_t DISPON = 0x29;
-static constexpr uint8_t CASET = 0x2A;
-static constexpr uint8_t RASET = 0x2B;
-static constexpr uint8_t RAMWR = 0x2C;
-static constexpr uint8_t RAMRD = 0x2E;
-static constexpr uint8_t PTLAR = 0x30;
-static constexpr uint8_t TEOFF = 0x34;
-static constexpr uint8_t TEON = 0x35;
-static constexpr uint8_t MADCTL = 0x36;
-static constexpr uint8_t COLMOD = 0x3A;
+static constexpr uint8_t NOP = 0x00;
+static constexpr uint8_t SWRESET = 0x01;
+static constexpr uint8_t RDDID = 0x04;
+static constexpr uint8_t RDDST = 0x09;
+static constexpr uint8_t SLPIN = 0x10;
+static constexpr uint8_t SLPOUT = 0x11;
+static constexpr uint8_t PTLON = 0x12;
+static constexpr uint8_t NORON = 0x13;
+static constexpr uint8_t INVOFF = 0x20;
+static constexpr uint8_t INVON = 0x21;
+static constexpr uint8_t DISPOFF = 0x28;
+static constexpr uint8_t DISPON = 0x29;
+static constexpr uint8_t CASET = 0x2A;
+static constexpr uint8_t RASET = 0x2B;
+static constexpr uint8_t RAMWR = 0x2C;
+static constexpr uint8_t RAMRD = 0x2E;
+static constexpr uint8_t PTLAR = 0x30;
+static constexpr uint8_t TEOFF = 0x34;
+static constexpr uint8_t TEON = 0x35;
+static constexpr uint8_t MADCTL = 0x36;
+static constexpr uint8_t COLMOD = 0x3A;
} // namespace cmd
namespace data {
/**
@@ -64,30 +64,29 @@ namespace data {
*
*/
/* Page Address Order ('0': Top to Bottom, '1': the opposite) */
-static constexpr uint8_t MADCTL_MY = 0x80;
+static constexpr uint8_t MADCTL_MY = 0x80;
/* Column Address Order ('0': Left to Right, '1': the opposite) */
-static constexpr uint8_t MADCTL_MX = 0x40;
+static constexpr uint8_t MADCTL_MX = 0x40;
/* Page/Column Order ('0' = Normal Mode, '1' = Reverse Mode) */
-static constexpr uint8_t MADCTL_MV = 0x20;
+static constexpr uint8_t MADCTL_MV = 0x20;
/* Line Address Order ('0' = LCD Refresh Top to Bottom, '1' = the opposite) */
-static constexpr uint8_t MADCTL_ML = 0x10;
+static constexpr uint8_t MADCTL_ML = 0x10;
/* RGB/BGR Order ('0' = RGB, '1' = BGR) */
-static constexpr uint8_t MADCTL_RGB = 0x00;
+static constexpr uint8_t MADCTL_RGB = 0x00;
} // namespace data
-//TODO Need to sort here
namespace colour {
-static constexpr uint16_t BLACK = 0x0000;
-static constexpr uint16_t WHITE = 0xFFFF;
-static constexpr uint16_t RED = 0xF800;
-static constexpr uint16_t GREEN = 0x07E0;
-static constexpr uint16_t BLUE = 0x001F;
-static constexpr uint16_t DARKBLUE = 0X01CF;
-static constexpr uint16_t CYAN = 0x07FF;
-static constexpr uint16_t MAGENTA = 0xF81F;
-static constexpr uint16_t YELLOW = 0xFFE0;
-static constexpr uint16_t ORANGE = 0xFC00;
-static constexpr uint16_t GRAY = 0X8430;
+static constexpr uint16_t BLACK = 0x0000;
+static constexpr uint16_t BLUE = 0x001F;
+static constexpr uint16_t CYAN = 0x07FF;
+static constexpr uint16_t DARKBLUE = 0X01CF;
+static constexpr uint16_t GRAY = 0X8430;
+static constexpr uint16_t GREEN = 0x07E0;
+static constexpr uint16_t MAGENTA = 0xF81F;
+static constexpr uint16_t ORANGE = 0xFC00;
+static constexpr uint16_t RED = 0xF800;
+static constexpr uint16_t WHITE = 0xFFFF;
+static constexpr uint16_t YELLOW = 0xFFE0;
} // namespace colour
} // namespace st77xx
diff --git a/lib-display/src/i2c/display.cpp b/lib-display/src/i2c/display.cpp
index 649b43b..ba2efcb 100644
--- a/lib-display/src/i2c/display.cpp
+++ b/lib-display/src/i2c/display.cpp
@@ -2,7 +2,7 @@
* @file display.cpp
*
*/
-/* Copyright (C) 2017-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,17 +29,27 @@
#include "display.h"
#include "displayset.h"
-#if defined(CONFIG_DISPLAY_ENABLE_HD44780)
-# include "i2c/hd44780.h"
-#endif
#include "i2c/ssd1306.h"
#if defined(CONFIG_DISPLAY_ENABLE_SSD1311)
# include "i2c/ssd1311.h"
#endif
-
-#include "display7segment.h"
+#if defined(CONFIG_DISPLAY_ENABLE_HD44780)
+# include "i2c/hd44780.h"
+#endif
#include "hal_i2c.h"
+#include "hal_gpio.h"
+
+namespace display {
+namespace timeout {
+static void gpio_init() {
+#if defined (DISPLAYTIMEOUT_GPIO)
+ FUNC_PREFIX(gpio_fsel(DISPLAYTIMEOUT_GPIO, GPIO_FSEL_INPUT));
+ FUNC_PREFIX(gpio_set_pud(DISPLAYTIMEOUT_GPIO, GPIO_PULL_UP));
+#endif
+}
+} // namespace timeout
+} // namespace display
Display *Display::s_pThis;
@@ -55,8 +65,6 @@ Display::Display() : m_nMillis(Hardware::Get()->Millis()), m_I2C(display::segmen
Detect(display::Type::SSD1306);
}
- Detect7Segment();
-
if (m_LcdDisplay != nullptr) {
display::timeout::gpio_init();
}
@@ -70,8 +78,6 @@ Display::Display(uint32_t nRows) : m_nMillis(Hardware::Get()->Millis()), m_I2C(d
Detect(nRows);
- Detect7Segment();
-
if (m_LcdDisplay != nullptr) {
display::timeout::gpio_init();
}
@@ -85,8 +91,6 @@ Display::Display(display::Type type): m_tType(type), m_nMillis(Hardware::Get()->
Detect(type);
- Detect7Segment();
-
if (m_LcdDisplay != nullptr) {
display::timeout::gpio_init();
}
diff --git a/lib-display/src/i2c/hd44780.cpp b/lib-display/src/i2c/hd44780.cpp
index 070476e..43990fc 100644
--- a/lib-display/src/i2c/hd44780.cpp
+++ b/lib-display/src/i2c/hd44780.cpp
@@ -2,7 +2,7 @@
* @file hd44780.cpp
*
*/
-/* Copyright (C) 2017-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -168,7 +168,7 @@ void Hd44780::ClearLine(uint32_t nLine) {
}
void Hd44780::PrintInfo() {
- printf("HD44780 [PCF8574T] (%d,%d)\n", m_nRows, m_nCols);
+ printf("HD44780 [PCF8574T] (%u,%u)\n", static_cast(m_nRows), static_cast(m_nCols));
}
void Hd44780::SetCursorPos(uint32_t nCol, uint32_t nRow) {
@@ -200,7 +200,7 @@ void Hd44780::WriteReg(const uint8_t nReg) {
#if defined(CONFIG_DISPLAY_ENABLE_CURSOR_MODE)
# define UNUSED
#else
-# define UNUSED __attribute__((unused))
+# define UNUSED [[maybe_unused]]
#endif
void Hd44780::SetCursor(UNUSED uint32_t nMode) {
diff --git a/lib-display/src/i2c/ssd1306.cpp b/lib-display/src/i2c/ssd1306.cpp
index 5281a4f..1829c10 100644
--- a/lib-display/src/i2c/ssd1306.cpp
+++ b/lib-display/src/i2c/ssd1306.cpp
@@ -233,7 +233,7 @@ Ssd1306::Ssd1306(uint8_t nSlaveAddress, TOledPanel tOledPanel) : m_I2C(nSlaveAdd
}
void Ssd1306::PrintInfo() {
- printf("%s (%d,%d)\n", m_bHaveSH1106 ? "SH1106" : "SSD1306", m_nRows, m_nCols);
+ printf("%s (%u,%u)\n", m_bHaveSH1106 ? "SH1106" : "SSD1306", static_cast(m_nRows), static_cast(m_nCols));
}
void Ssd1306::CheckSH1106() {
@@ -513,7 +513,7 @@ void Ssd1306::SendData(const uint8_t *pData, uint32_t nLength) {
#if defined(CONFIG_DISPLAY_ENABLE_CURSOR_MODE)
# define UNUSED
#else
-# define UNUSED __attribute__((unused))
+# define UNUSED [[maybe_unused]]
#endif
void Ssd1306::SetCursor(UNUSED uint32_t nCursorMode) {
diff --git a/lib-display/src/i2c/ssd1311.cpp b/lib-display/src/i2c/ssd1311.cpp
index 5c9c76d..712e48a 100644
--- a/lib-display/src/i2c/ssd1311.cpp
+++ b/lib-display/src/i2c/ssd1311.cpp
@@ -101,7 +101,7 @@ bool Ssd1311::Start() {
}
void Ssd1311::PrintInfo() {
- printf("SSD1311 (%d,%d)\n", m_nRows, m_nCols);
+ printf("SSD1311 (%u,%u)\n", static_cast(m_nRows), static_cast(m_nCols));
}
void Ssd1311::Cls() {
@@ -338,7 +338,7 @@ void Ssd1311::SetContrast(uint8_t nContrast) {
#if defined(CONFIG_DISPLAY_ENABLE_CURSOR_MODE)
# define UNUSED
#else
-# define UNUSED __attribute__((unused))
+# define UNUSED [[maybe_unused]]
#endif
void Ssd1311::SetCursor(UNUSED uint32_t nMode) {
diff --git a/lib-display/src/spi/display.cpp b/lib-display/src/spi/display.cpp
index 23f91db..33018c2 100644
--- a/lib-display/src/spi/display.cpp
+++ b/lib-display/src/spi/display.cpp
@@ -2,7 +2,7 @@
* @file display.cpp
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -58,13 +58,13 @@ Display::Display() : m_nMillis(Hardware::Get()->Millis()) {
FUNC_PREFIX(spi_set_speed_hz(20000000));
FUNC_PREFIX(spi_setDataMode(SPI_MODE0));
-#if defined (SPI_LCD_RST_PIN)
- FUNC_PREFIX(gpio_fsel(SPI_LCD_RST_PIN, GPIO_FSEL_OUTPUT));
+#if defined (SPI_LCD_RST_GPIO)
+ FUNC_PREFIX(gpio_fsel(SPI_LCD_RST_GPIO, GPIO_FSEL_OUTPUT));
#endif
- FUNC_PREFIX(gpio_fsel(SPI_LCD_DC_PIN, GPIO_FSEL_OUTPUT));
- FUNC_PREFIX(gpio_fsel(SPI_LCD_BL_PIN, GPIO_FSEL_OUTPUT));
-#if defined(SPI_LCD_HAVE_CS_PIN)
- FUNC_PREFIX(gpio_fsel(SPI_LCD_CS_PIN, GPIO_FSEL_OUTPUT));
+ FUNC_PREFIX(gpio_fsel(SPI_LCD_DC_GPIO, GPIO_FSEL_OUTPUT));
+ FUNC_PREFIX(gpio_fsel(SPI_LCD_BL_GPIO, GPIO_FSEL_OUTPUT));
+#if defined(SPI_LCD_HAVE_CS_GPIO)
+ FUNC_PREFIX(gpio_fsel(SPI_LCD_CS_GPIO, GPIO_FSEL_OUTPUT));
#endif
SpiLcd.SetBackLight(1);
@@ -75,7 +75,10 @@ Display::Display() : m_nMillis(Hardware::Get()->Millis()) {
m_nCols = static_cast(SpiLcd.GetWidth() / s_pFONT->Width);
m_nRows = static_cast(SpiLcd.GetHeight() / s_pFONT->Height);
- display::timeout::gpio_init();
+#if defined (DISPLAYTIMEOUT_GPIO)
+ FUNC_PREFIX(gpio_fsel(DISPLAYTIMEOUT_GPIO, GPIO_FSEL_INPUT));
+ FUNC_PREFIX(gpio_set_pud(DISPLAYTIMEOUT_GPIO, GPIO_PULL_UP));
+#endif
PrintInfo();
DEBUG_EXIT
diff --git a/lib-display/src/spi/ili9341.cpp b/lib-display/src/spi/ili9341.cpp
index f79903e..2a9b40f 100644
--- a/lib-display/src/spi/ili9341.cpp
+++ b/lib-display/src/spi/ili9341.cpp
@@ -50,7 +50,7 @@ ILI9341::~ILI9341() {
void ILI9341::Init() {
DEBUG_ENTRY
-#if defined(SPI_LCD_RST_PIN)
+#if defined(SPI_LCD_RST_GPIO)
HW_Reset();
#endif
@@ -161,7 +161,7 @@ void ILI9341::SetRotation(uint32_t nRotation) {
}
void ILI9341::SetBackLight(uint32_t nValue) {
- FUNC_PREFIX(gpio_write(SPI_LCD_BL_PIN, nValue == 0 ? LOW : HIGH));
+ FUNC_PREFIX(gpio_write(SPI_LCD_BL_GPIO, nValue == 0 ? LOW : HIGH));
}
void ILI9341::EnableDisplay(bool bEnable) {
diff --git a/lib-display/src/spi/st7789.cpp b/lib-display/src/spi/st7789.cpp
index 4a34009..0a25be2 100644
--- a/lib-display/src/spi/st7789.cpp
+++ b/lib-display/src/spi/st7789.cpp
@@ -51,7 +51,7 @@ ST7789::~ST7789() {
void ST7789::Init() {
DEBUG_ENTRY
-#if defined(SPI_LCD_RST_PIN)
+#if defined(SPI_LCD_RST_GPIO)
HW_Reset();
#endif
diff --git a/lib-display/src/spi/st7xx.cpp b/lib-display/src/spi/st7xx.cpp
index d4ddaef..cf613c9 100644
--- a/lib-display/src/spi/st7xx.cpp
+++ b/lib-display/src/spi/st7xx.cpp
@@ -58,7 +58,7 @@ void ST77XX::EnableSleep(bool bEnable) {
//TODO This should be a PWM pin
void ST77XX::SetBackLight(uint32_t nValue) {
- FUNC_PREFIX(gpio_write(SPI_LCD_BL_PIN, nValue == 0 ? LOW : HIGH));
+ FUNC_PREFIX(gpio_write(SPI_LCD_BL_GPIO, nValue == 0 ? LOW : HIGH));
}
void ST77XX::SetAddressWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
diff --git a/lib-flashcode/.cproject b/lib-flashcode/.cproject
index e4367ad..6e0d6c7 100755
--- a/lib-flashcode/.cproject
+++ b/lib-flashcode/.cproject
@@ -30,11 +30,9 @@
-
-
@@ -52,12 +50,10 @@
-
-
@@ -82,7 +78,6 @@
-
diff --git a/lib-flashcode/Makefile.GD32 b/lib-flashcode/Makefile.GD32
index e0ac745..3808855 100755
--- a/lib-flashcode/Makefile.GD32
+++ b/lib-flashcode/Makefile.GD32
@@ -4,7 +4,11 @@ ifneq ($(MAKE_FLAGS),)
ifeq ($(findstring gd32f4xx,$(FAMILY)), gd32f4xx)
EXTRA_SRCDIR=src/gd32/f4xx
else
- EXTRA_SRCDIR=src/gd32/fmc
+ ifeq ($(findstring gd32h7xx,$(FAMILY)), gd32h7xx)
+ EXTRA_SRCDIR=src/gd32/h7xx
+ else
+ EXTRA_SRCDIR=src/gd32/fmc
+ endif
endif
else
EXTRA_SRCDIR=src/gd32/fmc
diff --git a/lib-flashcode/include/flashcode.h b/lib-flashcode/include/flashcode.h
index 95eacb7..de55e14 100644
--- a/lib-flashcode/include/flashcode.h
+++ b/lib-flashcode/include/flashcode.h
@@ -2,7 +2,7 @@
* @file flashcode.h
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/lib-flashcode/src/gd32/f4xx/flashcode.cpp b/lib-flashcode/src/gd32/f4xx/flashcode.cpp
deleted file mode 100644
index 3a133f6..0000000
--- a/lib-flashcode/src/gd32/f4xx/flashcode.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * @file flashcode.cpp
- *
- */
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@gd32-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include
-#include
-#include
-
-#include "flashcode.h"
-
-#include "gd32.h"
-#include "fmc_operation.h"
-
-#include "debug.h"
-
-uint32_t FlashCode::GetSize() const {
- return FMC_SIZE * 1024U;
-}
-
-uint32_t FlashCode::GetSectorSize() const {
- return SIZE_16KB;
-}
-
-bool FlashCode::Read(uint32_t nOffset, uint32_t nLength, uint8_t *pBuffer, flashcode::result& nResult) {
- DEBUG_ENTRY
- DEBUG_PRINTF("nOffset=%p[%d], nLength=%u[%d], data=%p[%d]", nOffset, (((uint32_t)(nOffset) & 0x3) == 0), nLength, (((uint32_t)(nLength) & 0x3) == 0), data, (((uint32_t)(data) & 0x3) == 0));
-
- const uint32_t *src = (uint32_t *)(nOffset + FLASH_BASE);
- uint32_t *dst = (uint32_t *)pBuffer;
-
- while (nLength > 0) {
- *dst++ = *src++;
- nLength -= 4;
- }
-
- debug_dump((uint8_t *)(nOffset + FLASH_BASE), 64);
- debug_dump(pBuffer, 64);
-
- nResult = flashcode::result::OK;
-
- DEBUG_EXIT
- return 0;
-}
-
-bool FlashCode::Write(uint32_t nOffset, uint32_t nLength, const uint8_t *pBuffer, flashcode::result& nResult) {
- DEBUG_ENTRY
- DEBUG_PRINTF("nOffset=%p[%d], nLength=%u[%d], data=%p[%d]", nOffset, (((uint32_t)(nOffset) & 0x3) == 0), nLength, (((uint32_t)(nLength) & 0x3) == 0), pBuffer, (((uint32_t)(pBuffer) & 0x3) == 0));
-
- nResult = flashcode::result::ERROR;
-
- fmc_unlock();
- fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_OPERR | FMC_FLAG_WPERR | FMC_FLAG_PGMERR | FMC_FLAG_PGSERR);
-
- uint32_t address = nOffset + FLASH_BASE;
- const uint32_t *data = (uint32_t *)pBuffer;
-
- while (nLength >= 4) {
-
- fmc_state_enum state = fmc_word_program(address, *data);
-
- if (FMC_READY != state) {
- DEBUG_PRINTF("state=%d [%p]", state, address);
- DEBUG_EXIT
- return true;
- }
-
- data++;
- address += 4;
- nLength -= 4;
- }
-
- if (nLength > 0) {
- fmc_state_enum state = fmc_word_program(address, *data);
-
- if (FMC_READY != state) {
- DEBUG_PRINTF("state=%d [%p]", state, address);
- DEBUG_EXIT
- return true;
- }
- }
-
- fmc_lock();
-
- debug_dump(pBuffer, 64);
- debug_dump((uint8_t *)(nOffset + FLASH_BASE), 64);
-
- nResult = flashcode::result::OK;
-
- DEBUG_EXIT
- return true;
-}
-
-bool FlashCode::Erase(uint32_t nOffset, uint32_t nLength, flashcode::result& nResult) {
- DEBUG_ENTRY
- DEBUG_PRINTF("nOffset=%p[%d], nLength=%x[%d]", nOffset, (((uint32_t)(nOffset) & 0x3) == 0), nLength, (((uint32_t)(nLength) & 0x3) == 0));
-
- nResult = flashcode::result::ERROR;
-
- fmc_sector_info_struct sector_info;
- uint32_t address = nOffset + FLASH_BASE;
-
- int size = (int) nLength;
-
- while (size > 0) {
- sector_info = fmc_sector_info_get(address);
-
- if (FMC_WRONG_SECTOR_NAME == sector_info.sector_name) {
- return true;
- }
-
- DEBUG_PRINTF("Address 0x%08X is located in the : SECTOR_NUMBER_%d", address, sector_info.sector_name);
- DEBUG_PRINTF("Sector range: 0x%08X to 0x%08X", sector_info.sector_start_addr, sector_info.sector_end_addr);
- DEBUG_PRINTF("nSector size: %d KB\n", (sector_info.sector_size/1024));
-
- fmc_unlock();
- fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_OPERR | FMC_FLAG_WPERR | FMC_FLAG_PGMERR | FMC_FLAG_PGSERR);
-
- if (FMC_READY != fmc_sector_erase(sector_info.sector_num)) {
- return true;
- }
-
- fmc_lock();
-
- size -= sector_info.sector_size;
- address += sector_info.sector_size;
- }
-
-
- nResult = flashcode::result::OK;
-
- DEBUG_EXIT
- return true;
-}
diff --git a/lib-flashcode/src/gd32/f4xx/fmc_operation.cpp b/lib-flashcode/src/gd32/f4xx/fmc_operation.cpp
deleted file mode 100644
index 3247023..0000000
--- a/lib-flashcode/src/gd32/f4xx/fmc_operation.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/*!
- \file fmc_operation.c
- \brief flash program, erase
-
- \version 2016-08-15, V1.0.0, firmware for GD32F4xx
- \version 2018-12-12, V2.0.0, firmware for GD32F4xx
- \version 2020-09-30, V2.1.0, firmware for GD32F4xx
-*/
-
-/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
-
- Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
- specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
-OF SUCH DAMAGE.
-*/
-
-#include "gd32.h"
-#include "fmc_operation.h"
-
-/*!
- \brief get the sector number, size and range of the given address
- \param[in] address: The flash address
- \param[out] none
- \retval fmc_sector_info_struct: The information of a sector
-*/
-fmc_sector_info_struct fmc_sector_info_get(uint32_t addr)
-{
- fmc_sector_info_struct sector_info;
- uint32_t temp = 0x00000000U;
- if((FMC_START_ADDRESS <= addr)&&(FMC_END_ADDRESS >= addr)) {
- if ((FMC_BANK1_START_ADDRESS > addr)) {
- /* bank0 area */
- temp = (addr - FMC_BANK0_START_ADDRESS) / SIZE_16KB;
- if (4U > temp) {
- sector_info.sector_name = (uint32_t)temp;
- sector_info.sector_num = CTL_SN(temp);
- sector_info.sector_size = SIZE_16KB;
- sector_info.sector_start_addr = FMC_BANK0_START_ADDRESS + (SIZE_16KB * temp);
- sector_info.sector_end_addr = sector_info.sector_start_addr + SIZE_16KB - 1;
- } else if (8U > temp) {
- sector_info.sector_name = 0x00000004U;
- sector_info.sector_num = CTL_SN(4);
- sector_info.sector_size = SIZE_64KB;
- sector_info.sector_start_addr = 0x08010000U;
- sector_info.sector_end_addr = 0x0801FFFFU;
- } else {
- temp = (addr - FMC_BANK0_START_ADDRESS) / SIZE_128KB;
- sector_info.sector_name = (uint32_t)(temp + 4);
- sector_info.sector_num = CTL_SN(temp + 4);
- sector_info.sector_size = SIZE_128KB;
- sector_info.sector_start_addr = FMC_BANK0_START_ADDRESS + (SIZE_128KB * temp);
- sector_info.sector_end_addr = sector_info.sector_start_addr + SIZE_128KB - 1;
- }
- } else {
- /* bank1 area */
- temp = (addr - FMC_BANK1_START_ADDRESS) / SIZE_16KB;
- if (4U > temp) {
- sector_info.sector_name = (uint32_t)(temp + 12);
- sector_info.sector_num = CTL_SN(temp + 16);
- sector_info.sector_size = SIZE_16KB;
- sector_info.sector_start_addr = FMC_BANK0_START_ADDRESS + (SIZE_16KB * temp);
- sector_info.sector_end_addr = sector_info.sector_start_addr + SIZE_16KB - 1;
- } else if (8U > temp) {
- sector_info.sector_name = 0x00000010;
- sector_info.sector_num = CTL_SN(20);
- sector_info.sector_size = SIZE_64KB;
- sector_info.sector_start_addr = 0x08110000U;
- sector_info.sector_end_addr = 0x0811FFFFU;
- } else if (64U > temp){
- temp = (addr - FMC_BANK1_START_ADDRESS) / SIZE_128KB;
- sector_info.sector_name = (uint32_t)(temp + 16);
- sector_info.sector_num = CTL_SN(temp + 20);
- sector_info.sector_size = SIZE_128KB;
- sector_info.sector_start_addr = FMC_BANK1_START_ADDRESS + (SIZE_128KB * temp);
- sector_info.sector_end_addr = sector_info.sector_start_addr + SIZE_128KB - 1;
- } else {
- temp = (addr - FMC_BANK1_START_ADDRESS) / SIZE_256KB;
- sector_info.sector_name = (uint32_t)(temp + 20);
- sector_info.sector_num = CTL_SN(temp + 8);
- sector_info.sector_size = SIZE_256KB;
- sector_info.sector_start_addr = FMC_BANK1_START_ADDRESS + (SIZE_256KB * temp);
- sector_info.sector_end_addr = sector_info.sector_start_addr + SIZE_256KB - 1;
- }
- }
- } else {
- /* invalid address */
- sector_info.sector_name = FMC_WRONG_SECTOR_NAME;
- sector_info.sector_num = FMC_WRONG_SECTOR_NUM;
- sector_info.sector_size = FMC_INVALID_SIZE;
- sector_info.sector_start_addr = FMC_INVALID_ADDR;
- sector_info.sector_end_addr = FMC_INVALID_ADDR;
- }
- return sector_info;
-}
-
-/*!
- \brief get the sector number by a given sector name
- \param[in] address: a given sector name
- \param[out] none
- \retval uint32_t: sector number
-*/
-uint32_t sector_name_to_number(uint32_t sector_name)
-{
- if(11 >= sector_name){
- return CTL_SN(sector_name);
- }else if(23 >= sector_name){
- return CTL_SN(sector_name + 4);
- }else if(27 >= sector_name){
- return CTL_SN(sector_name - 12);
- }else{
- while(1);
- }
-}
-
-/*!
- \brief erases the sector of a given address
- \param[in] address: a given address
- \param[out] none
- \retval none
-*/
-void fmc_erase_sector_by_address(uint32_t address)
-{
- fmc_sector_info_struct sector_info;
- printf("\r\nFMC erase operation:\n");
- /* get information about the sector in which the specified address is located */
- sector_info = fmc_sector_info_get(address);
- if(FMC_WRONG_SECTOR_NAME == sector_info.sector_name){
- printf("\r\nWrong address!\n");
- while(1);
- }else{
- printf("\r\nErase start ......\n");
- /* unlock the flash program erase controller */
- fmc_unlock();
- /* clear pending flags */
- fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_OPERR | FMC_FLAG_WPERR | FMC_FLAG_PGMERR | FMC_FLAG_PGSERR);
- /* wait the erase operation complete*/
- if(FMC_READY != fmc_sector_erase(sector_info.sector_num)){
- while(1);
- }
- /* lock the flash program erase controller */
- fmc_lock();
- printf("\r\nAddress 0x%08X is located in the : SECTOR_NUMBER_%d !\n", address, sector_info.sector_name);
- printf("\r\nSector range: 0x%08X to 0x%08X\n", sector_info.sector_start_addr, sector_info.sector_end_addr);
- printf("\r\nSector size: %d KB\n", (sector_info.sector_size/1024));
- printf("\r\nErase success!\n");
- printf("\r\n");
- }
-}
-
-/*!
- \brief write 32 bit length data to a given address
- \param[in] address: a given address(0x08000000~0x082FFFFF)
- \param[in] length: data length
- \param[in] data_32: data pointer
- \param[out] none
- \retval none
-*/
-void fmc_write_32bit_data(uint32_t address, uint16_t length, int32_t* data_32)
-{
- fmc_sector_info_struct start_sector_info;
- fmc_sector_info_struct end_sector_info;
- uint32_t sector_num,i;
-
- printf("\r\nFMC word programe operation:\n");
- /* unlock the flash program erase controller */
- fmc_unlock();
- /* clear pending flags */
- fmc_flag_clear(FMC_FLAG_END | FMC_FLAG_OPERR | FMC_FLAG_WPERR | FMC_FLAG_PGMERR | FMC_FLAG_PGSERR);
- /* get the information of the start and end sectors */
- start_sector_info = fmc_sector_info_get(address);
- end_sector_info = fmc_sector_info_get(address + 4*length);
- /* erase sector */
- for(i = start_sector_info.sector_name; i <= end_sector_info.sector_name; i++){
- sector_num = sector_name_to_number(i);
- if(FMC_READY != fmc_sector_erase(sector_num)){
- while(1);
- }
- }
-
- /* write data_32 to the corresponding address */
- for(i=0; i
-#include "gd32f4xx.h"
-
-/* FMC sector information */
-typedef struct
-{
- uint32_t sector_name; /*!< the name of the sector */
- uint32_t sector_num; /*!< the number of the sector */
- uint32_t sector_size; /*!< the size of the sector */
- uint32_t sector_start_addr; /*!< the start address of the sector */
- uint32_t sector_end_addr; /*!< the end address of the sector */
-} fmc_sector_info_struct;
-
-/* sector size */
-#define SIZE_16KB ((uint32_t)0x00004000U) /*!< size of 16KB*/
-#define SIZE_64KB ((uint32_t)0x00010000U) /*!< size of 64KB*/
-#define SIZE_128KB ((uint32_t)0x00020000U) /*!< size of 128KB*/
-#define SIZE_256KB ((uint32_t)0x00040000U) /*!< size of 256KB*/
-
-/* FMC BANK address */
-#define FMC_START_ADDRESS FLASH_BASE /*!< FMC start address */
-#define FMC_BANK0_START_ADDRESS FMC_START_ADDRESS /*!< FMC BANK0 start address */
-#define FMC_BANK1_START_ADDRESS ((uint32_t)0x08100000U) /*!< FMC BANK1 start address */
-#define FMC_SIZE (*(uint16_t *)0x1FFF7A22U) /*!< FMC SIZE */
-#define FMC_END_ADDRESS (FLASH_BASE + (FMC_SIZE * 1024) - 1) /*!< FMC end address */
-#define FMC_MAX_END_ADDRESS ((uint32_t)0x08300000U) /*!< FMC maximum end address */
-
-/* FMC error message */
-#define FMC_WRONG_SECTOR_NAME ((uint32_t)0xFFFFFFFFU) /*!< wrong sector name*/
-#define FMC_WRONG_SECTOR_NUM ((uint32_t)0xFFFFFFFFU) /*!< wrong sector number*/
-#define FMC_INVALID_SIZE ((uint32_t)0xFFFFFFFFU) /*!< invalid sector size*/
-#define FMC_INVALID_ADDR ((uint32_t)0xFFFFFFFFU) /*!< invalid sector address*/
-
-/* get the sector number, size and range of the given address */
-fmc_sector_info_struct fmc_sector_info_get(uint32_t addr);
-/* get the sector number by sector name */
-uint32_t sector_name_to_number(uint32_t sector_name);
-/* erases the sector of a given sector number */
-void fmc_erase_sector_by_address(uint32_t address);
-/* write 32 bit length data to a given address */
-void fmc_write_32bit_data(uint32_t address, uint16_t length, int32_t* data_32);
-/* read 32 bit length data from a given address */
-void fmc_read_32bit_data(uint32_t address, uint16_t length, int32_t* data_32);
-/* write 16 bit length data to a given address */
-void fmc_write_16bit_data(uint32_t address, uint16_t length, int16_t* data_16);
-/* read 16 bit length data from a given address */
-void fmc_read_16bit_data(uint32_t address, uint16_t length, int16_t* data_16);
-/* write 8 bit length data to a given address */
-void fmc_write_8bit_data(uint32_t address, uint16_t length, int8_t* data_8);
-/* read 8 bit length data from a given address */
-void fmc_read_8bit_data(uint32_t address, uint16_t length, int8_t* data_8);
-
-#endif/* __FMC_OPERATION_H */
diff --git a/lib-flashcode/src/gd32/flashcode.cpp b/lib-flashcode/src/gd32/flashcode.cpp
index 449e416..f423d04 100644
--- a/lib-flashcode/src/gd32/flashcode.cpp
+++ b/lib-flashcode/src/gd32/flashcode.cpp
@@ -2,7 +2,7 @@
* @file flashcode.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ FlashCode::FlashCode() {
m_IsDetected = true;
- printf("FMC: Detected %s with total %d bytes [%d kB]\n", GetName(), GetSize(), GetSize() / 1024U);
+ printf("FMC: %s %u [%u]\n", GetName(), static_cast(GetSize()), static_cast(GetSize() / 1024U));
DEBUG_EXIT
}
diff --git a/lib-flashcode/src/gd32/fmc/flashcode.cpp b/lib-flashcode/src/gd32/fmc/flashcode.cpp
index 9338ba5..46c8e3a 100644
--- a/lib-flashcode/src/gd32/fmc/flashcode.cpp
+++ b/lib-flashcode/src/gd32/fmc/flashcode.cpp
@@ -2,7 +2,7 @@
* @file flashcode.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,6 +31,16 @@
#include "gd32.h"
+/**
+ * With the latest GD32F firmware, this function is declared as static.
+ */
+#if defined (GD32F20X)
+extern "C" {
+fmc_state_enum fmc_bank0_state_get(void);
+fmc_state_enum fmc_bank1_state_get(void);
+}
+#endif
+
#include "debug.h"
namespace flashcode {
diff --git a/lib-flashcode/src/gd32/h7xx/flashcode.cpp b/lib-flashcode/src/gd32/h7xx/flashcode.cpp
new file mode 100644
index 0000000..47cc26a
--- /dev/null
+++ b/lib-flashcode/src/gd32/h7xx/flashcode.cpp
@@ -0,0 +1,217 @@
+/**
+ * @file flashcode.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+#include
+#include
+
+#include "flashcode.h"
+
+#include "gd32.h"
+
+#include "debug.h"
+
+namespace flashcode {
+/* Backwards compatibility with SPI FLASH */
+static constexpr auto FLASH_SECTOR_SIZE = 4096U;
+/* The flash page size is 4KB for bank1 */
+static constexpr auto BANK1_FLASH_PAGE = (4U * 1024U);
+
+enum class State {
+ IDLE,
+ ERASE_BUSY,
+ ERASE_PROGAM,
+ WRITE_BUSY,
+ WRITE_PROGRAM,
+ ERROR
+};
+
+static State s_State = State::IDLE;
+static uint32_t s_nPage;
+static uint32_t s_nLength;
+static uint32_t s_nAddress;
+static uint32_t *s_pData;
+} // namespace flashcode
+
+using namespace flashcode;
+
+uint32_t FlashCode::GetSize() const {
+ const auto FLASH_DENSITY = ((REG32(0x1FF0F7E0) >> 16) & 0xFFFF) * 1024U;
+ return FLASH_DENSITY;
+}
+
+uint32_t FlashCode::GetSectorSize() const {
+ return flashcode::FLASH_SECTOR_SIZE;
+}
+
+bool FlashCode::Read(uint32_t nOffset, uint32_t nLength, uint8_t *pBuffer, flashcode::result& nResult) {
+ DEBUG_ENTRY
+ DEBUG_PRINTF("offset=%p[%d], len=%u[%d], data=%p[%d]", nOffset, (((uint32_t)(nOffset) & 0x3) == 0), nLength, (((uint32_t)(nLength) & 0x3) == 0), pBuffer, (((uint32_t)(pBuffer) & 0x3) == 0));
+
+ const auto *pSrc = reinterpret_cast(nOffset + FLASH_BASE);
+ auto *pDst = reinterpret_cast(pBuffer);
+
+ while (nLength > 0) {
+ *pDst++ = *pSrc++;
+ nLength -= 4;
+ }
+
+ nResult = flashcode::result::OK;
+
+ DEBUG_EXIT
+ return true;
+}
+
+bool FlashCode::Erase(uint32_t nOffset, uint32_t nLength, flashcode::result& nResult) {
+ DEBUG_ENTRY
+ DEBUG_PRINTF("State=%d", static_cast(s_State));
+
+ nResult = result::OK;
+
+ switch (s_State) {
+ case State::IDLE:
+ s_nPage = nOffset + FLASH_BASE;
+ s_nLength = nLength;
+ fmc_unlock();
+ s_State = State::ERASE_BUSY;
+ DEBUG_EXIT
+ return false;
+ break;
+ case State::ERASE_BUSY:
+ if (SET == fmc_flag_get(FMC_FLAG_BUSY)) {
+ DEBUG_EXIT
+ return false;
+ }
+
+ if (s_nLength == 0) {
+ s_State = State::IDLE;
+ fmc_lock();
+ DEBUG_EXIT
+ return true;
+ }
+
+ s_State = State::ERASE_PROGAM;
+ DEBUG_EXIT
+ return false;
+ break;
+ case State::ERASE_PROGAM:
+ if (s_nLength > 0) {
+ DEBUG_PRINTF("s_nPage=%p", s_nPage);
+
+ fmc_sector_erase(s_nPage);
+
+ s_nLength -= BANK1_FLASH_PAGE;
+ s_nPage += BANK1_FLASH_PAGE;
+ }
+
+ s_State = State::ERASE_BUSY;
+ DEBUG_EXIT
+ return false;
+ break;
+ default:
+ assert(0);
+ __builtin_unreachable();
+ break;
+ }
+
+ assert(0);
+ __builtin_unreachable();
+ return true;
+}
+
+bool FlashCode::Write(uint32_t nOffset, uint32_t nLength, const uint8_t *pBuffer, flashcode::result& nResult) {
+ if ((s_State == flashcode::State::WRITE_PROGRAM) || (s_State == flashcode::State::WRITE_BUSY)) {
+ } else {
+ DEBUG_ENTRY
+ }
+ nResult = result::OK;
+
+ switch (s_State) {
+ case flashcode::State::IDLE:
+ DEBUG_PUTS("State::IDLE");
+ flashcode::s_nAddress = nOffset + FLASH_BASE;
+ s_pData = const_cast(reinterpret_cast(pBuffer));
+ s_nLength = nLength;
+ fmc_unlock();
+ s_State = State::WRITE_BUSY;
+ DEBUG_EXIT
+ return false;
+ break;
+ case flashcode::State::WRITE_BUSY:
+ if (SET == fmc_flag_get(FMC_FLAG_BUSY)) {
+ DEBUG_EXIT
+ return false;
+ }
+
+ if (s_nLength == 0) {
+ fmc_lock();
+ s_State = State::IDLE;
+
+ if( memcmp(reinterpret_cast(nOffset + FLASH_BASE), pBuffer, nLength) == 0) {
+ DEBUG_PUTS("memcmp OK");
+ } else {
+ DEBUG_PUTS("memcmp failed");
+ }
+
+ DEBUG_EXIT
+ return true;
+ }
+
+ s_State = flashcode::State::WRITE_PROGRAM;
+ return false;
+ break;
+ case flashcode::State::WRITE_PROGRAM:
+ if (s_nLength >= 4) {
+ if (FMC_READY == fmc_ready_wait(0xFF)) {
+ /* set the PG bit to start program */
+ FMC_CTL |= FMC_CTL_PG;
+ __ISB();
+ __DSB();
+ REG32(s_nAddress) = *s_pData;
+ __ISB();
+ __DSB();
+ /* reset the PG bit */
+ FMC_CTL &= ~FMC_CTL_PG;
+ s_pData++;
+ s_nAddress += 4;
+ s_nLength -= 4;
+ }
+ } else if (s_nLength > 0) {
+ DEBUG_PUTS("Error!");
+ }
+ s_State = flashcode::State::WRITE_BUSY;
+ return false;
+ break;
+ default:
+ assert(0);
+ __builtin_unreachable();
+ break;
+ }
+
+ assert(0);
+ __builtin_unreachable();
+ return true;
+}
diff --git a/lib-flashcodeinstall/.cproject b/lib-flashcodeinstall/.cproject
index 933b396..47582c9 100755
--- a/lib-flashcodeinstall/.cproject
+++ b/lib-flashcodeinstall/.cproject
@@ -30,12 +30,10 @@
-
-
@@ -53,13 +51,11 @@
-
-
@@ -84,7 +80,6 @@
-
diff --git a/lib-flashcodeinstall/Makefile.H3 b/lib-flashcodeinstall/Makefile.H3
deleted file mode 100755
index 7b71798..0000000
--- a/lib-flashcodeinstall/Makefile.H3
+++ /dev/null
@@ -1,9 +0,0 @@
-DEFINES=NDEBUG
-
-EXTRA_INCLUDES=../lib-flashcodeinstall/src/params ../lib-properties/include
-
-EXTRA_SRCDIR=src/params
-
-include Rules.mk
-include ../firmware-template-h3/lib/Rules.mk
-
diff --git a/lib-flashcodeinstall/Rules.mk b/lib-flashcodeinstall/Rules.mk
old mode 100755
new mode 100644
index 7f2a5a1..ef90a18
--- a/lib-flashcodeinstall/Rules.mk
+++ b/lib-flashcodeinstall/Rules.mk
@@ -1,3 +1,3 @@
EXTRA_SRCDIR+=
-EXTRA_INCLUDES+=../lib-flashcode/include ../lib-hal/include ../lib-display/include
\ No newline at end of file
+EXTRA_INCLUDES+=../lib-flashcode/include ../lib-display/include
\ No newline at end of file
diff --git a/lib-flashcodeinstall/include/flashcodeinstall.h b/lib-flashcodeinstall/include/flashcodeinstall.h
old mode 100755
new mode 100644
index 42a379a..1a0cb88
--- a/lib-flashcodeinstall/include/flashcodeinstall.h
+++ b/lib-flashcodeinstall/include/flashcodeinstall.h
@@ -2,7 +2,7 @@
* @file flashcodeinstall.h
*
*/
-/* Copyright (C) 2018-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,9 +26,6 @@
#ifndef FLASHCODEINSTALL_H_
#define FLASHCODEINSTALL_H_
-#include
-#include
-
#if defined (H3)
// nuc-i5:~/uboot-spi/u-boot$ grep CONFIG_BOOTCOMMAND include/configs/sunxi-common.h
// #define CONFIG_BOOTCOMMAND "sf probe; sf read 48000000 180000 22000; bootm 48000000"
@@ -38,25 +35,51 @@
#elif defined (GD32)
# if defined (BOARD_GD32F107RC)
# define OFFSET_UIMAGE 0x007000 // 28K
-# define FIRMWARE_MAX_SIZE (74 * 1024) // 74K
+# define FIRMWARE_MAX_SIZE (76 * 1024) // 76K
# elif defined (BOARD_GD32F207RG)
-# define OFFSET_UIMAGE 0x007000 // 28K
+# define OFFSET_UIMAGE 0x008000 // 32K
# define FIRMWARE_MAX_SIZE (234 * 1024) // 234K
-# elif defined (BOARD_GD32F207VC)
-# define OFFSET_UIMAGE 0x007000 // 28K
+# elif defined (BOARD_GD32F207VC_2)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (106 * 1024) // 106K
+# elif defined (BOARD_GD32F207VC_4)
+# define OFFSET_UIMAGE 0x008000 // 32K
# define FIRMWARE_MAX_SIZE (106 * 1024) // 106K
# elif defined (BOARD_GD32F207C_EVAL)
-# define OFFSET_UIMAGE 0x007000 // 28K
+# define OFFSET_UIMAGE 0x008000 // 32K
# define FIRMWARE_MAX_SIZE (106 * 1024) // 106K
# elif defined (BOARD_GD32F407RE)
# define OFFSET_UIMAGE 0x008000 // 32K
-# define FIRMWARE_MAX_SIZE (106 * 1024) // 106K
+# define FIRMWARE_MAX_SIZE (116 * 1024) // 116K
+# elif defined (BOARD_BW_OPIDMX4)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (116 * 1024) // 116K
+# elif defined (BOARD_DMX3)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (116 * 1024) // 116K
+# elif defined (BOARD_DMX4)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (116 * 1024) // 116K
# elif defined (BOARD_GD32F450VE)
# define OFFSET_UIMAGE 0x008000 // 32K
-# define FIRMWARE_MAX_SIZE (168 * 1024) // 168K
+# define FIRMWARE_MAX_SIZE (180 * 1024) // 180K
# elif defined (BOARD_GD32F450VI)
# define OFFSET_UIMAGE 0x008000 // 32K
-# define FIRMWARE_MAX_SIZE (224 * 1024) // 224K
+# define FIRMWARE_MAX_SIZE (234 * 1024) // 234K
+# elif defined (BOARD_16X4U_PIXEL)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (234 * 1024) // 234K
+# elif defined (BOARD_GD32F470VG)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (234 * 1024) // 234K
+# elif defined (BOARD_GD32F470Z_EVAL)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (175 * 1024) // 175K
+# elif defined (BOARD_GD32H759I_EVAL)
+# define OFFSET_UIMAGE 0x008000 // 32K
+# define FIRMWARE_MAX_SIZE (300 * 1024) // 300K
+# else
+# error Board is not supported
# endif
#else
# define OFFSET_UIMAGE 0x0
@@ -64,6 +87,9 @@
#ifdef __cplusplus
+#include
+#include
+
#include "flashcode.h"
class FlashCodeInstall: FlashCode {
diff --git a/lib-flashcodeinstall/src/flashcodeinstall.cpp b/lib-flashcodeinstall/src/flashcodeinstall.cpp
old mode 100755
new mode 100644
index 370d192..f3018b2
--- a/lib-flashcodeinstall/src/flashcodeinstall.cpp
+++ b/lib-flashcodeinstall/src/flashcodeinstall.cpp
@@ -2,7 +2,7 @@
* @file flashcodeinstall.cpp
*
*/
-/* Copyright (C) 2018-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -39,10 +39,10 @@ bool FlashCodeInstall::WriteFirmware(const uint8_t *pBuffer, uint32_t nSize) {
assert(pBuffer != nullptr);
assert(nSize != 0);
- DEBUG_PRINTF("(%p + %p)=%p, m_nFlashSize=%d", OFFSET_UIMAGE, nSize, (OFFSET_UIMAGE + nSize), m_nFlashSize);
+ DEBUG_PRINTF("(%p + %p)=%p, m_nFlashSize=%u", OFFSET_UIMAGE, nSize, (OFFSET_UIMAGE + nSize), static_cast(m_nFlashSize));
if ((OFFSET_UIMAGE + nSize) > m_nFlashSize) {
- printf("error: flash size %d > %d\n", (OFFSET_UIMAGE + nSize), m_nFlashSize);
+ printf("error: flash size %u > %u\n", static_cast(OFFSET_UIMAGE + nSize), static_cast(m_nFlashSize));
DEBUG_EXIT
return false;
}
@@ -60,20 +60,20 @@ bool FlashCodeInstall::WriteFirmware(const uint8_t *pBuffer, uint32_t nSize) {
DEBUG_PRINTF("nSize=%x, nSectorSize=%x, nEraseSize=%x", nSize, nSectorSize, nEraseSize);
- Display::Get()->TextStatus("Erase", Display7SegmentMessage::INFO_SPI_ERASE, CONSOLE_GREEN);
+ Display::Get()->TextStatus("Erase", CONSOLE_GREEN);
flashcode::result nResult;
- FlashCode::Erase(OFFSET_UIMAGE, nEraseSize, nResult);
+ while(!FlashCode::Erase(OFFSET_UIMAGE, nEraseSize, nResult));
if (flashcode::result::ERROR == nResult) {
puts("error: flash erase");
return false;
}
- Display::Get()->TextStatus("Writing", Display7SegmentMessage::INFO_SPI_WRITING, CONSOLE_GREEN);
+ Display::Get()->TextStatus("Writing", CONSOLE_GREEN);
- FlashCode::Write(OFFSET_UIMAGE, nSize, pBuffer, nResult);
+ while(!FlashCode::Write(OFFSET_UIMAGE, nSize, pBuffer, nResult));
if (flashcode::result::ERROR == nResult) {
puts("error: flash write");
@@ -84,7 +84,7 @@ bool FlashCodeInstall::WriteFirmware(const uint8_t *pBuffer, uint32_t nSize) {
Hardware::Get()->WatchdogInit();
}
- Display::Get()->TextStatus("Done", Display7SegmentMessage::INFO_SPI_DONE, CONSOLE_GREEN);
+ Display::Get()->TextStatus("Done", CONSOLE_GREEN);
DEBUG_EXIT
return true;
diff --git a/lib-gd32/.cproject b/lib-gd32/.cproject
index 4fde332..e2b7c7f 100644
--- a/lib-gd32/.cproject
+++ b/lib-gd32/.cproject
@@ -30,13 +30,11 @@
-
-
@@ -51,7 +49,6 @@
-
diff --git a/lib-gd32/Makefile.GD32 b/lib-gd32/Makefile.GD32
index 3bbe2a4..a3896d5 100644
--- a/lib-gd32/Makefile.GD32
+++ b/lib-gd32/Makefile.GD32
@@ -1,79 +1,87 @@
+$(info "lib-gd32/Makefile.GD32")
$(info $$FAMILY [${FAMILY}])
+$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
-ifeq ($(FAMILY),)
- FAMILY=gd32f20x
-endif
-
-$(info $$FAMILY [${FAMILY}])
+DEFINES=NDEBUG
-ifeq ($(findstring gd32f10x,$(FAMILY)), gd32f10x)
- EXTRA_SRCDIR=gd32f10x/CMSIS/GD/GD32F10x/Source
- EXTRA_SRCDIR+=gd32f10x/GD32F10x_standard_peripheral/Source
-endif
+EXTRA_SRCDIR=
-ifeq ($(findstring gd32f20x,$(FAMILY)), gd32f20x)
- EXTRA_SRCDIR=gd32f20x/CMSIS/GD/GD32F20x/Source
- EXTRA_SRCDIR+=gd32f20x/GD32F20x_standard_peripheral/Source
- ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
- EXTRA_SRCDIR+=gd32f20x/GD32F20x_usbfs_library/host/core/Source
-
- EXTRA_C_SOURCE_FILES=gd32f20x/GD32F20x_usbfs_library/driver/Source/drv_usb_core.c
- EXTRA_C_SOURCE_FILES+=gd32f20x/GD32F20x_usbfs_library/driver/Source/drv_usb_host.c
- EXTRA_C_SOURCE_FILES+=gd32f20x/GD32F20x_usbfs_library/driver/Source/drv_usbh_int.c
-
- EXTRA_INCLUDES+=gd32f20x/GD32F20x_usbfs_library/driver/Include
- EXTRA_INCLUDES+=gd32f20x/GD32F20x_usbfs_library/host/core/Include
- EXTRA_INCLUDES+=gd32f20x/GD32F20x_usbfs_library/ustd/common
-
- ifeq ($(findstring CONFIG_USB_HOST_MSC,$(MAKE_FLAGS)), CONFIG_USB_HOST_MSC)
- EXTRA_SRCDIR+=gd32f20x/GD32F20x_usbfs_library/host/class/msc/Source
-
- EXTRA_INCLUDES+=gd32f20x/GD32F20x_usbfs_library/host/class/msc/Include
- EXTRA_INCLUDES+=gd32f20x/GD32F20x_usbfs_library/ustd/class/msc
-
- EXTRA_INCLUDES+=../lib-hal/ff12c
- endif
-
- endif
-endif
+ifneq ($(MAKE_FLAGS),)
+ ifeq ($(findstring CONFIG_HAL_USE_SYSTICK,$(MAKE_FLAGS)), CONFIG_HAL_USE_SYSTICK)
+ EXTRA_SRCDIR+=src/systick
+ endif
-ifeq ($(findstring gd32f30x,$(FAMILY)), gd32f30x)
- EXTRA_SRCDIR=gd32f30x/CMSIS/GD/GD32F30x/Source
- EXTRA_SRCDIR+=gd32f30x/GD32F30x_standard_peripheral/Source
-endif
+ ifeq ($(findstring gd32f10x,$(FAMILY)), gd32f10x)
+ EXTRA_SRCDIR+=gd32f10x/CMSIS/GD/GD32F10x/Source
+ EXTRA_SRCDIR+=gd32f10x/GD32F10x_standard_peripheral/Source
+ EXTRA_SRCDIR+=src/f
+ endif
-ifeq ($(findstring gd32f4xx,$(FAMILY)), gd32f4xx)
- EXTRA_SRCDIR=gd32f4xx/CMSIS/GD/GD32F4xx/Source
- EXTRA_SRCDIR+=gd32f4xx/GD32F4xx_standard_peripheral/Source
- ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
- EXTRA_SRCDIR+=gd32f4xx/GD32F4xx_usb_library/host/core/Source
+ ifeq ($(findstring gd32f20x,$(FAMILY)), gd32f20x)
+ EXTRA_SRCDIR+=gd32f20x/CMSIS/GD/GD32F20x/Source
+ EXTRA_SRCDIR+=gd32f20x/GD32F20x_standard_peripheral/Source
- EXTRA_C_SOURCE_FILES=gd32f4xx/GD32F4xx_usb_library/driver/Source/drv_usb_core.c
- EXTRA_C_SOURCE_FILES+=gd32f4xx/GD32F4xx_usb_library/driver/Source/drv_usb_host.c
- EXTRA_C_SOURCE_FILES+=gd32f4xx/GD32F4xx_usb_library/driver/Source/drv_usbh_int.c
-
- EXTRA_INCLUDES+=gd32f4xx/GD32F4xx_usb_library/driver/Include
- EXTRA_INCLUDES+=gd32f4xx/GD32F4xx_usb_library/host/core/Include
- EXTRA_INCLUDES+=gd32f4xx/GD32F4xx_usb_library/ustd/common
-
- ifeq ($(findstring CONFIG_USB_HOST_MSC,$(MAKE_FLAGS)), CONFIG_USB_HOST_MSC)
- EXTRA_SRCDIR+=gd32f4xx/GD32F4xx_usb_library/host/class/msc/Source
-
- EXTRA_INCLUDES+=gd32f4xx/GD32F4xx_usb_library/host/class/msc/Include
- EXTRA_INCLUDES+=gd32f4xx/GD32F4xx_usb_library/ustd/class/msc
-
- EXTRA_INCLUDES+=../lib-hal/ff12c
- endif
-
- endif
-endif
+ ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
+ EXTRA_SRCDIR+=device/usb/f
+ EXTRA_SRCDIR+=gd32f20x/GD32F20x_usbfs_library/host/core/Source
+ EXTRA_C_SOURCE_FILES=gd32f20x/GD32F20x_usbfs_library/driver/Source/drv_usb_core.c
+ EXTRA_C_SOURCE_FILES+=gd32f20x/GD32F20x_usbfs_library/driver/Source/drv_usb_host.c
+ EXTRA_C_SOURCE_FILES+=gd32f20x/GD32F20x_usbfs_library/driver/Source/drv_usbh_int.c
+
+ ifeq ($(findstring CONFIG_USB_HOST_MSC,$(MAKE_FLAGS)), CONFIG_USB_HOST_MSC)
+ EXTRA_SRCDIR+=gd32f20x/GD32F20x_usbfs_library/host/class/msc/Source
+ endif
+ endif
+ EXTRA_SRCDIR+=src/f
+ endif
-$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
+ ifeq ($(findstring gd32f30x,$(FAMILY)), gd32f30x)
+ EXTRA_SRCDIR+=gd32f30x/CMSIS/GD/GD32F30x/Source
+ EXTRA_SRCDIR+=gd32f30x/GD32F30x_standard_peripheral/Source
+ EXTRA_SRCDIR+=src/f
+ endif
+
+ ifeq ($(findstring gd32f4xx,$(FAMILY)), gd32f4xx)
+ EXTRA_SRCDIR+=gd32f4xx/CMSIS/GD/GD32F4xx/Source
+ EXTRA_SRCDIR+=gd32f4xx/GD32F4xx_standard_peripheral/Source
+
+ ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
+ EXTRA_SRCDIR+=device/usb/f
+ EXTRA_SRCDIR+=gd32f4xx/GD32F4xx_usb_library/host/core/Source
+ EXTRA_C_SOURCE_FILES=gd32f4xx/GD32F4xx_usb_library/driver/Source/drv_usb_core.c
+ EXTRA_C_SOURCE_FILES+=gd32f4xx/GD32F4xx_usb_library/driver/Source/drv_usb_host.c
+ EXTRA_C_SOURCE_FILES+=gd32f4xx/GD32F4xx_usb_library/driver/Source/drv_usbh_int.c
+
+ ifeq ($(findstring CONFIG_USB_HOST_MSC,$(MAKE_FLAGS)), CONFIG_USB_HOST_MSC)
+ EXTRA_SRCDIR+=gd32f4xx/GD32F4xx_usb_library/host/class/msc/Source
+ endif
+ endif
+ EXTRA_SRCDIR+=src/f
+ endif
+
+ ifeq ($(findstring gd32h7xx,$(FAMILY)), gd32h7xx)
+ EXTRA_SRCDIR+=gd32h7xx/CMSIS/GD/GD32H7xx/Source
+ EXTRA_SRCDIR+=gd32h7xx/GD32H7xx_standard_peripheral/Source
+
+ ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
+ EXTRA_SRCDIR+=device/usb/h
+ EXTRA_SRCDIR+=gd32h7xx/GD32H7xx_usbhs_library/host/core/Source
+ EXTRA_C_SOURCE_FILES=gd32h7xx/GD32H7xx_usbhs_library/driver/Source/drv_usb_core.c
+ EXTRA_C_SOURCE_FILES+=gd32h7xx/GD32H7xx_usbhs_library/driver/Source/drv_usb_host.c
+ EXTRA_C_SOURCE_FILES+=gd32h7xx/GD32H7xx_usbhs_library/driver/Source/drv_usbh_int.c
+
+ ifeq ($(findstring CONFIG_USB_HOST_MSC,$(MAKE_FLAGS)), CONFIG_USB_HOST_MSC)
+ EXTRA_SRCDIR+=gd32h7xx/GD32H7xx_usbhs_library/host/class/msc/Source
+ endif
+ endif
+ EXTRA_SRCDIR+=src/h
+ endif
-ifneq ($(MAKE_FLAGS),)
ifeq ($(findstring NO_EMAC,$(MAKE_FLAGS)), NO_EMAC)
else
- EXTRA_SRCDIR+=device/emac
+ ifeq ($(findstring CONFIG_ENET_ENABLE_PTP,$(MAKE_FLAGS)), CONFIG_ENET_ENABLE_PTP)
+ EXTRA_SRCDIR+=src/ptp
+ endif
endif
ifeq ($(findstring CONFIG_USE_SOFTUART0,$(MAKE_FLAGS)), CONFIG_USE_SOFTUART0)
@@ -85,19 +93,60 @@ ifneq ($(MAKE_FLAGS),)
endif
endif
- ifeq ($(findstring ENABLE_PHY_SWITCH,$(MAKE_FLAGS)), ENABLE_PHY_SWITCH)
- EXTRA_SRCDIR+=device/emac/dsa
- endif
-
ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
EXTRA_SRCDIR+=device/usb
- endif
+ endif
+
+ ifeq ($(findstring USE_FREE_RTOS,$(MAKE_FLAGS)), USE_FREE_RTOS)
+ EXTRA_SRCDIR+=FreeRTOS/FreeRTOS-Kernel
+ EXTRA_SRCDIR+=FreeRTOS/FreeRTOS-Kernel/portable/Common
+ ifeq ($(findstring ARM_CM3,$(MAKE_FLAGS)), ARM_CM3)
+# EXTRA_SRCDIR+=FreeRTOS/FreeRTOS-Kernel/portable/GCC/ARM_CM3
+ endif
+ ifeq ($(findstring ARM_CM3,$(MAKE_FLAGS)), ARM_CM4F)
+ # EXTRA_SRCDIR+=FreeRTOS/FreeRTOS-Kernel/portable/GCC/ARM_CM4F
+ endif
+ ifeq ($(findstring ARM_CM3,$(MAKE_FLAGS)), ARM_CM7)
+ # EXTRA_SRCDIR+=FreeRTOS/FreeRTOS-Kernel/portable/GCC/ARM_CM7/r0p1
+ endif
+ endif
else
- EXTRA_SRCDIR+=device/emac device/emac/dsa
+ ifeq ($(FAMILY),)
+ ifneq (, $(shell test -d '../lib-gd32/gd32f10x' && echo -n yes))
+ FAMILY=gd32f10x
+ EXTRA_SRCDIR+=src/f
+ endif
+ ifneq (, $(shell test -d '../lib-gd32/gd32f20x' && echo -n yes))
+ FAMILY=gd32f20x
+ HAVE_SOFTUART=1
+ # EXTRA_SRCDIR+=src/f
+ endif
+ ifneq (, $(shell test -d '../lib-gd32/gd32f30x' && echo -n yes))
+ FAMILY=gd32f30x
+# EXTRA_SRCDIR+=src/f
+ endif
+ ifneq (, $(shell test -d '../lib-gd32/gd32f4xx' && echo -n yes))
+ FAMILY=gd32f4xx
+ HAVE_SOFTUART=1
+# EXTRA_SRCDIR+=src/f
+ endif
+ ifneq (, $(shell test -d '../lib-gd32/gd32h7xx' && echo -n yes))
+ FAMILY=gd32h7xx
+ HAVE_SOFTUART=1
+# EXTRA_SRCDIR+=src/h
+ endif
+ endif
+
+ EXTRA_SRCDIR+=device/emac
EXTRA_SRCDIR+=device/usb
- EXTRA_SRCDIR+=src/uart0 src/softuart0
+ EXTRA_SRCDIR+=src/uart0
+ ifdef HAVE_SOFTUART
+ EXTRA_SRCDIR+=src/softuart0
+ endif
DEFINES=ENABLE_USB_HOST CONFIG_USB_HOST_MSC
endif
+$(info $$FAMILY [${FAMILY}])
+
include ../firmware-template-gd32/lib/Rules.mk
\ No newline at end of file
diff --git a/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Include/gd32f20x.h b/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Include/gd32f20x.h
index 1df4588..cfc73ab 100644
--- a/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Include/gd32f20x.h
+++ b/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Include/gd32f20x.h
@@ -2,14 +2,11 @@
\file gd32f20x.h
\brief general definitions for GD32F20x
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
@@ -55,42 +52,37 @@ OF SUCH DAMAGE.
#error "Please select first the target gd32f20x device used in your application (in gd32f20x.h file)"
#endif /* GD32F20X */
-/* enum definitions */
-typedef enum {DISABLE = 0, ENABLE = !DISABLE} EventStatus, ControlStatus;
-typedef enum {RESET = 0, SET = !RESET} FlagStatus;
-typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
-
/* define value of high speed crystal oscillator (HXTAL) in Hz */
#if !defined HXTAL_VALUE
#ifdef GD32F20X_CL
#define HXTAL_VALUE ((uint32_t)25000000) /*!< value of the external oscillator in Hz */
+#endif /* GD32F20X_CL */
#endif /* HXTAL_VALUE */
-#endif /* high speed crystal oscillator value */
/* define startup timeout value of high speed crystal oscillator (HXTAL) */
#if !defined (HXTAL_STARTUP_TIMEOUT)
#define HXTAL_STARTUP_TIMEOUT ((uint16_t)0xFFFF)
-#endif /* high speed crystal oscillator startup timeout */
+#endif /*HXTAL_STARTUP_TIMEOUT */
/* define value of internal 8MHz RC oscillator (IRC8M) in Hz */
#if !defined (IRC8M_VALUE)
#define IRC8M_VALUE ((uint32_t)8000000)
-#endif /* internal 8MHz RC oscillator value */
+#endif /* IRC8M_VALUE */
/* define startup timeout value of internal 8MHz RC oscillator (IRC8M) */
#if !defined (IRC8M_STARTUP_TIMEOUT)
#define IRC8M_STARTUP_TIMEOUT ((uint16_t)0x0500)
-#endif /* internal 8MHz RC oscillator startup timeout */
+#endif /* IRC8M_STARTUP_TIMEOUT */
/* define value of internal 40KHz RC oscillator(IRC40K) in Hz */
#if !defined (IRC40K_VALUE)
#define IRC40K_VALUE ((uint32_t)40000)
-#endif /* internal 40KHz RC oscillator value */
+#endif /* IRC40K_VALUE */
/* define value of low speed crystal oscillator (LXTAL)in Hz */
#if !defined (LXTAL_VALUE)
#define LXTAL_VALUE ((uint32_t)32768)
-#endif /* low speed crystal oscillator value */
+#endif /* LXTAL_VALUE */
/* GD32F20x firmware library version number V2.0 */
#define __GD32F20x_STDPERIPH_VERSION_MAIN (0x01) /*!< [31:24] main version */
@@ -105,13 +97,13 @@ typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
/* configuration of the Cortex-M3 processor and core peripherals */
#define __MPU_PRESENT 0 /*!< GD32 devices does not provide an MPU */
#define __NVIC_PRIO_BITS 4 /*!< GD32F20X uses 4 bits for the Priority levels */
-#define __VENDOR_SYSTICKCONFIG 0 /*!< set to 1 if different systick config is used */
+#define __Vendor_SysTickConfig 0 /*!< set to 1 if different systick config is used */
/* define interrupt number */
typedef enum IRQn
{
/* Cortex-M3 processor exceptions numbers */
- NonMaskableInt_IRQn = -14, /*!< 2 non maskable interrupt */
+ NonMaskableInt_IRQn = -14, /*!< 2 non mask-able interrupt */
MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 memory management interrupt */
BusFault_IRQn = -11, /*!< 5 Cortex-M3 bus fault interrupt */
UsageFault_IRQn = -10, /*!< 6 Cortex-M3 usage fault interrupt */
@@ -119,7 +111,7 @@ typedef enum IRQn
DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 debug monitor interrupt */
PendSV_IRQn = -2, /*!< 14 Cortex-M3 pend SV interrupt */
SysTick_IRQn = -1, /*!< 15 Cortex-M3 system tick interrupt */
- /* interruput numbers */
+ /* interrupt numbers */
WWDGT_IRQn = 0, /*!< WWDGT interrupt */
LVD_IRQn = 1, /*!< LVD from EXTI line interrupt */
TAMPER_IRQn = 2, /*!< tamper interrupt */
@@ -147,7 +139,7 @@ typedef enum IRQn
TIMER0_BRK_TIMER8_IRQn = 24, /*!< TIMER0 break interrupt and TIMER8 global interrupt */
TIMER0_UP_TIMER9_IRQn = 25, /*!< TIMER0 update Interrupt and TIMER9 global interrupt */
TIMER0_TRG_CMT_TIMER10_IRQn = 26, /*!< TIMER0 trigger and commutation interrupt and TIMER10 global interrupt */
- TIMER0_Channel_IRQn = 27, /*!< TIMER0 channel capture compare interrupt */
+ TIMER0_Channel_IRQn = 27, /*!< TIMER0 channel capture compare interrupt */
TIMER1_IRQn = 28, /*!< TIMER1 global interrupt */
TIMER2_IRQn = 29, /*!< TIMER2 global interrupt */
TIMER3_IRQn = 30, /*!< TIMER3 global interrupt */
@@ -166,7 +158,7 @@ typedef enum IRQn
TIMER7_BRK_TIMER11_IRQn = 43, /*!< TIMER7 break interrupt and TIMER11 global interrupt */
TIMER7_UP_TIMER12_IRQn = 44, /*!< TIMER7 update interrupt and TIMER12 global interrupt */
TIMER7_TRG_CMT_TIMER13_IRQn = 45, /*!< TIMER7 trigger and commutation interrupt and TIMER13 global interrupt */
- TIMER7_Channel_IRQn = 46, /*!< TIMER7 Channel Capture Compare Interrupt */
+ TIMER7_Channel_IRQn = 46, /*!< TIMER7 Channel Capture Compare Interrupt */
ADC2_IRQn = 47, /*!< ADC2 global interrupt */
EXMC_IRQn = 48, /*!< EXMC global interrupt */
SDIO_IRQn = 49, /*!< SDIO global interrupt */
@@ -187,19 +179,19 @@ typedef enum IRQn
CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
- USBFS_IRQn = 67, /*!< USBFS global interrupt */
- DMA1_Channel5_IRQn = 69, /*!< DMA1 Channel 5 global interrupt */
- DMA1_Channel6_IRQn = 70, /*!< DMA1 Channel 6 global interrupt */
- USART5_IRQn = 71, /*!< USART5 global interrupt */
- I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
- I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
- DCI_IRQn = 78, /*!< DCI global interrupt */
- CAU_IRQn = 79, /*!< CAU global interrupt */
- HAU_TRNG_IRQn = 80, /*!< HAU or TRNG global interrupt */
- UART6_IRQn = 82, /*!< UART6 global interrupt */
- UART7_IRQn = 83, /*!< UART7 global interrupt */
- TLI_IRQn = 88, /*!< TLI global interrupt */
- TLI_ER_IRQn = 89 /*!< TLI global error interrupt */
+ USBFS_IRQn = 67, /*!< USBFS global interrupt */
+ DMA1_Channel5_IRQn = 69, /*!< DMA1 Channel 5 global interrupt */
+ DMA1_Channel6_IRQn = 70, /*!< DMA1 Channel 6 global interrupt */
+ USART5_IRQn = 71, /*!< USART5 global interrupt */
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
+ DCI_IRQn = 78, /*!< DCI global interrupt */
+ CAU_IRQn = 79, /*!< CAU global interrupt */
+ HAU_TRNG_IRQn = 80, /*!< HAU or TRNG global interrupt */
+ UART6_IRQn = 82, /*!< UART6 global interrupt */
+ UART7_IRQn = 83, /*!< UART7 global interrupt */
+ TLI_IRQn = 88, /*!< TLI global interrupt */
+ TLI_ER_IRQn = 89 /*!< TLI global error interrupt */
} IRQn_Type;
/* includes */
@@ -207,6 +199,12 @@ typedef enum IRQn
#include "system_gd32f20x.h"
#include
+/* enum definitions */
+typedef enum {DISABLE = 0, ENABLE = !DISABLE} EventStatus, ControlStatus;
+// typedef enum {FALSE = 0, TRUE = !FALSE} bool; /** AvV **/
+typedef enum {RESET = 0, SET = !RESET} FlagStatus;
+typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
+
/* bit operations */
#define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
#define REG16(addr) (*(volatile uint16_t *)(uint32_t)(addr))
@@ -265,10 +263,10 @@ typedef enum IRQn
#define HAU_BASE (AHB2_BUS_BASE + 0x00060400U) /*!< HAU base address */
#define TRNG_BASE (AHB2_BUS_BASE + 0x00060800U) /*!< TRNG base address */
-/* define marco USE_STDPERIPH_DRIVER */
+/* define macro USE_STDPERIPH_DRIVER */
#if !defined USE_STDPERIPH_DRIVER
#define USE_STDPERIPH_DRIVER
-#endif
+#endif /* USE_STDPERIPH_DRIVER */
#ifdef USE_STDPERIPH_DRIVER
#include "gd32f20x_libopt.h"
#endif /* USE_STDPERIPH_DRIVER */
@@ -276,4 +274,5 @@ typedef enum IRQn
#ifdef __cplusplus
}
#endif
-#endif
+
+#endif /* GD32F20X_H */
diff --git a/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Source/system_gd32f20x.c b/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Source/system_gd32f20x.c
index 37004d4..39beb93 100644
--- a/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Source/system_gd32f20x.c
+++ b/lib-gd32/gd32f20x/CMSIS/GD/GD32F20x/Source/system_gd32f20x.c
@@ -59,6 +59,17 @@
//#define __SYSTEM_CLOCK_108M_PLL_HXTAL (uint32_t)(108000000)
#define __SYSTEM_CLOCK_120M_PLL_HXTAL (uint32_t)(120000000)
+#define RCU_MODIFY(__delay) do{ \
+ volatile uint32_t i; \
+ if(0 != __delay){ \
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV2; \
+ for(i=0; i<__delay; i++){ \
+ } \
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV4; \
+ for(i=0; i<__delay; i++){ \
+ } \
+ } \
+ }while(0)
#define SEL_IRC8M 0x00U
#define SEL_HXTAL 0x01U
@@ -114,27 +125,33 @@ static void system_clock_120m_hxtal(void);
static void system_clock_config(void);
/*!
- \brief setup the microcontroller system, initialize the system
+ \brief setup the micro-controller system, initialize the system
\param[in] none
\param[out] none
\retval none
*/
-void SystemInit (void)
+void SystemInit(void)
{
/* reset the RCC clock configuration to the default reset state */
/* enable IRC8M */
RCU_CTL |= RCU_CTL_IRC8MEN;
+ while(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
+ }
+ RCU_MODIFY(0x50);
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
+ /* reset HXTALEN, CKMEN, PLLEN bits */
+ RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
/* reset SCS, AHBPSC, APB1PSC, APB2PSC, ADCPSC, CKOUT0SEL bits */
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC | RCU_CFG0_APB2PSC |
RCU_CFG0_ADCPSC | RCU_CFG0_ADCPSC_2 | RCU_CFG0_CKOUT0SEL);
/* reset HXTALEN, CKMEN, PLLEN bits */
- RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN );
+ RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
/* Reset HXTALBPS bit */
RCU_CTL &= ~(RCU_CTL_HXTALBPS);
-
+
/* reset PLLSEL, PREDV0_LSB, PLLMF, USBFSPSC bits */
RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLMF |
RCU_CFG0_USBFSPSC | RCU_CFG0_PLLMF_4);
@@ -147,20 +164,20 @@ void SystemInit (void)
/* reset INT register */
RCU_INT = 0x00FF0000U;
-
+
/* reset CFG2 register */
RCU_CFG2 = 0x00000000U;
-
+
/* reset PLLTCTL register */
- RCU_PLLTCTL &= (~RCU_PLLTCTL_PLLTEN);
-
+ RCU_PLLTCTL &= (~RCU_PLLTCTL_PLLTEN);
+
/* reset PLLTINT register */
RCU_PLLTINT = 0x00400000U;
- /* Reset PLLTCFG register */
+ /* reset PLLTCFG register */
RCU_PLLTCFG = 0x20003010U;
- /* Configure the System clock source, PLL Multiplier, AHB/APBx prescalers and Flash settings */
+ /* configure the system clock source, PLL multiplier, AHB/APBx prescalers and flash settings */
system_clock_config();
}
/*!
@@ -214,36 +231,35 @@ static void system_clock_8m_irc8m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC8M */
RCU_CTL |= RCU_CTL_IRC8MEN;
-
+
/* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
- }
- while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
-
+ } while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
+
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)) {
+ while(1) {
}
}
-
+
/* AHB = SYSCLK */
RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
/* APB2 = AHB/1 */
RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
-
+
/* select IRC8M as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_IRC8M;
-
+
/* wait until IRC8M is selected as system clock */
- while(0U != (RCU_CFG0 & RCU_SCSS_IRC8M)){
+ while(RCU_SCSS_IRC8M != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
@@ -258,21 +274,20 @@ static void system_clock_48m_irc8m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC8M */
RCU_CTL |= RCU_CTL_IRC8MEN;
/* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
- }
- while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
- while(1){
- }
+ if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)) {
+ while(1) {
+ }
}
/* IRC8M is stable */
@@ -284,14 +299,14 @@ static void system_clock_48m_irc8m(void)
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
/* CK_PLL = (CK_IRC8M/2) * 12 = 48 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_IRC8M_DIV2 | RCU_PLL_MUL12);
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -299,7 +314,7 @@ static void system_clock_48m_irc8m(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
@@ -314,19 +329,19 @@ static void system_clock_72m_irc8m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC8M */
RCU_CTL |= RCU_CTL_IRC8MEN;
/* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
- }while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)) {
+ while(1) {
}
}
@@ -339,14 +354,14 @@ static void system_clock_72m_irc8m(void)
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
/* CK_PLL = (CK_IRC8M/2) * 18 = 72 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_IRC8M_DIV2 | RCU_PLL_MUL18);
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -354,7 +369,7 @@ static void system_clock_72m_irc8m(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
@@ -369,19 +384,19 @@ static void system_clock_108m_irc8m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC8M */
RCU_CTL |= RCU_CTL_IRC8MEN;
/* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
- }while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)) {
+ while(1) {
}
}
@@ -394,14 +409,14 @@ static void system_clock_108m_irc8m(void)
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
/* CK_PLL = (CK_IRC8M/2) * 27 = 108 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_IRC8M_DIV2 | RCU_PLL_MUL27);
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -409,7 +424,7 @@ static void system_clock_108m_irc8m(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
@@ -424,19 +439,19 @@ static void system_clock_120m_irc8m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC8M */
RCU_CTL |= RCU_CTL_IRC8MEN;
/* wait until IRC8M is stable or the startup time is longer than IRC8M_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
- }while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_IRC8MSTB)) {
+ while(1) {
}
}
@@ -449,14 +464,14 @@ static void system_clock_120m_irc8m(void)
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
/* CK_PLL = (CK_IRC8M/2) * 30 = 120 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_IRC8M_DIV2 | RCU_PLL_MUL30);
-
+
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -464,7 +479,7 @@ static void system_clock_120m_irc8m(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
@@ -479,41 +494,41 @@ static void system_clock_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
-
+
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
-
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
-
+
/* AHB = SYSCLK */
RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
/* APB2 = AHB/1 */
RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
-
+
/* select HXTAL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_HXTAL;
-
+
/* wait until HXTAL is selected as system clock */
- while(0 == (RCU_CFG0 & RCU_SCSS_HXTAL)){
+ while(RCU_SCSS_HXTAL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_24M_PLL_HXTAL)
/*!
- \brief configure the system clock to 24M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 24M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -527,14 +542,14 @@ static void system_clock_24m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -546,25 +561,25 @@ static void system_clock_24m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 6 = 24 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 6 = 24 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL6);
- /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
+ /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV10);
-
+
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -572,14 +587,14 @@ static void system_clock_24m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_36M_PLL_HXTAL)
/*!
- \brief configure the system clock to 36M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 36M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -593,14 +608,14 @@ static void system_clock_36m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -612,25 +627,25 @@ static void system_clock_36m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 9 = 36 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 9 = 36 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL9);
- /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
+ /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV10);
-
+
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -638,14 +653,14 @@ static void system_clock_36m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_48M_PLL_HXTAL)
/*!
- \brief configure the system clock to 48M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 48M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -659,14 +674,14 @@ static void system_clock_48m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -678,25 +693,25 @@ static void system_clock_48m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 6 = 48 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 6 = 48 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL6);
-
- /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
+
+ /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV5);
-
+
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -704,13 +719,13 @@ static void system_clock_48m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_56M_PLL_HXTAL)
/*!
- \brief configure the system clock to 56M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 56M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -724,14 +739,14 @@ static void system_clock_56m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -743,25 +758,25 @@ static void system_clock_56m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 7 = 56 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 7 = 56 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL7);
-
- /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
+
+ /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV5);
-
+
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -769,13 +784,13 @@ static void system_clock_56m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_72M_PLL_HXTAL)
/*!
- \brief configure the system clock to 72M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 72M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -789,14 +804,14 @@ static void system_clock_72m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -808,26 +823,26 @@ static void system_clock_72m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 9 = 72 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 9 = 72 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL9);
-
- /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
+
+ /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV5);
-
-
+
+
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -835,13 +850,13 @@ static void system_clock_72m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_96M_PLL_HXTAL)
/*!
- \brief configure the system clock to 96M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 96M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -855,14 +870,14 @@ static void system_clock_96m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -874,25 +889,25 @@ static void system_clock_96m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 12 = 96 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 12 = 96 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL12);
-
- /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
+
+ /* CK_PREDIV0 = (CK_HXTAL) / 5 * 8 /5 = 8 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL8 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV5);
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -900,13 +915,13 @@ static void system_clock_96m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_108M_PLL_HXTAL)
/*!
- \brief configure the system clock to 108M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 108M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -920,14 +935,14 @@ static void system_clock_108m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -939,25 +954,25 @@ static void system_clock_108m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 9 = 108 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 9 = 108 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL9);
-
- /* CK_PREDIV0 = (CK_HXTAL) / 5 * 12 /5 = 12 MHz */
+
+ /* CK_PREDIV0 = (CK_HXTAL) / 5 * 12 /5 = 12 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL12 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV5);
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0) {
}
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -965,13 +980,13 @@ static void system_clock_108m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#elif defined (__SYSTEM_CLOCK_120M_PLL_HXTAL)
/*!
- \brief configure the system clock to 120M by PLL which selects HXTAL(8M) as its clock source
+ \brief configure the system clock to 120M by PLL which selects HXTAL(25M) as its clock source
\param[in] none
\param[out] none
\retval none
@@ -985,14 +1000,14 @@ static void system_clock_120m_hxtal(void)
RCU_CTL |= RCU_CTL_HXTALEN;
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
- do{
+ do {
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ } while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
- if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
+ if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
+ while(1) {
}
}
@@ -1004,25 +1019,25 @@ static void system_clock_120m_hxtal(void)
/* APB1 = AHB/2 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;
- /* CK_PLL = (CK_PREDIV0) * 10 = 120 MHz */
- RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL );
+ /* CK_PLL = (CK_PREDIV0) * 10 = 120 MHz */
+ RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4 | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLSEL);
RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL10);
-
- /* CK_PREDIV0 = (CK_HXTAL) / 5 * 12 /5 = 12 MHz */
+
+ /* CK_PREDIV0 = (CK_HXTAL) / 5 * 12 /5 = 12 MHz */
RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PLL1MF | RCU_CFG1_PREDV1 | RCU_CFG1_PREDV0);
RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PLL1_MUL12 | RCU_PREDV1_DIV5 | RCU_PREDV0_DIV5);
/* enable PLL1 */
RCU_CTL |= RCU_CTL_PLL1EN;
/* wait till PLL1 is ready */
- while((RCU_CTL & RCU_CTL_PLL1STB) == 0U){
+ while((RCU_CTL & RCU_CTL_PLL1STB) == 0U) {
}
-
+
/* enable PLL */
RCU_CTL |= RCU_CTL_PLLEN;
/* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
+ while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
}
/* select PLL as system clock */
@@ -1030,26 +1045,28 @@ static void system_clock_120m_hxtal(void)
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
/* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
+ while(RCU_SCSS_PLL != (RCU_CFG0 & RCU_CFG0_SCSS)) {
}
}
#endif /* __SYSTEM_CLOCK_IRC8M */
/*!
- \brief update the SystemCoreClock with current core clock retrieved from cpu registers
+ \brief update the SystemCoreClock with current core clock retrieved from CPU registers
\param[in] none
\param[out] none
\retval none
*/
-void SystemCoreClockUpdate (void)
+void SystemCoreClockUpdate(void)
{
uint32_t sws;
- uint32_t pllsel, predv0sel, pllmf,ck_src;
+ uint32_t pllsel, predv0sel, pllmf, ck_src, idx, clk_exp;
uint32_t predv0, predv1, pll1mf;
+ /* exponent of AHB, APB1 and APB2 clock divider */
+ const uint8_t ahb_exp[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
sws = GET_BITS(RCU_CFG0, 2, 3);
- switch(sws){
+ switch(sws) {
/* IRC8M is selected as CK_SYS */
case SEL_IRC8M:
SystemCoreClock = IRC8M_VALUE;
@@ -1063,46 +1080,46 @@ void SystemCoreClockUpdate (void)
/* PLL clock source selection, HXTAL or IRC8M/2 */
pllsel = (RCU_CFG0 & RCU_CFG0_PLLSEL);
- if (RCU_PLLSRC_HXTAL == pllsel) {
+ if(RCU_PLLSRC_HXTAL == pllsel) {
/* PLL clock source is HXTAL */
ck_src = HXTAL_VALUE;
predv0sel = (RCU_CFG1 & RCU_CFG1_PREDV0SEL);
/* source clock use PLL1 */
- if(RCU_PREDV0SRC_CKPLL1 == predv0sel){
+ if(RCU_PREDV0SRC_CKPLL1 == predv0sel) {
predv1 = (uint32_t)((RCU_CFG1 & RCU_CFG1_PREDV1) >> 4) + 1U;
pll1mf = (uint32_t)((RCU_CFG1 & RCU_CFG1_PLL1MF) >> 8) + 2U;
- if(17U == pll1mf){
+ if(17U == pll1mf) {
pll1mf = 20U;
}
- ck_src = (ck_src/predv1)*pll1mf;
+ ck_src = (ck_src / predv1) * pll1mf;
}
predv0 = (RCU_CFG1 & RCU_CFG1_PREDV0) + 1U;
ck_src /= predv0;
- }else{
+ } else {
/* PLL clock source is IRC8M/2 */
- ck_src = IRC8M_VALUE/2U;
+ ck_src = IRC8M_VALUE / 2U;
}
/* PLL multiplication factor */
pllmf = GET_BITS(RCU_CFG0, 18, 21);
- if((RCU_CFG0 & RCU_CFG0_PLLMF_4)){
+ if((RCU_CFG0 & RCU_CFG0_PLLMF_4)) {
pllmf |= 0x10U;
}
- if(13U == pllmf){
+ if(13U == pllmf) {
/* PLL source clock multiply by 6.5 */
- SystemCoreClock = ck_src*6U + ck_src/2U;
- }else{
- if(pllmf < 15U){
+ SystemCoreClock = ck_src * 6U + ck_src / 2U;
+ } else {
+ if(pllmf < 15U) {
pllmf += 2U;
- }else{
+ } else {
pllmf += 1U;
}
- SystemCoreClock = ck_src*pllmf;
+ SystemCoreClock = ck_src * pllmf;
}
-
+
break;
/* IRC8M is selected as CK_SYS */
default:
@@ -1110,4 +1127,8 @@ void SystemCoreClockUpdate (void)
break;
}
+ /* calculate AHB clock frequency */
+ idx = GET_BITS(RCU_CFG0, 4, 7);
+ clk_exp = ahb_exp[idx];
+ SystemCoreClock = SystemCoreClock >> clk_exp;
}
diff --git a/lib-gd32/gd32f20x/CMSIS/core_cm3.h b/lib-gd32/gd32f20x/CMSIS/core_cm3.h
deleted file mode 100644
index 248d1e4..0000000
--- a/lib-gd32/gd32f20x/CMSIS/core_cm3.h
+++ /dev/null
@@ -1,1638 +0,0 @@
-/**************************************************************************//**
- * @file core_cm3.h
- * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File
- * @version V3.30
- * @date 17. February 2014
- *
- * @note
- *
- ******************************************************************************/
-/* Copyright (c) 2009 - 2014 ARM LIMITED
-
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- - Neither the name of ARM nor the names of its contributors may be used
- to endorse or promote products derived from this software without
- specific prior written permission.
- *
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- ---------------------------------------------------------------------------*/
-
-
-#if defined ( __ICCARM__ )
- #pragma system_include /* treat file as system include file for MISRA check */
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#ifndef __CORE_CM3_H_GENERIC
-#define __CORE_CM3_H_GENERIC
-
-/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
- CMSIS violates the following MISRA-C:2004 rules:
-
- \li Required Rule 8.5, object/function definition in header file.
- Function definitions in header files are used to allow 'inlining'.
-
- \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers.
-
- \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code.
- */
-
-
-/*******************************************************************************
- * CMSIS definitions
- ******************************************************************************/
-/** \ingroup Cortex_M3
- @{
- */
-
-/* CMSIS CM3 definitions */
-#define __CM3_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */
-#define __CM3_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */
-#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | \
- __CM3_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
-
-#define __CORTEX_M (0x03) /*!< Cortex-M Core */
-
-
-#if defined ( __CC_ARM )
- #define __ASM __asm /*!< asm keyword for ARM Compiler */
- #define __INLINE __inline /*!< inline keyword for ARM Compiler */
- #define __STATIC_INLINE static __inline
-
-#elif defined ( __GNUC__ )
- #define __ASM __asm /*!< asm keyword for GNU Compiler */
- #define __INLINE inline /*!< inline keyword for GNU Compiler */
- #define __STATIC_INLINE static inline
-
-#elif defined ( __ICCARM__ )
- #define __ASM __asm /*!< asm keyword for IAR Compiler */
- #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
- #define __STATIC_INLINE static inline
-
-#elif defined ( __TMS470__ )
- #define __ASM __asm /*!< asm keyword for TI CCS Compiler */
- #define __STATIC_INLINE static inline
-
-#elif defined ( __TASKING__ )
- #define __ASM __asm /*!< asm keyword for TASKING Compiler */
- #define __INLINE inline /*!< inline keyword for TASKING Compiler */
- #define __STATIC_INLINE static inline
-
-#elif defined ( __CSMC__ ) /* Cosmic */
- #define __packed
- #define __ASM _asm /*!< asm keyword for COSMIC Compiler */
- #define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
- #define __STATIC_INLINE static inline
-
-#endif
-
-/** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all
-*/
-#define __FPU_USED 0
-
-#if defined ( __CC_ARM )
- #if defined __TARGET_FPU_VFP
- #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
- #endif
-
-#elif defined ( __GNUC__ )
- #if defined (__VFP_FP__) && !defined(__SOFTFP__)
- #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
- #endif
-
-#elif defined ( __ICCARM__ )
- #if defined __ARMVFP__
- #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
- #endif
-
-#elif defined ( __TMS470__ )
- #if defined __TI__VFP_SUPPORT____
- #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
- #endif
-
-#elif defined ( __TASKING__ )
- #if defined __FPU_VFP__
- #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
- #endif
-
-#elif defined ( __CSMC__ ) /* Cosmic */
- #if ( __CSMC__ & 0x400) // FPU present for parser
- #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
- #endif
-#endif
-
-#include /* standard types definitions */
-#include /* Core Instruction Access */
-#include /* Core Function Access */
-
-#endif /* __CORE_CM3_H_GENERIC */
-
-#ifndef __CMSIS_GENERIC
-
-#ifndef __CORE_CM3_H_DEPENDANT
-#define __CORE_CM3_H_DEPENDANT
-
-/* check device defines and use defaults */
-#if defined __CHECK_DEVICE_DEFINES
- #ifndef __CM3_REV
- #define __CM3_REV 0x0200
- #warning "__CM3_REV not defined in device header file; using default!"
- #endif
-
- #ifndef __MPU_PRESENT
- #define __MPU_PRESENT 0
- #warning "__MPU_PRESENT not defined in device header file; using default!"
- #endif
-
- #ifndef __NVIC_PRIO_BITS
- #define __NVIC_PRIO_BITS 4
- #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
- #endif
-
- #ifndef __Vendor_SysTickConfig
- #define __Vendor_SysTickConfig 0
- #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
- #endif
-#endif
-
-/* IO definitions (access restrictions to peripheral registers) */
-/**
- \defgroup CMSIS_glob_defs CMSIS Global Defines
-
- IO Type Qualifiers are used
- \li to specify the access to peripheral variables.
- \li for automatic generation of peripheral register debug information.
-*/
-#ifdef __cplusplus
- #define __I volatile /*!< Defines 'read only' permissions */
-#else
- #define __I volatile const /*!< Defines 'read only' permissions */
-#endif
-#define __O volatile /*!< Defines 'write only' permissions */
-#define __IO volatile /*!< Defines 'read / write' permissions */
-
-/*@} end of group Cortex_M3 */
-
-
-
-/*******************************************************************************
- * Register Abstraction
- Core Register contain:
- - Core Register
- - Core NVIC Register
- - Core SCB Register
- - Core SysTick Register
- - Core Debug Register
- - Core MPU Register
- ******************************************************************************/
-/** \defgroup CMSIS_core_register Defines and Type Definitions
- \brief Type definitions and defines for Cortex-M processor based devices.
-*/
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_CORE Status and Control Registers
- \brief Core Register type definitions.
- @{
- */
-
-/** \brief Union type to access the Application Program Status Register (APSR).
- */
-typedef union
-{
- struct
- {
-#if (__CORTEX_M != 0x04)
- uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
-#else
- uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
- uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
- uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
-#endif
- uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
- uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
- uint32_t C:1; /*!< bit: 29 Carry condition code flag */
- uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
- uint32_t N:1; /*!< bit: 31 Negative condition code flag */
- } b; /*!< Structure used for bit access */
- uint32_t w; /*!< Type used for word access */
-} APSR_Type;
-
-
-/** \brief Union type to access the Interrupt Program Status Register (IPSR).
- */
-typedef union
-{
- struct
- {
- uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
- uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
- } b; /*!< Structure used for bit access */
- uint32_t w; /*!< Type used for word access */
-} IPSR_Type;
-
-
-/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
- */
-typedef union
-{
- struct
- {
- uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
-#if (__CORTEX_M != 0x04)
- uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
-#else
- uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
- uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
- uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
-#endif
- uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
- uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
- uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
- uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
- uint32_t C:1; /*!< bit: 29 Carry condition code flag */
- uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
- uint32_t N:1; /*!< bit: 31 Negative condition code flag */
- } b; /*!< Structure used for bit access */
- uint32_t w; /*!< Type used for word access */
-} xPSR_Type;
-
-
-/** \brief Union type to access the Control Registers (CONTROL).
- */
-typedef union
-{
- struct
- {
- uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
- uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
- uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
- uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
- } b; /*!< Structure used for bit access */
- uint32_t w; /*!< Type used for word access */
-} CONTROL_Type;
-
-/*@} end of group CMSIS_CORE */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
- \brief Type definitions for the NVIC Registers
- @{
- */
-
-/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
- */
-typedef struct
-{
- __IO uint32_t ISER[8]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
- uint32_t RESERVED0[24];
- __IO uint32_t ICER[8]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
- uint32_t RSERVED1[24];
- __IO uint32_t ISPR[8]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
- uint32_t RESERVED2[24];
- __IO uint32_t ICPR[8]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
- uint32_t RESERVED3[24];
- __IO uint32_t IABR[8]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
- uint32_t RESERVED4[56];
- __IO uint8_t IP[240]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
- uint32_t RESERVED5[644];
- __O uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
-} NVIC_Type;
-
-/* Software Triggered Interrupt Register Definitions */
-#define NVIC_STIR_INTID_Pos 0 /*!< STIR: INTLINESNUM Position */
-#define NVIC_STIR_INTID_Msk (0x1FFUL << NVIC_STIR_INTID_Pos) /*!< STIR: INTLINESNUM Mask */
-
-/*@} end of group CMSIS_NVIC */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_SCB System Control Block (SCB)
- \brief Type definitions for the System Control Block Registers
- @{
- */
-
-/** \brief Structure type to access the System Control Block (SCB).
- */
-typedef struct
-{
- __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
- __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
- __IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
- __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
- __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
- __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
- __IO uint8_t SHP[12]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
- __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
- __IO uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
- __IO uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
- __IO uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
- __IO uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
- __IO uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
- __IO uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
- __I uint32_t PFR[2]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
- __I uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
- __I uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
- __I uint32_t MMFR[4]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
- __I uint32_t ISAR[5]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
- uint32_t RESERVED0[5];
- __IO uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
-} SCB_Type;
-
-/* SCB CPUID Register Definitions */
-#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
-#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
-
-#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
-#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
-
-#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
-#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
-
-#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
-#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
-
-#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
-#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
-
-/* SCB Interrupt Control State Register Definitions */
-#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
-#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
-
-#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
-#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
-
-#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
-#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
-
-#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
-#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
-
-#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
-#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
-
-#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
-#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
-
-#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
-#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
-
-#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
-#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
-
-#define SCB_ICSR_RETTOBASE_Pos 11 /*!< SCB ICSR: RETTOBASE Position */
-#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */
-
-#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
-#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
-
-/* SCB Vector Table Offset Register Definitions */
-#if (__CM3_REV < 0x0201) /* core r2p1 */
-#define SCB_VTOR_TBLBASE_Pos 29 /*!< SCB VTOR: TBLBASE Position */
-#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */
-
-#define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */
-#define SCB_VTOR_TBLOFF_Msk (0x3FFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
-#else
-#define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */
-#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
-#endif
-
-/* SCB Application Interrupt and Reset Control Register Definitions */
-#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
-#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
-
-#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
-#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
-
-#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
-#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
-
-#define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */
-#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
-
-#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
-#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
-
-#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
-#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
-
-#define SCB_AIRCR_VECTRESET_Pos 0 /*!< SCB AIRCR: VECTRESET Position */
-#define SCB_AIRCR_VECTRESET_Msk (1UL << SCB_AIRCR_VECTRESET_Pos) /*!< SCB AIRCR: VECTRESET Mask */
-
-/* SCB System Control Register Definitions */
-#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
-#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
-
-#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
-#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
-
-#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
-#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
-
-/* SCB Configuration Control Register Definitions */
-#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
-#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
-
-#define SCB_CCR_BFHFNMIGN_Pos 8 /*!< SCB CCR: BFHFNMIGN Position */
-#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */
-
-#define SCB_CCR_DIV_0_TRP_Pos 4 /*!< SCB CCR: DIV_0_TRP Position */
-#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */
-
-#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
-#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
-
-#define SCB_CCR_USERSETMPEND_Pos 1 /*!< SCB CCR: USERSETMPEND Position */
-#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */
-
-#define SCB_CCR_NONBASETHRDENA_Pos 0 /*!< SCB CCR: NONBASETHRDENA Position */
-#define SCB_CCR_NONBASETHRDENA_Msk (1UL << SCB_CCR_NONBASETHRDENA_Pos) /*!< SCB CCR: NONBASETHRDENA Mask */
-
-/* SCB System Handler Control and State Register Definitions */
-#define SCB_SHCSR_USGFAULTENA_Pos 18 /*!< SCB SHCSR: USGFAULTENA Position */
-#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
-
-#define SCB_SHCSR_BUSFAULTENA_Pos 17 /*!< SCB SHCSR: BUSFAULTENA Position */
-#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
-
-#define SCB_SHCSR_MEMFAULTENA_Pos 16 /*!< SCB SHCSR: MEMFAULTENA Position */
-#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
-
-#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
-#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
-
-#define SCB_SHCSR_BUSFAULTPENDED_Pos 14 /*!< SCB SHCSR: BUSFAULTPENDED Position */
-#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
-
-#define SCB_SHCSR_MEMFAULTPENDED_Pos 13 /*!< SCB SHCSR: MEMFAULTPENDED Position */
-#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
-
-#define SCB_SHCSR_USGFAULTPENDED_Pos 12 /*!< SCB SHCSR: USGFAULTPENDED Position */
-#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
-
-#define SCB_SHCSR_SYSTICKACT_Pos 11 /*!< SCB SHCSR: SYSTICKACT Position */
-#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
-
-#define SCB_SHCSR_PENDSVACT_Pos 10 /*!< SCB SHCSR: PENDSVACT Position */
-#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
-
-#define SCB_SHCSR_MONITORACT_Pos 8 /*!< SCB SHCSR: MONITORACT Position */
-#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
-
-#define SCB_SHCSR_SVCALLACT_Pos 7 /*!< SCB SHCSR: SVCALLACT Position */
-#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
-
-#define SCB_SHCSR_USGFAULTACT_Pos 3 /*!< SCB SHCSR: USGFAULTACT Position */
-#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
-
-#define SCB_SHCSR_BUSFAULTACT_Pos 1 /*!< SCB SHCSR: BUSFAULTACT Position */
-#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
-
-#define SCB_SHCSR_MEMFAULTACT_Pos 0 /*!< SCB SHCSR: MEMFAULTACT Position */
-#define SCB_SHCSR_MEMFAULTACT_Msk (1UL << SCB_SHCSR_MEMFAULTACT_Pos) /*!< SCB SHCSR: MEMFAULTACT Mask */
-
-/* SCB Configurable Fault Status Registers Definitions */
-#define SCB_CFSR_USGFAULTSR_Pos 16 /*!< SCB CFSR: Usage Fault Status Register Position */
-#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */
-
-#define SCB_CFSR_BUSFAULTSR_Pos 8 /*!< SCB CFSR: Bus Fault Status Register Position */
-#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */
-
-#define SCB_CFSR_MEMFAULTSR_Pos 0 /*!< SCB CFSR: Memory Manage Fault Status Register Position */
-#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL << SCB_CFSR_MEMFAULTSR_Pos) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
-
-/* SCB Hard Fault Status Registers Definitions */
-#define SCB_HFSR_DEBUGEVT_Pos 31 /*!< SCB HFSR: DEBUGEVT Position */
-#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
-
-#define SCB_HFSR_FORCED_Pos 30 /*!< SCB HFSR: FORCED Position */
-#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */
-
-#define SCB_HFSR_VECTTBL_Pos 1 /*!< SCB HFSR: VECTTBL Position */
-#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */
-
-/* SCB Debug Fault Status Register Definitions */
-#define SCB_DFSR_EXTERNAL_Pos 4 /*!< SCB DFSR: EXTERNAL Position */
-#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */
-
-#define SCB_DFSR_VCATCH_Pos 3 /*!< SCB DFSR: VCATCH Position */
-#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */
-
-#define SCB_DFSR_DWTTRAP_Pos 2 /*!< SCB DFSR: DWTTRAP Position */
-#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */
-
-#define SCB_DFSR_BKPT_Pos 1 /*!< SCB DFSR: BKPT Position */
-#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */
-
-#define SCB_DFSR_HALTED_Pos 0 /*!< SCB DFSR: HALTED Position */
-#define SCB_DFSR_HALTED_Msk (1UL << SCB_DFSR_HALTED_Pos) /*!< SCB DFSR: HALTED Mask */
-
-/*@} end of group CMSIS_SCB */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
- \brief Type definitions for the System Control and ID Register not in the SCB
- @{
- */
-
-/** \brief Structure type to access the System Control and ID Register not in the SCB.
- */
-typedef struct
-{
- uint32_t RESERVED0[1];
- __I uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
-#if ((defined __CM3_REV) && (__CM3_REV >= 0x200))
- __IO uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
-#else
- uint32_t RESERVED1[1];
-#endif
-} SCnSCB_Type;
-
-/* Interrupt Controller Type Register Definitions */
-#define SCnSCB_ICTR_INTLINESNUM_Pos 0 /*!< ICTR: INTLINESNUM Position */
-#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL << SCnSCB_ICTR_INTLINESNUM_Pos) /*!< ICTR: INTLINESNUM Mask */
-
-/* Auxiliary Control Register Definitions */
-
-#define SCnSCB_ACTLR_DISFOLD_Pos 2 /*!< ACTLR: DISFOLD Position */
-#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
-
-#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1 /*!< ACTLR: DISDEFWBUF Position */
-#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */
-
-#define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */
-#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos) /*!< ACTLR: DISMCYCINT Mask */
-
-/*@} end of group CMSIS_SCnotSCB */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_SysTick System Tick Timer (SysTick)
- \brief Type definitions for the System Timer Registers.
- @{
- */
-
-/** \brief Structure type to access the System Timer (SysTick).
- */
-typedef struct
-{
- __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
- __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
- __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
- __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
-} SysTick_Type;
-
-/* SysTick Control / Status Register Definitions */
-#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
-#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
-
-#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
-#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
-
-#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
-#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
-
-#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
-#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
-
-/* SysTick Reload Register Definitions */
-#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
-#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
-
-/* SysTick Current Register Definitions */
-#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
-#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
-
-/* SysTick Calibration Register Definitions */
-#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
-#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
-
-#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
-#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
-
-#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
-#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
-
-/*@} end of group CMSIS_SysTick */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM)
- \brief Type definitions for the Instrumentation Trace Macrocell (ITM)
- @{
- */
-
-/** \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM).
- */
-typedef struct
-{
- __O union
- {
- __O uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */
- __O uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */
- __O uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */
- } PORT [32]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */
- uint32_t RESERVED0[864];
- __IO uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */
- uint32_t RESERVED1[15];
- __IO uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
- uint32_t RESERVED2[15];
- __IO uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
- uint32_t RESERVED3[29];
- __O uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */
- __I uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */
- __IO uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */
- uint32_t RESERVED4[43];
- __O uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
- __I uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
- uint32_t RESERVED5[6];
- __I uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */
- __I uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */
- __I uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */
- __I uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */
- __I uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */
- __I uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */
- __I uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */
- __I uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */
- __I uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */
- __I uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */
- __I uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */
- __I uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */
-} ITM_Type;
-
-/* ITM Trace Privilege Register Definitions */
-#define ITM_TPR_PRIVMASK_Pos 0 /*!< ITM TPR: PRIVMASK Position */
-#define ITM_TPR_PRIVMASK_Msk (0xFUL << ITM_TPR_PRIVMASK_Pos) /*!< ITM TPR: PRIVMASK Mask */
-
-/* ITM Trace Control Register Definitions */
-#define ITM_TCR_BUSY_Pos 23 /*!< ITM TCR: BUSY Position */
-#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */
-
-#define ITM_TCR_TraceBusID_Pos 16 /*!< ITM TCR: ATBID Position */
-#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */
-
-#define ITM_TCR_GTSFREQ_Pos 10 /*!< ITM TCR: Global timestamp frequency Position */
-#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */
-
-#define ITM_TCR_TSPrescale_Pos 8 /*!< ITM TCR: TSPrescale Position */
-#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */
-
-#define ITM_TCR_SWOENA_Pos 4 /*!< ITM TCR: SWOENA Position */
-#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */
-
-#define ITM_TCR_DWTENA_Pos 3 /*!< ITM TCR: DWTENA Position */
-#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */
-
-#define ITM_TCR_SYNCENA_Pos 2 /*!< ITM TCR: SYNCENA Position */
-#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */
-
-#define ITM_TCR_TSENA_Pos 1 /*!< ITM TCR: TSENA Position */
-#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */
-
-#define ITM_TCR_ITMENA_Pos 0 /*!< ITM TCR: ITM Enable bit Position */
-#define ITM_TCR_ITMENA_Msk (1UL << ITM_TCR_ITMENA_Pos) /*!< ITM TCR: ITM Enable bit Mask */
-
-/* ITM Integration Write Register Definitions */
-#define ITM_IWR_ATVALIDM_Pos 0 /*!< ITM IWR: ATVALIDM Position */
-#define ITM_IWR_ATVALIDM_Msk (1UL << ITM_IWR_ATVALIDM_Pos) /*!< ITM IWR: ATVALIDM Mask */
-
-/* ITM Integration Read Register Definitions */
-#define ITM_IRR_ATREADYM_Pos 0 /*!< ITM IRR: ATREADYM Position */
-#define ITM_IRR_ATREADYM_Msk (1UL << ITM_IRR_ATREADYM_Pos) /*!< ITM IRR: ATREADYM Mask */
-
-/* ITM Integration Mode Control Register Definitions */
-#define ITM_IMCR_INTEGRATION_Pos 0 /*!< ITM IMCR: INTEGRATION Position */
-#define ITM_IMCR_INTEGRATION_Msk (1UL << ITM_IMCR_INTEGRATION_Pos) /*!< ITM IMCR: INTEGRATION Mask */
-
-/* ITM Lock Status Register Definitions */
-#define ITM_LSR_ByteAcc_Pos 2 /*!< ITM LSR: ByteAcc Position */
-#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
-
-#define ITM_LSR_Access_Pos 1 /*!< ITM LSR: Access Position */
-#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */
-
-#define ITM_LSR_Present_Pos 0 /*!< ITM LSR: Present Position */
-#define ITM_LSR_Present_Msk (1UL << ITM_LSR_Present_Pos) /*!< ITM LSR: Present Mask */
-
-/*@}*/ /* end of group CMSIS_ITM */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT)
- \brief Type definitions for the Data Watchpoint and Trace (DWT)
- @{
- */
-
-/** \brief Structure type to access the Data Watchpoint and Trace Register (DWT).
- */
-typedef struct
-{
- __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
- __IO uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
- __IO uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */
- __IO uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */
- __IO uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */
- __IO uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */
- __IO uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */
- __I uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */
- __IO uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */
- __IO uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */
- __IO uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */
- uint32_t RESERVED0[1];
- __IO uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */
- __IO uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */
- __IO uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */
- uint32_t RESERVED1[1];
- __IO uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */
- __IO uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */
- __IO uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */
- uint32_t RESERVED2[1];
- __IO uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */
- __IO uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */
- __IO uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */
-} DWT_Type;
-
-/* DWT Control Register Definitions */
-#define DWT_CTRL_NUMCOMP_Pos 28 /*!< DWT CTRL: NUMCOMP Position */
-#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */
-
-#define DWT_CTRL_NOTRCPKT_Pos 27 /*!< DWT CTRL: NOTRCPKT Position */
-#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */
-
-#define DWT_CTRL_NOEXTTRIG_Pos 26 /*!< DWT CTRL: NOEXTTRIG Position */
-#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */
-
-#define DWT_CTRL_NOCYCCNT_Pos 25 /*!< DWT CTRL: NOCYCCNT Position */
-#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */
-
-#define DWT_CTRL_NOPRFCNT_Pos 24 /*!< DWT CTRL: NOPRFCNT Position */
-#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */
-
-#define DWT_CTRL_CYCEVTENA_Pos 22 /*!< DWT CTRL: CYCEVTENA Position */
-#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */
-
-#define DWT_CTRL_FOLDEVTENA_Pos 21 /*!< DWT CTRL: FOLDEVTENA Position */
-#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */
-
-#define DWT_CTRL_LSUEVTENA_Pos 20 /*!< DWT CTRL: LSUEVTENA Position */
-#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */
-
-#define DWT_CTRL_SLEEPEVTENA_Pos 19 /*!< DWT CTRL: SLEEPEVTENA Position */
-#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */
-
-#define DWT_CTRL_EXCEVTENA_Pos 18 /*!< DWT CTRL: EXCEVTENA Position */
-#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */
-
-#define DWT_CTRL_CPIEVTENA_Pos 17 /*!< DWT CTRL: CPIEVTENA Position */
-#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */
-
-#define DWT_CTRL_EXCTRCENA_Pos 16 /*!< DWT CTRL: EXCTRCENA Position */
-#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */
-
-#define DWT_CTRL_PCSAMPLENA_Pos 12 /*!< DWT CTRL: PCSAMPLENA Position */
-#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */
-
-#define DWT_CTRL_SYNCTAP_Pos 10 /*!< DWT CTRL: SYNCTAP Position */
-#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */
-
-#define DWT_CTRL_CYCTAP_Pos 9 /*!< DWT CTRL: CYCTAP Position */
-#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */
-
-#define DWT_CTRL_POSTINIT_Pos 5 /*!< DWT CTRL: POSTINIT Position */
-#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */
-
-#define DWT_CTRL_POSTPRESET_Pos 1 /*!< DWT CTRL: POSTPRESET Position */
-#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */
-
-#define DWT_CTRL_CYCCNTENA_Pos 0 /*!< DWT CTRL: CYCCNTENA Position */
-#define DWT_CTRL_CYCCNTENA_Msk (0x1UL << DWT_CTRL_CYCCNTENA_Pos) /*!< DWT CTRL: CYCCNTENA Mask */
-
-/* DWT CPI Count Register Definitions */
-#define DWT_CPICNT_CPICNT_Pos 0 /*!< DWT CPICNT: CPICNT Position */
-#define DWT_CPICNT_CPICNT_Msk (0xFFUL << DWT_CPICNT_CPICNT_Pos) /*!< DWT CPICNT: CPICNT Mask */
-
-/* DWT Exception Overhead Count Register Definitions */
-#define DWT_EXCCNT_EXCCNT_Pos 0 /*!< DWT EXCCNT: EXCCNT Position */
-#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL << DWT_EXCCNT_EXCCNT_Pos) /*!< DWT EXCCNT: EXCCNT Mask */
-
-/* DWT Sleep Count Register Definitions */
-#define DWT_SLEEPCNT_SLEEPCNT_Pos 0 /*!< DWT SLEEPCNT: SLEEPCNT Position */
-#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL << DWT_SLEEPCNT_SLEEPCNT_Pos) /*!< DWT SLEEPCNT: SLEEPCNT Mask */
-
-/* DWT LSU Count Register Definitions */
-#define DWT_LSUCNT_LSUCNT_Pos 0 /*!< DWT LSUCNT: LSUCNT Position */
-#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL << DWT_LSUCNT_LSUCNT_Pos) /*!< DWT LSUCNT: LSUCNT Mask */
-
-/* DWT Folded-instruction Count Register Definitions */
-#define DWT_FOLDCNT_FOLDCNT_Pos 0 /*!< DWT FOLDCNT: FOLDCNT Position */
-#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL << DWT_FOLDCNT_FOLDCNT_Pos) /*!< DWT FOLDCNT: FOLDCNT Mask */
-
-/* DWT Comparator Mask Register Definitions */
-#define DWT_MASK_MASK_Pos 0 /*!< DWT MASK: MASK Position */
-#define DWT_MASK_MASK_Msk (0x1FUL << DWT_MASK_MASK_Pos) /*!< DWT MASK: MASK Mask */
-
-/* DWT Comparator Function Register Definitions */
-#define DWT_FUNCTION_MATCHED_Pos 24 /*!< DWT FUNCTION: MATCHED Position */
-#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */
-
-#define DWT_FUNCTION_DATAVADDR1_Pos 16 /*!< DWT FUNCTION: DATAVADDR1 Position */
-#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */
-
-#define DWT_FUNCTION_DATAVADDR0_Pos 12 /*!< DWT FUNCTION: DATAVADDR0 Position */
-#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */
-
-#define DWT_FUNCTION_DATAVSIZE_Pos 10 /*!< DWT FUNCTION: DATAVSIZE Position */
-#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */
-
-#define DWT_FUNCTION_LNK1ENA_Pos 9 /*!< DWT FUNCTION: LNK1ENA Position */
-#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */
-
-#define DWT_FUNCTION_DATAVMATCH_Pos 8 /*!< DWT FUNCTION: DATAVMATCH Position */
-#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */
-
-#define DWT_FUNCTION_CYCMATCH_Pos 7 /*!< DWT FUNCTION: CYCMATCH Position */
-#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */
-
-#define DWT_FUNCTION_EMITRANGE_Pos 5 /*!< DWT FUNCTION: EMITRANGE Position */
-#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */
-
-#define DWT_FUNCTION_FUNCTION_Pos 0 /*!< DWT FUNCTION: FUNCTION Position */
-#define DWT_FUNCTION_FUNCTION_Msk (0xFUL << DWT_FUNCTION_FUNCTION_Pos) /*!< DWT FUNCTION: FUNCTION Mask */
-
-/*@}*/ /* end of group CMSIS_DWT */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_TPI Trace Port Interface (TPI)
- \brief Type definitions for the Trace Port Interface (TPI)
- @{
- */
-
-/** \brief Structure type to access the Trace Port Interface Register (TPI).
- */
-typedef struct
-{
- __IO uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
- __IO uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
- uint32_t RESERVED0[2];
- __IO uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
- uint32_t RESERVED1[55];
- __IO uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */
- uint32_t RESERVED2[131];
- __I uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */
- __IO uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
- __I uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
- uint32_t RESERVED3[759];
- __I uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */
- __I uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
- __I uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
- uint32_t RESERVED4[1];
- __I uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */
- __I uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */
- __IO uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */
- uint32_t RESERVED5[39];
- __IO uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */
- __IO uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */
- uint32_t RESERVED7[8];
- __I uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */
- __I uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */
-} TPI_Type;
-
-/* TPI Asynchronous Clock Prescaler Register Definitions */
-#define TPI_ACPR_PRESCALER_Pos 0 /*!< TPI ACPR: PRESCALER Position */
-#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL << TPI_ACPR_PRESCALER_Pos) /*!< TPI ACPR: PRESCALER Mask */
-
-/* TPI Selected Pin Protocol Register Definitions */
-#define TPI_SPPR_TXMODE_Pos 0 /*!< TPI SPPR: TXMODE Position */
-#define TPI_SPPR_TXMODE_Msk (0x3UL << TPI_SPPR_TXMODE_Pos) /*!< TPI SPPR: TXMODE Mask */
-
-/* TPI Formatter and Flush Status Register Definitions */
-#define TPI_FFSR_FtNonStop_Pos 3 /*!< TPI FFSR: FtNonStop Position */
-#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */
-
-#define TPI_FFSR_TCPresent_Pos 2 /*!< TPI FFSR: TCPresent Position */
-#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */
-
-#define TPI_FFSR_FtStopped_Pos 1 /*!< TPI FFSR: FtStopped Position */
-#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */
-
-#define TPI_FFSR_FlInProg_Pos 0 /*!< TPI FFSR: FlInProg Position */
-#define TPI_FFSR_FlInProg_Msk (0x1UL << TPI_FFSR_FlInProg_Pos) /*!< TPI FFSR: FlInProg Mask */
-
-/* TPI Formatter and Flush Control Register Definitions */
-#define TPI_FFCR_TrigIn_Pos 8 /*!< TPI FFCR: TrigIn Position */
-#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */
-
-#define TPI_FFCR_EnFCont_Pos 1 /*!< TPI FFCR: EnFCont Position */
-#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */
-
-/* TPI TRIGGER Register Definitions */
-#define TPI_TRIGGER_TRIGGER_Pos 0 /*!< TPI TRIGGER: TRIGGER Position */
-#define TPI_TRIGGER_TRIGGER_Msk (0x1UL << TPI_TRIGGER_TRIGGER_Pos) /*!< TPI TRIGGER: TRIGGER Mask */
-
-/* TPI Integration ETM Data Register Definitions (FIFO0) */
-#define TPI_FIFO0_ITM_ATVALID_Pos 29 /*!< TPI FIFO0: ITM_ATVALID Position */
-#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
-
-#define TPI_FIFO0_ITM_bytecount_Pos 27 /*!< TPI FIFO0: ITM_bytecount Position */
-#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
-
-#define TPI_FIFO0_ETM_ATVALID_Pos 26 /*!< TPI FIFO0: ETM_ATVALID Position */
-#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
-
-#define TPI_FIFO0_ETM_bytecount_Pos 24 /*!< TPI FIFO0: ETM_bytecount Position */
-#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
-
-#define TPI_FIFO0_ETM2_Pos 16 /*!< TPI FIFO0: ETM2 Position */
-#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */
-
-#define TPI_FIFO0_ETM1_Pos 8 /*!< TPI FIFO0: ETM1 Position */
-#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */
-
-#define TPI_FIFO0_ETM0_Pos 0 /*!< TPI FIFO0: ETM0 Position */
-#define TPI_FIFO0_ETM0_Msk (0xFFUL << TPI_FIFO0_ETM0_Pos) /*!< TPI FIFO0: ETM0 Mask */
-
-/* TPI ITATBCTR2 Register Definitions */
-#define TPI_ITATBCTR2_ATREADY_Pos 0 /*!< TPI ITATBCTR2: ATREADY Position */
-#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL << TPI_ITATBCTR2_ATREADY_Pos) /*!< TPI ITATBCTR2: ATREADY Mask */
-
-/* TPI Integration ITM Data Register Definitions (FIFO1) */
-#define TPI_FIFO1_ITM_ATVALID_Pos 29 /*!< TPI FIFO1: ITM_ATVALID Position */
-#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
-
-#define TPI_FIFO1_ITM_bytecount_Pos 27 /*!< TPI FIFO1: ITM_bytecount Position */
-#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
-
-#define TPI_FIFO1_ETM_ATVALID_Pos 26 /*!< TPI FIFO1: ETM_ATVALID Position */
-#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
-
-#define TPI_FIFO1_ETM_bytecount_Pos 24 /*!< TPI FIFO1: ETM_bytecount Position */
-#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
-
-#define TPI_FIFO1_ITM2_Pos 16 /*!< TPI FIFO1: ITM2 Position */
-#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */
-
-#define TPI_FIFO1_ITM1_Pos 8 /*!< TPI FIFO1: ITM1 Position */
-#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */
-
-#define TPI_FIFO1_ITM0_Pos 0 /*!< TPI FIFO1: ITM0 Position */
-#define TPI_FIFO1_ITM0_Msk (0xFFUL << TPI_FIFO1_ITM0_Pos) /*!< TPI FIFO1: ITM0 Mask */
-
-/* TPI ITATBCTR0 Register Definitions */
-#define TPI_ITATBCTR0_ATREADY_Pos 0 /*!< TPI ITATBCTR0: ATREADY Position */
-#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL << TPI_ITATBCTR0_ATREADY_Pos) /*!< TPI ITATBCTR0: ATREADY Mask */
-
-/* TPI Integration Mode Control Register Definitions */
-#define TPI_ITCTRL_Mode_Pos 0 /*!< TPI ITCTRL: Mode Position */
-#define TPI_ITCTRL_Mode_Msk (0x1UL << TPI_ITCTRL_Mode_Pos) /*!< TPI ITCTRL: Mode Mask */
-
-/* TPI DEVID Register Definitions */
-#define TPI_DEVID_NRZVALID_Pos 11 /*!< TPI DEVID: NRZVALID Position */
-#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */
-
-#define TPI_DEVID_MANCVALID_Pos 10 /*!< TPI DEVID: MANCVALID Position */
-#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */
-
-#define TPI_DEVID_PTINVALID_Pos 9 /*!< TPI DEVID: PTINVALID Position */
-#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */
-
-#define TPI_DEVID_MinBufSz_Pos 6 /*!< TPI DEVID: MinBufSz Position */
-#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */
-
-#define TPI_DEVID_AsynClkIn_Pos 5 /*!< TPI DEVID: AsynClkIn Position */
-#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */
-
-#define TPI_DEVID_NrTraceInput_Pos 0 /*!< TPI DEVID: NrTraceInput Position */
-#define TPI_DEVID_NrTraceInput_Msk (0x1FUL << TPI_DEVID_NrTraceInput_Pos) /*!< TPI DEVID: NrTraceInput Mask */
-
-/* TPI DEVTYPE Register Definitions */
-#define TPI_DEVTYPE_SubType_Pos 0 /*!< TPI DEVTYPE: SubType Position */
-#define TPI_DEVTYPE_SubType_Msk (0xFUL << TPI_DEVTYPE_SubType_Pos) /*!< TPI DEVTYPE: SubType Mask */
-
-#define TPI_DEVTYPE_MajorType_Pos 4 /*!< TPI DEVTYPE: MajorType Position */
-#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
-
-/*@}*/ /* end of group CMSIS_TPI */
-
-
-#if (__MPU_PRESENT == 1)
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_MPU Memory Protection Unit (MPU)
- \brief Type definitions for the Memory Protection Unit (MPU)
- @{
- */
-
-/** \brief Structure type to access the Memory Protection Unit (MPU).
- */
-typedef struct
-{
- __I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
- __IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
- __IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
- __IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
- __IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
- __IO uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */
- __IO uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */
- __IO uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */
- __IO uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */
- __IO uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */
- __IO uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
-} MPU_Type;
-
-/* MPU Type Register */
-#define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
-#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
-
-#define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
-#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
-
-#define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
-#define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */
-
-/* MPU Control Register */
-#define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
-#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
-
-#define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
-#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
-
-#define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
-#define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */
-
-/* MPU Region Number Register */
-#define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
-#define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */
-
-/* MPU Region Base Address Register */
-#define MPU_RBAR_ADDR_Pos 5 /*!< MPU RBAR: ADDR Position */
-#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
-
-#define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
-#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
-
-#define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
-#define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */
-
-/* MPU Region Attribute and Size Register */
-#define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */
-#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
-
-#define MPU_RASR_XN_Pos 28 /*!< MPU RASR: ATTRS.XN Position */
-#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
-
-#define MPU_RASR_AP_Pos 24 /*!< MPU RASR: ATTRS.AP Position */
-#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
-
-#define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: ATTRS.TEX Position */
-#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
-
-#define MPU_RASR_S_Pos 18 /*!< MPU RASR: ATTRS.S Position */
-#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
-
-#define MPU_RASR_C_Pos 17 /*!< MPU RASR: ATTRS.C Position */
-#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
-
-#define MPU_RASR_B_Pos 16 /*!< MPU RASR: ATTRS.B Position */
-#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
-
-#define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
-#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
-
-#define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
-#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
-
-#define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */
-#define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */
-
-/*@} end of group CMSIS_MPU */
-#endif
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
- \brief Type definitions for the Core Debug Registers
- @{
- */
-
-/** \brief Structure type to access the Core Debug Register (CoreDebug).
- */
-typedef struct
-{
- __IO uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
- __O uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
- __IO uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
- __IO uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
-} CoreDebug_Type;
-
-/* Debug Halting Control and Status Register */
-#define CoreDebug_DHCSR_DBGKEY_Pos 16 /*!< CoreDebug DHCSR: DBGKEY Position */
-#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */
-
-#define CoreDebug_DHCSR_S_RESET_ST_Pos 25 /*!< CoreDebug DHCSR: S_RESET_ST Position */
-#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */
-
-#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24 /*!< CoreDebug DHCSR: S_RETIRE_ST Position */
-#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */
-
-#define CoreDebug_DHCSR_S_LOCKUP_Pos 19 /*!< CoreDebug DHCSR: S_LOCKUP Position */
-#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */
-
-#define CoreDebug_DHCSR_S_SLEEP_Pos 18 /*!< CoreDebug DHCSR: S_SLEEP Position */
-#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */
-
-#define CoreDebug_DHCSR_S_HALT_Pos 17 /*!< CoreDebug DHCSR: S_HALT Position */
-#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */
-
-#define CoreDebug_DHCSR_S_REGRDY_Pos 16 /*!< CoreDebug DHCSR: S_REGRDY Position */
-#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */
-
-#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5 /*!< CoreDebug DHCSR: C_SNAPSTALL Position */
-#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */
-
-#define CoreDebug_DHCSR_C_MASKINTS_Pos 3 /*!< CoreDebug DHCSR: C_MASKINTS Position */
-#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */
-
-#define CoreDebug_DHCSR_C_STEP_Pos 2 /*!< CoreDebug DHCSR: C_STEP Position */
-#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */
-
-#define CoreDebug_DHCSR_C_HALT_Pos 1 /*!< CoreDebug DHCSR: C_HALT Position */
-#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */
-
-#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0 /*!< CoreDebug DHCSR: C_DEBUGEN Position */
-#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL << CoreDebug_DHCSR_C_DEBUGEN_Pos) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */
-
-/* Debug Core Register Selector Register */
-#define CoreDebug_DCRSR_REGWnR_Pos 16 /*!< CoreDebug DCRSR: REGWnR Position */
-#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */
-
-#define CoreDebug_DCRSR_REGSEL_Pos 0 /*!< CoreDebug DCRSR: REGSEL Position */
-#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL << CoreDebug_DCRSR_REGSEL_Pos) /*!< CoreDebug DCRSR: REGSEL Mask */
-
-/* Debug Exception and Monitor Control Register */
-#define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */
-#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
-
-#define CoreDebug_DEMCR_MON_REQ_Pos 19 /*!< CoreDebug DEMCR: MON_REQ Position */
-#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */
-
-#define CoreDebug_DEMCR_MON_STEP_Pos 18 /*!< CoreDebug DEMCR: MON_STEP Position */
-#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */
-
-#define CoreDebug_DEMCR_MON_PEND_Pos 17 /*!< CoreDebug DEMCR: MON_PEND Position */
-#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */
-
-#define CoreDebug_DEMCR_MON_EN_Pos 16 /*!< CoreDebug DEMCR: MON_EN Position */
-#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */
-
-#define CoreDebug_DEMCR_VC_HARDERR_Pos 10 /*!< CoreDebug DEMCR: VC_HARDERR Position */
-#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */
-
-#define CoreDebug_DEMCR_VC_INTERR_Pos 9 /*!< CoreDebug DEMCR: VC_INTERR Position */
-#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */
-
-#define CoreDebug_DEMCR_VC_BUSERR_Pos 8 /*!< CoreDebug DEMCR: VC_BUSERR Position */
-#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */
-
-#define CoreDebug_DEMCR_VC_STATERR_Pos 7 /*!< CoreDebug DEMCR: VC_STATERR Position */
-#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */
-
-#define CoreDebug_DEMCR_VC_CHKERR_Pos 6 /*!< CoreDebug DEMCR: VC_CHKERR Position */
-#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */
-
-#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5 /*!< CoreDebug DEMCR: VC_NOCPERR Position */
-#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */
-
-#define CoreDebug_DEMCR_VC_MMERR_Pos 4 /*!< CoreDebug DEMCR: VC_MMERR Position */
-#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */
-
-#define CoreDebug_DEMCR_VC_CORERESET_Pos 0 /*!< CoreDebug DEMCR: VC_CORERESET Position */
-#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL << CoreDebug_DEMCR_VC_CORERESET_Pos) /*!< CoreDebug DEMCR: VC_CORERESET Mask */
-
-/*@} end of group CMSIS_CoreDebug */
-
-
-/** \ingroup CMSIS_core_register
- \defgroup CMSIS_core_base Core Definitions
- \brief Definitions for base addresses, unions, and structures.
- @{
- */
-
-/* Memory mapping of Cortex-M3 Hardware */
-#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
-#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
-#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
-#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */
-#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
-#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
-#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
-#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
-
-#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
-#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
-#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
-#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
-#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */
-#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */
-#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
-#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
-
-#if (__MPU_PRESENT == 1)
- #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
- #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
-#endif
-
-/*@} */
-
-
-
-/*******************************************************************************
- * Hardware Abstraction Layer
- Core Function Interface contains:
- - Core NVIC Functions
- - Core SysTick Functions
- - Core Debug Functions
- - Core Register Access Functions
- ******************************************************************************/
-/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
-*/
-
-
-
-/* ########################## NVIC functions #################################### */
-/** \ingroup CMSIS_Core_FunctionInterface
- \defgroup CMSIS_Core_NVICFunctions NVIC Functions
- \brief Functions that manage interrupts and exceptions via the NVIC.
- @{
- */
-
-/** \brief Set Priority Grouping
-
- The function sets the priority grouping field using the required unlock sequence.
- The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
- Only values from 0..7 are used.
- In case of a conflict between priority grouping and available
- priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
-
- \param [in] PriorityGroup Priority grouping field.
- */
-__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
-{
- uint32_t reg_value;
- uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */
-
- reg_value = SCB->AIRCR; /* read old register configuration */
- reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
- reg_value = (reg_value |
- ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) |
- (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
- SCB->AIRCR = reg_value;
-}
-
-
-/** \brief Get Priority Grouping
-
- The function reads the priority grouping field from the NVIC Interrupt Controller.
-
- \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
- */
-__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void)
-{
- return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */
-}
-
-
-/** \brief Enable External Interrupt
-
- The function enables a device-specific interrupt in the NVIC interrupt controller.
-
- \param [in] IRQn External interrupt number. Value cannot be negative.
- */
-__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
-{
- NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
-}
-
-
-/** \brief Disable External Interrupt
-
- The function disables a device-specific interrupt in the NVIC interrupt controller.
-
- \param [in] IRQn External interrupt number. Value cannot be negative.
- */
-__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
-{
- NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */
-}
-
-
-/** \brief Get Pending Interrupt
-
- The function reads the pending register in the NVIC and returns the pending bit
- for the specified interrupt.
-
- \param [in] IRQn Interrupt number.
-
- \return 0 Interrupt status is not pending.
- \return 1 Interrupt status is pending.
- */
-__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
-{
- return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */
-}
-
-
-/** \brief Set Pending Interrupt
-
- The function sets the pending bit of an external interrupt.
-
- \param [in] IRQn Interrupt number. Value cannot be negative.
- */
-__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
-{
- NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */
-}
-
-
-/** \brief Clear Pending Interrupt
-
- The function clears the pending bit of an external interrupt.
-
- \param [in] IRQn External interrupt number. Value cannot be negative.
- */
-__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
-{
- NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
-}
-
-
-/** \brief Get Active Interrupt
-
- The function reads the active register in NVIC and returns the active bit.
-
- \param [in] IRQn Interrupt number.
-
- \return 0 Interrupt status is not active.
- \return 1 Interrupt status is active.
- */
-__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
-{
- return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */
-}
-
-
-/** \brief Set Interrupt Priority
-
- The function sets the priority of an interrupt.
-
- \note The priority cannot be set for every core interrupt.
-
- \param [in] IRQn Interrupt number.
- \param [in] priority Priority to set.
- */
-__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
-{
- if(IRQn < 0) {
- SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M System Interrupts */
- else {
- NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
-}
-
-
-/** \brief Get Interrupt Priority
-
- The function reads the priority of an interrupt. The interrupt
- number can be positive to specify an external (device specific)
- interrupt, or negative to specify an internal (core) interrupt.
-
-
- \param [in] IRQn Interrupt number.
- \return Interrupt Priority. Value is aligned automatically to the implemented
- priority bits of the microcontroller.
- */
-__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
-{
-
- if(IRQn < 0) {
- return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M system interrupts */
- else {
- return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
-}
-
-
-/** \brief Encode Priority
-
- The function encodes the priority for an interrupt with the given priority group,
- preemptive priority value, and subpriority value.
- In case of a conflict between priority grouping and available
- priority bits (__NVIC_PRIO_BITS), the samllest possible priority group is set.
-
- \param [in] PriorityGroup Used priority group.
- \param [in] PreemptPriority Preemptive priority value (starting from 0).
- \param [in] SubPriority Subpriority value (starting from 0).
- \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
- */
-__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
-{
- uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
- uint32_t PreemptPriorityBits;
- uint32_t SubPriorityBits;
-
- PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
- SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
-
- return (
- ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
- ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
- );
-}
-
-
-/** \brief Decode Priority
-
- The function decodes an interrupt priority value with a given priority group to
- preemptive priority value and subpriority value.
- In case of a conflict between priority grouping and available
- priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.
-
- \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
- \param [in] PriorityGroup Used priority group.
- \param [out] pPreemptPriority Preemptive priority value (starting from 0).
- \param [out] pSubPriority Subpriority value (starting from 0).
- */
-__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
-{
- uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
- uint32_t PreemptPriorityBits;
- uint32_t SubPriorityBits;
-
- PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
- SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
-
- *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
- *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
-}
-
-
-/** \brief System Reset
-
- The function initiates a system reset request to reset the MCU.
- */
-__STATIC_INLINE void NVIC_SystemReset(void)
-{
- __DSB(); /* Ensure all outstanding memory accesses included
- buffered write are completed before reset */
- SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
- (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
- SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
- __DSB(); /* Ensure completion of memory access */
- while(1); /* wait until reset */
-}
-
-/*@} end of CMSIS_Core_NVICFunctions */
-
-
-
-/* ################################## SysTick function ############################################ */
-/** \ingroup CMSIS_Core_FunctionInterface
- \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
- \brief Functions that configure the System.
- @{
- */
-
-#if (__Vendor_SysTickConfig == 0)
-
-/** \brief System Tick Configuration
-
- The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
- Counter is in free running mode to generate periodic interrupts.
-
- \param [in] ticks Number of ticks between two interrupts.
-
- \return 0 Function succeeded.
- \return 1 Function failed.
-
- \note When the variable __Vendor_SysTickConfig is set to 1, then the
- function SysTick_Config is not included. In this case, the file device .h
- must contain a vendor-specific implementation of this function.
-
- */
-__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
-{
- if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
-
- SysTick->LOAD = ticks - 1; /* set reload register */
- NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
- SysTick->VAL = 0; /* Load the SysTick Counter Value */
- SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
- SysTick_CTRL_TICKINT_Msk |
- SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
- return (0); /* Function successful */
-}
-
-#endif
-
-/*@} end of CMSIS_Core_SysTickFunctions */
-
-
-
-/* ##################################### Debug In/Output function ########################################### */
-/** \ingroup CMSIS_Core_FunctionInterface
- \defgroup CMSIS_core_DebugFunctions ITM Functions
- \brief Functions that access the ITM debug interface.
- @{
- */
-
-extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
-#define ITM_RXBUFFER_EMPTY 0x5AA55AA5 /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
-
-
-/** \brief ITM Send Character
-
- The function transmits a character via the ITM channel 0, and
- \li Just returns when no debugger is connected that has booked the output.
- \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
-
- \param [in] ch Character to transmit.
-
- \returns Character to transmit.
- */
-__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
-{
- if ((ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
- (ITM->TER & (1UL << 0) ) ) /* ITM Port #0 enabled */
- {
- while (ITM->PORT[0].u32 == 0);
- ITM->PORT[0].u8 = (uint8_t) ch;
- }
- return (ch);
-}
-
-
-/** \brief ITM Receive Character
-
- The function inputs a character via the external variable \ref ITM_RxBuffer.
-
- \return Received character.
- \return -1 No character pending.
- */
-__STATIC_INLINE int32_t ITM_ReceiveChar (void) {
- int32_t ch = -1; /* no character available */
-
- if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
- ch = ITM_RxBuffer;
- ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
- }
-
- return (ch);
-}
-
-
-/** \brief ITM Check Character
-
- The function checks whether a character is pending for reading in the variable \ref ITM_RxBuffer.
-
- \return 0 No character available.
- \return 1 Character available.
- */
-__STATIC_INLINE int32_t ITM_CheckChar (void) {
-
- if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
- return (0); /* no character available */
- } else {
- return (1); /* character available */
- }
-}
-
-/*@} end of CMSIS_core_DebugFunctions */
-
-#endif /* __CORE_CM3_H_DEPENDANT */
-
-#endif /* __CMSIS_GENERIC */
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/lib-gd32/gd32f20x/CMSIS/core_cmFunc.h b/lib-gd32/gd32f20x/CMSIS/core_cmFunc.h
deleted file mode 100644
index adb07b5..0000000
--- a/lib-gd32/gd32f20x/CMSIS/core_cmFunc.h
+++ /dev/null
@@ -1,616 +0,0 @@
-/**************************************************************************//**
- * @file core_cmFunc.h
- * @brief CMSIS Cortex-M Core Function Access Header File
- * @version V3.01
- * @date 06. March 2012
- *
- * @note
- * Copyright (C) 2009-2012 ARM Limited. All rights reserved.
- *
- * @par
- * ARM Limited (ARM) is supplying this software for use with Cortex-M
- * processor based microcontrollers. This file can be freely distributed
- * within development tools that are supporting such ARM based processors.
- *
- * @par
- * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
- * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
- * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
- * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
- *
- ******************************************************************************/
-
-#ifndef __CORE_CMFUNC_H
-#define __CORE_CMFUNC_H
-
-
-/* ########################### Core Function Access ########################### */
-/** \ingroup CMSIS_Core_FunctionInterface
- \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
- @{
- */
-
-#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
-/* ARM armcc specific functions */
-
-#if (__ARMCC_VERSION < 400677)
- #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
-#endif
-
-/* intrinsic void __enable_irq(); */
-/* intrinsic void __disable_irq(); */
-
-/** \brief Get Control Register
-
- This function returns the content of the Control Register.
-
- \return Control Register value
- */
-__STATIC_INLINE uint32_t __get_CONTROL(void)
-{
- register uint32_t __regControl __ASM("control");
- return(__regControl);
-}
-
-
-/** \brief Set Control Register
-
- This function writes the given value to the Control Register.
-
- \param [in] control Control Register value to set
- */
-__STATIC_INLINE void __set_CONTROL(uint32_t control)
-{
- register uint32_t __regControl __ASM("control");
- __regControl = control;
-}
-
-
-/** \brief Get IPSR Register
-
- This function returns the content of the IPSR Register.
-
- \return IPSR Register value
- */
-__STATIC_INLINE uint32_t __get_IPSR(void)
-{
- register uint32_t __regIPSR __ASM("ipsr");
- return(__regIPSR);
-}
-
-
-/** \brief Get APSR Register
-
- This function returns the content of the APSR Register.
-
- \return APSR Register value
- */
-__STATIC_INLINE uint32_t __get_APSR(void)
-{
- register uint32_t __regAPSR __ASM("apsr");
- return(__regAPSR);
-}
-
-
-/** \brief Get xPSR Register
-
- This function returns the content of the xPSR Register.
-
- \return xPSR Register value
- */
-__STATIC_INLINE uint32_t __get_xPSR(void)
-{
- register uint32_t __regXPSR __ASM("xpsr");
- return(__regXPSR);
-}
-
-
-/** \brief Get Process Stack Pointer
-
- This function returns the current value of the Process Stack Pointer (PSP).
-
- \return PSP Register value
- */
-__STATIC_INLINE uint32_t __get_PSP(void)
-{
- register uint32_t __regProcessStackPointer __ASM("psp");
- return(__regProcessStackPointer);
-}
-
-
-/** \brief Set Process Stack Pointer
-
- This function assigns the given value to the Process Stack Pointer (PSP).
-
- \param [in] topOfProcStack Process Stack Pointer value to set
- */
-__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
-{
- register uint32_t __regProcessStackPointer __ASM("psp");
- __regProcessStackPointer = topOfProcStack;
-}
-
-
-/** \brief Get Main Stack Pointer
-
- This function returns the current value of the Main Stack Pointer (MSP).
-
- \return MSP Register value
- */
-__STATIC_INLINE uint32_t __get_MSP(void)
-{
- register uint32_t __regMainStackPointer __ASM("msp");
- return(__regMainStackPointer);
-}
-
-
-/** \brief Set Main Stack Pointer
-
- This function assigns the given value to the Main Stack Pointer (MSP).
-
- \param [in] topOfMainStack Main Stack Pointer value to set
- */
-__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
-{
- register uint32_t __regMainStackPointer __ASM("msp");
- __regMainStackPointer = topOfMainStack;
-}
-
-
-/** \brief Get Priority Mask
-
- This function returns the current state of the priority mask bit from the Priority Mask Register.
-
- \return Priority Mask value
- */
-__STATIC_INLINE uint32_t __get_PRIMASK(void)
-{
- register uint32_t __regPriMask __ASM("primask");
- return(__regPriMask);
-}
-
-
-/** \brief Set Priority Mask
-
- This function assigns the given value to the Priority Mask Register.
-
- \param [in] priMask Priority Mask
- */
-__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
-{
- register uint32_t __regPriMask __ASM("primask");
- __regPriMask = (priMask);
-}
-
-
-#if (__CORTEX_M >= 0x03)
-
-/** \brief Enable FIQ
-
- This function enables FIQ interrupts by clearing the F-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-#define __enable_fault_irq __enable_fiq
-
-
-/** \brief Disable FIQ
-
- This function disables FIQ interrupts by setting the F-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-#define __disable_fault_irq __disable_fiq
-
-
-/** \brief Get Base Priority
-
- This function returns the current value of the Base Priority register.
-
- \return Base Priority register value
- */
-__STATIC_INLINE uint32_t __get_BASEPRI(void)
-{
- register uint32_t __regBasePri __ASM("basepri");
- return(__regBasePri);
-}
-
-
-/** \brief Set Base Priority
-
- This function assigns the given value to the Base Priority register.
-
- \param [in] basePri Base Priority value to set
- */
-__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
-{
- register uint32_t __regBasePri __ASM("basepri");
- __regBasePri = (basePri & 0xff);
-}
-
-
-/** \brief Get Fault Mask
-
- This function returns the current value of the Fault Mask register.
-
- \return Fault Mask register value
- */
-__STATIC_INLINE uint32_t __get_FAULTMASK(void)
-{
- register uint32_t __regFaultMask __ASM("faultmask");
- return(__regFaultMask);
-}
-
-
-/** \brief Set Fault Mask
-
- This function assigns the given value to the Fault Mask register.
-
- \param [in] faultMask Fault Mask value to set
- */
-__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
-{
- register uint32_t __regFaultMask __ASM("faultmask");
- __regFaultMask = (faultMask & (uint32_t)1);
-}
-
-#endif /* (__CORTEX_M >= 0x03) */
-
-
-#if (__CORTEX_M == 0x04)
-
-/** \brief Get FPSCR
-
- This function returns the current value of the Floating Point Status/Control register.
-
- \return Floating Point Status/Control register value
- */
-__STATIC_INLINE uint32_t __get_FPSCR(void)
-{
-#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
- register uint32_t __regfpscr __ASM("fpscr");
- return(__regfpscr);
-#else
- return(0);
-#endif
-}
-
-
-/** \brief Set FPSCR
-
- This function assigns the given value to the Floating Point Status/Control register.
-
- \param [in] fpscr Floating Point Status/Control value to set
- */
-__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
-{
-#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
- register uint32_t __regfpscr __ASM("fpscr");
- __regfpscr = (fpscr);
-#endif
-}
-
-#endif /* (__CORTEX_M == 0x04) */
-
-
-#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
-/* IAR iccarm specific functions */
-
-#include
-
-
-#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
-/* TI CCS specific functions */
-
-#include
-
-
-#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
-/* GNU gcc specific functions */
-
-/** \brief Enable IRQ Interrupts
-
- This function enables IRQ interrupts by clearing the I-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
-{
- __ASM volatile ("cpsie i");
-}
-
-
-/** \brief Disable IRQ Interrupts
-
- This function disables IRQ interrupts by setting the I-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
-{
- __ASM volatile ("cpsid i");
-}
-
-
-/** \brief Get Control Register
-
- This function returns the content of the Control Register.
-
- \return Control Register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, control" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Set Control Register
-
- This function writes the given value to the Control Register.
-
- \param [in] control Control Register value to set
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
-{
- __ASM volatile ("MSR control, %0" : : "r" (control) );
-}
-
-
-/** \brief Get IPSR Register
-
- This function returns the content of the IPSR Register.
-
- \return IPSR Register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Get APSR Register
-
- This function returns the content of the APSR Register.
-
- \return APSR Register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, apsr" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Get xPSR Register
-
- This function returns the content of the xPSR Register.
-
- \return xPSR Register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Get Process Stack Pointer
-
- This function returns the current value of the Process Stack Pointer (PSP).
-
- \return PSP Register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
-{
- register uint32_t result;
-
- __ASM volatile ("MRS %0, psp\n" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Set Process Stack Pointer
-
- This function assigns the given value to the Process Stack Pointer (PSP).
-
- \param [in] topOfProcStack Process Stack Pointer value to set
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
-{
- __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) );
-}
-
-
-/** \brief Get Main Stack Pointer
-
- This function returns the current value of the Main Stack Pointer (MSP).
-
- \return MSP Register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
-{
- register uint32_t result;
-
- __ASM volatile ("MRS %0, msp\n" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Set Main Stack Pointer
-
- This function assigns the given value to the Main Stack Pointer (MSP).
-
- \param [in] topOfMainStack Main Stack Pointer value to set
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
-{
- __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) );
-}
-
-
-/** \brief Get Priority Mask
-
- This function returns the current state of the priority mask bit from the Priority Mask Register.
-
- \return Priority Mask value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, primask" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Set Priority Mask
-
- This function assigns the given value to the Priority Mask Register.
-
- \param [in] priMask Priority Mask
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
-{
- __ASM volatile ("MSR primask, %0" : : "r" (priMask) );
-}
-
-
-#if (__CORTEX_M >= 0x03)
-
-/** \brief Enable FIQ
-
- This function enables FIQ interrupts by clearing the F-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
-{
- __ASM volatile ("cpsie f");
-}
-
-
-/** \brief Disable FIQ
-
- This function disables FIQ interrupts by setting the F-bit in the CPSR.
- Can only be executed in Privileged modes.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
-{
- __ASM volatile ("cpsid f");
-}
-
-
-/** \brief Get Base Priority
-
- This function returns the current value of the Base Priority register.
-
- \return Base Priority register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Set Base Priority
-
- This function assigns the given value to the Base Priority register.
-
- \param [in] basePri Base Priority value to set
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
-{
- __ASM volatile ("MSR basepri, %0" : : "r" (value) );
-}
-
-
-/** \brief Get Fault Mask
-
- This function returns the current value of the Fault Mask register.
-
- \return Fault Mask register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
-{
- uint32_t result;
-
- __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
- return(result);
-}
-
-
-/** \brief Set Fault Mask
-
- This function assigns the given value to the Fault Mask register.
-
- \param [in] faultMask Fault Mask value to set
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
-{
- __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) );
-}
-
-#endif /* (__CORTEX_M >= 0x03) */
-
-
-#if (__CORTEX_M == 0x04)
-
-/** \brief Get FPSCR
-
- This function returns the current value of the Floating Point Status/Control register.
-
- \return Floating Point Status/Control register value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
-{
-#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
- uint32_t result;
-
- __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
- return(result);
-#else
- return(0);
-#endif
-}
-
-
-/** \brief Set FPSCR
-
- This function assigns the given value to the Floating Point Status/Control register.
-
- \param [in] fpscr Floating Point Status/Control value to set
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
-{
-#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
- __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) );
-#endif
-}
-
-#endif /* (__CORTEX_M == 0x04) */
-
-
-#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
-/* TASKING carm specific functions */
-
-/*
- * The CMSIS functions have been implemented as intrinsics in the compiler.
- * Please use "carm -?i" to get an up to date list of all instrinsics,
- * Including the CMSIS ones.
- */
-
-#endif
-
-/*@} end of CMSIS_Core_RegAccFunctions */
-
-
-#endif /* __CORE_CMFUNC_H */
diff --git a/lib-gd32/gd32f20x/CMSIS/core_cmInstr.h b/lib-gd32/gd32f20x/CMSIS/core_cmInstr.h
deleted file mode 100644
index 624c175..0000000
--- a/lib-gd32/gd32f20x/CMSIS/core_cmInstr.h
+++ /dev/null
@@ -1,618 +0,0 @@
-/**************************************************************************//**
- * @file core_cmInstr.h
- * @brief CMSIS Cortex-M Core Instruction Access Header File
- * @version V3.01
- * @date 06. March 2012
- *
- * @note
- * Copyright (C) 2009-2012 ARM Limited. All rights reserved.
- *
- * @par
- * ARM Limited (ARM) is supplying this software for use with Cortex-M
- * processor based microcontrollers. This file can be freely distributed
- * within development tools that are supporting such ARM based processors.
- *
- * @par
- * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
- * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
- * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
- * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
- *
- ******************************************************************************/
-
-#ifndef __CORE_CMINSTR_H
-#define __CORE_CMINSTR_H
-
-
-/* ########################## Core Instruction Access ######################### */
-/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
- Access to dedicated instructions
- @{
-*/
-
-#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
-/* ARM armcc specific functions */
-
-#if (__ARMCC_VERSION < 400677)
- #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
-#endif
-
-
-/** \brief No Operation
-
- No Operation does nothing. This instruction can be used for code alignment purposes.
- */
-#define __NOP __nop
-
-
-/** \brief Wait For Interrupt
-
- Wait For Interrupt is a hint instruction that suspends execution
- until one of a number of events occurs.
- */
-#define __WFI __wfi
-
-
-/** \brief Wait For Event
-
- Wait For Event is a hint instruction that permits the processor to enter
- a low-power state until one of a number of events occurs.
- */
-#define __WFE __wfe
-
-
-/** \brief Send Event
-
- Send Event is a hint instruction. It causes an event to be signaled to the CPU.
- */
-#define __SEV __sev
-
-
-/** \brief Instruction Synchronization Barrier
-
- Instruction Synchronization Barrier flushes the pipeline in the processor,
- so that all instructions following the ISB are fetched from cache or
- memory, after the instruction has been completed.
- */
-#define __ISB() __isb(0xF)
-
-
-/** \brief Data Synchronization Barrier
-
- This function acts as a special kind of Data Memory Barrier.
- It completes when all explicit memory accesses before this instruction complete.
- */
-#define __DSB() __dsb(0xF)
-
-
-/** \brief Data Memory Barrier
-
- This function ensures the apparent order of the explicit memory operations before
- and after the instruction, without ensuring their completion.
- */
-#define __DMB() __dmb(0xF)
-
-
-/** \brief Reverse byte order (32 bit)
-
- This function reverses the byte order in integer value.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-#define __REV __rev
-
-
-/** \brief Reverse byte order (16 bit)
-
- This function reverses the byte order in two unsigned short values.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
-{
- rev16 r0, r0
- bx lr
-}
-
-
-/** \brief Reverse byte order in signed short value
-
- This function reverses the byte order in a signed short value with sign extension to integer.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
-{
- revsh r0, r0
- bx lr
-}
-
-
-/** \brief Rotate Right in unsigned value (32 bit)
-
- This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
-
- \param [in] value Value to rotate
- \param [in] value Number of Bits to rotate
- \return Rotated value
- */
-#define __ROR __ror
-
-
-#if (__CORTEX_M >= 0x03)
-
-/** \brief Reverse bit order of value
-
- This function reverses the bit order of the given value.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-#define __RBIT __rbit
-
-
-/** \brief LDR Exclusive (8 bit)
-
- This function performs a exclusive LDR command for 8 bit value.
-
- \param [in] ptr Pointer to data
- \return value of type uint8_t at (*ptr)
- */
-#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
-
-
-/** \brief LDR Exclusive (16 bit)
-
- This function performs a exclusive LDR command for 16 bit values.
-
- \param [in] ptr Pointer to data
- \return value of type uint16_t at (*ptr)
- */
-#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
-
-
-/** \brief LDR Exclusive (32 bit)
-
- This function performs a exclusive LDR command for 32 bit values.
-
- \param [in] ptr Pointer to data
- \return value of type uint32_t at (*ptr)
- */
-#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
-
-
-/** \brief STR Exclusive (8 bit)
-
- This function performs a exclusive STR command for 8 bit values.
-
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-#define __STREXB(value, ptr) __strex(value, ptr)
-
-
-/** \brief STR Exclusive (16 bit)
-
- This function performs a exclusive STR command for 16 bit values.
-
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-#define __STREXH(value, ptr) __strex(value, ptr)
-
-
-/** \brief STR Exclusive (32 bit)
-
- This function performs a exclusive STR command for 32 bit values.
-
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-#define __STREXW(value, ptr) __strex(value, ptr)
-
-
-/** \brief Remove the exclusive lock
-
- This function removes the exclusive lock which is created by LDREX.
-
- */
-#define __CLREX __clrex
-
-
-/** \brief Signed Saturate
-
- This function saturates a signed value.
-
- \param [in] value Value to be saturated
- \param [in] sat Bit position to saturate to (1..32)
- \return Saturated value
- */
-#define __SSAT __ssat
-
-
-/** \brief Unsigned Saturate
-
- This function saturates an unsigned value.
-
- \param [in] value Value to be saturated
- \param [in] sat Bit position to saturate to (0..31)
- \return Saturated value
- */
-#define __USAT __usat
-
-
-/** \brief Count leading zeros
-
- This function counts the number of leading zeros of a data value.
-
- \param [in] value Value to count the leading zeros
- \return number of leading zeros in value
- */
-#define __CLZ __clz
-
-#endif /* (__CORTEX_M >= 0x03) */
-
-
-
-#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
-/* IAR iccarm specific functions */
-
-#include
-
-
-#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
-/* TI CCS specific functions */
-
-#include
-
-
-#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
-/* GNU gcc specific functions */
-
-/** \brief No Operation
-
- No Operation does nothing. This instruction can be used for code alignment purposes.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void)
-{
- __ASM volatile ("nop");
-}
-
-
-/** \brief Wait For Interrupt
-
- Wait For Interrupt is a hint instruction that suspends execution
- until one of a number of events occurs.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void)
-{
- __ASM volatile ("wfi");
-}
-
-
-/** \brief Wait For Event
-
- Wait For Event is a hint instruction that permits the processor to enter
- a low-power state until one of a number of events occurs.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void)
-{
- __ASM volatile ("wfe");
-}
-
-
-/** \brief Send Event
-
- Send Event is a hint instruction. It causes an event to be signaled to the CPU.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void)
-{
- __ASM volatile ("sev");
-}
-
-
-/** \brief Instruction Synchronization Barrier
-
- Instruction Synchronization Barrier flushes the pipeline in the processor,
- so that all instructions following the ISB are fetched from cache or
- memory, after the instruction has been completed.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void)
-{
- __ASM volatile ("isb");
-}
-
-
-/** \brief Data Synchronization Barrier
-
- This function acts as a special kind of Data Memory Barrier.
- It completes when all explicit memory accesses before this instruction complete.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void)
-{
- __ASM volatile ("dsb");
-}
-
-
-/** \brief Data Memory Barrier
-
- This function ensures the apparent order of the explicit memory operations before
- and after the instruction, without ensuring their completion.
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void)
-{
- __ASM volatile ("dmb");
-}
-
-
-/** \brief Reverse byte order (32 bit)
-
- This function reverses the byte order in integer value.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value)
-{
- uint32_t result;
-
- __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
- return(result);
-}
-
-
-/** \brief Reverse byte order (16 bit)
-
- This function reverses the byte order in two unsigned short values.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value)
-{
- uint32_t result;
-
- __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
- return(result);
-}
-
-
-/** \brief Reverse byte order in signed short value
-
- This function reverses the byte order in a signed short value with sign extension to integer.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value)
-{
- uint32_t result;
-
- __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
- return(result);
-}
-
-
-/** \brief Rotate Right in unsigned value (32 bit)
-
- This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
-
- \param [in] value Value to rotate
- \param [in] value Number of Bits to rotate
- \return Rotated value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
-{
-
- __ASM volatile ("ror %0, %0, %1" : "+r" (op1) : "r" (op2) );
- return(op1);
-}
-
-
-#if (__CORTEX_M >= 0x03)
-
-/** \brief Reverse bit order of value
-
- This function reverses the bit order of the given value.
-
- \param [in] value Value to reverse
- \return Reversed value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
-{
- uint32_t result;
-
- __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
- return(result);
-}
-
-
-/** \brief LDR Exclusive (8 bit)
-
- This function performs a exclusive LDR command for 8 bit value.
-
- \param [in] ptr Pointer to data
- \return value of type uint8_t at (*ptr)
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
-{
- uint8_t result;
-
- __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
- return(result);
-}
-
-
-/** \brief LDR Exclusive (16 bit)
-
- This function performs a exclusive LDR command for 16 bit values.
-
- \param [in] ptr Pointer to data
- \return value of type uint16_t at (*ptr)
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
-{
- uint16_t result;
-
- __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
- return(result);
-}
-
-
-/** \brief LDR Exclusive (32 bit)
-
- This function performs a exclusive LDR command for 32 bit values.
-
- \param [in] ptr Pointer to data
- \return value of type uint32_t at (*ptr)
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
-{
- uint32_t result;
-
- __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
- return(result);
-}
-
-
-/** \brief STR Exclusive (8 bit)
-
- This function performs a exclusive STR command for 8 bit values.
-
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
-{
- uint32_t result;
-
- __ASM volatile ("strexb %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );
- return(result);
-}
-
-
-/** \brief STR Exclusive (16 bit)
-
- This function performs a exclusive STR command for 16 bit values.
-
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
-{
- uint32_t result;
-
- __ASM volatile ("strexh %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );
- return(result);
-}
-
-
-/** \brief STR Exclusive (32 bit)
-
- This function performs a exclusive STR command for 32 bit values.
-
- \param [in] value Value to store
- \param [in] ptr Pointer to location
- \return 0 Function succeeded
- \return 1 Function failed
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
-{
- uint32_t result;
-
- __ASM volatile ("strex %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );
- return(result);
-}
-
-
-/** \brief Remove the exclusive lock
-
- This function removes the exclusive lock which is created by LDREX.
-
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void)
-{
- __ASM volatile ("clrex");
-}
-
-
-/** \brief Signed Saturate
-
- This function saturates a signed value.
-
- \param [in] value Value to be saturated
- \param [in] sat Bit position to saturate to (1..32)
- \return Saturated value
- */
-#define __SSAT(ARG1,ARG2) \
-({ \
- uint32_t __RES, __ARG1 = (ARG1); \
- __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
- __RES; \
- })
-
-
-/** \brief Unsigned Saturate
-
- This function saturates an unsigned value.
-
- \param [in] value Value to be saturated
- \param [in] sat Bit position to saturate to (0..31)
- \return Saturated value
- */
-#define __USAT(ARG1,ARG2) \
-({ \
- uint32_t __RES, __ARG1 = (ARG1); \
- __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
- __RES; \
- })
-
-
-/** \brief Count leading zeros
-
- This function counts the number of leading zeros of a data value.
-
- \param [in] value Value to count the leading zeros
- \return number of leading zeros in value
- */
-__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value)
-{
- uint8_t result;
-
- __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
- return(result);
-}
-
-#endif /* (__CORTEX_M >= 0x03) */
-
-
-
-
-#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
-/* TASKING carm specific functions */
-
-/*
- * The CMSIS functions have been implemented as intrinsics in the compiler.
- * Please use "carm -?i" to get an up to date list of all intrinsics,
- * Including the CMSIS ones.
- */
-
-#endif
-
-/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
-
-#endif /* __CORE_CMINSTR_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_adc.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_adc.h
index 265cbfa..fb18a2b 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_adc.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_adc.h
@@ -2,36 +2,33 @@
\file gd32f20x_adc.h
\brief definitions for the ADC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,31 +39,31 @@ OF SUCH DAMAGE.
/* ADC definitions */
#define ADC0 ADC_BASE
-#define ADC1 (ADC_BASE + 0x400U)
-#define ADC2 (ADC_BASE + 0x1800U)
+#define ADC1 (ADC_BASE + 0x00000400U)
+#define ADC2 (ADC_BASE + 0x00001800U)
/* registers definitions */
-#define ADC_STAT(adcx) REG32((adcx) + 0x00U) /*!< ADC status register */
-#define ADC_CTL0(adcx) REG32((adcx) + 0x04U) /*!< ADC control register 0 */
-#define ADC_CTL1(adcx) REG32((adcx) + 0x08U) /*!< ADC control register 1 */
-#define ADC_SAMPT0(adcx) REG32((adcx) + 0x0CU) /*!< ADC sampling time register 0 */
-#define ADC_SAMPT1(adcx) REG32((adcx) + 0x10U) /*!< ADC sampling time register 1 */
-#define ADC_IOFF0(adcx) REG32((adcx) + 0x14U) /*!< ADC inserted channel data offset register 0 */
-#define ADC_IOFF1(adcx) REG32((adcx) + 0x18U) /*!< ADC inserted channel data offset register 1 */
-#define ADC_IOFF2(adcx) REG32((adcx) + 0x1CU) /*!< ADC inserted channel data offset register 2 */
-#define ADC_IOFF3(adcx) REG32((adcx) + 0x20U) /*!< ADC inserted channel data offset register 3 */
-#define ADC_WDHT(adcx) REG32((adcx) + 0x24U) /*!< ADC watchdog high threshold register */
-#define ADC_WDLT(adcx) REG32((adcx) + 0x28U) /*!< ADC watchdog low threshold register */
-#define ADC_RSQ0(adcx) REG32((adcx) + 0x2CU) /*!< ADC regular sequence register 0 */
-#define ADC_RSQ1(adcx) REG32((adcx) + 0x30U) /*!< ADC regular sequence register 1 */
-#define ADC_RSQ2(adcx) REG32((adcx) + 0x34U) /*!< ADC regular sequence register 2 */
-#define ADC_ISQ(adcx) REG32((adcx) + 0x38U) /*!< ADC inserted sequence register */
-#define ADC_IDATA0(adcx) REG32((adcx) + 0x3CU) /*!< ADC inserted data register 0 */
-#define ADC_IDATA1(adcx) REG32((adcx) + 0x40U) /*!< ADC inserted data register 1 */
-#define ADC_IDATA2(adcx) REG32((adcx) + 0x44U) /*!< ADC inserted data register 2 */
-#define ADC_IDATA3(adcx) REG32((adcx) + 0x48U) /*!< ADC inserted data register 3 */
-#define ADC_RDATA(adcx) REG32((adcx) + 0x4CU) /*!< ADC regular data register */
-#define ADC_OVSAMPCTL(adcx) REG32((adcx) + 0x80U) /*!< ADC oversampling control register */
+#define ADC_STAT(adcx) REG32((adcx) + 0x00000000U) /*!< ADC status register */
+#define ADC_CTL0(adcx) REG32((adcx) + 0x00000004U) /*!< ADC control register 0 */
+#define ADC_CTL1(adcx) REG32((adcx) + 0x00000008U) /*!< ADC control register 1 */
+#define ADC_SAMPT0(adcx) REG32((adcx) + 0x0000000CU) /*!< ADC sampling time register 0 */
+#define ADC_SAMPT1(adcx) REG32((adcx) + 0x00000010U) /*!< ADC sampling time register 1 */
+#define ADC_IOFF0(adcx) REG32((adcx) + 0x00000014U) /*!< ADC inserted channel data offset register 0 */
+#define ADC_IOFF1(adcx) REG32((adcx) + 0x00000018U) /*!< ADC inserted channel data offset register 1 */
+#define ADC_IOFF2(adcx) REG32((adcx) + 0x0000001CU) /*!< ADC inserted channel data offset register 2 */
+#define ADC_IOFF3(adcx) REG32((adcx) + 0x00000020U) /*!< ADC inserted channel data offset register 3 */
+#define ADC_WDHT(adcx) REG32((adcx) + 0x00000024U) /*!< ADC watchdog high threshold register */
+#define ADC_WDLT(adcx) REG32((adcx) + 0x00000028U) /*!< ADC watchdog low threshold register */
+#define ADC_RSQ0(adcx) REG32((adcx) + 0x0000002CU) /*!< ADC regular sequence register 0 */
+#define ADC_RSQ1(adcx) REG32((adcx) + 0x00000030U) /*!< ADC regular sequence register 1 */
+#define ADC_RSQ2(adcx) REG32((adcx) + 0x00000034U) /*!< ADC regular sequence register 2 */
+#define ADC_ISQ(adcx) REG32((adcx) + 0x00000038U) /*!< ADC inserted sequence register */
+#define ADC_IDATA0(adcx) REG32((adcx) + 0x0000003CU) /*!< ADC inserted data register 0 */
+#define ADC_IDATA1(adcx) REG32((adcx) + 0x00000040U) /*!< ADC inserted data register 1 */
+#define ADC_IDATA2(adcx) REG32((adcx) + 0x00000044U) /*!< ADC inserted data register 2 */
+#define ADC_IDATA3(adcx) REG32((adcx) + 0x00000048U) /*!< ADC inserted data register 3 */
+#define ADC_RDATA(adcx) REG32((adcx) + 0x0000004CU) /*!< ADC regular data register */
+#define ADC_OVSAMPCTL(adcx) REG32((adcx) + 0x00000080U) /*!< ADC oversampling control register */
/* bits definitions */
/* ADC_STAT */
@@ -96,7 +93,7 @@ OF SUCH DAMAGE.
#define ADC_CTL1_CTN BIT(1) /*!< continuous conversion */
#define ADC_CTL1_CLB BIT(2) /*!< ADC calibration */
#define ADC_CTL1_RSTCLB BIT(3) /*!< reset calibration */
-#define ADC_CTL1_DMA BIT(8) /*!< direct memory access mode */
+#define ADC_CTL1_DMA BIT(8) /*!< DMA request enable */
#define ADC_CTL1_DAL BIT(11) /*!< data alignment */
#define ADC_CTL1_ETSIC BITS(12,14) /*!< external trigger select for inserted channel */
#define ADC_CTL1_ETEIC BIT(15) /*!< external trigger enable for inserted channel */
@@ -138,15 +135,15 @@ OF SUCH DAMAGE.
#define ADC_OVSAMPCTL_OVSR BITS(2,4) /*!< oversampling ratio */
#define ADC_OVSAMPCTL_OVSS BITS(5,8) /*!< oversampling shift */
#define ADC_OVSAMPCTL_TOVS BIT(9) /*!< triggered oversampling */
-#define ADC_OVSAMPCTL_DRES BITS(12,13) /*!< oversampling shift */
+#define ADC_OVSAMPCTL_DRES BITS(12, 13) /*!< ADC resolution */
/* constants definitions */
-/* adc_stat register value */
-#define ADC_FLAG_WDE ADC_STAT_WDE /*!< analog watchdog event flag */
-#define ADC_FLAG_EOC ADC_STAT_EOC /*!< end of group conversion flag */
-#define ADC_FLAG_EOIC ADC_STAT_EOIC /*!< end of inserted channel group conversion flag */
-#define ADC_FLAG_STIC ADC_STAT_STIC /*!< inserted channel start flag */
-#define ADC_FLAG_STRC ADC_STAT_STRC /*!< regular channel start flag */
+/* ADC flag definitions */
+#define ADC_FLAG_WDE ADC_STAT_WDE /*!< analog watchdog event flag */
+#define ADC_FLAG_EOC ADC_STAT_EOC /*!< end of conversion */
+#define ADC_FLAG_EOIC ADC_STAT_EOIC /*!< end of inserted channel group conversion flag */
+#define ADC_FLAG_STIC ADC_STAT_STIC /*!< inserted channel start flag */
+#define ADC_FLAG_STRC ADC_STAT_STRC /*!< regular channel start flag */
/* adc_ctl0 register value */
#define CTL0_DISNUM(regval) (BITS(13,15) & ((uint32_t)(regval) << 13)) /*!< write value to ADC_CTL0_DISNUM bit field */
@@ -198,7 +195,7 @@ OF SUCH DAMAGE.
#define ADC2_EXTTRIG_REGULAR_T4_CH0 CTL1_ETSRC(5) /*!< TIMER4 CH0 event select */
#define ADC2_EXTTRIG_REGULAR_T4_CH2 CTL1_ETSRC(6) /*!< TIMER4 CH2 event select */
-/* external trigger mode for inserted channel */
+/* ADC external trigger select for inserted channel */
#define CTL1_ETSIC(regval) (BITS(12,14) & ((uint32_t)(regval) << 12)) /*!< write value to ADC_CTL1_ETSIC bit field */
/* for ADC0 and ADC1 inserted channel */
#define ADC0_1_EXTTRIG_INSERTED_T0_TRGO CTL1_ETSIC(0) /*!< TIMER0 TRGO event select */
@@ -246,12 +243,14 @@ OF SUCH DAMAGE.
#define ISQ_IL(regval) (BITS(20,21) & ((uint32_t)(regval) << 20)) /*!< write value to ADC_ISQ_IL bit field */
/* adc_ovsampctl register value */
+/* ADC resolution */
#define OVSAMPCTL_DRES(regval) (BITS(12,13) & ((uint32_t)(regval) << 12)) /*!< write value to ADC_OVSAMPCTL_DRES bit field */
#define ADC_RESOLUTION_12B OVSAMPCTL_DRES(0) /*!< 12-bit ADC resolution */
#define ADC_RESOLUTION_10B OVSAMPCTL_DRES(1) /*!< 10-bit ADC resolution */
#define ADC_RESOLUTION_8B OVSAMPCTL_DRES(2) /*!< 8-bit ADC resolution */
#define ADC_RESOLUTION_6B OVSAMPCTL_DRES(3) /*!< 6-bit ADC resolution */
+/* oversampling shift */
#define OVSAMPCTL_OVSS(regval) (BITS(5,8) & ((uint32_t)(regval) << 5)) /*!< write value to ADC_OVSAMPCTL_OVSS bit field */
#define ADC_OVERSAMPLING_SHIFT_NONE OVSAMPCTL_OVSS(0) /*!< no oversampling shift */
#define ADC_OVERSAMPLING_SHIFT_1B OVSAMPCTL_OVSS(1) /*!< 1-bit oversampling shift */
@@ -263,6 +262,7 @@ OF SUCH DAMAGE.
#define ADC_OVERSAMPLING_SHIFT_7B OVSAMPCTL_OVSS(7) /*!< 7-bit oversampling shift */
#define ADC_OVERSAMPLING_SHIFT_8B OVSAMPCTL_OVSS(8) /*!< 8-bit oversampling shift */
+/* oversampling ratio */
#define OVSAMPCTL_OVSR(regval) (BITS(2,4) & ((uint32_t)(regval) << 2)) /*!< write value to ADC_OVSAMPCTL_OVSR bit field */
#define ADC_OVERSAMPLING_RATIO_MUL2 OVSAMPCTL_OVSR(0) /*!< oversampling ratio multiple 2 */
#define ADC_OVERSAMPLING_RATIO_MUL4 OVSAMPCTL_OVSR(1) /*!< oversampling ratio multiple 4 */
@@ -273,6 +273,7 @@ OF SUCH DAMAGE.
#define ADC_OVERSAMPLING_RATIO_MUL128 OVSAMPCTL_OVSR(6) /*!< oversampling ratio multiple 128 */
#define ADC_OVERSAMPLING_RATIO_MUL256 OVSAMPCTL_OVSR(7) /*!< oversampling ratio multiple 256 */
+/* triggered oversampling */
#define ADC_OVERSAMPLING_ALL_CONVERT 0U /*!< all oversampled conversions for a channel are done consecutively after a trigger */
#define ADC_OVERSAMPLING_ONE_CONVERT 1U /*!< each oversampled conversion for a channel needs a trigger */
@@ -367,7 +368,7 @@ void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group,
/* enable ADC software trigger */
void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group);
-/* get channel data */
+/* ADC data read functions */
/* read ADC regular group data register */
uint16_t adc_regular_data_read(uint32_t adc_periph);
/* read ADC inserted group data register */
@@ -375,7 +376,7 @@ uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel);
/* read the last ADC0 and ADC1 conversion result data in sync mode */
uint32_t adc_sync_mode_convert_value_read(void);
-/* watchdog configure */
+/* ADC analog watchdog functions */
/* configure ADC analog watchdog single channel */
void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel);
/* configure ADC analog watchdog group channel */
@@ -385,20 +386,6 @@ void adc_watchdog_disable(uint32_t adc_periph);
/* configure ADC analog watchdog threshold */
void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold, uint16_t high_threshold);
-/* interrupt & flag functions */
-/* get the ADC flag bits */
-FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag);
-/* clear the ADC flag bits */
-void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag);
-/* get the ADC interrupt flag */
-FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt);
-/* clear the ADC interrupt flag */
-void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt);
-/* enable ADC interrupt */
-void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt);
-/* disable ADC interrupt */
-void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt);
-
/* configure ADC resolution */
void adc_resolution_config(uint32_t adc_periph, uint32_t resolution);
/* configure ADC oversample mode */
@@ -408,4 +395,18 @@ void adc_oversample_mode_enable(uint32_t adc_periph);
/* disable ADC oversample mode */
void adc_oversample_mode_disable(uint32_t adc_periph);
+/* interrupt & flag functions */
+/* get the ADC flag */
+FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag);
+/* clear the ADC flag */
+void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag);
+/* enable ADC interrupt */
+void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt);
+/* disable ADC interrupt */
+void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt);
+/* get the ADC interrupt flag */
+FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt);
+/* clear the ADC interrupt flag */
+void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt);
+
#endif /* GD32F20X_ADC_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_bkp.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_bkp.h
index fe853a8..2453d79 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_bkp.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_bkp.h
@@ -2,36 +2,33 @@
\file gd32f20x_bkp.h
\brief definitions for the BKP
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -111,13 +108,13 @@ OF SUCH DAMAGE.
#define BKP_TPCS_TER0 BIT(0) /*!< tamper0 event reset */
#define BKP_TPCS_TIR0 BIT(1) /*!< tamper0 interrupt reset */
#define BKP_TPCS_TPIE0 BIT(2) /*!< tamper0 interrupt enable */
-#define BKP_TPCS_TER1 BIT(5) /*!< tamper1 event reset */
-#define BKP_TPCS_TIR1 BIT(6) /*!< tamper1 interrupt reset */
-#define BKP_TPCS_TPIE1 BIT(7) /*!< tamper1 interrupt enable */
+#define BKP_TPCS_TER1 BIT(5) /*!< tamper1/waveform detect event reset */
+#define BKP_TPCS_TIR1 BIT(6) /*!< tamper1/waveform detect interrupt reset */
+#define BKP_TPCS_TPIE1 BIT(7) /*!< tamper1/waveform detect interrupt enable */
#define BKP_TPCS_TEF0 BIT(8) /*!< tamper0 event flag */
#define BKP_TPCS_TIF0 BIT(9) /*!< tamper0 interrupt flag */
-#define BKP_TPCS_TEF1 BIT(14) /*!< tamper1 event flag */
-#define BKP_TPCS_TIF1 BIT(15) /*!< tamper1 interrupt flag */
+#define BKP_TPCS_TEF1 BIT(14) /*!< tamper1/waveform detect event flag */
+#define BKP_TPCS_TIF1 BIT(15) /*!< tamper1/waveform detect interrupt flag */
/* BKP_TPCTL1 */
#define BKP_TPCTL1_TPEN1 BIT(8) /*!< tamper1 detection enable */
@@ -126,16 +123,8 @@ OF SUCH DAMAGE.
#define BKP_TPCTL1_TPM1 BIT(15) /*!< the first waveform detection enable */
/* constants definitions */
-/* tamperx definitions */
-typedef enum
-{
- TAMPER_0 = 0, /*!< BKP tamper0 */
- TAMPER_1, /*!< BKP tamper1 */
-}bkp_tamper_enum;
-
/* BKP data register number */
-typedef enum
-{
+typedef enum {
BKP_DATA_0 = 1, /*!< BKP data register 0 */
BKP_DATA_1, /*!< BKP data register 1 */
BKP_DATA_2, /*!< BKP data register 2 */
@@ -177,8 +166,14 @@ typedef enum
BKP_DATA_38, /*!< BKP data register 38 */
BKP_DATA_39, /*!< BKP data register 39 */
BKP_DATA_40, /*!< BKP data register 40 */
- BKP_DATA_41, /*!< BKP data register 41 */
-}bkp_data_register_enum;
+ BKP_DATA_41 /*!< BKP data register 41 */
+} bkp_data_register_enum;
+
+/* tamperx definitions */
+typedef enum {
+ TAMPER_0 = 0, /*!< BKP tamper0 */
+ TAMPER_1 /*!< BKP tamper1 */
+} bkp_tamper_enum;
/* BKP register */
#define BKP_DATA0_9(number) REG16((BKP) + 0x04U + (number) * 0x04U)
@@ -199,7 +194,7 @@ typedef enum
#define RTC_CLOCK_DIV1 ((uint16_t)0x4000U) /*!< RTC clock div 1 */
/* RTC clock calibration direction */
-#define RTC_CLOCK_SLOWED_DOWN ((uint16_t)0x0000U) /*!< RTC clock slow down */
+#define RTC_CLOCK_SLOW_DOWN ((uint16_t)0x0000U) /*!< RTC clock slow down */
#define RTC_CLOCK_SPEED_UP ((uint16_t)0x8000U) /*!< RTC clock speed up */
/* tamper pin active level */
@@ -210,6 +205,10 @@ typedef enum
#define BKP_FLAG_TAMPER0 BKP_TPCS_TEF0 /*!< tamper0 event flag */
#define BKP_FLAG_TAMPER1_WAVEDETECT BKP_TPCS_TEF1 /*!< tamper1/waveform detect event flag */
+/* tamper interrupt */
+#define BKP_INT_TAMPER0 BKP_TPCS_TPIE0 /*!< tamper0 interrupt */
+#define BKP_INT_TAMPER1_WAVEDETECT BKP_TPCS_TPIE1 /*!< tamper1/waveform detect interrupt */
+
/* tamper interrupt flag */
#define BKP_INT_FLAG_TAMPER0 BKP_TPCS_TIF0 /*!< tamper0 interrupt flag */
#define BKP_INT_FLAG_TAMPER1_WAVEDETECT BKP_TPCS_TIF1 /*!< tamper1/waveform detect interrupt flag */
@@ -253,21 +252,21 @@ void bkp_tamper_detection_enable(bkp_tamper_enum tamperx);
void bkp_tamper_detection_disable(bkp_tamper_enum tamperx);
/* set tamper pin active level */
void bkp_tamper_active_level_set(bkp_tamper_enum tamperx, uint16_t level);
+/* waveform detect configure */
+void bkp_waveform_detect_config(uint16_t waveform_detect_mode, ControlStatus newvalue);
/* interrupt & flag functions */
-/* enable tamper pin interrupt */
-void bkp_tamper_interrupt_enable(bkp_tamper_enum tamperx);
-/* disable tamper pin interrupt */
-void bkp_tamper_interrupt_disable(bkp_tamper_enum tamperx);
-/* waveform detect configure */
-void bkp_waveform_detect_enable(uint16_t waveform_detect_mode, ControlStatus newvalue);
-/* get BKP flag state */
+/* get BKP flag */
FlagStatus bkp_flag_get(uint16_t flag);
-/* clear BKP flag state */
+/* clear BKP flag */
void bkp_flag_clear(uint16_t flag);
-/* get BKP interrupt flag state */
+/* enable tamper interrupt */
+void bkp_tamper_interrupt_enable(uint16_t bkp_interrupt);
+/* disable tamper interrupt */
+void bkp_tamper_interrupt_disable(uint16_t bkp_interrupt);
+/* get BKP interrupt flag */
FlagStatus bkp_interrupt_flag_get(uint16_t flag);
-/* clear BKP interrupt flag state */
+/* clear BKP interrupt flag */
void bkp_interrupt_flag_clear(uint16_t flag);
#endif /* GD32F20X_BKP_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_can.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_can.h
index 0f25d4a..c4e089c 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_can.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_can.h
@@ -2,37 +2,33 @@
\file gd32f20x_can.h
\brief definitions for the CAN
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
- \version 2019-11-27, V2.1.1, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,115 +38,115 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* CAN definitions */
-#define CAN0 CAN_BASE /*!< CAN0 base address */
-#define CAN1 (CAN0 + 0x00000400U) /*!< CAN1 base address */
+#define CAN0 CAN_BASE /*!< CAN0 base address */
+#define CAN1 (CAN0 + 0x00000400U) /*!< CAN1 base address */
/* registers definitions */
-#define CAN_CTL(canx) REG32((canx) + 0x00U) /*!< CAN control register */
-#define CAN_STAT(canx) REG32((canx) + 0x04U) /*!< CAN status register */
-#define CAN_TSTAT(canx) REG32((canx) + 0x08U) /*!< CAN transmit status register*/
-#define CAN_RFIFO0(canx) REG32((canx) + 0x0CU) /*!< CAN receive FIFO0 register */
-#define CAN_RFIFO1(canx) REG32((canx) + 0x10U) /*!< CAN receive FIFO1 register */
-#define CAN_INTEN(canx) REG32((canx) + 0x14U) /*!< CAN interrupt enable register */
-#define CAN_ERR(canx) REG32((canx) + 0x18U) /*!< CAN error register */
-#define CAN_BT(canx) REG32((canx) + 0x1CU) /*!< CAN bit timing register */
-#define CAN_TMI0(canx) REG32((canx) + 0x180U) /*!< CAN transmit mailbox0 identifier register */
-#define CAN_TMP0(canx) REG32((canx) + 0x184U) /*!< CAN transmit mailbox0 property register */
-#define CAN_TMDATA00(canx) REG32((canx) + 0x188U) /*!< CAN transmit mailbox0 data0 register */
-#define CAN_TMDATA10(canx) REG32((canx) + 0x18CU) /*!< CAN transmit mailbox0 data1 register */
-#define CAN_TMI1(canx) REG32((canx) + 0x190U) /*!< CAN transmit mailbox1 identifier register */
-#define CAN_TMP1(canx) REG32((canx) + 0x194U) /*!< CAN transmit mailbox1 property register */
-#define CAN_TMDATA01(canx) REG32((canx) + 0x198U) /*!< CAN transmit mailbox1 data0 register */
-#define CAN_TMDATA11(canx) REG32((canx) + 0x19CU) /*!< CAN transmit mailbox1 data1 register */
-#define CAN_TMI2(canx) REG32((canx) + 0x1A0U) /*!< CAN transmit mailbox2 identifier register */
-#define CAN_TMP2(canx) REG32((canx) + 0x1A4U) /*!< CAN transmit mailbox2 property register */
-#define CAN_TMDATA02(canx) REG32((canx) + 0x1A8U) /*!< CAN transmit mailbox2 data0 register */
-#define CAN_TMDATA12(canx) REG32((canx) + 0x1ACU) /*!< CAN transmit mailbox2 data1 register */
-#define CAN_RFIFOMI0(canx) REG32((canx) + 0x1B0U) /*!< CAN receive FIFO0 mailbox identifier register */
-#define CAN_RFIFOMP0(canx) REG32((canx) + 0x1B4U) /*!< CAN receive FIFO0 mailbox property register */
-#define CAN_RFIFOMDATA00(canx) REG32((canx) + 0x1B8U) /*!< CAN receive FIFO0 mailbox data0 register */
-#define CAN_RFIFOMDATA10(canx) REG32((canx) + 0x1BCU) /*!< CAN receive FIFO0 mailbox data1 register */
-#define CAN_RFIFOMI1(canx) REG32((canx) + 0x1C0U) /*!< CAN receive FIFO1 mailbox identifier register */
-#define CAN_RFIFOMP1(canx) REG32((canx) + 0x1C4U) /*!< CAN receive FIFO1 mailbox property register */
-#define CAN_RFIFOMDATA01(canx) REG32((canx) + 0x1C8U) /*!< CAN receive FIFO1 mailbox data0 register */
-#define CAN_RFIFOMDATA11(canx) REG32((canx) + 0x1CCU) /*!< CAN receive FIFO1 mailbox data1 register */
-#define CAN_FCTL(canx) REG32((canx) + 0x200U) /*!< CAN filter control register */
-#define CAN_FMCFG(canx) REG32((canx) + 0x204U) /*!< CAN filter mode register */
-#define CAN_FSCFG(canx) REG32((canx) + 0x20CU) /*!< CAN filter scale register */
-#define CAN_FAFIFO(canx) REG32((canx) + 0x214U) /*!< CAN filter associated FIFO register */
-#define CAN_FW(canx) REG32((canx) + 0x21CU) /*!< CAN filter working register */
-#define CAN_F0DATA0(canx) REG32((canx) + 0x240U) /*!< CAN filter 0 data 0 register */
-#define CAN_F1DATA0(canx) REG32((canx) + 0x248U) /*!< CAN filter 1 data 0 register */
-#define CAN_F2DATA0(canx) REG32((canx) + 0x250U) /*!< CAN filter 2 data 0 register */
-#define CAN_F3DATA0(canx) REG32((canx) + 0x258U) /*!< CAN filter 3 data 0 register */
-#define CAN_F4DATA0(canx) REG32((canx) + 0x260U) /*!< CAN filter 4 data 0 register */
-#define CAN_F5DATA0(canx) REG32((canx) + 0x268U) /*!< CAN filter 5 data 0 register */
-#define CAN_F6DATA0(canx) REG32((canx) + 0x270U) /*!< CAN filter 6 data 0 register */
-#define CAN_F7DATA0(canx) REG32((canx) + 0x278U) /*!< CAN filter 7 data 0 register */
-#define CAN_F8DATA0(canx) REG32((canx) + 0x280U) /*!< CAN filter 8 data 0 register */
-#define CAN_F9DATA0(canx) REG32((canx) + 0x288U) /*!< CAN filter 9 data 0 register */
-#define CAN_F10DATA0(canx) REG32((canx) + 0x290U) /*!< CAN filter 10 data 0 register */
-#define CAN_F11DATA0(canx) REG32((canx) + 0x298U) /*!< CAN filter 11 data 0 register */
-#define CAN_F12DATA0(canx) REG32((canx) + 0x2A0U) /*!< CAN filter 12 data 0 register */
-#define CAN_F13DATA0(canx) REG32((canx) + 0x2A8U) /*!< CAN filter 13 data 0 register */
-#define CAN_F14DATA0(canx) REG32((canx) + 0x2B0U) /*!< CAN filter 14 data 0 register */
-#define CAN_F15DATA0(canx) REG32((canx) + 0x2B8U) /*!< CAN filter 15 data 0 register */
-#define CAN_F16DATA0(canx) REG32((canx) + 0x2C0U) /*!< CAN filter 16 data 0 register */
-#define CAN_F17DATA0(canx) REG32((canx) + 0x2C8U) /*!< CAN filter 17 data 0 register */
-#define CAN_F18DATA0(canx) REG32((canx) + 0x2D0U) /*!< CAN filter 18 data 0 register */
-#define CAN_F19DATA0(canx) REG32((canx) + 0x2D8U) /*!< CAN filter 19 data 0 register */
-#define CAN_F20DATA0(canx) REG32((canx) + 0x2E0U) /*!< CAN filter 20 data 0 register */
-#define CAN_F21DATA0(canx) REG32((canx) + 0x2E8U) /*!< CAN filter 21 data 0 register */
-#define CAN_F22DATA0(canx) REG32((canx) + 0x2F0U) /*!< CAN filter 22 data 0 register */
-#define CAN_F23DATA0(canx) REG32((canx) + 0x3F8U) /*!< CAN filter 23 data 0 register */
-#define CAN_F24DATA0(canx) REG32((canx) + 0x300U) /*!< CAN filter 24 data 0 register */
-#define CAN_F25DATA0(canx) REG32((canx) + 0x308U) /*!< CAN filter 25 data 0 register */
-#define CAN_F26DATA0(canx) REG32((canx) + 0x310U) /*!< CAN filter 26 data 0 register */
-#define CAN_F27DATA0(canx) REG32((canx) + 0x318U) /*!< CAN filter 27 data 0 register */
-#define CAN_F0DATA1(canx) REG32((canx) + 0x244U) /*!< CAN filter 0 data 1 register */
-#define CAN_F1DATA1(canx) REG32((canx) + 0x24CU) /*!< CAN filter 1 data 1 register */
-#define CAN_F2DATA1(canx) REG32((canx) + 0x254U) /*!< CAN filter 2 data 1 register */
-#define CAN_F3DATA1(canx) REG32((canx) + 0x25CU) /*!< CAN filter 3 data 1 register */
-#define CAN_F4DATA1(canx) REG32((canx) + 0x264U) /*!< CAN filter 4 data 1 register */
-#define CAN_F5DATA1(canx) REG32((canx) + 0x26CU) /*!< CAN filter 5 data 1 register */
-#define CAN_F6DATA1(canx) REG32((canx) + 0x274U) /*!< CAN filter 6 data 1 register */
-#define CAN_F7DATA1(canx) REG32((canx) + 0x27CU) /*!< CAN filter 7 data 1 register */
-#define CAN_F8DATA1(canx) REG32((canx) + 0x284U) /*!< CAN filter 8 data 1 register */
-#define CAN_F9DATA1(canx) REG32((canx) + 0x28CU) /*!< CAN filter 9 data 1 register */
-#define CAN_F10DATA1(canx) REG32((canx) + 0x294U) /*!< CAN filter 10 data 1 register */
-#define CAN_F11DATA1(canx) REG32((canx) + 0x29CU) /*!< CAN filter 11 data 1 register */
-#define CAN_F12DATA1(canx) REG32((canx) + 0x2A4U) /*!< CAN filter 12 data 1 register */
-#define CAN_F13DATA1(canx) REG32((canx) + 0x2ACU) /*!< CAN filter 13 data 1 register */
-#define CAN_F14DATA1(canx) REG32((canx) + 0x2B4U) /*!< CAN filter 14 data 1 register */
-#define CAN_F15DATA1(canx) REG32((canx) + 0x2BCU) /*!< CAN filter 15 data 1 register */
-#define CAN_F16DATA1(canx) REG32((canx) + 0x2C4U) /*!< CAN filter 16 data 1 register */
-#define CAN_F17DATA1(canx) REG32((canx) + 0x24CU) /*!< CAN filter 17 data 1 register */
-#define CAN_F18DATA1(canx) REG32((canx) + 0x2D4U) /*!< CAN filter 18 data 1 register */
-#define CAN_F19DATA1(canx) REG32((canx) + 0x2DCU) /*!< CAN filter 19 data 1 register */
-#define CAN_F20DATA1(canx) REG32((canx) + 0x2E4U) /*!< CAN filter 20 data 1 register */
-#define CAN_F21DATA1(canx) REG32((canx) + 0x2ECU) /*!< CAN filter 21 data 1 register */
-#define CAN_F22DATA1(canx) REG32((canx) + 0x2F4U) /*!< CAN filter 22 data 1 register */
-#define CAN_F23DATA1(canx) REG32((canx) + 0x2FCU) /*!< CAN filter 23 data 1 register */
-#define CAN_F24DATA1(canx) REG32((canx) + 0x304U) /*!< CAN filter 24 data 1 register */
-#define CAN_F25DATA1(canx) REG32((canx) + 0x30CU) /*!< CAN filter 25 data 1 register */
-#define CAN_F26DATA1(canx) REG32((canx) + 0x314U) /*!< CAN filter 26 data 1 register */
-#define CAN_F27DATA1(canx) REG32((canx) + 0x31CU) /*!< CAN filter 27 data 1 register */
+#define CAN_CTL(canx) REG32((canx) + 0x00000000U) /*!< CAN control register */
+#define CAN_STAT(canx) REG32((canx) + 0x00000004U) /*!< CAN status register */
+#define CAN_TSTAT(canx) REG32((canx) + 0x00000008U) /*!< CAN transmit status register*/
+#define CAN_RFIFO0(canx) REG32((canx) + 0x0000000CU) /*!< CAN receive FIFO0 register */
+#define CAN_RFIFO1(canx) REG32((canx) + 0x00000010U) /*!< CAN receive FIFO1 register */
+#define CAN_INTEN(canx) REG32((canx) + 0x00000014U) /*!< CAN interrupt enable register */
+#define CAN_ERR(canx) REG32((canx) + 0x00000018U) /*!< CAN error register */
+#define CAN_BT(canx) REG32((canx) + 0x0000001CU) /*!< CAN bit timing register */
+#define CAN_TMI0(canx) REG32((canx) + 0x00000180U) /*!< CAN transmit mailbox0 identifier register */
+#define CAN_TMP0(canx) REG32((canx) + 0x00000184U) /*!< CAN transmit mailbox0 property register */
+#define CAN_TMDATA00(canx) REG32((canx) + 0x00000188U) /*!< CAN transmit mailbox0 data0 register */
+#define CAN_TMDATA10(canx) REG32((canx) + 0x0000018CU) /*!< CAN transmit mailbox0 data1 register */
+#define CAN_TMI1(canx) REG32((canx) + 0x00000190U) /*!< CAN transmit mailbox1 identifier register */
+#define CAN_TMP1(canx) REG32((canx) + 0x00000194U) /*!< CAN transmit mailbox1 property register */
+#define CAN_TMDATA01(canx) REG32((canx) + 0x00000198U) /*!< CAN transmit mailbox1 data0 register */
+#define CAN_TMDATA11(canx) REG32((canx) + 0x0000019CU) /*!< CAN transmit mailbox1 data1 register */
+#define CAN_TMI2(canx) REG32((canx) + 0x000001A0U) /*!< CAN transmit mailbox2 identifier register */
+#define CAN_TMP2(canx) REG32((canx) + 0x000001A4U) /*!< CAN transmit mailbox2 property register */
+#define CAN_TMDATA02(canx) REG32((canx) + 0x000001A8U) /*!< CAN transmit mailbox2 data0 register */
+#define CAN_TMDATA12(canx) REG32((canx) + 0x000001ACU) /*!< CAN transmit mailbox2 data1 register */
+#define CAN_RFIFOMI0(canx) REG32((canx) + 0x000001B0U) /*!< CAN receive FIFO0 mailbox identifier register */
+#define CAN_RFIFOMP0(canx) REG32((canx) + 0x000001B4U) /*!< CAN receive FIFO0 mailbox property register */
+#define CAN_RFIFOMDATA00(canx) REG32((canx) + 0x000001B8U) /*!< CAN receive FIFO0 mailbox data0 register */
+#define CAN_RFIFOMDATA10(canx) REG32((canx) + 0x000001BCU) /*!< CAN receive FIFO0 mailbox data1 register */
+#define CAN_RFIFOMI1(canx) REG32((canx) + 0x000001C0U) /*!< CAN receive FIFO1 mailbox identifier register */
+#define CAN_RFIFOMP1(canx) REG32((canx) + 0x000001C4U) /*!< CAN receive FIFO1 mailbox property register */
+#define CAN_RFIFOMDATA01(canx) REG32((canx) + 0x000001C8U) /*!< CAN receive FIFO1 mailbox data0 register */
+#define CAN_RFIFOMDATA11(canx) REG32((canx) + 0x000001CCU) /*!< CAN receive FIFO1 mailbox data1 register */
+#define CAN_FCTL(canx) REG32((canx) + 0x00000200U) /*!< CAN filter control register */
+#define CAN_FMCFG(canx) REG32((canx) + 0x00000204U) /*!< CAN filter mode register */
+#define CAN_FSCFG(canx) REG32((canx) + 0x0000020CU) /*!< CAN filter scale register */
+#define CAN_FAFIFO(canx) REG32((canx) + 0x00000214U) /*!< CAN filter associated FIFO register */
+#define CAN_FW(canx) REG32((canx) + 0x0000021CU) /*!< CAN filter working register */
+#define CAN_F0DATA0(canx) REG32((canx) + 0x00000240U) /*!< CAN filter 0 data 0 register */
+#define CAN_F1DATA0(canx) REG32((canx) + 0x00000248U) /*!< CAN filter 1 data 0 register */
+#define CAN_F2DATA0(canx) REG32((canx) + 0x00000250U) /*!< CAN filter 2 data 0 register */
+#define CAN_F3DATA0(canx) REG32((canx) + 0x00000258U) /*!< CAN filter 3 data 0 register */
+#define CAN_F4DATA0(canx) REG32((canx) + 0x00000260U) /*!< CAN filter 4 data 0 register */
+#define CAN_F5DATA0(canx) REG32((canx) + 0x00000268U) /*!< CAN filter 5 data 0 register */
+#define CAN_F6DATA0(canx) REG32((canx) + 0x00000270U) /*!< CAN filter 6 data 0 register */
+#define CAN_F7DATA0(canx) REG32((canx) + 0x00000278U) /*!< CAN filter 7 data 0 register */
+#define CAN_F8DATA0(canx) REG32((canx) + 0x00000280U) /*!< CAN filter 8 data 0 register */
+#define CAN_F9DATA0(canx) REG32((canx) + 0x00000288U) /*!< CAN filter 9 data 0 register */
+#define CAN_F10DATA0(canx) REG32((canx) + 0x00000290U) /*!< CAN filter 10 data 0 register */
+#define CAN_F11DATA0(canx) REG32((canx) + 0x00000298U) /*!< CAN filter 11 data 0 register */
+#define CAN_F12DATA0(canx) REG32((canx) + 0x000002A0U) /*!< CAN filter 12 data 0 register */
+#define CAN_F13DATA0(canx) REG32((canx) + 0x000002A8U) /*!< CAN filter 13 data 0 register */
+#define CAN_F14DATA0(canx) REG32((canx) + 0x000002B0U) /*!< CAN filter 14 data 0 register */
+#define CAN_F15DATA0(canx) REG32((canx) + 0x000002B8U) /*!< CAN filter 15 data 0 register */
+#define CAN_F16DATA0(canx) REG32((canx) + 0x000002C0U) /*!< CAN filter 16 data 0 register */
+#define CAN_F17DATA0(canx) REG32((canx) + 0x000002C8U) /*!< CAN filter 17 data 0 register */
+#define CAN_F18DATA0(canx) REG32((canx) + 0x000002D0U) /*!< CAN filter 18 data 0 register */
+#define CAN_F19DATA0(canx) REG32((canx) + 0x000002D8U) /*!< CAN filter 19 data 0 register */
+#define CAN_F20DATA0(canx) REG32((canx) + 0x000002E0U) /*!< CAN filter 20 data 0 register */
+#define CAN_F21DATA0(canx) REG32((canx) + 0x000002E8U) /*!< CAN filter 21 data 0 register */
+#define CAN_F22DATA0(canx) REG32((canx) + 0x000002F0U) /*!< CAN filter 22 data 0 register */
+#define CAN_F23DATA0(canx) REG32((canx) + 0x000003F8U) /*!< CAN filter 23 data 0 register */
+#define CAN_F24DATA0(canx) REG32((canx) + 0x00000300U) /*!< CAN filter 24 data 0 register */
+#define CAN_F25DATA0(canx) REG32((canx) + 0x00000308U) /*!< CAN filter 25 data 0 register */
+#define CAN_F26DATA0(canx) REG32((canx) + 0x00000310U) /*!< CAN filter 26 data 0 register */
+#define CAN_F27DATA0(canx) REG32((canx) + 0x00000318U) /*!< CAN filter 27 data 0 register */
+#define CAN_F0DATA1(canx) REG32((canx) + 0x00000244U) /*!< CAN filter 0 data 1 register */
+#define CAN_F1DATA1(canx) REG32((canx) + 0x0000024CU) /*!< CAN filter 1 data 1 register */
+#define CAN_F2DATA1(canx) REG32((canx) + 0x00000254U) /*!< CAN filter 2 data 1 register */
+#define CAN_F3DATA1(canx) REG32((canx) + 0x0000025CU) /*!< CAN filter 3 data 1 register */
+#define CAN_F4DATA1(canx) REG32((canx) + 0x00000264U) /*!< CAN filter 4 data 1 register */
+#define CAN_F5DATA1(canx) REG32((canx) + 0x0000026CU) /*!< CAN filter 5 data 1 register */
+#define CAN_F6DATA1(canx) REG32((canx) + 0x00000274U) /*!< CAN filter 6 data 1 register */
+#define CAN_F7DATA1(canx) REG32((canx) + 0x0000027CU) /*!< CAN filter 7 data 1 register */
+#define CAN_F8DATA1(canx) REG32((canx) + 0x00000284U) /*!< CAN filter 8 data 1 register */
+#define CAN_F9DATA1(canx) REG32((canx) + 0x0000028CU) /*!< CAN filter 9 data 1 register */
+#define CAN_F10DATA1(canx) REG32((canx) + 0x00000294U) /*!< CAN filter 10 data 1 register */
+#define CAN_F11DATA1(canx) REG32((canx) + 0x0000029CU) /*!< CAN filter 11 data 1 register */
+#define CAN_F12DATA1(canx) REG32((canx) + 0x000002A4U) /*!< CAN filter 12 data 1 register */
+#define CAN_F13DATA1(canx) REG32((canx) + 0x000002ACU) /*!< CAN filter 13 data 1 register */
+#define CAN_F14DATA1(canx) REG32((canx) + 0x000002B4U) /*!< CAN filter 14 data 1 register */
+#define CAN_F15DATA1(canx) REG32((canx) + 0x000002BCU) /*!< CAN filter 15 data 1 register */
+#define CAN_F16DATA1(canx) REG32((canx) + 0x000002C4U) /*!< CAN filter 16 data 1 register */
+#define CAN_F17DATA1(canx) REG32((canx) + 0x0000024CU) /*!< CAN filter 17 data 1 register */
+#define CAN_F18DATA1(canx) REG32((canx) + 0x000002D4U) /*!< CAN filter 18 data 1 register */
+#define CAN_F19DATA1(canx) REG32((canx) + 0x000002DCU) /*!< CAN filter 19 data 1 register */
+#define CAN_F20DATA1(canx) REG32((canx) + 0x000002E4U) /*!< CAN filter 20 data 1 register */
+#define CAN_F21DATA1(canx) REG32((canx) + 0x000002ECU) /*!< CAN filter 21 data 1 register */
+#define CAN_F22DATA1(canx) REG32((canx) + 0x000002F4U) /*!< CAN filter 22 data 1 register */
+#define CAN_F23DATA1(canx) REG32((canx) + 0x000002FCU) /*!< CAN filter 23 data 1 register */
+#define CAN_F24DATA1(canx) REG32((canx) + 0x00000304U) /*!< CAN filter 24 data 1 register */
+#define CAN_F25DATA1(canx) REG32((canx) + 0x0000030CU) /*!< CAN filter 25 data 1 register */
+#define CAN_F26DATA1(canx) REG32((canx) + 0x00000314U) /*!< CAN filter 26 data 1 register */
+#define CAN_F27DATA1(canx) REG32((canx) + 0x0000031CU) /*!< CAN filter 27 data 1 register */
/* CAN transmit mailbox bank */
-#define CAN_TMI(canx, bank) REG32((canx) + 0x180U + ((bank) * 0x10U)) /*!< CAN transmit mailbox identifier register */
-#define CAN_TMP(canx, bank) REG32((canx) + 0x184U + ((bank) * 0x10U)) /*!< CAN transmit mailbox property register */
-#define CAN_TMDATA0(canx, bank) REG32((canx) + 0x188U + ((bank) * 0x10U)) /*!< CAN transmit mailbox data0 register */
-#define CAN_TMDATA1(canx, bank) REG32((canx) + 0x18CU + ((bank) * 0x10U)) /*!< CAN transmit mailbox data1 register */
+#define CAN_TMI(canx, bank) REG32((canx) + 0x180U + ((bank) * 0x10U)) /*!< CAN transmit mailbox identifier register */
+#define CAN_TMP(canx, bank) REG32((canx) + 0x184U + ((bank) * 0x10U)) /*!< CAN transmit mailbox property register */
+#define CAN_TMDATA0(canx, bank) REG32((canx) + 0x188U + ((bank) * 0x10U)) /*!< CAN transmit mailbox data0 register */
+#define CAN_TMDATA1(canx, bank) REG32((canx) + 0x18CU + ((bank) * 0x10U)) /*!< CAN transmit mailbox data1 register */
/* CAN filter bank */
-#define CAN_FDATA0(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x0U) /*!< CAN filter data 0 register */
-#define CAN_FDATA1(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x4U) /*!< CAN filter data 1 register */
+#define CAN_FDATA0(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x0U) /*!< CAN filter data 0 register */
+#define CAN_FDATA1(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x4U) /*!< CAN filter data 1 register */
-/* CAN receive fifo mailbox bank */
-#define CAN_RFIFOMI(canx, bank) REG32((canx) + 0x1B0U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox identifier register */
-#define CAN_RFIFOMP(canx, bank) REG32((canx) + 0x1B4U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox property register */
-#define CAN_RFIFOMDATA0(canx, bank) REG32((canx) + 0x1B8U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data0 register */
-#define CAN_RFIFOMDATA1(canx, bank) REG32((canx) + 0x1BCU + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data1 register */
+/* CAN receive FIFO mailbox bank */
+#define CAN_RFIFOMI(canx, bank) REG32((canx) + 0x1B0U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox identifier register */
+#define CAN_RFIFOMP(canx, bank) REG32((canx) + 0x1B4U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox property register */
+#define CAN_RFIFOMDATA0(canx, bank) REG32((canx) + 0x1B8U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data0 register */
+#define CAN_RFIFOMDATA1(canx, bank) REG32((canx) + 0x1BCU + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data1 register */
/* bits definitions */
/* CAN_CTL */
@@ -296,10 +292,10 @@ OF SUCH DAMAGE.
#define CAN_FCTL_HBC1F BITS(8,13) /*!< header bank of CAN1 filter */
/* CAN_FMCFG */
-#define CAN_FMCFG_FMOD(regval) BIT(regval) /*!< filter mode, list or mask*/
+#define CAN_FMCFG_FMOD(regval) BIT(regval) /*!< filter mode, list or mask */
/* CAN_FSCFG */
-#define CAN_FSCFG_FS(regval) BIT(regval) /*!< filter scale, 32 bits or 16 bits*/
+#define CAN_FSCFG_FS(regval) BIT(regval) /*!< filter scale, 32 bits or 16 bits */
/* CAN_FAFIFO */
#define CAN_FAFIFOR_FAF(regval) BIT(regval) /*!< filter associated with FIFO */
@@ -329,56 +325,54 @@ OF SUCH DAMAGE.
#define ERR_REG_OFFSET ((uint8_t)0x18U) /*!< ERR register offset */
/* CAN flags */
-typedef enum
-{
+typedef enum {
/* flags in STAT register */
- CAN_FLAG_RXL = CAN_REGIDX_BIT(STAT_REG_OFFSET, 11U), /*!< RX level */
- CAN_FLAG_LASTRX = CAN_REGIDX_BIT(STAT_REG_OFFSET, 10U), /*!< last sample value of RX pin */
- CAN_FLAG_RS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 9U), /*!< receiving state */
- CAN_FLAG_TS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 8U), /*!< transmitting state */
- CAN_FLAG_SLPIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 4U), /*!< status change flag of entering sleep working mode */
- CAN_FLAG_WUIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 3U), /*!< status change flag of wakeup from sleep working mode */
- CAN_FLAG_ERRIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 2U), /*!< error flag */
- CAN_FLAG_SLPWS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 1U), /*!< sleep working state */
- CAN_FLAG_IWS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 0U), /*!< initial working state */
+ CAN_FLAG_RXL = CAN_REGIDX_BIT(STAT_REG_OFFSET, 11U), /*!< RX level */
+ CAN_FLAG_LASTRX = CAN_REGIDX_BIT(STAT_REG_OFFSET, 10U), /*!< last sample value of RX pin */
+ CAN_FLAG_RS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 9U), /*!< receiving state */
+ CAN_FLAG_TS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 8U), /*!< transmitting state */
+ CAN_FLAG_SLPIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 4U), /*!< status change flag of entering sleep working mode */
+ CAN_FLAG_WUIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 3U), /*!< status change flag of wakeup from sleep working mode */
+ CAN_FLAG_ERRIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 2U), /*!< error flag */
+ CAN_FLAG_SLPWS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 1U), /*!< sleep working state */
+ CAN_FLAG_IWS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 0U), /*!< initial working state */
/* flags in TSTAT register */
- CAN_FLAG_TMLS2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 31U), /*!< transmit mailbox 2 last sending in Tx FIFO */
- CAN_FLAG_TMLS1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 30U), /*!< transmit mailbox 1 last sending in Tx FIFO */
- CAN_FLAG_TMLS0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 29U), /*!< transmit mailbox 0 last sending in Tx FIFO */
- CAN_FLAG_TME2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 28U), /*!< transmit mailbox 2 empty */
- CAN_FLAG_TME1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 27U), /*!< transmit mailbox 1 empty */
- CAN_FLAG_TME0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 26U), /*!< transmit mailbox 0 empty */
- CAN_FLAG_MTE2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 19U), /*!< mailbox 2 transmit error */
- CAN_FLAG_MTE1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 11U), /*!< mailbox 1 transmit error */
- CAN_FLAG_MTE0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 3U), /*!< mailbox 0 transmit error */
- CAN_FLAG_MAL2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 18U), /*!< mailbox 2 arbitration lost */
- CAN_FLAG_MAL1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 10U), /*!< mailbox 1 arbitration lost */
- CAN_FLAG_MAL0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 2U), /*!< mailbox 0 arbitration lost */
- CAN_FLAG_MTFNERR2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 17U), /*!< mailbox 2 transmit finished with no error */
- CAN_FLAG_MTFNERR1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 9U), /*!< mailbox 1 transmit finished with no error */
- CAN_FLAG_MTFNERR0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 1U), /*!< mailbox 0 transmit finished with no error */
- CAN_FLAG_MTF2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 16U), /*!< mailbox 2 transmit finished */
- CAN_FLAG_MTF1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 8U), /*!< mailbox 1 transmit finished */
- CAN_FLAG_MTF0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 0U), /*!< mailbox 0 transmit finished */
+ CAN_FLAG_TMLS2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 31U), /*!< transmit mailbox 2 last sending in TX FIFO */
+ CAN_FLAG_TMLS1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 30U), /*!< transmit mailbox 1 last sending in TX FIFO */
+ CAN_FLAG_TMLS0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 29U), /*!< transmit mailbox 0 last sending in TX FIFO */
+ CAN_FLAG_TME2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 28U), /*!< transmit mailbox 2 empty */
+ CAN_FLAG_TME1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 27U), /*!< transmit mailbox 1 empty */
+ CAN_FLAG_TME0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 26U), /*!< transmit mailbox 0 empty */
+ CAN_FLAG_MTE2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 19U), /*!< mailbox 2 transmit error */
+ CAN_FLAG_MTE1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 11U), /*!< mailbox 1 transmit error */
+ CAN_FLAG_MTE0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 3U), /*!< mailbox 0 transmit error */
+ CAN_FLAG_MAL2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 18U), /*!< mailbox 2 arbitration lost */
+ CAN_FLAG_MAL1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 10U), /*!< mailbox 1 arbitration lost */
+ CAN_FLAG_MAL0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 2U), /*!< mailbox 0 arbitration lost */
+ CAN_FLAG_MTFNERR2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 17U), /*!< mailbox 2 transmit finished with no error */
+ CAN_FLAG_MTFNERR1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 9U), /*!< mailbox 1 transmit finished with no error */
+ CAN_FLAG_MTFNERR0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 1U), /*!< mailbox 0 transmit finished with no error */
+ CAN_FLAG_MTF2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 16U), /*!< mailbox 2 transmit finished */
+ CAN_FLAG_MTF1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 8U), /*!< mailbox 1 transmit finished */
+ CAN_FLAG_MTF0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 0U), /*!< mailbox 0 transmit finished */
/* flags in RFIFO0 register */
- CAN_FLAG_RFO0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 4U), /*!< receive FIFO0 overfull */
- CAN_FLAG_RFF0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 3U), /*!< receive FIFO0 full */
+ CAN_FLAG_RFO0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 4U), /*!< receive FIFO0 overfull */
+ CAN_FLAG_RFF0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 3U), /*!< receive FIFO0 full */
/* flags in RFIFO1 register */
- CAN_FLAG_RFO1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 4U), /*!< receive FIFO1 overfull */
- CAN_FLAG_RFF1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 3U), /*!< receive FIFO1 full */
+ CAN_FLAG_RFO1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 4U), /*!< receive FIFO1 overfull */
+ CAN_FLAG_RFF1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 3U), /*!< receive FIFO1 full */
/* flags in ERR register */
- CAN_FLAG_BOERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 2U), /*!< bus-off error */
- CAN_FLAG_PERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 1U), /*!< passive error */
- CAN_FLAG_WERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 0U), /*!< warning error */
-}can_flag_enum;
+ CAN_FLAG_BOERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 2U), /*!< bus-off error */
+ CAN_FLAG_PERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 1U), /*!< passive error */
+ CAN_FLAG_WERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 0U), /*!< warning error */
+} can_flag_enum;
/* CAN interrupt flags */
-typedef enum
-{
+typedef enum {
/* interrupt flags in STAT register */
- CAN_INT_FLAG_SLPIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 4U, 17U), /*!< status change interrupt flag of sleep working mode entering */
- CAN_INT_FLAG_WUIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 3U, 16), /*!< status change interrupt flag of wakeup from sleep working mode */
- CAN_INT_FLAG_ERRIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 2U, 15), /*!< error interrupt flag */
+ CAN_INT_FLAG_SLPIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 4U, 17U), /*!< status change interrupt flag of sleep working mode entering */
+ CAN_INT_FLAG_WUIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 3U, 16), /*!< status change interrupt flag of wakeup from sleep working mode */
+ CAN_INT_FLAG_ERRIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 2U, 15), /*!< error interrupt flag */
/* interrupt flags in TSTAT register */
CAN_INT_FLAG_MTF2 = CAN_REGIDX_BITS(TSTAT_REG_OFFSET, 16U, 0U), /*!< mailbox 2 transmit finished interrupt flag */
CAN_INT_FLAG_MTF1 = CAN_REGIDX_BITS(TSTAT_REG_OFFSET, 8U, 0U), /*!< mailbox 1 transmit finished interrupt flag */
@@ -392,42 +386,39 @@ typedef enum
CAN_INT_FLAG_RFF1 = CAN_REGIDX_BITS(RFIFO1_REG_OFFSET, 3U, 5U), /*!< receive FIFO1 full interrupt flag */
CAN_INT_FLAG_RFL1 = CAN_REGIDX_BITS(RFIFO1_REG_OFFSET, 2U, 4U), /*!< receive FIFO1 not empty interrupt flag */
/* interrupt flags in ERR register */
- CAN_INT_FLAG_ERRN = CAN_REGIDX_BITS(ERR_REG_OFFSET, 3U, 11U), /*!< error number interrupt flag */
- CAN_INT_FLAG_BOERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 2U, 10U), /*!< bus-off error interrupt flag */
- CAN_INT_FLAG_PERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 1U, 9U), /*!< passive error interrupt flag */
- CAN_INT_FLAG_WERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 0U, 8U), /*!< warning error interrupt flag */
-}can_interrupt_flag_enum;
+ CAN_INT_FLAG_ERRN = CAN_REGIDX_BITS(ERR_REG_OFFSET, 3U, 11U), /*!< error number interrupt flag */
+ CAN_INT_FLAG_BOERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 2U, 10U), /*!< bus-off error interrupt flag */
+ CAN_INT_FLAG_PERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 1U, 9U), /*!< passive error interrupt flag */
+ CAN_INT_FLAG_WERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 0U, 8U), /*!< warning error interrupt flag */
+} can_interrupt_flag_enum;
/* CAN initiliaze parameters structure */
-typedef struct
-{
- uint8_t working_mode; /*!< CAN working mode */
+typedef struct {
+ uint8_t working_mode; /*!< CAN working mode */
uint8_t resync_jump_width; /*!< CAN resynchronization jump width */
uint8_t time_segment_1; /*!< time segment 1 */
uint8_t time_segment_2; /*!< time segment 2 */
ControlStatus time_triggered; /*!< time triggered communication mode */
ControlStatus auto_bus_off_recovery; /*!< automatic bus-off recovery */
ControlStatus auto_wake_up; /*!< automatic wake-up mode */
- ControlStatus no_auto_retrans; /*!< automatic retransmission mode disable */
+ ControlStatus auto_retrans; /*!< automatic retransmission mode */
ControlStatus rec_fifo_overwrite; /*!< receive FIFO overwrite mode */
ControlStatus trans_fifo_order; /*!< transmit FIFO order */
uint16_t prescaler; /*!< baudrate prescaler */
-}can_parameter_struct;
+} can_parameter_struct;
/* CAN transmit message structure */
-typedef struct
-{
+typedef struct {
uint32_t tx_sfid; /*!< standard format frame identifier */
uint32_t tx_efid; /*!< extended format frame identifier */
uint8_t tx_ff; /*!< format of frame, standard or extended format */
uint8_t tx_ft; /*!< type of frame, data or remote */
uint8_t tx_dlen; /*!< data length */
uint8_t tx_data[8]; /*!< transmit data */
-}can_trasnmit_message_struct;
+} can_trasnmit_message_struct;
/* CAN receive message structure */
-typedef struct
-{
+typedef struct {
uint32_t rx_sfid; /*!< standard format frame identifier */
uint32_t rx_efid; /*!< extended format frame identifier */
uint8_t rx_ff; /*!< format of frame, standard or extended format */
@@ -438,9 +429,8 @@ typedef struct
} can_receive_message_struct;
/* CAN filter parameters structure */
-typedef struct
-{
- uint16_t filter_list_high; /*!< filter list number high bits*/
+typedef struct {
+ uint16_t filter_list_high; /*!< filter list number high bits */
uint16_t filter_list_low; /*!< filter list number low bits */
uint16_t filter_mask_high; /*!< filter mask number high bits */
uint16_t filter_mask_low; /*!< filter mask number low bits */
@@ -449,11 +439,10 @@ typedef struct
uint16_t filter_mode; /*!< filter mode, list or mask */
uint16_t filter_bits; /*!< filter scale */
ControlStatus filter_enable; /*!< filter work or not */
-}can_filter_parameter_struct;
+} can_filter_parameter_struct;
/* CAN errors */
-typedef enum
-{
+typedef enum {
CAN_ERROR_NONE = 0, /*!< no error */
CAN_ERROR_FILL, /*!< fill error */
CAN_ERROR_FORMATE, /*!< format error */
@@ -462,38 +451,36 @@ typedef enum
CAN_ERROR_BITDOMINANTER, /*!< bit dominant error */
CAN_ERROR_CRC, /*!< CRC error */
CAN_ERROR_SOFTWARECFG, /*!< software configure */
-}can_error_enum;
+} can_error_enum;
/* transmit states */
-typedef enum
-{
- CAN_TRANSMIT_FAILED = 0, /*!< CAN transmitted failure */
- CAN_TRANSMIT_OK = 1, /*!< CAN transmitted success */
- CAN_TRANSMIT_PENDING = 2, /*!< CAN transmitted pending */
- CAN_TRANSMIT_NOMAILBOX = 4, /*!< no empty mailbox to be used for CAN */
-}can_transmit_state_enum;
-
-typedef enum
-{
- CAN_INIT_STRUCT = 0, /* CAN initiliaze parameters struct */
+typedef enum {
+ CAN_TRANSMIT_FAILED = 0U, /*!< CAN transmitted failure */
+ CAN_TRANSMIT_OK = 1U, /*!< CAN transmitted success */
+ CAN_TRANSMIT_PENDING = 2U, /*!< CAN transmitted pending */
+ CAN_TRANSMIT_NOMAILBOX = 4U, /*!< no empty mailbox to be used for CAN */
+} can_transmit_state_enum;
+
+typedef enum {
+ CAN_INIT_STRUCT = 0, /* CAN initialize parameters struct */
CAN_FILTER_STRUCT, /* CAN filter parameters struct */
CAN_TX_MESSAGE_STRUCT, /* CAN transmit message struct */
CAN_RX_MESSAGE_STRUCT, /* CAN receive message struct */
-}can_struct_type_enum;
+} can_struct_type_enum;
-/* CAN baudrate prescaler*/
+/* CAN baudrate prescaler */
#define BT_BAUDPSC(regval) (BITS(0,9) & ((uint32_t)(regval) << 0))
-/* CAN bit segment 1*/
+/* CAN bit segment 1 */
#define BT_BS1(regval) (BITS(16,19) & ((uint32_t)(regval) << 16))
-/* CAN bit segment 2*/
+/* CAN bit segment 2 */
#define BT_BS2(regval) (BITS(20,22) & ((uint32_t)(regval) << 20))
-/* CAN resynchronization jump width*/
+/* CAN resynchronization jump width */
#define BT_SJW(regval) (BITS(24,25) & ((uint32_t)(regval) << 24))
-/* CAN communication mode*/
+/* CAN communication mode */
#define BT_MODE(regval) (BITS(30,31) & ((uint32_t)(regval) << 30))
/* CAN FDATA high 16 bits */
@@ -502,13 +489,13 @@ typedef enum
/* CAN FDATA low 16 bits */
#define FDATA_MASK_LOW(regval) (BITS(0,15) & ((uint32_t)(regval) << 0))
-/* CAN1 filter start bank_number*/
+/* CAN1 filter start bank_number */
#define FCTL_HBC1F(regval) (BITS(8,13) & ((uint32_t)(regval) << 8))
-/* CAN transmit mailbox extended identifier*/
+/* CAN transmit mailbox extended identifier */
#define TMI_EFID(regval) (BITS(3,31) & ((uint32_t)(regval) << 3))
-/* CAN transmit mailbox standard identifier*/
+/* CAN transmit mailbox standard identifier */
#define TMI_SFID(regval) (BITS(21,31) & ((uint32_t)(regval) << 21))
/* transmit data byte 0 */
@@ -520,76 +507,76 @@ typedef enum
/* transmit data byte 2 */
#define TMDATA0_DB2(regval) (BITS(16,23) & ((uint32_t)(regval) << 16))
-/* transmit data byte 3 */
+/* transmit data byte 3 */
#define TMDATA0_DB3(regval) (BITS(24,31) & ((uint32_t)(regval) << 24))
-/* transmit data byte 4 */
+/* transmit data byte 4 */
#define TMDATA1_DB4(regval) (BITS(0,7) & ((uint32_t)(regval) << 0))
-/* transmit data byte 5 */
+/* transmit data byte 5 */
#define TMDATA1_DB5(regval) (BITS(8,15) & ((uint32_t)(regval) << 8))
-/* transmit data byte 6 */
+/* transmit data byte 6 */
#define TMDATA1_DB6(regval) (BITS(16,23) & ((uint32_t)(regval) << 16))
-/* transmit data byte 7 */
+/* transmit data byte 7 */
#define TMDATA1_DB7(regval) (BITS(24,31) & ((uint32_t)(regval) << 24))
-/* receive mailbox extended identifier*/
-#define GET_RFIFOMI_EFID(regval) GET_BITS((uint32_t)(regval), 3, 31)
+/* receive mailbox extended identifier */
+#define GET_RFIFOMI_EFID(regval) GET_BITS((uint32_t)(regval), 3U, 31U)
-/* receive mailbox standrad identifier*/
-#define GET_RFIFOMI_SFID(regval) GET_BITS((uint32_t)(regval), 21, 31)
+/* receive mailbox standard identifier */
+#define GET_RFIFOMI_SFID(regval) GET_BITS((uint32_t)(regval), 21U, 31U)
/* receive data length */
-#define GET_RFIFOMP_DLENC(regval) GET_BITS((uint32_t)(regval), 0, 3)
+#define GET_RFIFOMP_DLENC(regval) GET_BITS((uint32_t)(regval), 0U, 3U)
/* the index of the filter by which the frame is passed */
-#define GET_RFIFOMP_FI(regval) GET_BITS((uint32_t)(regval), 8, 15)
+#define GET_RFIFOMP_FI(regval) GET_BITS((uint32_t)(regval), 8U, 15U)
/* receive data byte 0 */
-#define GET_RFIFOMDATA0_DB0(regval) GET_BITS((uint32_t)(regval), 0, 7)
+#define GET_RFIFOMDATA0_DB0(regval) GET_BITS((uint32_t)(regval), 0U, 7U)
/* receive data byte 1 */
-#define GET_RFIFOMDATA0_DB1(regval) GET_BITS((uint32_t)(regval), 8, 15)
+#define GET_RFIFOMDATA0_DB1(regval) GET_BITS((uint32_t)(regval), 8U, 15U)
/* receive data byte 2 */
-#define GET_RFIFOMDATA0_DB2(regval) GET_BITS((uint32_t)(regval), 16, 23)
+#define GET_RFIFOMDATA0_DB2(regval) GET_BITS((uint32_t)(regval), 16U, 23U)
/* receive data byte 3 */
-#define GET_RFIFOMDATA0_DB3(regval) GET_BITS((uint32_t)(regval), 24, 31)
+#define GET_RFIFOMDATA0_DB3(regval) GET_BITS((uint32_t)(regval), 24U, 31U)
/* receive data byte 4 */
-#define GET_RFIFOMDATA1_DB4(regval) GET_BITS((uint32_t)(regval), 0, 7)
+#define GET_RFIFOMDATA1_DB4(regval) GET_BITS((uint32_t)(regval), 0U, 7U)
/* receive data byte 5 */
-#define GET_RFIFOMDATA1_DB5(regval) GET_BITS((uint32_t)(regval), 8, 15)
+#define GET_RFIFOMDATA1_DB5(regval) GET_BITS((uint32_t)(regval), 8U, 15U)
/* receive data byte 6 */
-#define GET_RFIFOMDATA1_DB6(regval) GET_BITS((uint32_t)(regval), 16, 23)
+#define GET_RFIFOMDATA1_DB6(regval) GET_BITS((uint32_t)(regval), 16U, 23U)
/* receive data byte 7 */
-#define GET_RFIFOMDATA1_DB7(regval) GET_BITS((uint32_t)(regval), 24, 31)
+#define GET_RFIFOMDATA1_DB7(regval) GET_BITS((uint32_t)(regval), 24U, 31U)
-/* error number */
-#define GET_ERR_ERRN(regval) GET_BITS((uint32_t)(regval), 4, 6)
+/* error number */
+#define GET_ERR_ERRN(regval) GET_BITS((uint32_t)(regval), 4U, 6U)
-/* transmit error count */
-#define GET_ERR_TECNT(regval) GET_BITS((uint32_t)(regval), 16, 23)
+/* transmit error count */
+#define GET_ERR_TECNT(regval) GET_BITS((uint32_t)(regval), 16U, 23U)
-/* receive error count */
-#define GET_ERR_RECNT(regval) GET_BITS((uint32_t)(regval), 24, 31)
+/* receive error count */
+#define GET_ERR_RECNT(regval) GET_BITS((uint32_t)(regval), 24U, 31U)
/* CAN errors */
#define ERR_ERRN(regval) (BITS(4,6) & ((uint32_t)(regval) << 4))
-#define CAN_ERRN_0 ERR_ERRN(0) /*!< no error */
-#define CAN_ERRN_1 ERR_ERRN(1) /*!< fill error */
-#define CAN_ERRN_2 ERR_ERRN(2) /*!< format error */
-#define CAN_ERRN_3 ERR_ERRN(3) /*!< ACK error */
-#define CAN_ERRN_4 ERR_ERRN(4) /*!< bit recessive error */
-#define CAN_ERRN_5 ERR_ERRN(5) /*!< bit dominant error */
-#define CAN_ERRN_6 ERR_ERRN(6) /*!< CRC error */
-#define CAN_ERRN_7 ERR_ERRN(7) /*!< software error */
+#define CAN_ERRN_0 ERR_ERRN(0U) /*!< no error */
+#define CAN_ERRN_1 ERR_ERRN(1U) /*!< fill error */
+#define CAN_ERRN_2 ERR_ERRN(2U) /*!< format error */
+#define CAN_ERRN_3 ERR_ERRN(3U) /*!< ACK error */
+#define CAN_ERRN_4 ERR_ERRN(4U) /*!< bit recessive error */
+#define CAN_ERRN_5 ERR_ERRN(5U) /*!< bit dominant error */
+#define CAN_ERRN_6 ERR_ERRN(6U) /*!< CRC error */
+#define CAN_ERRN_7 ERR_ERRN(7U) /*!< software error */
#define CAN_STATE_PENDING ((uint32_t)0x00000000U) /*!< CAN pending */
@@ -643,11 +630,11 @@ typedef enum
#define CAN_FF_STANDARD ((uint32_t)0x00000000U) /*!< standard frame */
#define CAN_FF_EXTENDED ((uint32_t)0x00000004U) /*!< extended frame */
-/* CAN receive fifo */
+/* CAN receive FIFO */
#define CAN_FIFO0 ((uint8_t)0x00U) /*!< receive FIFO0 */
#define CAN_FIFO1 ((uint8_t)0x01U) /*!< receive FIFO1 */
-/* frame number of receive fifo */
+/* frame number of receive FIFO */
#define CAN_RFIF_RFL_MASK ((uint32_t)0x00000003U) /*!< mask for frame number in receive FIFOx */
#define CAN_SFID_MASK ((uint32_t)0x000007FFU) /*!< mask of standard identifier */
@@ -697,11 +684,11 @@ typedef enum
/* deinitialize CAN */
void can_deinit(uint32_t can_periph);
/* initialize CAN structure */
-void can_struct_para_init(can_struct_type_enum type, void* p_struct);
+void can_struct_para_init(can_struct_type_enum type, void *p_struct);
/* initialize CAN */
-ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init);
+ErrStatus can_init(uint32_t can_periph, can_parameter_struct *can_parameter_init);
/* CAN filter initialization */
-void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init);
+void can_filter_init(can_filter_parameter_struct *can_filter_parameter_init);
/* function configuration */
/* set can1 filter start bank number */
@@ -718,14 +705,14 @@ void can_time_trigger_mode_disable(uint32_t can_periph);
/* transmit functions */
/* transmit CAN message */
-uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* transmit_message);
+uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct *transmit_message);
/* get CAN transmit state */
can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox_number);
/* stop CAN transmission */
void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number);
/* CAN receive message */
-void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct* receive_message);
-/* CAN release fifo */
+void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct *receive_message);
+/* CAN release FIFO */
void can_fifo_release(uint32_t can_periph, uint8_t fifo_number);
/* CAN receive message length */
uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number);
@@ -734,7 +721,7 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode);
/* CAN wakeup from sleep mode */
ErrStatus can_wakeup(uint32_t can_periph);
-/* CAN get error */
+/* CAN get error type */
can_error_enum can_error_get(uint32_t can_periph);
/* get CAN receive error number */
uint8_t can_receive_error_number_get(uint32_t can_periph);
@@ -742,14 +729,14 @@ uint8_t can_receive_error_number_get(uint32_t can_periph);
uint8_t can_transmit_error_number_get(uint32_t can_periph);
/* interrupt & flag functions */
-/* CAN interrupt enable */
-void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt);
-/* CAN interrupt disable */
-void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt);
/* CAN get flag state */
FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag);
/* CAN clear flag state */
void can_flag_clear(uint32_t can_periph, can_flag_enum flag);
+/* CAN interrupt enable */
+void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt);
+/* CAN interrupt disable */
+void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt);
/* CAN get interrupt flag state */
FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum flag);
/* CAN clear interrupt flag state */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_cau.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_cau.h
index 35946b6..a6776af 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_cau.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_cau.h
@@ -2,36 +2,33 @@
\file gd32f20x_cau.h
\brief definitions for the CAU
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,29 +38,29 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* CAU definitions */
-#define CAU CAU_BASE
+#define CAU CAU_BASE /*!< CAU base address */
/* registers definitions */
-#define CAU_CTL REG32(CAU + 0x00U) /*!< control register */
-#define CAU_STAT0 REG32(CAU + 0x04U) /*!< status register 0 */
-#define CAU_DI REG32(CAU + 0x08U) /*!< data input register */
-#define CAU_DO REG32(CAU + 0x0CU) /*!< data output register */
-#define CAU_DMAEN REG32(CAU + 0x10U) /*!< DMA enable register */
-#define CAU_INTEN REG32(CAU + 0x14U) /*!< interrupt enable register */
-#define CAU_STAT1 REG32(CAU + 0x18U) /*!< status register 1 */
-#define CAU_INTF REG32(CAU + 0x1CU) /*!< interrupt flag register */
-#define CAU_KEY0H REG32(CAU + 0x20U) /*!< key 0 high register */
-#define CAU_KEY0L REG32(CAU + 0x24U) /*!< key 0 low register */
-#define CAU_KEY1H REG32(CAU + 0x28U) /*!< key 1 high register */
-#define CAU_KEY1L REG32(CAU + 0x2CU) /*!< key 1 low register */
-#define CAU_KEY2H REG32(CAU + 0x30U) /*!< key 2 high register */
-#define CAU_KEY2L REG32(CAU + 0x34U) /*!< key 2 low register */
-#define CAU_KEY3H REG32(CAU + 0x38U) /*!< key 3 high register */
-#define CAU_KEY3L REG32(CAU + 0x3CU) /*!< key 3 low register */
-#define CAU_IV0H REG32(CAU + 0x40U) /*!< initial vector 0 high register */
-#define CAU_IV0L REG32(CAU + 0x44U) /*!< initial vector 0 low register */
-#define CAU_IV1H REG32(CAU + 0x48U) /*!< initial vector 1 high register */
-#define CAU_IV1L REG32(CAU + 0x4CU) /*!< initial vector 1 low register */
+#define CAU_CTL REG32(CAU + 0x00000000U) /*!< control register */
+#define CAU_STAT0 REG32(CAU + 0x00000004U) /*!< status register 0 */
+#define CAU_DI REG32(CAU + 0x00000008U) /*!< data input register */
+#define CAU_DO REG32(CAU + 0x0000000CU) /*!< data output register */
+#define CAU_DMAEN REG32(CAU + 0x00000010U) /*!< DMA enable register */
+#define CAU_INTEN REG32(CAU + 0x00000014U) /*!< interrupt enable register */
+#define CAU_STAT1 REG32(CAU + 0x00000018U) /*!< status register 1 */
+#define CAU_INTF REG32(CAU + 0x0000001CU) /*!< interrupt flag register */
+#define CAU_KEY0H REG32(CAU + 0x00000020U) /*!< key 0 high register */
+#define CAU_KEY0L REG32(CAU + 0x00000024U) /*!< key 0 low register */
+#define CAU_KEY1H REG32(CAU + 0x00000028U) /*!< key 1 high register */
+#define CAU_KEY1L REG32(CAU + 0x0000002CU) /*!< key 1 low register */
+#define CAU_KEY2H REG32(CAU + 0x00000030U) /*!< key 2 high register */
+#define CAU_KEY2L REG32(CAU + 0x00000034U) /*!< key 2 low register */
+#define CAU_KEY3H REG32(CAU + 0x00000038U) /*!< key 3 high register */
+#define CAU_KEY3L REG32(CAU + 0x0000003CU) /*!< key 3 low register */
+#define CAU_IV0H REG32(CAU + 0x00000040U) /*!< initial vector 0 high register */
+#define CAU_IV0L REG32(CAU + 0x00000044U) /*!< initial vector 0 low register */
+#define CAU_IV1H REG32(CAU + 0x00000048U) /*!< initial vector 1 high register */
+#define CAU_IV1L REG32(CAU + 0x0000004CU) /*!< initial vector 1 low register */
/* bits definitions */
/* CAU_CTL */
@@ -117,8 +114,7 @@ OF SUCH DAMAGE.
/* constants definitions */
/* structure for keys initialization of the cau */
-typedef struct
-{
+typedef struct {
uint32_t key_0_high; /*!< key 0 high */
uint32_t key_0_low; /*!< key 0 low */
uint32_t key_1_high; /*!< key 1 high */
@@ -127,28 +123,26 @@ typedef struct
uint32_t key_2_low; /*!< key 2 low */
uint32_t key_3_high; /*!< key 3 high */
uint32_t key_3_low; /*!< key 3 low */
-}cau_key_parameter_struct;
+} cau_key_parameter_struct;
/* structure for vectors initialization of the cau */
-typedef struct
-{
+typedef struct {
uint32_t iv_0_high; /*!< init vector 0 high */
uint32_t iv_0_low; /*!< init vector 0 low */
uint32_t iv_1_high; /*!< init vector 1 high */
uint32_t iv_1_low; /*!< init vector 1 low */
-}cau_iv_parameter_struct;
+} cau_iv_parameter_struct;
/* structure for vectors initialization of the cau */
-typedef struct
-{
+typedef struct {
uint8_t *input; /*!< pointer to the input buffer */
- uint32_t in_length; /*!< length of the input buffer,
+ uint32_t in_length; /*!< length of the input buffer,
must be a multiple of 8(DES and TDES) or 16(AES) */
uint8_t *output; /*!< pointer to the returned buffer */
-}cau_text_struct;
+} cau_text_struct;
/* cau_ctl register value */
-#define CAU_ENCRYPT ((uint32_t)0x00000000) /*!< encrypt */
+#define CAU_ENCRYPT ((uint32_t)0x00000000U) /*!< encrypt */
#define CAU_DECRYPT CAU_CTL_CAUDIR /*!< decrypt */
#define CTL_ALGM(regval) (BITS(3,5) & ((uint32_t)(regval) << 3)) /*!< write value to CAU_CTL_ALGM bit field */
@@ -172,7 +166,7 @@ typedef struct
#define CAU_KEYSIZE_192BIT CTL_KEYM(1) /*!< 192 bit key length */
#define CAU_KEYSIZE_256BIT CTL_KEYM(2) /*!< 256 bit key length */
-/* cau_stat0 register value */
+/* cau_stat0 register value */
#define CAU_FLAG_INFIFO_EMPTY CAU_STAT0_IEM /*!< IN FIFO empty */
#define CAU_FLAG_INFIFO_NO_FULL CAU_STAT0_INF /*!< IN FIFO is not full */
#define CAU_FLAG_OUTFIFO_NO_EMPTY CAU_STAT0_ONE /*!< OUT FIFO not empty */
@@ -212,13 +206,13 @@ void cau_init(uint32_t algo_dir, uint32_t algo_mode, uint32_t swapping);
/* configure key size if used AES algorithm */
void cau_aes_keysize_config(uint32_t key_size);
/* initialize the key parameters */
-void cau_key_init(cau_key_parameter_struct* key_initpara);
+void cau_key_init(cau_key_parameter_struct *key_initpara);
/* initialize the structure cau_key_initpara */
-void cau_key_parameter_init(cau_key_parameter_struct* key_initpara);
+void cau_key_parameter_init(cau_key_parameter_struct *key_initpara);
/* initialize the vectors parameters */
-void cau_iv_init(cau_iv_parameter_struct* iv_initpara);
+void cau_iv_init(cau_iv_parameter_struct *iv_initpara);
/* initialize the vectors parameters */
-void cau_iv_parameter_init(cau_iv_parameter_struct* iv_initpara);
+void cau_iv_parameter_init(cau_iv_parameter_struct *iv_initpara);
/* flush the IN and OUT FIFOs */
void cau_fifo_flush(void);
/* return whether CAU peripheral is enabled or disabled */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_crc.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_crc.h
index 4980cd3..721c230 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_crc.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_crc.h
@@ -2,36 +2,33 @@
\file gd32f20x_crc.h
\brief definitions for the CRC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,12 +38,12 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* CRC definitions */
-#define CRC CRC_BASE
+#define CRC CRC_BASE /*!< CRC base address */
/* registers definitions */
-#define CRC_DATA REG32(CRC + 0x00U) /*!< CRC data register */
-#define CRC_FDATA REG32(CRC + 0x04U) /*!< CRC free data register */
-#define CRC_CTL REG32(CRC + 0x08U) /*!< CRC control register */
+#define CRC_DATA REG32(CRC + 0x00000000U) /*!< CRC data register */
+#define CRC_FDATA REG32(CRC + 0x00000004U) /*!< CRC free data register */
+#define CRC_CTL REG32(CRC + 0x00000008U) /*!< CRC control register */
/* bits definitions */
/* CRC_DATA */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dac.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dac.h
index 0ef9fbf..c4dd08a 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dac.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dac.h
@@ -2,36 +2,33 @@
\file gd32f20x_dac.h
\brief definitions for the DAC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -46,76 +43,76 @@ OF SUCH DAMAGE.
#define DAC1 1U
/* registers definitions */
-#define DAC_CTL REG32(DAC + 0x00U) /*!< DAC control register */
-#define DAC_SWT REG32(DAC + 0x04U) /*!< DAC software trigger register */
-#define DAC0_R12DH REG32(DAC + 0x08U) /*!< DAC0 12-bit right-aligned data holding register */
-#define DAC0_L12DH REG32(DAC + 0x0CU) /*!< DAC0 12-bit left-aligned data holding register */
-#define DAC0_R8DH REG32(DAC + 0x10U) /*!< DAC0 8-bit right-aligned data holding register */
-#define DAC1_R12DH REG32(DAC + 0x14U) /*!< DAC1 12-bit right-aligned data holding register */
-#define DAC1_L12DH REG32(DAC + 0x18U) /*!< DAC1 12-bit left-aligned data holding register */
-#define DAC1_R8DH REG32(DAC + 0x1CU) /*!< DAC1 8-bit right-aligned data holding register */
-#define DACC_R12DH REG32(DAC + 0x20U) /*!< DAC concurrent mode 12-bit right-aligned data holding register */
-#define DACC_L12DH REG32(DAC + 0x24U) /*!< DAC concurrent mode 12-bit left-aligned data holding register */
-#define DACC_R8DH REG32(DAC + 0x28U) /*!< DAC concurrent mode 8-bit right-aligned data holding register */
-#define DAC0_DO REG32(DAC + 0x2CU) /*!< DAC0 data output register */
-#define DAC1_DO REG32(DAC + 0x30U) /*!< DAC1 data output register */
+#define DAC_CTL REG32(DAC + 0x00000000U) /*!< DAC control register */
+#define DAC_SWT REG32(DAC + 0x00000004U) /*!< DAC software trigger register */
+#define DAC0_R12DH REG32(DAC + 0x00000008U) /*!< DAC0 12-bit right-aligned data holding register */
+#define DAC0_L12DH REG32(DAC + 0x0000000CU) /*!< DAC0 12-bit left-aligned data holding register */
+#define DAC0_R8DH REG32(DAC + 0x00000010U) /*!< DAC0 8-bit right-aligned data holding register */
+#define DAC1_R12DH REG32(DAC + 0x00000014U) /*!< DAC1 12-bit right-aligned data holding register */
+#define DAC1_L12DH REG32(DAC + 0x00000018U) /*!< DAC1 12-bit left-aligned data holding register */
+#define DAC1_R8DH REG32(DAC + 0x0000001CU) /*!< DAC1 8-bit right-aligned data holding register */
+#define DACC_R12DH REG32(DAC + 0x00000020U) /*!< DAC concurrent mode 12-bit right-aligned data holding register */
+#define DACC_L12DH REG32(DAC + 0x00000024U) /*!< DAC concurrent mode 12-bit left-aligned data holding register */
+#define DACC_R8DH REG32(DAC + 0x00000028U) /*!< DAC concurrent mode 8-bit right-aligned data holding register */
+#define DAC0_DO REG32(DAC + 0x0000002CU) /*!< DAC0 data output register */
+#define DAC1_DO REG32(DAC + 0x00000030U) /*!< DAC1 data output register */
/* bits definitions */
/* DAC_CTL */
-#define DAC_CTL_DEN0 BIT(0) /*!< DAC0 enable/disable bit */
-#define DAC_CTL_DBOFF0 BIT(1) /*!< DAC0 output buffer turn on/off bit */
-#define DAC_CTL_DTEN0 BIT(2) /*!< DAC0 trigger enable/disable bit */
-#define DAC_CTL_DTSEL0 BITS(3,5) /*!< DAC0 trigger source selection enable/disable bits */
-#define DAC_CTL_DWM0 BITS(6,7) /*!< DAC0 noise wave mode */
-#define DAC_CTL_DWBW0 BITS(8,11) /*!< DAC0 noise wave bit width */
-#define DAC_CTL_DDMAEN0 BIT(12) /*!< DAC0 DMA enable/disable bit */
-#define DAC_CTL_DEN1 BIT(16) /*!< DAC1 enable/disable bit */
-#define DAC_CTL_DBOFF1 BIT(17) /*!< DAC1 output buffer turn on/turn off bit */
-#define DAC_CTL_DTEN1 BIT(18) /*!< DAC1 trigger enable/disable bit */
-#define DAC_CTL_DTSEL1 BITS(19,21) /*!< DAC1 trigger source selection enable/disable bits */
-#define DAC_CTL_DWM1 BITS(22,23) /*!< DAC1 noise wave mode */
-#define DAC_CTL_DWBW1 BITS(24,27) /*!< DAC1 noise wave bit width */
-#define DAC_CTL_DDMAEN1 BIT(28) /*!< DAC1 DMA enable/disable bit */
+#define DAC_CTL_DEN0 BIT(0) /*!< DAC0 enable/disable bit */
+#define DAC_CTL_DBOFF0 BIT(1) /*!< DAC0 output buffer turn on/off bit */
+#define DAC_CTL_DTEN0 BIT(2) /*!< DAC0 trigger enable/disable bit */
+#define DAC_CTL_DTSEL0 BITS(3,5) /*!< DAC0 trigger source selection enable/disable bits */
+#define DAC_CTL_DWM0 BITS(6,7) /*!< DAC0 noise wave mode */
+#define DAC_CTL_DWBW0 BITS(8,11) /*!< DAC0 noise wave bit width */
+#define DAC_CTL_DDMAEN0 BIT(12) /*!< DAC0 DMA enable/disable bit */
+#define DAC_CTL_DEN1 BIT(16) /*!< DAC1 enable/disable bit */
+#define DAC_CTL_DBOFF1 BIT(17) /*!< DAC1 output buffer turn on/turn off bit */
+#define DAC_CTL_DTEN1 BIT(18) /*!< DAC1 trigger enable/disable bit */
+#define DAC_CTL_DTSEL1 BITS(19,21) /*!< DAC1 trigger source selection enable/disable bits */
+#define DAC_CTL_DWM1 BITS(22,23) /*!< DAC1 noise wave mode */
+#define DAC_CTL_DWBW1 BITS(24,27) /*!< DAC1 noise wave bit width */
+#define DAC_CTL_DDMAEN1 BIT(28) /*!< DAC1 DMA enable/disable bit */
/* DAC_SWT */
-#define DAC_SWT_SWTR0 BIT(0) /*!< DAC0 software trigger bit, cleared by hardware */
-#define DAC_SWT_SWTR1 BIT(1) /*!< DAC1 software trigger bit, cleared by hardware */
+#define DAC_SWT_SWTR0 BIT(0) /*!< DAC0 software trigger bit, cleared by hardware */
+#define DAC_SWT_SWTR1 BIT(1) /*!< DAC1 software trigger bit, cleared by hardware */
/* DAC0_R12DH */
-#define DAC0_R12DH_DAC0_DH BITS(0,11) /*!< DAC0 12-bit right-aligned data bits */
+#define DAC0_R12DH_DAC0_DH BITS(0,11) /*!< DAC0 12-bit right-aligned data bits */
/* DAC0_L12DH */
-#define DAC0_L12DH_DAC0_DH BITS(4,15) /*!< DAC0 12-bit left-aligned data bits */
+#define DAC0_L12DH_DAC0_DH BITS(4,15) /*!< DAC0 12-bit left-aligned data bits */
/* DAC0_R8DH */
-#define DAC0_R8DH_DAC0_DH BITS(0,7) /*!< DAC0 8-bit right-aligned data bits */
+#define DAC0_R8DH_DAC0_DH BITS(0,7) /*!< DAC0 8-bit right-aligned data bits */
/* DAC1_R12DH */
-#define DAC1_R12DH_DAC1_DH BITS(0,11) /*!< DAC1 12-bit right-aligned data bits */
+#define DAC1_R12DH_DAC1_DH BITS(0,11) /*!< DAC1 12-bit right-aligned data bits */
/* DAC1_L12DH */
-#define DAC1_L12DH_DAC1_DH BITS(4,15) /*!< DAC1 12-bit left-aligned data bits */
+#define DAC1_L12DH_DAC1_DH BITS(4,15) /*!< DAC1 12-bit left-aligned data bits */
/* DAC1_R8DH */
-#define DAC1_R8DH_DAC1_DH BITS(0,7) /*!< DAC1 8-bit right-aligned data bits */
+#define DAC1_R8DH_DAC1_DH BITS(0,7) /*!< DAC1 8-bit right-aligned data bits */
/* DACC_R12DH */
-#define DACC_R12DH_DAC0_DH BITS(0,11) /*!< DAC concurrent mode DAC0 12-bit right-aligned data bits */
-#define DACC_R12DH_DAC1_DH BITS(16,27) /*!< DAC concurrent mode DAC1 12-bit right-aligned data bits */
+#define DACC_R12DH_DAC0_DH BITS(0,11) /*!< DAC concurrent mode DAC0 12-bit right-aligned data bits */
+#define DACC_R12DH_DAC1_DH BITS(16,27) /*!< DAC concurrent mode DAC1 12-bit right-aligned data bits */
/* DACC_L12DH */
-#define DACC_L12DH_DAC0_DH BITS(4,15) /*!< DAC concurrent mode DAC0 12-bit left-aligned data bits */
-#define DACC_L12DH_DAC1_DH BITS(20,31) /*!< DAC concurrent mode DAC1 12-bit left-aligned data bits */
+#define DACC_L12DH_DAC0_DH BITS(4,15) /*!< DAC concurrent mode DAC0 12-bit left-aligned data bits */
+#define DACC_L12DH_DAC1_DH BITS(20,31) /*!< DAC concurrent mode DAC1 12-bit left-aligned data bits */
/* DACC_R8DH */
-#define DACC_R8DH_DAC0_DH BITS(0,7) /*!< DAC concurrent mode DAC0 8-bit right-aligned data bits */
-#define DACC_R8DH_DAC1_DH BITS(8,15) /*!< DAC concurrent mode DAC1 8-bit right-aligned data bits */
+#define DACC_R8DH_DAC0_DH BITS(0,7) /*!< DAC concurrent mode DAC0 8-bit right-aligned data bits */
+#define DACC_R8DH_DAC1_DH BITS(8,15) /*!< DAC concurrent mode DAC1 8-bit right-aligned data bits */
/* DAC0_DO */
-#define DAC0_DO_DAC0_DO BITS(0,11) /*!< DAC0 12-bit output data bits */
+#define DAC0_DO_DAC0_DO BITS(0,11) /*!< DAC0 12-bit output data bits */
/* DAC1_DO */
-#define DAC1_DO_DAC1_DO BITS(0,11) /*!< DAC1 12-bit output data bits */
+#define DAC1_DO_DAC1_DO BITS(0,11) /*!< DAC1 12-bit output data bits */
/* constants definitions */
/* DAC trigger source */
@@ -195,12 +192,12 @@ void dac_disable(uint32_t dac_periph);
/* enable DAC DMA */
void dac_dma_enable(uint32_t dac_periph);
/* disable DAC DMA */
-void dac_dma_disable(uint32_t dac_periph);
+void dac_dma_disable(uint32_t dac_periph);
/* enable DAC output buffer */
void dac_output_buffer_enable(uint32_t dac_periph);
/* disable DAC output buffer */
void dac_output_buffer_disable(uint32_t dac_periph);
-/* get the last data output value */
+/* get DAC output value */
uint16_t dac_output_value_get(uint32_t dac_periph);
/* set DAC data holding register value */
void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data);
@@ -242,6 +239,6 @@ void dac_concurrent_output_buffer_enable(void);
/* disable DAC concurrent buffer function */
void dac_concurrent_output_buffer_disable(void);
/* set DAC concurrent mode data holding register value */
-void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1);
+void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1);
#endif /* GD32F20X_DAC_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dbg.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dbg.h
index 0029be4..93adde3 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dbg.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dbg.h
@@ -2,37 +2,33 @@
\file gd32f20x_dbg.h
\brief definitions for the DBG
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
- \version 2020-12-14, V2.2.1, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,15 +38,15 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* DBG definitions */
-#define DBG DBG_BASE
+#define DBG DBG_BASE
/* registers definitions */
-#define DBG_ID REG32(DBG + 0x00U) /*!< DBG_ID code register */
-#define DBG_CTL REG32(DBG + 0x04U) /*!< DBG control register */
+#define DBG_ID REG32(DBG + 0x00000000U) /*!< DBG_ID code register */
+#define DBG_CTL REG32(DBG + 0x00000004U) /*!< DBG control register */
/* bits definitions */
/* DBG_ID */
-#define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
+#define DBG_ID_ID_CODE BITS(0,31) /*!< DBG ID code values */
/* DBG_CTL */
#define DBG_CTL_SLP_HOLD BIT(0) /*!< keep debugger connection during sleep mode */
@@ -78,32 +74,33 @@ OF SUCH DAMAGE.
#define DBG_CTL_TIMER8_HOLD BIT(28) /*!< hold TIMER8 counter when core is halted */
#define DBG_CTL_TIMER9_HOLD BIT(29) /*!< hold TIMER9 counter when core is halted */
#define DBG_CTL_TIMER10_HOLD BIT(30) /*!< hold TIMER10 counter when core is halted */
+#define DBG_CTL_I2C2_HOLD BIT(31) /*!< hold I2C2 smbus when core is halted */
/* constants definitions */
/* debug hold when core is halted */
-typedef enum
-{
- DBG_FWDGT_HOLD = BIT(8), /*!< debug FWDGT kept when core is halted */
- DBG_WWDGT_HOLD = BIT(9), /*!< debug WWDGT kept when core is halted */
- DBG_TIMER0_HOLD = BIT(10), /*!< hold TIMER0 counter when core is halted */
- DBG_TIMER1_HOLD = BIT(11), /*!< hold TIMER1 counter when core is halted */
- DBG_TIMER2_HOLD = BIT(12), /*!< hold TIMER2 counter when core is halted */
- DBG_TIMER3_HOLD = BIT(13), /*!< hold TIMER3 counter when core is halted */
- DBG_CAN0_HOLD = BIT(14), /*!< debug CAN0 kept when core is halted */
- DBG_I2C0_HOLD = BIT(15), /*!< hold I2C0 smbus when core is halted */
- DBG_I2C1_HOLD = BIT(16), /*!< hold I2C1 smbus when core is halted */
- DBG_TIMER7_HOLD = BIT(17), /*!< hold TIMER7 counter when core is halted */
- DBG_TIMER4_HOLD = BIT(18), /*!< hold TIMER4 counter when core is halted */
- DBG_TIMER5_HOLD = BIT(19), /*!< hold TIMER5 counter when core is halted */
- DBG_TIMER6_HOLD = BIT(20), /*!< hold TIMER6 counter when core is halted */
- DBG_CAN1_HOLD = BIT(21), /*!< debug CAN1 kept when core is halted */
- DBG_TIMER11_HOLD = BIT(25), /*!< hold TIMER11 counter when core is halted */
- DBG_TIMER12_HOLD = BIT(26), /*!< hold TIMER12 counter when core is halted */
- DBG_TIMER13_HOLD = BIT(27), /*!< hold TIMER13 counter when core is halted */
- DBG_TIMER8_HOLD = BIT(28), /*!< hold TIMER8 counter when core is halted */
- DBG_TIMER9_HOLD = BIT(29), /*!< hold TIMER9 counter when core is halted */
- DBG_TIMER10_HOLD = BIT(30), /*!< hold TIMER10 counter when core is halted */
-}dbg_periph_enum;
+typedef enum {
+ DBG_FWDGT_HOLD = (int)BIT(8), /*!< debug FWDGT kept when core is halted */
+ DBG_WWDGT_HOLD = (int)BIT(9), /*!< debug WWDGT kept when core is halted */
+ DBG_TIMER0_HOLD = (int)BIT(10), /*!< hold TIMER0 counter when core is halted */
+ DBG_TIMER1_HOLD = (int)BIT(11), /*!< hold TIMER1 counter when core is halted */
+ DBG_TIMER2_HOLD = (int)BIT(12), /*!< hold TIMER2 counter when core is halted */
+ DBG_TIMER3_HOLD = (int)BIT(13), /*!< hold TIMER3 counter when core is halted */
+ DBG_CAN0_HOLD = (int)BIT(14), /*!< debug CAN0 kept when core is halted */
+ DBG_I2C0_HOLD = (int)BIT(15), /*!< hold I2C0 smbus when core is halted */
+ DBG_I2C1_HOLD = (int)BIT(16), /*!< hold I2C1 smbus when core is halted */
+ DBG_TIMER7_HOLD = (int)BIT(17), /*!< hold TIMER7 counter when core is halted */
+ DBG_TIMER4_HOLD = (int)BIT(18), /*!< hold TIMER4 counter when core is halted */
+ DBG_TIMER5_HOLD = (int)BIT(19), /*!< hold TIMER5 counter when core is halted */
+ DBG_TIMER6_HOLD = (int)BIT(20), /*!< hold TIMER6 counter when core is halted */
+ DBG_CAN1_HOLD = (int)BIT(21), /*!< debug CAN1 kept when core is halted */
+ DBG_TIMER11_HOLD = (int)BIT(25), /*!< hold TIMER11 counter when core is halted */
+ DBG_TIMER12_HOLD = (int)BIT(26), /*!< hold TIMER12 counter when core is halted */
+ DBG_TIMER13_HOLD = (int)BIT(27), /*!< hold TIMER13 counter when core is halted */
+ DBG_TIMER8_HOLD = (int)BIT(28), /*!< hold TIMER8 counter when core is halted */
+ DBG_TIMER9_HOLD = (int)BIT(29), /*!< hold TIMER9 counter when core is halted */
+ DBG_TIMER10_HOLD = (int)BIT(30), /*!< hold TIMER10 counter when core is halted */
+ DBG_I2C2_HOLD = (int)BIT(31), /*!< hold I2C2 smbus when core is halted */
+} dbg_periph_enum;
/* DBG low power mode configurations */
#define DBG_LOW_POWER_SLEEP DBG_CTL_SLP_HOLD /*!< keep debugger connection during sleep mode */
@@ -111,7 +108,7 @@ typedef enum
#define DBG_LOW_POWER_STANDBY DBG_CTL_STB_HOLD /*!< keep debugger connection during standby mode */
/* DBG_CTL0_TRACE_MODE configurations */
-#define CTL_TRACE_MODE(regval) (BITS(6,7) & ((uint32_t)(regval) << 6U))
+#define CTL_TRACE_MODE(regval) (BITS(6,7) & ((uint32_t)(regval) << 6U))
#define TRACE_MODE_ASYNC CTL_TRACE_MODE(0) /*!< trace pin used for async mode */
#define TRACE_MODE_SYNC_DATASIZE_1 CTL_TRACE_MODE(1) /*!< trace pin used for sync mode and data size is 1 */
#define TRACE_MODE_SYNC_DATASIZE_2 CTL_TRACE_MODE(2) /*!< trace pin used for sync mode and data size is 2 */
@@ -119,7 +116,7 @@ typedef enum
/* function declarations */
/* initialization functions */
-/* read DBG_ID code register */
+/* read DBG_ID register */
uint32_t dbg_id_get(void);
/* function configuration */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dci.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dci.h
index 1e779a2..8b9d818 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dci.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dci.h
@@ -2,36 +2,33 @@
\file gd32f20x_dci.h
\brief definitions for the DCI
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -125,15 +122,14 @@ OF SUCH DAMAGE.
/* constants definitions */
/* DCI parameter structure definitions */
-typedef struct
-{
+typedef struct {
uint32_t capture_mode; /*!< DCI capture mode: continuous or snapshot */
uint32_t clock_polarity; /*!< clock polarity selection */
uint32_t hsync_polarity; /*!< horizontal polarity selection */
uint32_t vsync_polarity; /*!< vertical polarity selection */
uint32_t frame_rate; /*!< frame capture rate */
uint32_t interface_format; /*!< digital camera interface format */
-}dci_parameter_struct;
+} dci_parameter_struct;
#define DCI_CAPTURE_MODE_CONTINUOUS ((uint32_t)0x00000000U) /*!< continuous capture mode */
#define DCI_CAPTURE_MODE_SNAPSHOT DCI_CTL_SNAP /*!< snapshot capture mode */
@@ -146,13 +142,13 @@ typedef struct
#define DCI_VSYNC_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level during blanking period */
#define DCI_VSYNC_POLARITY_HIGH DCI_CTL_VPS /*!< high level during blanking period*/
-
-#define CTL_FR(regval) (BITS(8,9)&((uint32_t)(regval) << 8U))
+
+#define CTL_FR(regval) (BITS(8,9)&((uint32_t)(regval) << 8U))
#define DCI_FRAME_RATE_ALL CTL_FR(0) /*!< capture all frames */
#define DCI_FRAME_RATE_1_2 CTL_FR(1) /*!< capture one in 2 frames */
#define DCI_FRAME_RATE_1_4 CTL_FR(2) /*!< capture one in 4 frames */
-#define CTL_DCIF(regval) (BITS(10,11)&((uint32_t)(regval) << 10U))
+#define CTL_DCIF(regval) (BITS(10,11)&((uint32_t)(regval) << 10U))
#define DCI_INTERFACE_FORMAT_8BITS CTL_DCIF(0) /*!< 8-bit data on every pixel clock */
#define DCI_INTERFACE_FORMAT_10BITS CTL_DCIF(1) /*!< 10-bit data on every pixel clock */
#define DCI_INTERFACE_FORMAT_12BITS CTL_DCIF(2) /*!< 12-bit data on every pixel clock */
@@ -172,7 +168,7 @@ typedef struct
#define DCI_INT_FLAG_VSYNC BIT(3) /*!< vsync interrupt flag */
#define DCI_INT_FLAG_EL BIT(4) /*!< end of line interrupt flag */
-/* DCI flag definitions */
+/* DCI flag definitions */
#define DCI_FLAG_HS DCI_STAT0_HS /*!< HS line status */
#define DCI_FLAG_VS DCI_STAT0_VS /*!< VS line status */
#define DCI_FLAG_FV DCI_STAT0_FV /*!< FIFO valid */
@@ -187,7 +183,7 @@ typedef struct
/* DCI deinit */
void dci_deinit(void);
/* initialize DCI registers */
-void dci_init(dci_parameter_struct* dci_struct);
+void dci_init(dci_parameter_struct *dci_struct);
/* enable DCI function */
void dci_enable(void);
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dma.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dma.h
index aefef26..c1ffc25 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dma.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_dma.h
@@ -2,36 +2,33 @@
\file gd32f20x_dma.h
\brief definitions for the DMA
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,118 +38,115 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* DMA definitions */
-#define DMA0 (DMA_BASE) /*!< DMA0 base address */
-#define DMA1 (DMA_BASE + 0x0400U) /*!< DMA1 base address */
+#define DMA0 (DMA_BASE) /*!< DMA0 base address */
+#define DMA1 (DMA_BASE + 0x00000400U) /*!< DMA1 base address */
/* registers definitions */
-#define DMA_INTF(dmax) REG32((dmax) + 0x00U) /*!< DMA interrupt flag register */
-#define DMA_INTC(dmax) REG32((dmax) + 0x04U) /*!< DMA interrupt flag clear register */
-
-#define DMA_CH0CTL(dmax) REG32((dmax) + 0x08U) /*!< DMA channel 0 control register */
-#define DMA_CH0CNT(dmax) REG32((dmax) + 0x0CU) /*!< DMA channel 0 counter register */
-#define DMA_CH0PADDR(dmax) REG32((dmax) + 0x10U) /*!< DMA channel 0 peripheral base address register */
-#define DMA_CH0MADDR(dmax) REG32((dmax) + 0x14U) /*!< DMA channel 0 memory base address register */
-
-#define DMA_CH1CTL(dmax) REG32((dmax) + 0x1CU) /*!< DMA channel 1 control register */
-#define DMA_CH1CNT(dmax) REG32((dmax) + 0x20U) /*!< DMA channel 1 counter register */
-#define DMA_CH1PADDR(dmax) REG32((dmax) + 0x24U) /*!< DMA channel 1 peripheral base address register */
-#define DMA_CH1MADDR(dmax) REG32((dmax) + 0x28U) /*!< DMA channel 1 memory base address register */
-
-#define DMA_CH2CTL(dmax) REG32((dmax) + 0x30U) /*!< DMA channel 2 control register */
-#define DMA_CH2CNT(dmax) REG32((dmax) + 0x34U) /*!< DMA channel 2 counter register */
-#define DMA_CH2PADDR(dmax) REG32((dmax) + 0x38U) /*!< DMA channel 2 peripheral base address register */
-#define DMA_CH2MADDR(dmax) REG32((dmax) + 0x3CU) /*!< DMA channel 2 memory base address register */
-
-#define DMA_CH3CTL(dmax) REG32((dmax) + 0x44U) /*!< DMA channel 3 control register */
-#define DMA_CH3CNT(dmax) REG32((dmax) + 0x48U) /*!< DMA channel 3 counter register */
-#define DMA_CH3PADDR(dmax) REG32((dmax) + 0x4CU) /*!< DMA channel 3 peripheral base address register */
-#define DMA_CH3MADDR(dmax) REG32((dmax) + 0x50U) /*!< DMA channel 3 memory base address register */
-
-#define DMA_CH4CTL(dmax) REG32((dmax) + 0x58U) /*!< DMA channel 4 control register */
-#define DMA_CH4CNT(dmax) REG32((dmax) + 0x5CU) /*!< DMA channel 4 counter register */
-#define DMA_CH4PADDR(dmax) REG32((dmax) + 0x60U) /*!< DMA channel 4 peripheral base address register */
-#define DMA_CH4MADDR(dmax) REG32((dmax) + 0x64U) /*!< DMA channel 4 memory base address register */
-
-#define DMA_CH5CTL(dmax) REG32((dmax) + 0x6CU) /*!< DMA channel 5 control register */
-#define DMA_CH5CNT(dmax) REG32((dmax) + 0x70U) /*!< DMA channel 5 counter register */
-#define DMA_CH5PADDR(dmax) REG32((dmax) + 0x74U) /*!< DMA channel 5 peripheral base address register */
-#define DMA_CH5MADDR(dmax) REG32((dmax) + 0x78U) /*!< DMA channel 5 memory base address register */
-
-#define DMA_CH6CTL(dmax) REG32((dmax) + 0x80U) /*!< DMA channel 6 control register */
-#define DMA_CH6CNT(dmax) REG32((dmax) + 0x84U) /*!< DMA channel 6 counter register */
-#define DMA_CH6PADDR(dmax) REG32((dmax) + 0x88U) /*!< DMA channel 6 peripheral base address register */
-#define DMA_CH6MADDR(dmax) REG32((dmax) + 0x8CU) /*!< DMA channel 6 memory base address register */
-
-#define DMA_ACFG REG32((DMA1) + 0x300U) /*!< DMA additional configuration register */
+#define DMA_INTF(dmax) REG32((dmax) + 0x00000000U) /*!< DMA interrupt flag register */
+#define DMA_INTC(dmax) REG32((dmax) + 0x00000004U) /*!< DMA interrupt flag clear register */
+
+#define DMA_CH0CTL(dmax) REG32((dmax) + 0x00000008U) /*!< DMA channel 0 control register */
+#define DMA_CH0CNT(dmax) REG32((dmax) + 0x0000000CU) /*!< DMA channel 0 counter register */
+#define DMA_CH0PADDR(dmax) REG32((dmax) + 0x00000010U) /*!< DMA channel 0 peripheral base address register */
+#define DMA_CH0MADDR(dmax) REG32((dmax) + 0x00000014U) /*!< DMA channel 0 memory base address register */
+
+#define DMA_CH1CTL(dmax) REG32((dmax) + 0x0000001CU) /*!< DMA channel 1 control register */
+#define DMA_CH1CNT(dmax) REG32((dmax) + 0x00000020U) /*!< DMA channel 1 counter register */
+#define DMA_CH1PADDR(dmax) REG32((dmax) + 0x00000024U) /*!< DMA channel 1 peripheral base address register */
+#define DMA_CH1MADDR(dmax) REG32((dmax) + 0x00000028U) /*!< DMA channel 1 memory base address register */
+
+#define DMA_CH2CTL(dmax) REG32((dmax) + 0x00000030U) /*!< DMA channel 2 control register */
+#define DMA_CH2CNT(dmax) REG32((dmax) + 0x00000034U) /*!< DMA channel 2 counter register */
+#define DMA_CH2PADDR(dmax) REG32((dmax) + 0x00000038U) /*!< DMA channel 2 peripheral base address register */
+#define DMA_CH2MADDR(dmax) REG32((dmax) + 0x0000003CU) /*!< DMA channel 2 memory base address register */
+
+#define DMA_CH3CTL(dmax) REG32((dmax) + 0x00000044U) /*!< DMA channel 3 control register */
+#define DMA_CH3CNT(dmax) REG32((dmax) + 0x00000048U) /*!< DMA channel 3 counter register */
+#define DMA_CH3PADDR(dmax) REG32((dmax) + 0x0000004CU) /*!< DMA channel 3 peripheral base address register */
+#define DMA_CH3MADDR(dmax) REG32((dmax) + 0x00000050U) /*!< DMA channel 3 memory base address register */
+
+#define DMA_CH4CTL(dmax) REG32((dmax) + 0x00000058U) /*!< DMA channel 4 control register */
+#define DMA_CH4CNT(dmax) REG32((dmax) + 0x0000005CU) /*!< DMA channel 4 counter register */
+#define DMA_CH4PADDR(dmax) REG32((dmax) + 0x00000060U) /*!< DMA channel 4 peripheral base address register */
+#define DMA_CH4MADDR(dmax) REG32((dmax) + 0x00000064U) /*!< DMA channel 4 memory base address register */
+
+#define DMA_CH5CTL(dmax) REG32((dmax) + 0x0000006CU) /*!< DMA channel 5 control register */
+#define DMA_CH5CNT(dmax) REG32((dmax) + 0x00000070U) /*!< DMA channel 5 counter register */
+#define DMA_CH5PADDR(dmax) REG32((dmax) + 0x00000074U) /*!< DMA channel 5 peripheral base address register */
+#define DMA_CH5MADDR(dmax) REG32((dmax) + 0x00000078U) /*!< DMA channel 5 memory base address register */
+
+#define DMA_CH6CTL(dmax) REG32((dmax) + 0x00000080U) /*!< DMA channel 6 control register */
+#define DMA_CH6CNT(dmax) REG32((dmax) + 0x00000084U) /*!< DMA channel 6 counter register */
+#define DMA_CH6PADDR(dmax) REG32((dmax) + 0x00000088U) /*!< DMA channel 6 peripheral base address register */
+#define DMA_CH6MADDR(dmax) REG32((dmax) + 0x0000008CU) /*!< DMA channel 6 memory base address register */
+
+#define DMA_ACFG REG32((DMA1) + 0x00000300U) /*!< DMA additional configuration register */
/* bits definitions */
/* DMA_INTF */
-#define DMA_INTF_GIF BIT(0) /*!< global interrupt flag of channel */
-#define DMA_INTF_FTFIF BIT(1) /*!< full transfer finish flag of channel */
-#define DMA_INTF_HTFIF BIT(2) /*!< half transfer finish flag of channel */
-#define DMA_INTF_ERRIF BIT(3) /*!< error flag of channel */
+#define DMA_INTF_GIF BIT(0) /*!< global interrupt flag of channel */
+#define DMA_INTF_FTFIF BIT(1) /*!< full transfer finish flag of channel */
+#define DMA_INTF_HTFIF BIT(2) /*!< half transfer finish flag of channel */
+#define DMA_INTF_ERRIF BIT(3) /*!< error flag of channel */
/* DMA_INTC */
-#define DMA_INTC_GIFC BIT(0) /*!< clear global interrupt flag of channel */
-#define DMA_INTC_FTFIFC BIT(1) /*!< clear transfer finish flag of channel */
-#define DMA_INTC_HTFIFC BIT(2) /*!< clear half transfer finish flag of channel */
-#define DMA_INTC_ERRIFC BIT(3) /*!< clear error flag of channel */
+#define DMA_INTC_GIFC BIT(0) /*!< clear global interrupt flag of channel */
+#define DMA_INTC_FTFIFC BIT(1) /*!< clear transfer finish flag of channel */
+#define DMA_INTC_HTFIFC BIT(2) /*!< clear half transfer finish flag of channel */
+#define DMA_INTC_ERRIFC BIT(3) /*!< clear error flag of channel */
/* DMA_CHxCTL, x=0..6 */
-#define DMA_CHXCTL_CHEN BIT(0) /*!< channel enable */
-#define DMA_CHXCTL_FTFIE BIT(1) /*!< enable bit for channel full transfer finish interrupt */
-#define DMA_CHXCTL_HTFIE BIT(2) /*!< enable bit for channel half transfer finish interrupt */
-#define DMA_CHXCTL_ERRIE BIT(3) /*!< enable bit for channel error interrupt */
-#define DMA_CHXCTL_DIR BIT(4) /*!< transfer direction */
-#define DMA_CHXCTL_CMEN BIT(5) /*!< circular mode enable */
-#define DMA_CHXCTL_PNAGA BIT(6) /*!< next address generation algorithm of peripheral */
-#define DMA_CHXCTL_MNAGA BIT(7) /*!< next address generation algorithm of memory */
-#define DMA_CHXCTL_PWIDTH BITS(8,9) /*!< transfer data width of peripheral */
-#define DMA_CHXCTL_MWIDTH BITS(10,11) /*!< transfer data width of memory */
-#define DMA_CHXCTL_PRIO BITS(12,13) /*!< priority level */
-#define DMA_CHXCTL_M2M BIT(14) /*!< memory to memory mode */
+#define DMA_CHXCTL_CHEN BIT(0) /*!< channel enable */
+#define DMA_CHXCTL_FTFIE BIT(1) /*!< enable bit for channel full transfer finish interrupt */
+#define DMA_CHXCTL_HTFIE BIT(2) /*!< enable bit for channel half transfer finish interrupt */
+#define DMA_CHXCTL_ERRIE BIT(3) /*!< enable bit for channel error interrupt */
+#define DMA_CHXCTL_DIR BIT(4) /*!< transfer direction */
+#define DMA_CHXCTL_CMEN BIT(5) /*!< enable circular mode */
+#define DMA_CHXCTL_PNAGA BIT(6) /*!< next address generation algorithm of peripheral */
+#define DMA_CHXCTL_MNAGA BIT(7) /*!< next address generation algorithm of memory */
+#define DMA_CHXCTL_PWIDTH BITS(8,9) /*!< transfer data width of peripheral */
+#define DMA_CHXCTL_MWIDTH BITS(10,11) /*!< transfer data width of memory */
+#define DMA_CHXCTL_PRIO BITS(12,13) /*!< priority level */
+#define DMA_CHXCTL_M2M BIT(14) /*!< memory to memory mode */
/* DMA_CHxCNT, x=0..6 */
-#define DMA_CHXCNT_CNT BITS(0,15) /*!< transfer counter */
+#define DMA_CHXCNT_CNT BITS(0,15) /*!< transfer counter */
/* DMA_CHxPADDR, x=0..6 */
-#define DMA_CHXPADDR_PADDR BITS(0,31) /*!< peripheral base address */
+#define DMA_CHXPADDR_PADDR BITS(0,31) /*!< peripheral base address */
/* DMA_CHxMADDR, x=0..6 */
-#define DMA_CHXMADDR_MADDR BITS(0,31) /*!< memory base address */
+#define DMA_CHXMADDR_MADDR BITS(0,31) /*!< memory base address */
/* DMA_ACFG */
-#define DMA_ACFG_FD_CH5EN BIT(5) /*!< enable bit for DMA1 channel 5 Full_Data transfer mode */
+#define DMA_ACFG_FD_CH5EN BIT(5) /*!< enable bit for DMA1 channel 5 Full_Data transfer mode */
/* constants definitions */
-/* DMA channel select */
-typedef enum
-{
- DMA_CH0 = 0, /*!< DMA channel 0 */
- DMA_CH1, /*!< DMA channel 1 */
- DMA_CH2, /*!< DMA channel 2 */
- DMA_CH3, /*!< DMA channel 3 */
- DMA_CH4, /*!< DMA channel 4 */
- DMA_CH5, /*!< DMA channel 5 */
- DMA_CH6 /*!< DMA channel 6 */
+/* DMA channel selection */
+typedef enum {
+ DMA_CH0 = 0, /*!< DMA channel 0 */
+ DMA_CH1, /*!< DMA channel 1 */
+ DMA_CH2, /*!< DMA channel 2 */
+ DMA_CH3, /*!< DMA channel 3 */
+ DMA_CH4, /*!< DMA channel 4 */
+ DMA_CH5, /*!< DMA channel 5 */
+ DMA_CH6 /*!< DMA channel 6 */
} dma_channel_enum;
-/* DMA initialize struct */
-typedef struct
-{
- uint32_t periph_addr; /*!< peripheral base address */
- uint32_t periph_width; /*!< transfer data size of peripheral */
- uint32_t memory_addr; /*!< memory base address */
- uint32_t memory_width; /*!< transfer data size of memory */
- uint32_t number; /*!< channel transfer number */
- uint32_t priority; /*!< channel priority level */
- uint8_t periph_inc; /*!< peripheral increasing mode */
- uint8_t memory_inc; /*!< memory increasing mode */
- uint8_t direction; /*!< channel data transfer direction */
-
+/* DMA initialize structure */
+typedef struct {
+ uint32_t periph_addr; /*!< peripheral base address */
+ uint32_t periph_width; /*!< transfer data size of peripheral */
+ uint32_t memory_addr; /*!< memory base address */
+ uint32_t memory_width; /*!< transfer data size of memory */
+ uint32_t number; /*!< channel transfer number */
+ uint32_t priority; /*!< channel priority level */
+ uint8_t periph_inc; /*!< peripheral increasing mode */
+ uint8_t memory_inc; /*!< memory increasing mode */
+ uint8_t direction; /*!< channel data transfer direction */
} dma_parameter_struct;
-#define DMA_FLAG_ADD(flag, shift) ((flag) << ((shift) * 4U)) /*!< DMA channel flag shift */
+#define DMA_FLAG_ADD(flag, shift) ((flag) << ((shift) * 4U)) /*!< DMA channel flag shift */
/* DMA_register address */
#define DMA_CHCTL(dma, channel) REG32(((dma) + 0x08U) + 0x14U * (uint32_t)(channel)) /*!< the address of DMA channel CHXCTL register */
@@ -233,10 +227,10 @@ typedef struct
/* function declarations */
/* initialization functions */
-/* deinitialize DMA a channel registers */
+/* deinitialize a DMA channel registers */
void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx);
/* initialize the parameters of DMA structure with the default values */
-void dma_struct_para_init(dma_parameter_struct* init_struct);
+void dma_struct_para_init(dma_parameter_struct *init_struct);
/* initialize DMA channel */
void dma_init(uint32_t dma_periph, dma_channel_enum channelx, dma_parameter_struct *init_struct);
/* enable DMA circulation mode */
@@ -278,23 +272,23 @@ void dma_periph_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
/* configure the direction of data transfer on the channel */
void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t direction);
+/* enable the DMA1 channel 5 Full_Data transfer mode */
+void dma_1_channel_5_fulldata_transfer_enable(void);
+/* disable the DMA1 channel 5 Full_Data transfer mode */
+void dma_1_channel_5_fulldata_transfer_disable(void);
+
/* flag and interrupt functions */
/* check DMA flag is set or not */
FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
/* clear the flag of a DMA channel */
void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
-/* check DMA flag and interrupt enable bit is set or not */
-FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
-/* clear the interrupt flag of a DMA channel */
-void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
/* enable DMA interrupt */
void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source);
/* disable DMA interrupt */
void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source);
-
-/* enable the DMA1 channel 5 Full_Data transfer mode */
-void dma_1_channel_5_fulldata_transfer_enable(void);
-/* disable the DMA1 channel 5 Full_Data transfer mode */
-void dma_1_channel_5_fulldata_transfer_disable(void);
+/* check DMA flag and interrupt enable bit is set or not */
+FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
+/* clear the interrupt flag of a DMA channel */
+void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
#endif /* GD32F20X_DMA_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_enet.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_enet.h
index 689448a..822ef36 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_enet.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_enet.h
@@ -2,36 +2,33 @@
\file gd32f20x_enet.h
\brief definitions for the ENET
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,17 +38,17 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
#include
-#define IF_USE_EXTERNPHY_LIB 0
+#define IF_USE_EXTERNPHY_LIB 0U
#if (1 == IF_USE_EXTERNPHY_LIB)
#include "phy.h"
#endif
#ifndef ENET_RXBUF_NUM
-#define ENET_RXBUF_NUM 2U /*!< ethernet Rx DMA descriptor number */
+#define ENET_RXBUF_NUM 5U /*!< ethernet Rx DMA descriptor number */
#endif
#ifndef ENET_TXBUF_NUM
-#define ENET_TXBUF_NUM 1U /*!< ethernet Tx DMA descriptor number */
+#define ENET_TXBUF_NUM 5U /*!< ethernet Tx DMA descriptor number */
#endif
#ifndef ENET_RXBUF_SIZE
@@ -74,7 +71,7 @@ OF SUCH DAMAGE.
#define PHY_ADDRESS ((uint16_t)1U) /*!< phy address determined by the hardware */
-/* PHY read write timeouts */
+/* PHY read write timeouts */
#define PHY_READ_TO ((uint32_t)0x0004FFFFU) /*!< PHY read timeout */
#define PHY_WRITE_TO ((uint32_t)0x0004FFFFU) /*!< PHY write timeout */
@@ -82,35 +79,35 @@ OF SUCH DAMAGE.
#define PHY_RESETDELAY ((uint32_t)0x008FFFFFU) /*!< PHY reset delay */
#define PHY_CONFIGDELAY ((uint32_t)0x00FFFFFFU) /*!< PHY configure delay */
-/* PHY register address */
+/* PHY register address */
#define PHY_REG_BCR 0U /*!< tranceiver basic control register */
#define PHY_REG_BSR 1U /*!< tranceiver basic status register */
/* PHY basic control register */
-#define PHY_RESET ((uint16_t)0x8000) /*!< PHY reset */
-#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< enable phy loop-back mode */
-#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< configure speed to 100 Mbit/s and the full-duplex mode */
-#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< configure speed to 100 Mbit/s and the half-duplex mode */
-#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< configure speed to 10 Mbit/s and the full-duplex mode */
-#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< configure speed to 10 Mbit/s and the half-duplex mode */
-#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< enable auto-negotiation function */
-#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< restart auto-negotiation function */
-#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< enable the power down mode */
-#define PHY_ISOLATE ((uint16_t)0x0400) /*!< isolate PHY from MII */
+#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< enable phy loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< configure speed to 100 Mbit/s and the full-duplex mode */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< configure speed to 100 Mbit/s and the half-duplex mode */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< configure speed to 10 Mbit/s and the full-duplex mode */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< configure speed to 10 Mbit/s and the half-duplex mode */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< enable the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< isolate PHY from MII */
/* PHY basic status register */
-#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< auto-negotioation process completed */
-#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< valid link established */
-#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< jabber condition detected */
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< auto-negotioation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< jabber condition detected */
-#if(PHY_TYPE == LAN8700)
+#if(PHY_TYPE == LAN8700)
#define PHY_SR 31U /*!< tranceiver status register */
-#define PHY_SPEED_STATUS ((uint16_t)0x0004) /*!< configured information of speed: 10Mbit/s */
-#define PHY_DUPLEX_STATUS ((uint16_t)0x0010) /*!< configured information of duplex: full-duplex */
+#define PHY_SPEED_STATUS ((uint16_t)0x0004U) /*!< configured information of speed: 10Mbit/s */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0010U) /*!< configured information of duplex: full-duplex */
#elif(PHY_TYPE == DP83848)
#define PHY_SR 16U /*!< tranceiver status register */
-#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< configured information of speed: 10Mbit/s */
-#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< configured information of duplex: full-duplex */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< configured information of speed: 10Mbit/s */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< configured information of duplex: full-duplex */
#elif(PHY_TYPE == RTL8201F) /** AvV **/
# define PHY_SR 0U /*!< tranceiver status register */
# define PHY_SPEED_STATUS ((uint16_t)0x2000) /*!< configured information of speed: 100Mbit/s */
@@ -124,63 +121,63 @@ OF SUCH DAMAGE.
#define ENET ENET_BASE
/* registers definitions */
-#define ENET_MAC_CFG REG32((ENET) + 0x00U) /*!< ethernet MAC configuration register */
-#define ENET_MAC_FRMF REG32((ENET) + 0x04U) /*!< ethernet MAC frame filter register */
-#define ENET_MAC_HLH REG32((ENET) + 0x08U) /*!< ethernet MAC hash list high register */
-#define ENET_MAC_HLL REG32((ENET) + 0x0CU) /*!< ethernet MAC hash list low register */
-#define ENET_MAC_PHY_CTL REG32((ENET) + 0x10U) /*!< ethernet MAC PHY control register */
-#define ENET_MAC_PHY_DATA REG32((ENET) + 0x14U) /*!< ethernet MAC MII data register */
-#define ENET_MAC_FCTL REG32((ENET) + 0x18U) /*!< ethernet MAC flow control register */
-#define ENET_MAC_FCTH REG32((ENET) + 0x1080U) /*!< ethernet MAC flow control threshold register */
-#define ENET_MAC_VLT REG32((ENET) + 0x1CU) /*!< ethernet MAC VLAN tag register */
-#define ENET_MAC_RWFF REG32((ENET) + 0x28U) /*!< ethernet MAC remote wakeup frame filter register */
-#define ENET_MAC_WUM REG32((ENET) + 0x2CU) /*!< ethernet MAC wakeup management register */
-#define ENET_MAC_INTF REG32((ENET) + 0x38U) /*!< ethernet MAC interrupt flag register */
-#define ENET_MAC_INTMSK REG32((ENET) + 0x3CU) /*!< ethernet MAC interrupt mask register */
-#define ENET_MAC_ADDR0H REG32((ENET) + 0x40U) /*!< ethernet MAC address 0 high register */
-#define ENET_MAC_ADDR0L REG32((ENET) + 0x44U) /*!< ethernet MAC address 0 low register */
-#define ENET_MAC_ADDR1H REG32((ENET) + 0x48U) /*!< ethernet MAC address 1 high register */
-#define ENET_MAC_ADDR1L REG32((ENET) + 0x4CU) /*!< ethernet MAC address 1 low register */
-#define ENET_MAC_ADDT2H REG32((ENET) + 0x50U) /*!< ethernet MAC address 2 high register */
-#define ENET_MAC_ADDR2L REG32((ENET) + 0x54U) /*!< ethernet MAC address 2 low register */
-#define ENET_MAC_ADDR3H REG32((ENET) + 0x58U) /*!< ethernet MAC address 3 high register */
-#define ENET_MAC_ADDR3L REG32((ENET) + 0x5CU) /*!< ethernet MAC address 3 low register */
-
-#define ENET_MSC_CTL REG32((ENET) + 0x100U) /*!< ethernet MSC control register */
-#define ENET_MSC_RINTF REG32((ENET) + 0x104U) /*!< ethernet MSC receive interrupt flag register */
-#define ENET_MSC_TINTF REG32((ENET) + 0x108U) /*!< ethernet MSC transmit interrupt flag register */
-#define ENET_MSC_RINTMSK REG32((ENET) + 0x10CU) /*!< ethernet MSC receive interrupt mask register */
-#define ENET_MSC_TINTMSK REG32((ENET) + 0x110U) /*!< ethernet MSC transmit interrupt mask register */
-#define ENET_MSC_SCCNT REG32((ENET) + 0x14CU) /*!< ethernet MSC transmitted good frames after a single collision counter register */
-#define ENET_MSC_MSCCNT REG32((ENET) + 0x150U) /*!< ethernet MSC transmitted good frames after more than a single collision counter register */
-#define ENET_MSC_TGFCNT REG32((ENET) + 0x168U) /*!< ethernet MSC transmitted good frames counter register */
-#define ENET_MSC_RFCECNT REG32((ENET) + 0x194U) /*!< ethernet MSC received frames with CRC error counter register */
-#define ENET_MSC_RFAECNT REG32((ENET) + 0x198U) /*!< ethernet MSC received frames with alignment error counter register */
-#define ENET_MSC_RGUFCNT REG32((ENET) + 0x1C4U) /*!< ethernet MSC received good unicast frames counter register */
-
-#define ENET_PTP_TSCTL REG32((ENET) + 0x700U) /*!< ethernet PTP time stamp control register */
-#define ENET_PTP_SSINC REG32((ENET) + 0x704U) /*!< ethernet PTP subsecond increment register */
-#define ENET_PTP_TSH REG32((ENET) + 0x708U) /*!< ethernet PTP time stamp high register */
-#define ENET_PTP_TSL REG32((ENET) + 0x70CU) /*!< ethernet PTP time stamp low register */
-#define ENET_PTP_TSUH REG32((ENET) + 0x710U) /*!< ethernet PTP time stamp update high register */
-#define ENET_PTP_TSUL REG32((ENET) + 0x714U) /*!< ethernet PTP time stamp update low register */
-#define ENET_PTP_TSADDEND REG32((ENET) + 0x718U) /*!< ethernet PTP time stamp addend register */
-#define ENET_PTP_ETH REG32((ENET) + 0x71CU) /*!< ethernet PTP expected time high register */
-#define ENET_PTP_ETL REG32((ENET) + 0x720U) /*!< ethernet PTP expected time low register */
-
-#define ENET_DMA_BCTL REG32((ENET) + 0x1000U) /*!< ethernet DMA bus control register */
-#define ENET_DMA_TPEN REG32((ENET) + 0x1004U) /*!< ethernet DMA transmit poll enable register */
-#define ENET_DMA_RPEN REG32((ENET) + 0x1008U) /*!< ethernet DMA receive poll enable register */
-#define ENET_DMA_RDTADDR REG32((ENET) + 0x100CU) /*!< ethernet DMA receive descriptor table address register */
-#define ENET_DMA_TDTADDR REG32((ENET) + 0x1010U) /*!< ethernet DMA transmit descriptor table address register */
-#define ENET_DMA_STAT REG32((ENET) + 0x1014U) /*!< ethernet DMA status register */
-#define ENET_DMA_CTL REG32((ENET) + 0x1018U) /*!< ethernet DMA control register */
-#define ENET_DMA_INTEN REG32((ENET) + 0x101CU) /*!< ethernet DMA interrupt enable register */
-#define ENET_DMA_MFBOCNT REG32((ENET) + 0x1020U) /*!< ethernet DMA missed frame and buffer overflow counter register */
-#define ENET_DMA_CTDADDR REG32((ENET) + 0x1048U) /*!< ethernet DMA current transmit descriptor address register */
-#define ENET_DMA_CRDADDR REG32((ENET) + 0x104CU) /*!< ethernet DMA current receive descriptor address register */
-#define ENET_DMA_CTBADDR REG32((ENET) + 0x1050U) /*!< ethernet DMA current transmit buffer address register */
-#define ENET_DMA_CRBADDR REG32((ENET) + 0x1054U) /*!< ethernet DMA current receive buffer address register */
+#define ENET_MAC_CFG REG32((ENET) + 0x00000000U) /*!< ethernet MAC configuration register */
+#define ENET_MAC_FRMF REG32((ENET) + 0x00000004U) /*!< ethernet MAC frame filter register */
+#define ENET_MAC_HLH REG32((ENET) + 0x00000008U) /*!< ethernet MAC hash list high register */
+#define ENET_MAC_HLL REG32((ENET) + 0x0000000CU) /*!< ethernet MAC hash list low register */
+#define ENET_MAC_PHY_CTL REG32((ENET) + 0x00000010U) /*!< ethernet MAC PHY control register */
+#define ENET_MAC_PHY_DATA REG32((ENET) + 0x00000014U) /*!< ethernet MAC PHY data register */
+#define ENET_MAC_FCTL REG32((ENET) + 0x00000018U) /*!< ethernet MAC flow control register */
+#define ENET_MAC_FCTH REG32((ENET) + 0x00001080U) /*!< ethernet MAC flow control threshold register */
+#define ENET_MAC_VLT REG32((ENET) + 0x0000001CU) /*!< ethernet MAC VLAN tag register */
+#define ENET_MAC_RWFF REG32((ENET) + 0x00000028U) /*!< ethernet MAC remote wakeup frame filter register */
+#define ENET_MAC_WUM REG32((ENET) + 0x0000002CU) /*!< ethernet MAC wakeup management register */
+#define ENET_MAC_INTF REG32((ENET) + 0x00000038U) /*!< ethernet MAC interrupt flag register */
+#define ENET_MAC_INTMSK REG32((ENET) + 0x0000003CU) /*!< ethernet MAC interrupt mask register */
+#define ENET_MAC_ADDR0H REG32((ENET) + 0x00000040U) /*!< ethernet MAC address 0 high register */
+#define ENET_MAC_ADDR0L REG32((ENET) + 0x00000044U) /*!< ethernet MAC address 0 low register */
+#define ENET_MAC_ADDR1H REG32((ENET) + 0x00000048U) /*!< ethernet MAC address 1 high register */
+#define ENET_MAC_ADDR1L REG32((ENET) + 0x0000004CU) /*!< ethernet MAC address 1 low register */
+#define ENET_MAC_ADDT2H REG32((ENET) + 0x00000050U) /*!< ethernet MAC address 2 high register */
+#define ENET_MAC_ADDR2L REG32((ENET) + 0x00000054U) /*!< ethernet MAC address 2 low register */
+#define ENET_MAC_ADDR3H REG32((ENET) + 0x00000058U) /*!< ethernet MAC address 3 high register */
+#define ENET_MAC_ADDR3L REG32((ENET) + 0x0000005CU) /*!< ethernet MAC address 3 low register */
+
+#define ENET_MSC_CTL REG32((ENET) + 0x00000100U) /*!< ethernet MSC control register */
+#define ENET_MSC_RINTF REG32((ENET) + 0x00000104U) /*!< ethernet MSC receive interrupt flag register */
+#define ENET_MSC_TINTF REG32((ENET) + 0x00000108U) /*!< ethernet MSC transmit interrupt flag register */
+#define ENET_MSC_RINTMSK REG32((ENET) + 0x0000010CU) /*!< ethernet MSC receive interrupt mask register */
+#define ENET_MSC_TINTMSK REG32((ENET) + 0x00000110U) /*!< ethernet MSC transmit interrupt mask register */
+#define ENET_MSC_SCCNT REG32((ENET) + 0x0000014CU) /*!< ethernet MSC transmitted good frames after a single collision counter register */
+#define ENET_MSC_MSCCNT REG32((ENET) + 0x00000150U) /*!< ethernet MSC transmitted good frames after more than a single collision counter register */
+#define ENET_MSC_TGFCNT REG32((ENET) + 0x00000168U) /*!< ethernet MSC transmitted good frames counter register */
+#define ENET_MSC_RFCECNT REG32((ENET) + 0x00000194U) /*!< ethernet MSC received frames with CRC error counter register */
+#define ENET_MSC_RFAECNT REG32((ENET) + 0x00000198U) /*!< ethernet MSC received frames with alignment error counter register */
+#define ENET_MSC_RGUFCNT REG32((ENET) + 0x000001C4U) /*!< ethernet MSC received good unicast frames counter register */
+
+#define ENET_PTP_TSCTL REG32((ENET) + 0x00000700U) /*!< ethernet PTP time stamp control register */
+#define ENET_PTP_SSINC REG32((ENET) + 0x00000704U) /*!< ethernet PTP subsecond increment register */
+#define ENET_PTP_TSH REG32((ENET) + 0x00000708U) /*!< ethernet PTP time stamp high register */
+#define ENET_PTP_TSL REG32((ENET) + 0x0000070CU) /*!< ethernet PTP time stamp low register */
+#define ENET_PTP_TSUH REG32((ENET) + 0x00000710U) /*!< ethernet PTP time stamp update high register */
+#define ENET_PTP_TSUL REG32((ENET) + 0x00000714U) /*!< ethernet PTP time stamp update low register */
+#define ENET_PTP_TSADDEND REG32((ENET) + 0x00000718U) /*!< ethernet PTP time stamp addend register */
+#define ENET_PTP_ETH REG32((ENET) + 0x0000071CU) /*!< ethernet PTP expected time high register */
+#define ENET_PTP_ETL REG32((ENET) + 0x00000720U) /*!< ethernet PTP expected time low register */
+
+#define ENET_DMA_BCTL REG32((ENET) + 0x00001000U) /*!< ethernet DMA bus control register */
+#define ENET_DMA_TPEN REG32((ENET) + 0x00001004U) /*!< ethernet DMA transmit poll enable register */
+#define ENET_DMA_RPEN REG32((ENET) + 0x00001008U) /*!< ethernet DMA receive poll enable register */
+#define ENET_DMA_RDTADDR REG32((ENET) + 0x0000100CU) /*!< ethernet DMA receive descriptor table address register */
+#define ENET_DMA_TDTADDR REG32((ENET) + 0x00001010U) /*!< ethernet DMA transmit descriptor table address register */
+#define ENET_DMA_STAT REG32((ENET) + 0x00001014U) /*!< ethernet DMA status register */
+#define ENET_DMA_CTL REG32((ENET) + 0x00001018U) /*!< ethernet DMA control register */
+#define ENET_DMA_INTEN REG32((ENET) + 0x0000101CU) /*!< ethernet DMA interrupt enable register */
+#define ENET_DMA_MFBOCNT REG32((ENET) + 0x00001020U) /*!< ethernet DMA missed frame and buffer overflow counter register */
+#define ENET_DMA_CTDADDR REG32((ENET) + 0x00001048U) /*!< ethernet DMA current transmit descriptor address register */
+#define ENET_DMA_CRDADDR REG32((ENET) + 0x0000104CU) /*!< ethernet DMA current receive descriptor address register */
+#define ENET_DMA_CTBADDR REG32((ENET) + 0x00001050U) /*!< ethernet DMA current transmit buffer address register */
+#define ENET_DMA_CRBADDR REG32((ENET) + 0x00001054U) /*!< ethernet DMA current receive buffer address register */
/* bits definitions */
/* ENET_MAC_CFG */
@@ -196,60 +193,60 @@ OF SUCH DAMAGE.
#define ENET_MAC_CFG_ROD BIT(13) /*!< receive own disable */
#define ENET_MAC_CFG_SPD BIT(14) /*!< fast eneternet speed */
#define ENET_MAC_CFG_CSD BIT(16) /*!< carrier sense disable */
-#define ENET_MAC_CFG_IGBS BITS(17,19) /*!< inter-frame gap bit selection */
+#define ENET_MAC_CFG_IGBS BITS(17,19) /*!< inter-frame gap bit selection */
#define ENET_MAC_CFG_JBD BIT(22) /*!< jabber disable */
#define ENET_MAC_CFG_WDD BIT(23) /*!< watchdog disable */
/* ENET_MAC_FRMF */
#define ENET_MAC_FRMF_PM BIT(0) /*!< promiscuous mode */
#define ENET_MAC_FRMF_HUF BIT(1) /*!< hash unicast filter */
-#define ENET_MAC_FRMF_HMF BIT(2) /*!< hash multicast filter */
-#define ENET_MAC_FRMF_DAIFLT BIT(3) /*!< destination address inverse filtering enable */
-#define ENET_MAC_FRMF_MFD BIT(4) /*!< multicast filter disable */
-#define ENET_MAC_FRMF_BFRMD BIT(5) /*!< broadcast frame disable */
-#define ENET_MAC_FRMF_PCFRM BITS(6,7) /*!< pass control frames */
-#define ENET_MAC_FRMF_SAIFLT BIT(8) /*!< source address inverse filtering */
-#define ENET_MAC_FRMF_SAFLT BIT(9) /*!< source address filter */
-#define ENET_MAC_FRMF_HPFLT BIT(10) /*!< hash or perfect filter */
-#define ENET_MAC_FRMF_FAR BIT(31) /*!< frames all receive */
-
+#define ENET_MAC_FRMF_HMF BIT(2) /*!< hash multicast filter */
+#define ENET_MAC_FRMF_DAIFLT BIT(3) /*!< destination address inverse filtering enable */
+#define ENET_MAC_FRMF_MFD BIT(4) /*!< multicast filter disable */
+#define ENET_MAC_FRMF_BFRMD BIT(5) /*!< broadcast frame disable */
+#define ENET_MAC_FRMF_PCFRM BITS(6,7) /*!< pass control frames */
+#define ENET_MAC_FRMF_SAIFLT BIT(8) /*!< source address inverse filtering */
+#define ENET_MAC_FRMF_SAFLT BIT(9) /*!< source address filter */
+#define ENET_MAC_FRMF_HPFLT BIT(10) /*!< hash or perfect filter */
+#define ENET_MAC_FRMF_FAR BIT(31) /*!< frames all receive */
+
/* ENET_MAC_HLH */
#define ENET_MAC_HLH_HLH BITS(0,31) /*!< hash list high */
-
+
/* ENET_MAC_HLL */
#define ENET_MAC_HLL_HLL BITS(0,31) /*!< hash list low */
-
+
/* ENET_MAC_PHY_CTL */
-#define ENET_MAC_PHY_CTL_PB BIT(0) /*!< PHY busy */
-#define ENET_MAC_PHY_CTL_PW BIT(1) /*!< PHY write */
-#define ENET_MAC_PHY_CTL_CLR BITS(2,4) /*!< clock range */
-#define ENET_MAC_PHY_CTL_PR BITS(6,10) /*!< PHY register */
-#define ENET_MAC_PHY_CTL_PA BITS(11,15) /*!< PHY address */
-
+#define ENET_MAC_PHY_CTL_PB BIT(0) /*!< PHY busy */
+#define ENET_MAC_PHY_CTL_PW BIT(1) /*!< PHY write */
+#define ENET_MAC_PHY_CTL_CLR BITS(2,4) /*!< clock range */
+#define ENET_MAC_PHY_CTL_PR BITS(6,10) /*!< PHY register */
+#define ENET_MAC_PHY_CTL_PA BITS(11,15) /*!< PHY address */
+
/* ENET_MAC_PHY_DATA */
#define ENET_MAC_PHY_DATA_PD BITS(0,15) /*!< PHY data */
-
+
/* ENET_MAC_FCTL */
#define ENET_MAC_FCTL_FLCBBKPA BIT(0) /*!< flow control busy(in full duplex mode)/backpressure activate(in half duplex mode) */
#define ENET_MAC_FCTL_TFCEN BIT(1) /*!< transmit flow control enable */
#define ENET_MAC_FCTL_RFCEN BIT(2) /*!< receive flow control enable */
#define ENET_MAC_FCTL_UPFDT BIT(3) /*!< unicast pause frame detect */
-#define ENET_MAC_FCTL_PLTS BITS(4,5) /*!< pause low threshold */
+#define ENET_MAC_FCTL_PLTS BITS(4,5) /*!< pause low threshold */
#define ENET_MAC_FCTL_DZQP BIT(7) /*!< disable zero-quanta pause */
#define ENET_MAC_FCTL_PTM BITS(16,31) /*!< pause time */
-
+
/* ENET_MAC_FCTH */
#define ENET_MAC_FCTH_RFA BITS(0,2) /*!< threshold of active flow control */
#define ENET_MAC_FCTH_RFD BITS(4,6) /*!< threshold of deactive flow control */
-
+
/* ENET_MAC_VLT */
#define ENET_MAC_VLT_VLTI BITS(0,15) /*!< VLAN tag identifier(for receive frames) */
#define ENET_MAC_VLT_VLTC BIT(16) /*!< 12-bit VLAN tag comparison */
-
+
/* ENET_MAC_RWFF */
#define ENET_MAC_RWFF_DATA BITS(0,31) /*!< wakeup frame filter register data */
-
-/* ENET_MAC_WUM */
+
+/* ENET_MAC_WUM */
#define ENET_MAC_WUM_PWD BIT(0) /*!< power down */
#define ENET_MAC_WUM_MPEN BIT(1) /*!< magic packet enable */
#define ENET_MAC_WUM_WFEN BIT(2) /*!< wakeup frame enable */
@@ -258,7 +255,7 @@ OF SUCH DAMAGE.
#define ENET_MAC_WUM_GU BIT(9) /*!< global unicast */
#define ENET_MAC_WUM_WUFFRPR BIT(31) /*!< wakeup frame filter register pointer reset */
-/* ENET_MAC_INTF */
+/* ENET_MAC_INTF */
#define ENET_MAC_INTF_WUM BIT(3) /*!< WUM status */
#define ENET_MAC_INTF_MSC BIT(4) /*!< MSC status */
#define ENET_MAC_INTF_MSCR BIT(5) /*!< MSC receive status */
@@ -272,28 +269,28 @@ OF SUCH DAMAGE.
/* ENET_MAC_ADDR0H */
#define ENET_MAC_ADDR0H_ADDR0H BITS(0,15) /*!< MAC address0 high */
#define ENET_MAC_ADDR0H_MO BIT(31) /*!< always read 1 and must be kept */
-
+
/* ENET_MAC_ADDR0L */
#define ENET_MAC_ADDR0L_ADDR0L BITS(0,31) /*!< MAC address0 low */
-
+
/* ENET_MAC_ADDR1H */
#define ENET_MAC_ADDR1H_ADDR1H BITS(0,15) /*!< MAC address1 high */
-#define ENET_MAC_ADDR1H_MB BITS(24,29) /*!< mask byte */
+#define ENET_MAC_ADDR1H_MB BITS(24,29) /*!< mask byte */
#define ENET_MAC_ADDR1H_SAF BIT(30) /*!< source address filter */
#define ENET_MAC_ADDR1H_AFE BIT(31) /*!< address filter enable */
-
+
/* ENET_MAC_ADDR1L */
#define ENET_MAC_ADDR1L_ADDR1L BITS(0,31) /*!< MAC address1 low */
-
+
/* ENET_MAC_ADDR2H */
#define ENET_MAC_ADDR2H_ADDR2H BITS(0,15) /*!< MAC address2 high */
#define ENET_MAC_ADDR2H_MB BITS(24,29) /*!< mask byte */
#define ENET_MAC_ADDR2H_SAF BIT(30) /*!< source address filter */
#define ENET_MAC_ADDR2H_AFE BIT(31) /*!< address filter enable */
-
+
/* ENET_MAC_ADDR2L */
#define ENET_MAC_ADDR2L_ADDR2L BITS(0,31) /*!< MAC address2 low */
-
+
/* ENET_MAC_ADDR3H */
#define ENET_MAC_ADDR3H_ADDR3H BITS(0,15) /*!< MAC address3 high */
#define ENET_MAC_ADDR3H_MB BITS(24,29) /*!< mask byte */
@@ -302,7 +299,7 @@ OF SUCH DAMAGE.
/* ENET_MAC_ADDR3L */
#define ENET_MAC_ADDR3L_ADDR3L BITS(0,31) /*!< MAC address3 low */
-
+
/* ENET_MSC_CTL */
#define ENET_MSC_CTL_CTR BIT(0) /*!< counter reset */
#define ENET_MSC_CTL_CTSR BIT(1) /*!< counter stop rollover */
@@ -313,7 +310,7 @@ OF SUCH DAMAGE.
#define ENET_MSC_RINTF_RFCE BIT(5) /*!< received frames CRC error */
#define ENET_MSC_RINTF_RFAE BIT(6) /*!< received frames alignment error */
#define ENET_MSC_RINTF_RGUF BIT(17) /*!< receive good unicast frames */
-
+
/* ENET_MSC_TINTF */
#define ENET_MSC_TINTF_TGFSC BIT(14) /*!< transmitted good frames single collision */
#define ENET_MSC_TINTF_TGFMSC BIT(15) /*!< transmitted good frames more single collision */
@@ -323,30 +320,30 @@ OF SUCH DAMAGE.
#define ENET_MSC_RINTMSK_RFCEIM BIT(5) /*!< received frame CRC error interrupt mask */
#define ENET_MSC_RINTMSK_RFAEIM BIT(6) /*!< received frames alignment error interrupt mask */
#define ENET_MSC_RINTMSK_RGUFIM BIT(17) /*!< received good unicast frames interrupt mask */
-
+
/* ENET_MSC_TINTMSK */
#define ENET_MSC_TINTMSK_TGFSCIM BIT(14) /*!< transmitted good frames single collision interrupt mask */
#define ENET_MSC_TINTMSK_TGFMSCIM BIT(15) /*!< transmitted good frames more single collision interrupt mask */
#define ENET_MSC_TINTMSK_TGFIM BIT(21) /*!< transmitted good frames interrupt mask */
-
+
/* ENET_MSC_SCCNT */
#define ENET_MSC_SCCNT_SCC BITS(0,31) /*!< transmitted good frames single collision counter */
-
+
/* ENET_MSC_MSCCNT */
#define ENET_MSC_MSCCNT_MSCC BITS(0,31) /*!< transmitted good frames more one single collision counter */
-
+
/* ENET_MSC_TGFCNT */
#define ENET_MSC_TGFCNT_TGF BITS(0,31) /*!< transmitted good frames counter */
-
+
/* ENET_MSC_RFCECNT */
#define ENET_MSC_RFCECNT_RFCER BITS(0,31) /*!< received frames with CRC error counter */
-
+
/* ENET_MSC_RFAECNT */
#define ENET_MSC_RFAECNT_RFAER BITS(0,31) /*!< received frames alignment error counter */
-
+
/* ENET_MSC_RGUFCNT */
#define ENET_MSC_RGUFCNT_RGUF BITS(0,31) /*!< received good unicast frames counter */
-
+
/* ENET_PTP_TSCTL */
#define ENET_PTP_TSCTL_TMSEN BIT(0) /*!< timestamp enable */
#define ENET_PTP_TSCTL_TMSFCU BIT(1) /*!< timestamp fine or coarse update */
@@ -357,30 +354,30 @@ OF SUCH DAMAGE.
/* ENET_PTP_SSINC */
#define ENET_PTP_SSINC_STMSSI BITS(0,7) /*!< system time subsecond increment */
-
+
/* ENET_PTP_TSH */
#define ENET_PTP_TSH_STMS BITS(0,31) /*!< system time second */
-
+
/* ENET_PTP_TSL */
#define ENET_PTP_TSL_STMSS BITS(0,30) /*!< system time subseconds */
#define ENET_PTP_TSL_STS BIT(31) /*!< system time sign */
-
+
/* ENET_PTP_TSUH */
#define ENET_PTP_TSUH_TMSUS BITS(0,31) /*!< timestamp update seconds */
-
+
/* ENET_PTP_TSUL */
#define ENET_PTP_TSUL_TMSUSS BITS(0,30) /*!< timestamp update subseconds */
#define ENET_PTP_TSUL_TMSUPNS BIT(31) /*!< timestamp update positive or negative sign */
/* ENET_PTP_TSADDEND */
#define ENET_PTP_TSADDEND_TMSA BITS(0,31) /*!< timestamp addend */
-
+
/* ENET_PTP_ETH */
#define ENET_PTP_ETH_ETSH BITS(0,31) /*!< expected time high */
-
+
/* ENET_PTP_ETL */
#define ENET_PTP_ETL_ETSL BITS(0,31) /*!< expected time low */
-
+
/* ENET_DMA_BCTL */
#define ENET_DMA_BCTL_SWR BIT(0) /*!< software reset */
#define ENET_DMA_BCTL_DAB BIT(1) /*!< DMA arbitration */
@@ -392,19 +389,19 @@ OF SUCH DAMAGE.
#define ENET_DMA_BCTL_UIP BIT(23) /*!< use independent PGBL */
#define ENET_DMA_BCTL_FPBL BIT(24) /*!< four times PGBL mode */
#define ENET_DMA_BCTL_AA BIT(25) /*!< address-aligned */
-
+
/* ENET_DMA_TPEN */
#define ENET_DMA_TPEN_TPE BITS(0,31) /*!< transmit poll enable */
-
+
/* ENET_DMA_RPEN */
#define ENET_DMA_RPEN_RPE BITS(0,31) /*!< receive poll enable */
/* ENET_DMA_RDTADDR */
#define ENET_DMA_RDTADDR_SRT BITS(0,31) /*!< start address of receive table */
-
+
/* ENET_DMA_TDTADDR */
#define ENET_DMA_TDTADDR_STT BITS(0,31) /*!< start address of transmit table */
-
+
/* ENET_DMA_STAT */
#define ENET_DMA_STAT_TS BIT(0) /*!< transmit status */
#define ENET_DMA_STAT_TPS BIT(1) /*!< transmit process stopped status */
@@ -427,7 +424,7 @@ OF SUCH DAMAGE.
#define ENET_DMA_STAT_MSC BIT(27) /*!< MSC status */
#define ENET_DMA_STAT_WUM BIT(28) /*!< WUM status */
#define ENET_DMA_STAT_TST BIT(29) /*!< timestamp trigger status */
-
+
/* ENET_DMA_CTL */
#define ENET_DMA_CTL_SRE BIT(1) /*!< start/stop receive enable */
#define ENET_DMA_CTL_OSF BIT(2) /*!< operate on second frame */
@@ -441,7 +438,7 @@ OF SUCH DAMAGE.
#define ENET_DMA_CTL_DAFRF BIT(24) /*!< disable flushing of received frames */
#define ENET_DMA_CTL_RSFD BIT(25) /*!< receive store-and-forward */
#define ENET_DMA_CTL_DTCERFD BIT(26) /*!< dropping of TCP/IP checksum error frames disable */
-
+
/* ENET_DMA_INTEN */
#define ENET_DMA_INTEN_TIE BIT(0) /*!< transmit interrupt enable */
#define ENET_DMA_INTEN_TPSIE BIT(1) /*!< transmit process stopped interrupt enable */
@@ -458,7 +455,7 @@ OF SUCH DAMAGE.
#define ENET_DMA_INTEN_ERIE BIT(14) /*!< early receive interrupt enable */
#define ENET_DMA_INTEN_AIE BIT(15) /*!< abnormal interrupt summary enable */
#define ENET_DMA_INTEN_NIE BIT(16) /*!< normal interrupt summary enable */
-
+
/* ENET_DMA_MFBOCNT */
#define ENET_DMA_MFBOCNT_MSFC BITS(0,15) /*!< missed frames by the controller */
#define ENET_DMA_MFBOCNT_OBMFC BIT(16) /*!< overflow bit for missed frame counter */
@@ -470,10 +467,10 @@ OF SUCH DAMAGE.
/* ENET_DMA_CRDADDR */
#define ENET_DMA_CRDADDR_RDAP BITS(0,31) /*!< receive descriptor address pointer */
-
+
/* ENET_DMA_CTBADDR */
#define ENET_DMA_CTBADDR_TBAP BITS(0,31) /*!< transmit buffer address pointer */
-
+
/* ENET_DMA_CRBADDR */
#define ENET_DMA_CRBADDR_RBAP BITS(0,31) /*!< receive buffer address pointer */
@@ -523,7 +520,7 @@ OF SUCH DAMAGE.
#define ENET_RDES0_FRMT BIT(5) /*!< frame type */
#define ENET_RDES0_LCO BIT(6) /*!< late collision */
#define ENET_RDES0_IPHERR BIT(7) /*!< IP frame header error */
-#define ENET_RDES0_LDES BIT(8) /*!< last descriptor */
+#define ENET_RDES0_LDES BIT(8) /*!< last descriptor */
#define ENET_RDES0_FDES BIT(9) /*!< first descriptor */
#define ENET_RDES0_VTAG BIT(10) /*!< VLAN tag */
#define ENET_RDES0_OERR BIT(11) /*!< overflow Error */
@@ -535,7 +532,7 @@ OF SUCH DAMAGE.
#define ENET_RDES0_DAFF BIT(30) /*!< destination address filter fail */
#define ENET_RDES0_DAV BIT(31) /*!< descriptor available */
-/* ENET DMA Rx descriptor RDES1 */
+/* ENET DMA Rx descriptor RDES1 */
#define ENET_RDES1_RB1S BITS(0,12) /*!< receive buffer 1 size */
#define ENET_RDES1_RCHM BIT(14) /*!< receive chained mode for second address */
#define ENET_RDES1_RERM BIT(15) /*!< receive end of ring mode*/
@@ -550,52 +547,51 @@ OF SUCH DAMAGE.
/* constants definitions */
/* define bit position and its register index offset */
-#define ENET_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
-#define ENET_REG_VAL(periph) (REG32(ENET + ((uint32_t)(periph)>>6)))
-#define ENET_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+#define ENET_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6U) | (uint32_t)(bitpos))
+#define ENET_REG_VAL(periph) (REG32(ENET + ((uint32_t)(periph) >> 6U)))
+#define ENET_BIT_POS(val) ((uint32_t)(val) & 0x0000001FU)
/* ENET clock range judgement */
#define ENET_RANGE(hclk, n, m) (((hclk) >= (n))&&((hclk) < (m)))
/* define MAC address configuration and reference address */
-#define ENET_SET_MACADDRH(p) (((uint32_t)(p)[5] << 8) | (uint32_t)(p)[4])
-#define ENET_SET_MACADDRL(p) (((uint32_t)(p)[3] << 24) | ((uint32_t)(p)[2] << 16) | ((uint32_t)(p)[1] << 8) | (uint32_t)(p)[0])
-#define ENET_ADDRH_BASE ((ENET) + 0x40U)
-#define ENET_ADDRL_BASE ((ENET) + 0x44U)
+#define ENET_SET_MACADDRH(p) (((uint32_t)(p)[5] << 8U) | (uint32_t)(p)[4])
+#define ENET_SET_MACADDRL(p) (((uint32_t)(p)[3] << 24U) | ((uint32_t)(p)[2] << 16U) | ((uint32_t)(p)[1] << 8U) | (uint32_t)(p)[0])
+#define ENET_ADDRH_BASE ((ENET) + 0x00000040U)
+#define ENET_ADDRL_BASE ((ENET) + 0x00000044U)
#define ENET_GET_MACADDR(offset, n) ((uint8_t)((REG32((ENET_ADDRL_BASE + (offset)) - (((n) / 4U) * 4U)) >> (8U * ((n) % 4U))) & 0xFFU))
/* register offset */
-#define MAC_FCTL_REG_OFFSET 0x0018U /*!< MAC flow control register offset */
-#define MAC_WUM_REG_OFFSET 0x002CU /*!< MAC wakeup management register offset */
-#define MAC_INTF_REG_OFFSET 0x0038U /*!< MAC interrupt flag register offset */
-#define MAC_INTMSK_REG_OFFSET 0x003CU /*!< MAC interrupt mask register offset */
-
-#define MSC_RINTF_REG_OFFSET 0x0104U /*!< MSC receive interrupt flag register offset */
-#define MSC_TINTF_REG_OFFSET 0x0108U /*!< MSC transmit interrupt flag register offset */
-#define MSC_RINTMSK_REG_OFFSET 0x010CU /*!< MSC receive interrupt mask register offset */
-#define MSC_TINTMSK_REG_OFFSET 0x0110U /*!< MSC transmit interrupt mask register offset */
-#define MSC_SCCNT_REG_OFFSET 0x014CU /*!< MSC transmitted good frames after a single collision counter register offset */
-#define MSC_MSCCNT_REG_OFFSET 0x0150U /*!< MSC transmitted good frames after more than a single collision counter register offset */
-#define MSC_TGFCNT_REG_OFFSET 0x0168U /*!< MSC transmitted good frames counter register offset */
-#define MSC_RFCECNT_REG_OFFSET 0x0194U /*!< MSC received frames with CRC error counter register offset */
-#define MSC_RFAECNT_REG_OFFSET 0x0198U /*!< MSC received frames with alignment error counter register offset */
-#define MSC_RGUFCNT_REG_OFFSET 0x01C4U /*!< MSC received good unicast frames counter register offset */
-
-#define DMA_STAT_REG_OFFSET 0x1014U /*!< DMA status register offset */
-#define DMA_INTEN_REG_OFFSET 0x101CU /*!< DMA interrupt enable register offset */
-#define DMA_TDTADDR_REG_OFFSET 0x1010U /*!< DMA transmit descriptor table address register offset */
-#define DMA_CTDADDR_REG_OFFSET 0x1048U /*!< DMA current transmit descriptor address register */
-#define DMA_CTBADDR_REG_OFFSET 0x1050U /*!< DMA current transmit buffer address register */
-#define DMA_RDTADDR_REG_OFFSET 0x100CU /*!< DMA receive descriptor table address register */
-#define DMA_CRDADDR_REG_OFFSET 0x104CU /*!< DMA current receive descriptor address register */
-#define DMA_CRBADDR_REG_OFFSET 0x1054U /*!< DMA current receive buffer address register */
+#define MAC_FCTL_REG_OFFSET 0x00000018U /*!< MAC flow control register offset */
+#define MAC_WUM_REG_OFFSET 0x0000002CU /*!< MAC wakeup management register offset */
+#define MAC_INTF_REG_OFFSET 0x00000038U /*!< MAC interrupt flag register offset */
+#define MAC_INTMSK_REG_OFFSET 0x0000003CU /*!< MAC interrupt mask register offset */
+
+#define MSC_RINTF_REG_OFFSET 0x00000104U /*!< MSC receive interrupt flag register offset */
+#define MSC_TINTF_REG_OFFSET 0x00000108U /*!< MSC transmit interrupt flag register offset */
+#define MSC_RINTMSK_REG_OFFSET 0x0000010CU /*!< MSC receive interrupt mask register offset */
+#define MSC_TINTMSK_REG_OFFSET 0x00000110U /*!< MSC transmit interrupt mask register offset */
+#define MSC_SCCNT_REG_OFFSET 0x0000014CU /*!< MSC transmitted good frames after a single collision counter register offset */
+#define MSC_MSCCNT_REG_OFFSET 0x00000150U /*!< MSC transmitted good frames after more than a single collision counter register offset */
+#define MSC_TGFCNT_REG_OFFSET 0x00000168U /*!< MSC transmitted good frames counter register offset */
+#define MSC_RFCECNT_REG_OFFSET 0x00000194U /*!< MSC received frames with CRC error counter register offset */
+#define MSC_RFAECNT_REG_OFFSET 0x00000198U /*!< MSC received frames with alignment error counter register offset */
+#define MSC_RGUFCNT_REG_OFFSET 0x000001C4U /*!< MSC received good unicast frames counter register offset */
+
+#define DMA_STAT_REG_OFFSET 0x00001014U /*!< DMA status register offset */
+#define DMA_INTEN_REG_OFFSET 0x0000101CU /*!< DMA interrupt enable register offset */
+#define DMA_TDTADDR_REG_OFFSET 0x00001010U /*!< DMA transmit descriptor table address register offset */
+#define DMA_CTDADDR_REG_OFFSET 0x00001048U /*!< DMA current transmit descriptor address register */
+#define DMA_CTBADDR_REG_OFFSET 0x00001050U /*!< DMA current transmit buffer address register */
+#define DMA_RDTADDR_REG_OFFSET 0x0000100CU /*!< DMA receive descriptor table address register */
+#define DMA_CRDADDR_REG_OFFSET 0x0000104CU /*!< DMA current receive descriptor address register */
+#define DMA_CRBADDR_REG_OFFSET 0x00001054U /*!< DMA current receive buffer address register */
/* ENET status flag get */
-typedef enum
-{
+typedef enum {
/* ENET_MAC_WUM register */
ENET_MAC_FLAG_MPKR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 5U), /*!< magic packet received flag */
- ENET_MAC_FLAG_WUFR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 6U), /*!< wakeup frame received flag */
+ ENET_MAC_FLAG_WUFR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 6U), /*!< wakeup frame received flag */
/* ENET_MAC_FCTL register */
ENET_MAC_FLAG_FLOWCONTROL = ENET_REGIDX_BIT(MAC_FCTL_REG_OFFSET, 0U), /*!< flow control status flag */
/* ENET_MAC_INTF register */
@@ -608,7 +604,7 @@ typedef enum
ENET_MSC_FLAG_RFCE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 5U), /*!< received frames CRC error flag */
ENET_MSC_FLAG_RFAE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 6U), /*!< received frames alignment error flag */
ENET_MSC_FLAG_RGUF = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 17U), /*!< received good unicast frames flag */
- /* ENET_MSC_TINTF register */
+ /* ENET_MSC_TINTF register */
ENET_MSC_FLAG_TGFSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 14U), /*!< transmitted good frames single collision flag */
ENET_MSC_FLAG_TGFMSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 15U), /*!< transmitted good frames more single collision flag */
ENET_MSC_FLAG_TGF = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 21U), /*!< transmitted good frames flag */
@@ -633,12 +629,11 @@ typedef enum
ENET_DMA_FLAG_EB_ACCESS_ERROR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 25U), /*!< error during data buffer/descriptor access flag */
ENET_DMA_FLAG_MSC = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 27U), /*!< MSC status flag */
ENET_DMA_FLAG_WUM = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 28U), /*!< WUM status flag */
- ENET_DMA_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
-}enet_flag_enum;
+ ENET_DMA_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U) /*!< timestamp trigger status flag */
+} enet_flag_enum;
/* ENET status flag clear */
-typedef enum
-{
+typedef enum {
/* ENET_DMA_STAT register */
ENET_DMA_FLAG_TS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 0U), /*!< transmit status flag */
ENET_DMA_FLAG_TPS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 1U), /*!< transmit process stopped status flag */
@@ -654,24 +649,23 @@ typedef enum
ENET_DMA_FLAG_FBE_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
ENET_DMA_FLAG_ER_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
ENET_DMA_FLAG_AI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
- ENET_DMA_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
-}enet_flag_clear_enum;
+ ENET_DMA_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U) /*!< normal interrupt summary flag */
+} enet_flag_clear_enum;
/* ENET interrupt enable/disable */
-typedef enum
-{
+typedef enum {
/* ENET_MAC_INTMSK register */
ENET_MAC_INT_WUMIM = ENET_REGIDX_BIT(MAC_INTMSK_REG_OFFSET, 3U), /*!< WUM interrupt mask */
ENET_MAC_INT_TMSTIM = ENET_REGIDX_BIT(MAC_INTMSK_REG_OFFSET, 9U), /*!< timestamp trigger interrupt mask */
- /* ENET_MSC_RINTMSK register */
+ /* ENET_MSC_RINTMSK register */
ENET_MSC_INT_RFCEIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 5U), /*!< received frame CRC error interrupt mask */
ENET_MSC_INT_RFAEIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 6U), /*!< received frames alignment error interrupt mask */
ENET_MSC_INT_RGUFIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 17U), /*!< received good unicast frames interrupt mask */
- /* ENET_MSC_TINTMSK register */
+ /* ENET_MSC_TINTMSK register */
ENET_MSC_INT_TGFSCIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 14U), /*!< transmitted good frames single collision interrupt mask */
ENET_MSC_INT_TGFMSCIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 15U), /*!< transmitted good frames more single collision interrupt mask */
ENET_MSC_INT_TGFIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 21U), /*!< transmitted good frames interrupt mask */
- /* ENET_DMA_INTEN register */
+ /* ENET_DMA_INTEN register */
ENET_DMA_INT_TIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 0U), /*!< transmit interrupt enable */
ENET_DMA_INT_TPSIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 1U), /*!< transmit process stopped interrupt enable */
ENET_DMA_INT_TBUIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 2U), /*!< transmit buffer unavailable interrupt enable */
@@ -686,12 +680,11 @@ typedef enum
ENET_DMA_INT_FBEIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 13U), /*!< fatal bus error interrupt enable */
ENET_DMA_INT_ERIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 14U), /*!< early receive interrupt enable */
ENET_DMA_INT_AIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 15U), /*!< abnormal interrupt summary enable */
- ENET_DMA_INT_NIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 16U), /*!< normal interrupt summary enable */
-}enet_int_enum;
-
+ ENET_DMA_INT_NIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 16U) /*!< normal interrupt summary enable */
+} enet_int_enum;
+
/* ENET interrupt flag get */
-typedef enum
-{
+typedef enum {
/* ENET_MAC_INTF register */
ENET_MAC_INT_FLAG_WUM = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 3U), /*!< WUM status flag */
ENET_MAC_INT_FLAG_MSC = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 4U), /*!< MSC status flag */
@@ -724,12 +717,11 @@ typedef enum
ENET_DMA_INT_FLAG_NI = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
ENET_DMA_INT_FLAG_MSC = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 27U), /*!< MSC status flag */
ENET_DMA_INT_FLAG_WUM = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 28U), /*!< WUM status flag */
- ENET_DMA_INT_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
-}enet_int_flag_enum;
+ ENET_DMA_INT_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U) /*!< timestamp trigger status flag */
+} enet_int_flag_enum;
/* ENET interrupt flag clear */
-typedef enum
-{
+typedef enum {
/* ENET_DMA_STAT register */
ENET_DMA_INT_FLAG_TS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 0U), /*!< transmit status flag */
ENET_DMA_INT_FLAG_TPS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 1U), /*!< transmit process stopped status flag */
@@ -745,34 +737,31 @@ typedef enum
ENET_DMA_INT_FLAG_FBE_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
ENET_DMA_INT_FLAG_ER_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
ENET_DMA_INT_FLAG_AI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
- ENET_DMA_INT_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
-}enet_int_flag_clear_enum;
+ ENET_DMA_INT_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U) /*!< normal interrupt summary flag */
+} enet_int_flag_clear_enum;
/* current RX/TX descriptor/buffer/descriptor table address get */
-typedef enum
-{
+typedef enum {
ENET_RX_DESC_TABLE = DMA_RDTADDR_REG_OFFSET, /*!< RX descriptor table */
ENET_RX_CURRENT_DESC = DMA_CRDADDR_REG_OFFSET, /*!< current RX descriptor */
ENET_RX_CURRENT_BUFFER = DMA_CRBADDR_REG_OFFSET, /*!< current RX buffer */
ENET_TX_DESC_TABLE = DMA_TDTADDR_REG_OFFSET, /*!< TX descriptor table */
ENET_TX_CURRENT_DESC = DMA_CTDADDR_REG_OFFSET, /*!< current TX descriptor */
ENET_TX_CURRENT_BUFFER = DMA_CTBADDR_REG_OFFSET /*!< current TX buffer */
-}enet_desc_reg_enum;
+} enet_desc_reg_enum;
/* MAC statistics counter get */
-typedef enum
-{
+typedef enum {
ENET_MSC_TX_SCCNT = MSC_SCCNT_REG_OFFSET, /*!< MSC transmitted good frames after a single collision counter */
ENET_MSC_TX_MSCCNT = MSC_MSCCNT_REG_OFFSET, /*!< MSC transmitted good frames after more than a single collision counter */
ENET_MSC_TX_TGFCNT = MSC_TGFCNT_REG_OFFSET, /*!< MSC transmitted good frames counter */
ENET_MSC_RX_RFCECNT = MSC_RFCECNT_REG_OFFSET, /*!< MSC received frames with CRC error counter */
ENET_MSC_RX_RFAECNT = MSC_RFAECNT_REG_OFFSET, /*!< MSC received frames with alignment error counter */
ENET_MSC_RX_RGUFCNT = MSC_RGUFCNT_REG_OFFSET /*!< MSC received good unicast frames counter */
-}enet_msc_counter_enum;
+} enet_msc_counter_enum;
/* function option, used for ENET initialization */
-typedef enum
-{
+typedef enum {
FORWARD_OPTION = BIT(0), /*!< configure the frame forward related parameters */
DMABUS_OPTION = BIT(1), /*!< configure the DMA bus mode related parameters */
DMA_MAXBURST_OPTION = BIT(2), /*!< configure the DMA max burst related parameters */
@@ -786,152 +775,140 @@ typedef enum
FILTER_OPTION = BIT(10), /*!< configure the frame filter control related parameters */
HALFDUPLEX_OPTION = BIT(11), /*!< configure the halfduplex related parameters */
TIMER_OPTION = BIT(12), /*!< configure the frame timer related parameters */
- INTERFRAMEGAP_OPTION = BIT(13), /*!< configure the inter frame gap related parameters */
-}enet_option_enum;
+ INTERFRAMEGAP_OPTION = BIT(13) /*!< configure the inter frame gap related parameters */
+} enet_option_enum;
/* phy mode and mac loopback configurations */
-typedef enum
-{
+typedef enum {
ENET_AUTO_NEGOTIATION = 0x01U, /*!< PHY auto negotiation */
ENET_100M_FULLDUPLEX = (ENET_MAC_CFG_SPD | ENET_MAC_CFG_DPM), /*!< 100Mbit/s, full-duplex */
- ENET_100M_HALFDUPLEX = ENET_MAC_CFG_SPD , /*!< 100Mbit/s, half-duplex */
+ ENET_100M_HALFDUPLEX = ENET_MAC_CFG_SPD, /*!< 100Mbit/s, half-duplex */
ENET_10M_FULLDUPLEX = ENET_MAC_CFG_DPM, /*!< 10Mbit/s, full-duplex */
ENET_10M_HALFDUPLEX = (uint32_t)0x00000000U, /*!< 10Mbit/s, half-duplex */
ENET_LOOPBACKMODE = (ENET_MAC_CFG_LBM | ENET_MAC_CFG_DPM) /*!< MAC in loopback mode at the MII */
-}enet_mediamode_enum;
+} enet_mediamode_enum;
/* IP frame checksum function */
-typedef enum
-{
+typedef enum {
ENET_NO_AUTOCHECKSUM = (uint32_t)0x00000000U, /*!< disable IP frame checksum function */
ENET_AUTOCHECKSUM_DROP_FAILFRAMES = ENET_MAC_CFG_IPFCO, /*!< enable IP frame checksum function */
- ENET_AUTOCHECKSUM_ACCEPT_FAILFRAMES = (ENET_MAC_CFG_IPFCO|ENET_DMA_CTL_DTCERFD) /*!< enable IP frame checksum function, and the received frame
+ ENET_AUTOCHECKSUM_ACCEPT_FAILFRAMES = (ENET_MAC_CFG_IPFCO | ENET_DMA_CTL_DTCERFD) /*!< enable IP frame checksum function, and the received frame
with only payload error but no other errors will not be dropped */
-}enet_chksumconf_enum;
+} enet_chksumconf_enum;
/* received frame filter function */
-typedef enum
-{
+typedef enum {
ENET_PROMISCUOUS_MODE = ENET_MAC_FRMF_PM, /*!< promiscuous mode enabled */
ENET_RECEIVEALL = (int32_t)ENET_MAC_FRMF_FAR, /*!< all received frame are forwarded to application */
- ENET_CUSTOM = BIT(4),
+ ENET_CUSTOM = BIT(4), /** AvV **/
ENET_BROADCAST_FRAMES_PASS = (uint32_t)0x00000000U, /*!< the address filters pass all received broadcast frames */
ENET_BROADCAST_FRAMES_DROP = ENET_MAC_FRMF_BFRMD /*!< the address filters filter all incoming broadcast frames */
-}enet_frmrecept_enum;
+} enet_frmrecept_enum;
/* register group value get */
-typedef enum
-{
- ALL_MAC_REG = 0, /*!< MAC register group */
- ALL_MSC_REG = 22, /*!< MSC register group */
- ALL_PTP_REG = 33, /*!< PTP register group */
- ALL_DMA_REG = 44, /*!< DMA register group */
-}enet_registers_type_enum;
+typedef enum {
+ ALL_MAC_REG = 0U, /*!< MAC register group */
+ ALL_MSC_REG = 22U, /*!< MSC register group */
+ ALL_PTP_REG = 33U, /*!< PTP register group */
+ ALL_DMA_REG = 44U /*!< DMA register group */
+} enet_registers_type_enum;
/* dma direction select */
-typedef enum
-{
+typedef enum {
ENET_DMA_TX = ENET_DMA_STAT_TP, /*!< DMA transmit direction */
ENET_DMA_RX = ENET_DMA_STAT_RP /*!< DMA receive direction */
-}enet_dmadirection_enum;
+} enet_dmadirection_enum;
/* PHY operation direction select */
-typedef enum
-{
- ENET_PHY_READ = (uint32_t)0x00000000, /*!< read PHY */
+typedef enum {
+ ENET_PHY_READ = (uint32_t)0x00000000U, /*!< read PHY */
ENET_PHY_WRITE = ENET_MAC_PHY_CTL_PW /*!< write PHY */
-}enet_phydirection_enum;
+} enet_phydirection_enum;
/* register operation direction select */
-typedef enum
-{
+typedef enum {
ENET_REG_READ, /*!< read register */
ENET_REG_WRITE /*!< write register */
-}enet_regdirection_enum;
+} enet_regdirection_enum;
-/* ENET MAC addresses */
-typedef enum
-{
- ENET_MAC_ADDRESS0 = ((uint32_t)0x00000000), /*!< MAC address0 */
- ENET_MAC_ADDRESS1 = ((uint32_t)0x00000008), /*!< MAC address1 */
- ENET_MAC_ADDRESS2 = ((uint32_t)0x00000010), /*!< MAC address2 */
- ENET_MAC_ADDRESS3 = ((uint32_t)0x00000018) /*!< MAC address3 */
-}enet_macaddress_enum;
+/* ENET MAC addresses */
+typedef enum {
+ ENET_MAC_ADDRESS0 = ((uint32_t)0x00000000U), /*!< MAC address0 */
+ ENET_MAC_ADDRESS1 = ((uint32_t)0x00000008U), /*!< MAC address1 */
+ ENET_MAC_ADDRESS2 = ((uint32_t)0x00000010U), /*!< MAC address2 */
+ ENET_MAC_ADDRESS3 = ((uint32_t)0x00000018U) /*!< MAC address3 */
+} enet_macaddress_enum;
/* descriptor information */
-typedef enum
-{
+typedef enum {
TXDESC_COLLISION_COUNT, /*!< the number of collisions occurred before the frame was transmitted */
TXDESC_BUFFER_1_ADDR, /*!< transmit frame buffer 1 address */
RXDESC_FRAME_LENGTH, /*!< the byte length of the received frame that was transferred to the buffer */
RXDESC_BUFFER_1_SIZE, /*!< receive buffer 1 size */
RXDESC_BUFFER_2_SIZE, /*!< receive buffer 2 size */
RXDESC_BUFFER_1_ADDR /*!< receive frame buffer 1 address */
-}enet_descstate_enum;
+} enet_descstate_enum;
/* structure for initialization of the ENET */
-typedef struct
-{
+typedef struct {
uint32_t option_enable; /*!< select which function to configure */
- uint32_t forward_frame; /*!< frame forward related parameters */
+ uint32_t forward_frame; /*!< frame forward related parameters */
uint32_t dmabus_mode; /*!< DMA bus mode related parameters */
uint32_t dma_maxburst; /*!< DMA max burst related parameters */
uint32_t dma_arbitration; /*!< DMA Tx and Rx arbitration related parameters */
uint32_t store_forward_mode; /*!< store forward mode related parameters */
uint32_t dma_function; /*!< DMA control related parameters */
- uint32_t vlan_config; /*!< VLAN tag related parameters */
+ uint32_t vlan_config; /*!< VLAN tag related parameters */
uint32_t flow_control; /*!< flow control related parameters */
uint32_t hashtable_high; /*!< hash list high 32-bit related parameters */
uint32_t hashtable_low; /*!< hash list low 32-bit related parameters */
uint32_t framesfilter_mode; /*!< frame filter control related parameters */
- uint32_t halfduplex_param; /*!< halfduplex related parameters */
+ uint32_t halfduplex_param; /*!< halfduplex related parameters */
uint32_t timer_config; /*!< frame timer related parameters */
uint32_t interframegap; /*!< inter frame gap related parameters */
-}enet_initpara_struct;
+} enet_initpara_struct;
-/* structure for ENET DMA descriptors */
-typedef struct
-{
+/* structure for ENET DMA descriptors */
+typedef struct {
uint32_t status; /*!< status */
uint32_t control_buffer_size; /*!< control and buffer1, buffer2 lengths */
uint32_t buffer1_addr; /*!< buffer1 address pointer/timestamp low */
uint32_t buffer2_next_desc_addr; /*!< buffer2 or next descriptor address pointer/timestamp high */
} enet_descriptors_struct;
-/* structure of PTP system time */
-typedef struct
-{
+/* structure of PTP system time */
+typedef struct {
uint32_t second; /*!< second of system time */
uint32_t nanosecond; /*!< nanosecond of system time */
uint32_t sign; /*!< sign of system time */
-}enet_ptp_systime_struct;
+} enet_ptp_systime_struct;
/* mac_cfg register value */
-#define MAC_CFG_BOL(regval) (BITS(5,6) & ((uint32_t)(regval) << 5)) /*!< write value to ENET_MAC_CFG_BOL bit field */
+#define MAC_CFG_BOL(regval) (BITS(5,6) & ((uint32_t)(regval) << 5U)) /*!< write value to ENET_MAC_CFG_BOL bit field */
#define ENET_BACKOFFLIMIT_10 MAC_CFG_BOL(0) /*!< min (n, 10) */
#define ENET_BACKOFFLIMIT_8 MAC_CFG_BOL(1) /*!< min (n, 8) */
#define ENET_BACKOFFLIMIT_4 MAC_CFG_BOL(2) /*!< min (n, 4) */
-#define ENET_BACKOFFLIMIT_1 MAC_CFG_BOL(3) /*!< min (n, 1) */
+#define ENET_BACKOFFLIMIT_1 MAC_CFG_BOL(3) /*!< min (n, 1) */
-#define MAC_CFG_IGBS(regval) (BITS(17,19) & ((uint32_t)(regval) << 17)) /*!< write value to ENET_MAC_CFG_IGBS bit field */
-#define ENET_INTERFRAMEGAP_96BIT MAC_CFG_IGBS(0) /*!< minimum 96 bit times */
+#define MAC_CFG_IGBS(regval) (BITS(17,19) & ((uint32_t)(regval) << 17U)) /*!< write value to ENET_MAC_CFG_IGBS bit field */
+#define ENET_INTERFRAMEGAP_96BIT MAC_CFG_IGBS(0) /*!< minimum 96 bit times */
#define ENET_INTERFRAMEGAP_88BIT MAC_CFG_IGBS(1) /*!< minimum 88 bit times */
#define ENET_INTERFRAMEGAP_80BIT MAC_CFG_IGBS(2) /*!< minimum 80 bit times */
#define ENET_INTERFRAMEGAP_72BIT MAC_CFG_IGBS(3) /*!< minimum 72 bit times */
-#define ENET_INTERFRAMEGAP_64BIT MAC_CFG_IGBS(4) /*!< minimum 64 bit times */
+#define ENET_INTERFRAMEGAP_64BIT MAC_CFG_IGBS(4) /*!< minimum 64 bit times */
#define ENET_INTERFRAMEGAP_56BIT MAC_CFG_IGBS(5) /*!< minimum 56 bit times */
#define ENET_INTERFRAMEGAP_48BIT MAC_CFG_IGBS(6) /*!< minimum 48 bit times */
-#define ENET_INTERFRAMEGAP_40BIT MAC_CFG_IGBS(7) /*!< minimum 40 bit times */
+#define ENET_INTERFRAMEGAP_40BIT MAC_CFG_IGBS(7) /*!< minimum 40 bit times */
#define ENET_WATCHDOG_ENABLE ((uint32_t)0x00000000U) /*!< the MAC allows no more than 2048 bytes of the frame being received */
#define ENET_WATCHDOG_DISABLE ENET_MAC_CFG_WDD /*!< the MAC disables the watchdog timer on the receiver, and can receive frames of up to 16384 bytes */
-
+
#define ENET_JABBER_ENABLE ((uint32_t)0x00000000U) /*!< the maximum transmission byte is 2048 */
#define ENET_JABBER_DISABLE ENET_MAC_CFG_JBD /*!< the maximum transmission byte can be 16384 */
#define ENET_CARRIERSENSE_ENABLE ((uint32_t)0x00000000U) /*!< the MAC transmitter generates carrier sense error and aborts the transmission */
#define ENET_CARRIERSENSE_DISABLE ENET_MAC_CFG_CSD /*!< the MAC transmitter ignores the MII CRS signal during frame transmission in half-duplex mode */
-
+
#define ENET_SPEEDMODE_10M ((uint32_t)0x00000000U) /*!< 10 Mbit/s */
#define ENET_SPEEDMODE_100M ENET_MAC_CFG_SPD /*!< 100 Mbit/s */
@@ -958,15 +935,15 @@ typedef struct
#define ENET_DEFERRALCHECK_DISABLE ((uint32_t)0x00000000U) /*!< the deferral check function is disabled */
/* mac_frmf register value */
-#define MAC_FRMF_PCFRM(regval) (BITS(6,7) & ((uint32_t)(regval) << 6)) /*!< write value to ENET_MAC_FRMF_PCFRM bit field */
+#define MAC_FRMF_PCFRM(regval) (BITS(6,7) & ((uint32_t)(regval) << 6U)) /*!< write value to ENET_MAC_FRMF_PCFRM bit field */
#define ENET_PCFRM_PREVENT_ALL MAC_FRMF_PCFRM(0) /*!< MAC prevents all control frames from reaching the application */
#define ENET_PCFRM_PREVENT_PAUSEFRAME MAC_FRMF_PCFRM(1) /*!< MAC only forwards all other control frames except pause control frame */
#define ENET_PCFRM_FORWARD_ALL MAC_FRMF_PCFRM(2) /*!< MAC forwards all control frames to application even if they fail the address filter */
#define ENET_PCFRM_FORWARD_FILTERED MAC_FRMF_PCFRM(3) /*!< MAC forwards control frames that only pass the address filter */
-
+
#define ENET_RX_FILTER_DISABLE ENET_MAC_FRMF_FAR /*!< all received frame are forwarded to application */
#define ENET_RX_FILTER_ENABLE ((uint32_t)0x00000000U) /*!< only the frame passed the filter can be forwarded to application */
-
+
#define ENET_SRC_FILTER_NORMAL_ENABLE ENET_MAC_FRMF_SAFLT /*!< filter source address */
#define ENET_SRC_FILTER_INVERSE_ENABLE (ENET_MAC_FRMF_SAFLT | ENET_MAC_FRMF_SAIFLT) /*!< inverse source address filtering result */
#define ENET_SRC_FILTER_DISABLE ((uint32_t)0x00000000U) /*!< source address function in filter disable */
@@ -975,14 +952,14 @@ typedef struct
#define ENET_BROADCASTFRAMES_ENABLE ((uint32_t)0x00000000U) /*!< the address filters pass all received broadcast frames */
#define ENET_BROADCASTFRAMES_DISABLE ENET_MAC_FRMF_BFRMD /*!< the address filters filter all incoming broadcast frames */
-
+
#define ENET_DEST_FILTER_INVERSE_ENABLE ENET_MAC_FRMF_DAIFLT /*!< inverse DA filtering result */
#define ENET_DEST_FILTER_INVERSE_DISABLE ((uint32_t)0x00000000U) /*!< not inverse DA filtering result */
#define ENET_DEST_FILTER_INVERSE ENET_MAC_FRMF_DAIFLT /*!< inverse DA filtering result function */
#define ENET_PROMISCUOUS_ENABLE ENET_MAC_FRMF_PM /*!< promiscuous mode enabled */
#define ENET_PROMISCUOUS_DISABLE ((uint32_t)0x00000000U) /*!< promiscuous mode disabled */
-
+
#define ENET_MULTICAST_FILTER_HASH_OR_PERFECT (ENET_MAC_FRMF_HMF | ENET_MAC_FRMF_HPFLT) /*!< pass multicast frames that match either the perfect or the hash filtering */
#define ENET_MULTICAST_FILTER_HASH ENET_MAC_FRMF_HMF /*!< pass multicast frames that match the hash filtering */
#define ENET_MULTICAST_FILTER_PERFECT ((uint32_t)0x00000000U) /*!< pass multicast frames that match the perfect filtering */
@@ -997,25 +974,25 @@ typedef struct
#define ENET_UNICAST_FILTER_HASH_MODE ENET_MAC_FRMF_HUF /*!< HASH unicast filter function */
/* mac_phy_ctl register value */
-#define MAC_PHY_CTL_CLR(regval) (BITS(2,4) & ((uint32_t)(regval) << 2)) /*!< write value to ENET_MAC_PHY_CTL_CLR bit field */
+#define MAC_PHY_CTL_CLR(regval) (BITS(2,4) & ((uint32_t)(regval) << 2U)) /*!< write value to ENET_MAC_PHY_CTL_CLR bit field */
#define ENET_MDC_HCLK_DIV42 MAC_PHY_CTL_CLR(0) /*!< HCLK:60-100 MHz; MDC clock= HCLK/42 */
#define ENET_MDC_HCLK_DIV62 MAC_PHY_CTL_CLR(1) /*!< HCLK:100-120 MHz; MDC clock= HCLK/62 */
#define ENET_MDC_HCLK_DIV16 MAC_PHY_CTL_CLR(2) /*!< HCLK:20-35 MHz; MDC clock= HCLK/16 */
#define ENET_MDC_HCLK_DIV26 MAC_PHY_CTL_CLR(3) /*!< HCLK:35-60 MHz; MDC clock= HCLK/26 */
-#define MAC_PHY_CTL_PR(regval) (BITS(6,10) & ((uint32_t)(regval) << 6)) /*!< write value to ENET_MAC_PHY_CTL_PR bit field */
+#define MAC_PHY_CTL_PR(regval) (BITS(6,10) & ((uint32_t)(regval) << 6U)) /*!< write value to ENET_MAC_PHY_CTL_PR bit field */
-#define MAC_PHY_CTL_PA(regval) (BITS(11,15) & ((uint32_t)(regval) << 11)) /*!< write value to ENET_MAC_PHY_CTL_PA bit field */
+#define MAC_PHY_CTL_PA(regval) (BITS(11,15) & ((uint32_t)(regval) << 11U)) /*!< write value to ENET_MAC_PHY_CTL_PA bit field */
/* mac_phy_data register value */
-#define MAC_PHY_DATA_PD(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_PHY_DATA_PD bit field */
+#define MAC_PHY_DATA_PD(regval) (BITS(0,15) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET_MAC_PHY_DATA_PD bit field */
/* mac_fctl register value */
-#define MAC_FCTL_PLTS(regval) (BITS(4,5) & ((uint32_t)(regval) << 4)) /*!< write value to ENET_MAC_FCTL_PLTS bit field */
+#define MAC_FCTL_PLTS(regval) (BITS(4,5) & ((uint32_t)(regval) << 4U)) /*!< write value to ENET_MAC_FCTL_PLTS bit field */
#define ENET_PAUSETIME_MINUS4 MAC_FCTL_PLTS(0) /*!< pause time minus 4 slot times */
#define ENET_PAUSETIME_MINUS28 MAC_FCTL_PLTS(1) /*!< pause time minus 28 slot times */
#define ENET_PAUSETIME_MINUS144 MAC_FCTL_PLTS(2) /*!< pause time minus 144 slot times */
-#define ENET_PAUSETIME_MINUS256 MAC_FCTL_PLTS(3) /*!< pause time minus 256 slot times */
+#define ENET_PAUSETIME_MINUS256 MAC_FCTL_PLTS(3) /*!< pause time minus 256 slot times */
#define ENET_ZERO_QUANTA_PAUSE_ENABLE ((uint32_t)0x00000000U) /*!< enable the automatic zero-quanta generation function */
#define ENET_ZERO_QUANTA_PAUSE_DISABLE ENET_MAC_FCTL_DZQP /*!< disable the automatic zero-quanta generation function */
@@ -1023,7 +1000,7 @@ typedef struct
#define ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT ENET_MAC_FCTL_UPFDT /*!< besides the unique multicast address, MAC also use the MAC0 address to detect pause frame */
#define ENET_UNIQUE_PAUSEDETECT ((uint32_t)0x00000000U) /*!< only the unique multicast address for pause frame which is specified in IEEE802.3 can be detected */
-
+
#define ENET_RX_FLOWCONTROL_ENABLE ENET_MAC_FCTL_RFCEN /*!< enable decoding function for the received pause frame and process it */
#define ENET_RX_FLOWCONTROL_DISABLE ((uint32_t)0x00000000U) /*!< decode function for pause frame is disabled */
#define ENET_RX_FLOWCONTROL ENET_MAC_FCTL_RFCEN /*!< decoding function for the received pause frame and process it */
@@ -1035,28 +1012,28 @@ typedef struct
#define ENET_BACK_PRESSURE_ENABLE ENET_MAC_FCTL_FLCBBKPA /*!< enable the back pressure operation in the MAC */
#define ENET_BACK_PRESSURE_DISABLE ((uint32_t)0x00000000U) /*!< disable the back pressure operation in the MAC */
#define ENET_BACK_PRESSURE ENET_MAC_FCTL_FLCBBKPA /*!< the back pressure operation in the MAC */
-
-#define MAC_FCTL_PTM(regval) (BITS(16,31) & ((uint32_t)(regval) << 16)) /*!< write value to ENET_MAC_FCTL_PTM bit field */
+
+#define MAC_FCTL_PTM(regval) (BITS(16,31) & ((uint32_t)(regval) << 16U)) /*!< write value to ENET_MAC_FCTL_PTM bit field */
/* mac_vlt register value */
-#define MAC_VLT_VLTI(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_VLT_VLTI bit field */
-
+#define MAC_VLT_VLTI(regval) (BITS(0,15) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET_MAC_VLT_VLTI bit field */
+
#define ENET_VLANTAGCOMPARISON_12BIT ENET_MAC_VLT_VLTC /*!< only low 12 bits of the VLAN tag are used for comparison */
#define ENET_VLANTAGCOMPARISON_16BIT ((uint32_t)0x00000000U) /*!< all 16 bits of the VLAN tag are used for comparison */
-/* mac_wum register value */
+/* mac_wum register value */
#define ENET_WUM_FLAG_WUFFRPR ENET_MAC_WUM_WUFFRPR /*!< wakeup frame filter register poniter reset */
#define ENET_WUM_FLAG_WUFR ENET_MAC_WUM_WUFR /*!< wakeup frame received */
#define ENET_WUM_FLAG_MPKR ENET_MAC_WUM_MPKR /*!< magic packet received */
-#define ENET_WUM_POWER_DOWN ENET_MAC_WUM_PWD /*!< power down mode */
-#define ENET_WUM_MAGIC_PACKET_FRAME ENET_MAC_WUM_MPEN /*!< enable a wakeup event due to magic packet reception */
-#define ENET_WUM_WAKE_UP_FRAME ENET_MAC_WUM_WFEN /*!< enable a wakeup event due to wakeup frame reception */
+#define ENET_WUM_POWER_DOWN ENET_MAC_WUM_PWD /*!< power down mode */
+#define ENET_WUM_MAGIC_PACKET_FRAME ENET_MAC_WUM_MPEN /*!< enable a wakeup event due to magic packet reception */
+#define ENET_WUM_WAKE_UP_FRAME ENET_MAC_WUM_WFEN /*!< enable a wakeup event due to wakeup frame reception */
#define ENET_WUM_GLOBAL_UNICAST ENET_MAC_WUM_GU /*!< any received unicast frame passed filter is considered to be a wakeup frame */
/* mac_addr0h register value */
-#define MAC_ADDR0H_ADDR0H(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_ADDR0H_ADDR0H bit field */
+#define MAC_ADDR0H_ADDR0H(regval) (BITS(0,15) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET_MAC_ADDR0H_ADDR0H bit field */
/* mac_addrxh register value, x = 1,2,3 */
-#define MAC_ADDR123H_ADDR123H(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_ADDRxH_ADDRxH(x=1,2,3) bit field */
+#define MAC_ADDR123H_ADDR123H(regval) (BITS(0,15) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET_MAC_ADDRxH_ADDRxH(x=1,2,3) bit field */
#define ENET_ADDRESS_MASK_BYTE0 BIT(24) /*!< low register bits [7:0] */
#define ENET_ADDRESS_MASK_BYTE1 BIT(25) /*!< low register bits [15:8] */
@@ -1066,10 +1043,10 @@ typedef struct
#define ENET_ADDRESS_MASK_BYTE5 BIT(29) /*!< high register bits [15:8] */
#define ENET_ADDRESS_FILTER_SA BIT(30) /*!< use MAC address[47:0] is to compare with the SA fields of the received frame */
-#define ENET_ADDRESS_FILTER_DA ((uint32_t)0x00000000) /*!< use MAC address[47:0] is to compare with the DA fields of the received frame */
-
+#define ENET_ADDRESS_FILTER_DA ((uint32_t)0x00000000U) /*!< use MAC address[47:0] is to compare with the DA fields of the received frame */
+
/* mac_fcth register value */
-#define MAC_FCTH_RFA(regval) ((BITS(0,2) & ((uint32_t)(regval) << 0))<<8) /*!< write value to ENET_MAC_FCTH_RFA bit field */
+#define MAC_FCTH_RFA(regval) ((BITS(0,2) & ((uint32_t)(regval) << 0U)) << 8U) /*!< write value to ENET_MAC_FCTH_RFA bit field */
#define ENET_ACTIVE_THRESHOLD_256BYTES MAC_FCTH_RFA(0) /*!< threshold level is 256 bytes */
#define ENET_ACTIVE_THRESHOLD_512BYTES MAC_FCTH_RFA(1) /*!< threshold level is 512 bytes */
#define ENET_ACTIVE_THRESHOLD_768BYTES MAC_FCTH_RFA(2) /*!< threshold level is 768 bytes */
@@ -1078,7 +1055,7 @@ typedef struct
#define ENET_ACTIVE_THRESHOLD_1536BYTES MAC_FCTH_RFA(5) /*!< threshold level is 1536 bytes */
#define ENET_ACTIVE_THRESHOLD_1792BYTES MAC_FCTH_RFA(6) /*!< threshold level is 1792 bytes */
-#define MAC_FCTH_RFD(regval) ((BITS(4,6) & ((uint32_t)(regval) << 4))<<8) /*!< write value to ENET_MAC_FCTH_RFD bit field */
+#define MAC_FCTH_RFD(regval) ((BITS(4,6) & ((uint32_t)(regval) << 4U)) << 8U) /*!< write value to ENET_MAC_FCTH_RFD bit field */
#define ENET_DEACTIVE_THRESHOLD_256BYTES MAC_FCTH_RFD(0) /*!< threshold level is 256 bytes */
#define ENET_DEACTIVE_THRESHOLD_512BYTES MAC_FCTH_RFD(1) /*!< threshold level is 512 bytes */
#define ENET_DEACTIVE_THRESHOLD_768BYTES MAC_FCTH_RFD(2) /*!< threshold level is 768 bytes */
@@ -1097,100 +1074,100 @@ typedef struct
#define ENET_PTP_TIMESTAMP_INT ENET_PTP_TSCTL_TMSITEN /*!< timestamp interrupt trigger enable */
/* ptp_ssinc register value */
-#define PTP_SSINC_STMSSI(regval) (BITS(0,7) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_PTP_SSINC_STMSSI bit field */
+#define PTP_SSINC_STMSSI(regval) (BITS(0,7) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET_PTP_SSINC_STMSSI bit field */
/* ptp_tsl register value */
-#define GET_PTP_TSL_STMSS(regval) GET_BITS((uint32_t)(regval),0,30) /*!< get value of ENET_PTP_TSL_STMSS bit field */
-
-#define ENET_PTP_TIME_POSITIVE ((uint32_t)0x00000000) /*!< time value is positive */
-#define ENET_PTP_TIME_NEGATIVE ENET_PTP_TSL_STS /*!< time value is negative */
+#define GET_PTP_TSL_STMSS(regval) GET_BITS((uint32_t)(regval), 0U, 30U) /*!< get value of ENET_PTP_TSL_STMSS bit field */
-#define GET_PTP_TSL_STS(regval) (((regval) & BIT(31)) >> (31U)) /*!< get value of ENET_PTP_TSL_STS bit field */
+#define ENET_PTP_TIME_POSITIVE ((uint32_t)0x00000000U) /*!< time value is positive */
+#define ENET_PTP_TIME_NEGATIVE ENET_PTP_TSL_STS /*!< time value is negative */
+
+#define GET_PTP_TSL_STS(regval) (((regval) & BIT(31)) >> (31U)) /*!< get value of ENET_PTP_TSL_STS bit field */
/* ptp_tsul register value */
-#define PTP_TSUL_TMSUSS(regval) (BITS(0,30) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_PTP_TSUL_TMSUSS bit field */
+#define PTP_TSUL_TMSUSS(regval) (BITS(0,30) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET_PTP_TSUL_TMSUSS bit field */
-#define ENET_PTP_ADD_TO_TIME ((uint32_t)0x00000000) /*!< timestamp update value is added to system time */
-#define ENET_PTP_SUBSTRACT_FROM_TIME ENET_PTP_TSUL_TMSUPNS /*!< timestamp update value is subtracted from system time */
+#define ENET_PTP_ADD_TO_TIME ((uint32_t)0x00000000U) /*!< timestamp update value is added to system time */
+#define ENET_PTP_SUBSTRACT_FROM_TIME ENET_PTP_TSUL_TMSUPNS /*!< timestamp update value is subtracted from system time */
/* dma_bctl register value */
-#define DMA_BCTL_DPSL(regval) (BITS(2,6) & ((uint32_t)(regval) << 2)) /*!< write value to ENET_DMA_BCTL_DPSL bit field */
-#define GET_DMA_BCTL_DPSL(regval) GET_BITS((regval),2,6) /*!< get value of ENET_DMA_BCTL_DPSL bit field */
-
-#define DMA_BCTL_PGBL(regval) (BITS(8,13) & ((uint32_t)(regval) << 8)) /*!< write value to ENET_DMA_BCTL_PGBL bit field */
-#define ENET_PGBL_1BEAT DMA_BCTL_PGBL(1) /*!< maximum number of beats is 1 */
-#define ENET_PGBL_2BEAT DMA_BCTL_PGBL(2) /*!< maximum number of beats is 2 */
-#define ENET_PGBL_4BEAT DMA_BCTL_PGBL(4) /*!< maximum number of beats is 4 */
-#define ENET_PGBL_8BEAT DMA_BCTL_PGBL(8) /*!< maximum number of beats is 8 */
-#define ENET_PGBL_16BEAT DMA_BCTL_PGBL(16) /*!< maximum number of beats is 16 */
-#define ENET_PGBL_32BEAT DMA_BCTL_PGBL(32) /*!< maximum number of beats is 32 */
-#define ENET_PGBL_4xPGBL_4BEAT (DMA_BCTL_PGBL(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 4 */
-#define ENET_PGBL_4xPGBL_8BEAT (DMA_BCTL_PGBL(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 8 */
-#define ENET_PGBL_4xPGBL_16BEAT (DMA_BCTL_PGBL(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 16 */
-#define ENET_PGBL_4xPGBL_32BEAT (DMA_BCTL_PGBL(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 32 */
-#define ENET_PGBL_4xPGBL_64BEAT (DMA_BCTL_PGBL(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 64 */
-#define ENET_PGBL_4xPGBL_128BEAT (DMA_BCTL_PGBL(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 128 */
-
-#define DMA_BCTL_RTPR(regval) (BITS(14,15) & ((uint32_t)(regval) << 14)) /*!< write value to ENET_DMA_BCTL_RTPR bit field */
-#define ENET_ARBITRATION_RXTX_1_1 DMA_BCTL_RTPR(0) /*!< receive and transmit priority ratio is 1:1*/
-#define ENET_ARBITRATION_RXTX_2_1 DMA_BCTL_RTPR(1) /*!< receive and transmit priority ratio is 2:1*/
-#define ENET_ARBITRATION_RXTX_3_1 DMA_BCTL_RTPR(2) /*!< receive and transmit priority ratio is 3:1 */
-#define ENET_ARBITRATION_RXTX_4_1 DMA_BCTL_RTPR(3) /*!< receive and transmit priority ratio is 4:1 */
-#define ENET_ARBITRATION_RXPRIORTX ENET_DMA_BCTL_DAB /*!< RxDMA has higher priority than TxDMA */
-
-#define ENET_FIXED_BURST_ENABLE ENET_DMA_BCTL_FB /*!< AHB can only use SINGLE/INCR4/INCR8/INCR16 during start of normal burst transfers */
-#define ENET_FIXED_BURST_DISABLE ((uint32_t)0x00000000) /*!< AHB can use SINGLE/INCR burst transfer operations */
-
-#define DMA_BCTL_RXDP(regval) (BITS(17,22) & ((uint32_t)(regval) << 17)) /*!< write value to ENET_DMA_BCTL_RXDP bit field */
-#define ENET_RXDP_1BEAT DMA_BCTL_RXDP(1) /*!< maximum number of beats 1 */
-#define ENET_RXDP_2BEAT DMA_BCTL_RXDP(2) /*!< maximum number of beats 2 */
-#define ENET_RXDP_4BEAT DMA_BCTL_RXDP(4) /*!< maximum number of beats 4 */
-#define ENET_RXDP_8BEAT DMA_BCTL_RXDP(8) /*!< maximum number of beats 8 */
-#define ENET_RXDP_16BEAT DMA_BCTL_RXDP(16) /*!< maximum number of beats 16 */
-#define ENET_RXDP_32BEAT DMA_BCTL_RXDP(32) /*!< maximum number of beats 32 */
-#define ENET_RXDP_4xPGBL_4BEAT (DMA_BCTL_RXDP(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 4 */
-#define ENET_RXDP_4xPGBL_8BEAT (DMA_BCTL_RXDP(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 8 */
-#define ENET_RXDP_4xPGBL_16BEAT (DMA_BCTL_RXDP(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 16 */
-#define ENET_RXDP_4xPGBL_32BEAT (DMA_BCTL_RXDP(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 32 */
-#define ENET_RXDP_4xPGBL_64BEAT (DMA_BCTL_RXDP(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 64 */
-#define ENET_RXDP_4xPGBL_128BEAT (DMA_BCTL_RXDP(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 128 */
-
-#define ENET_RXTX_DIFFERENT_PGBL ENET_DMA_BCTL_UIP /*!< RxDMA uses the RXDP[5:0], while TxDMA uses the PGBL[5:0] */
-#define ENET_RXTX_SAME_PGBL ((uint32_t)0x00000000) /*!< RxDMA/TxDMA uses PGBL[5:0] */
-
-#define ENET_ADDRESS_ALIGN_ENABLE ENET_DMA_BCTL_AA /*!< enabled address-aligned */
-#define ENET_ADDRESS_ALIGN_DISABLE ((uint32_t)0x00000000) /*!< disable address-aligned */
+#define DMA_BCTL_DPSL(regval) (BITS(2,6) & ((uint32_t)(regval) << 2U)) /*!< write value to ENET_DMA_BCTL_DPSL bit field */
+#define GET_DMA_BCTL_DPSL(regval) GET_BITS((regval), 2U, 6U) /*!< get value of ENET_DMA_BCTL_DPSL bit field */
+
+#define DMA_BCTL_PGBL(regval) (BITS(8,13) & ((uint32_t)(regval) << 8U)) /*!< write value to ENET_DMA_BCTL_PGBL bit field */
+#define ENET_PGBL_1BEAT DMA_BCTL_PGBL(1) /*!< maximum number of beats is 1 */
+#define ENET_PGBL_2BEAT DMA_BCTL_PGBL(2) /*!< maximum number of beats is 2 */
+#define ENET_PGBL_4BEAT DMA_BCTL_PGBL(4) /*!< maximum number of beats is 4 */
+#define ENET_PGBL_8BEAT DMA_BCTL_PGBL(8) /*!< maximum number of beats is 8 */
+#define ENET_PGBL_16BEAT DMA_BCTL_PGBL(16) /*!< maximum number of beats is 16 */
+#define ENET_PGBL_32BEAT DMA_BCTL_PGBL(32) /*!< maximum number of beats is 32 */
+#define ENET_PGBL_4xPGBL_4BEAT (DMA_BCTL_PGBL(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 4 */
+#define ENET_PGBL_4xPGBL_8BEAT (DMA_BCTL_PGBL(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 8 */
+#define ENET_PGBL_4xPGBL_16BEAT (DMA_BCTL_PGBL(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 16 */
+#define ENET_PGBL_4xPGBL_32BEAT (DMA_BCTL_PGBL(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 32 */
+#define ENET_PGBL_4xPGBL_64BEAT (DMA_BCTL_PGBL(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 64 */
+#define ENET_PGBL_4xPGBL_128BEAT (DMA_BCTL_PGBL(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 128 */
+
+#define DMA_BCTL_RTPR(regval) (BITS(14,15) & ((uint32_t)(regval) << 14U)) /*!< write value to ENET_DMA_BCTL_RTPR bit field */
+#define ENET_ARBITRATION_RXTX_1_1 DMA_BCTL_RTPR(0) /*!< receive and transmit priority ratio is 1:1*/
+#define ENET_ARBITRATION_RXTX_2_1 DMA_BCTL_RTPR(1) /*!< receive and transmit priority ratio is 2:1*/
+#define ENET_ARBITRATION_RXTX_3_1 DMA_BCTL_RTPR(2) /*!< receive and transmit priority ratio is 3:1 */
+#define ENET_ARBITRATION_RXTX_4_1 DMA_BCTL_RTPR(3) /*!< receive and transmit priority ratio is 4:1 */
+#define ENET_ARBITRATION_RXPRIORTX ENET_DMA_BCTL_DAB /*!< RxDMA has higher priority than TxDMA */
+
+#define ENET_FIXED_BURST_ENABLE ENET_DMA_BCTL_FB /*!< AHB can only use SINGLE/INCR4/INCR8/INCR16 during start of normal burst transfers */
+#define ENET_FIXED_BURST_DISABLE ((uint32_t)0x00000000U) /*!< AHB can use SINGLE/INCR burst transfer operations */
+
+#define DMA_BCTL_RXDP(regval) (BITS(17,22) & ((uint32_t)(regval) << 17U)) /*!< write value to ENET_DMA_BCTL_RXDP bit field */
+#define ENET_RXDP_1BEAT DMA_BCTL_RXDP(1) /*!< maximum number of beats 1 */
+#define ENET_RXDP_2BEAT DMA_BCTL_RXDP(2) /*!< maximum number of beats 2 */
+#define ENET_RXDP_4BEAT DMA_BCTL_RXDP(4) /*!< maximum number of beats 4 */
+#define ENET_RXDP_8BEAT DMA_BCTL_RXDP(8) /*!< maximum number of beats 8 */
+#define ENET_RXDP_16BEAT DMA_BCTL_RXDP(16) /*!< maximum number of beats 16 */
+#define ENET_RXDP_32BEAT DMA_BCTL_RXDP(32) /*!< maximum number of beats 32 */
+#define ENET_RXDP_4xPGBL_4BEAT (DMA_BCTL_RXDP(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 4 */
+#define ENET_RXDP_4xPGBL_8BEAT (DMA_BCTL_RXDP(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 8 */
+#define ENET_RXDP_4xPGBL_16BEAT (DMA_BCTL_RXDP(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 16 */
+#define ENET_RXDP_4xPGBL_32BEAT (DMA_BCTL_RXDP(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 32 */
+#define ENET_RXDP_4xPGBL_64BEAT (DMA_BCTL_RXDP(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 64 */
+#define ENET_RXDP_4xPGBL_128BEAT (DMA_BCTL_RXDP(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 128 */
+
+#define ENET_RXTX_DIFFERENT_PGBL ENET_DMA_BCTL_UIP /*!< RxDMA uses the RXDP[5:0], while TxDMA uses the PGBL[5:0] */
+#define ENET_RXTX_SAME_PGBL ((uint32_t)0x00000000U) /*!< RxDMA/TxDMA uses PGBL[5:0] */
+
+#define ENET_ADDRESS_ALIGN_ENABLE ENET_DMA_BCTL_AA /*!< enabled address-aligned */
+#define ENET_ADDRESS_ALIGN_DISABLE ((uint32_t)0x00000000U) /*!< disable address-aligned */
/* dma_stat register value */
-#define GET_DMA_STAT_RP(regval) GET_BITS((uint32_t)(regval),17,19) /*!< get value of ENET_DMA_STAT_RP bit field */
-#define ENET_RX_STATE_STOPPED ((uint32_t)0x00000000) /*!< reset or stop rx command issued */
+#define GET_DMA_STAT_RP(regval) GET_BITS((uint32_t)(regval), 17U, 19U) /*!< get value of ENET_DMA_STAT_RP bit field */
+#define ENET_RX_STATE_STOPPED ((uint32_t)0x00000000U) /*!< reset or stop rx command issued */
#define ENET_RX_STATE_FETCHING BIT(17) /*!< fetching the Rx descriptor */
#define ENET_RX_STATE_WAITING (BIT(17)|BIT(18)) /*!< waiting for receive packet */
#define ENET_RX_STATE_SUSPENDED BIT(19) /*!< Rx descriptor unavailable */
#define ENET_RX_STATE_CLOSING (BIT(17)|BIT(19)) /*!< closing receive descriptor */
#define ENET_RX_STATE_QUEUING ENET_DMA_STAT_RP /*!< transferring the receive packet data from recevie buffer to host memory */
-#define GET_DMA_STAT_TP(regval) GET_BITS((uint32_t)(regval),20,22) /*!< get value of ENET_DMA_STAT_TP bit field */
-#define ENET_TX_STATE_STOPPED ((uint32_t)0x00000000) /*!< reset or stop Tx Command issued */
+#define GET_DMA_STAT_TP(regval) GET_BITS((uint32_t)(regval), 20U, 22U) /*!< get value of ENET_DMA_STAT_TP bit field */
+#define ENET_TX_STATE_STOPPED ((uint32_t)0x00000000U) /*!< reset or stop Tx Command issued */
#define ENET_TX_STATE_FETCHING BIT(20) /*!< fetching the Tx descriptor */
#define ENET_TX_STATE_WAITING BIT(21) /*!< waiting for status */
#define ENET_TX_STATE_READING (BIT(20)|BIT(21)) /*!< reading the data from host memory buffer and queuing it to transmit buffer */
#define ENET_TX_STATE_SUSPENDED (BIT(21)|BIT(22)) /*!< Tx descriptor unavailabe or transmit buffer underflow */
#define ENET_TX_STATE_CLOSING ENET_DMA_STAT_TP /*!< closing Tx descriptor */
-#define GET_DMA_STAT_EB(regval) GET_BITS((uint32_t)(regval),23,25) /*!< get value of ENET_DMA_STAT_EB bit field */
+#define GET_DMA_STAT_EB(regval) GET_BITS((uint32_t)(regval), 23U, 25U) /*!< get value of ENET_DMA_STAT_EB bit field */
#define ENET_ERROR_TXDATA_TRANSFER BIT(23) /*!< error during data transfer by TxDMA or RxDMA */
#define ENET_ERROR_READ_TRANSFER BIT(24) /*!< error during write transfer or read transfer */
#define ENET_ERROR_DESC_ACCESS BIT(25) /*!< error during descriptor or buffer access */
/* dma_ctl register value */
-#define DMA_CTL_RTHC(regval) (BITS(3,4) & ((uint32_t)(regval) << 3)) /*!< write value to ENET_DMA_CTL_RTHC bit field */
+#define DMA_CTL_RTHC(regval) (BITS(3,4) & ((uint32_t)(regval) << 3U)) /*!< write value to ENET_DMA_CTL_RTHC bit field */
#define ENET_RX_THRESHOLD_64BYTES DMA_CTL_RTHC(0) /*!< threshold level is 64 Bytes */
#define ENET_RX_THRESHOLD_32BYTES DMA_CTL_RTHC(1) /*!< threshold level is 32 Bytes */
#define ENET_RX_THRESHOLD_96BYTES DMA_CTL_RTHC(2) /*!< threshold level is 96 Bytes */
#define ENET_RX_THRESHOLD_128BYTES DMA_CTL_RTHC(3) /*!< threshold level is 128 Bytes */
-#define DMA_CTL_TTHC(regval) (BITS(14,16) & ((uint32_t)(regval) << 14)) /*!< write value to ENET_DMA_CTL_TTHC bit field */
+#define DMA_CTL_TTHC(regval) (BITS(14,16) & ((uint32_t)(regval) << 14U)) /*!< write value to ENET_DMA_CTL_TTHC bit field */
#define ENET_TX_THRESHOLD_64BYTES DMA_CTL_TTHC(0) /*!< threshold level is 64 Bytes */
#define ENET_TX_THRESHOLD_128BYTES DMA_CTL_TTHC(1) /*!< threshold level is 128 Bytes */
#define ENET_TX_THRESHOLD_192BYTES DMA_CTL_TTHC(2) /*!< threshold level is 192 Bytes */
@@ -1201,68 +1178,68 @@ typedef struct
#define ENET_TX_THRESHOLD_16BYTES DMA_CTL_TTHC(7) /*!< threshold level is 16 Bytes */
#define ENET_TCPIP_CKSUMERROR_ACCEPT ENET_DMA_CTL_DTCERFD /*!< Rx frame with only payload error but no other errors will not be dropped */
-#define ENET_TCPIP_CKSUMERROR_DROP ((uint32_t)0x00000000) /*!< all error frames will be dropped when FERF = 0 */
+#define ENET_TCPIP_CKSUMERROR_DROP ((uint32_t)0x00000000U) /*!< all error frames will be dropped when FERF = 0 */
#define ENET_RX_MODE_STOREFORWARD ENET_DMA_CTL_RSFD /*!< RxFIFO operates in store-and-forward mode */
-#define ENET_RX_MODE_CUTTHROUGH ((uint32_t)0x00000000) /*!< RxFIFO operates in cut-through mode */
+#define ENET_RX_MODE_CUTTHROUGH ((uint32_t)0x00000000U) /*!< RxFIFO operates in cut-through mode */
-#define ENET_FLUSH_RXFRAME_ENABLE ((uint32_t)0x00000000) /*!< RxDMA flushes all frames */
+#define ENET_FLUSH_RXFRAME_ENABLE ((uint32_t)0x00000000U) /*!< RxDMA flushes all frames */
#define ENET_FLUSH_RXFRAME_DISABLE ENET_DMA_CTL_DAFRF /*!< RxDMA does not flush any frames */
#define ENET_NO_FLUSH_RXFRAME ENET_DMA_CTL_DAFRF /*!< RxDMA does not flush frames function */
#define ENET_TX_MODE_STOREFORWARD ENET_DMA_CTL_TSFD /*!< TxFIFO operates in store-and-forward mode */
-#define ENET_TX_MODE_CUTTHROUGH ((uint32_t)0x00000000) /*!< TxFIFO operates in cut-through mode */
+#define ENET_TX_MODE_CUTTHROUGH ((uint32_t)0x00000000U) /*!< TxFIFO operates in cut-through mode */
-#define ENET_FORWARD_ERRFRAMES_ENABLE (ENET_DMA_CTL_FERF<<2) /*!< all frame received with error except runt error are forwarded to memory */
+#define ENET_FORWARD_ERRFRAMES_ENABLE (ENET_DMA_CTL_FERF << 2U) /*!< all frame received with error except runt error are forwarded to memory */
#define ENET_FORWARD_ERRFRAMES_DISABLE ((uint32_t)0x00000000) /*!< RxFIFO drop error frame */
-#define ENET_FORWARD_ERRFRAMES (ENET_DMA_CTL_FERF<<2) /*!< the function that all frame received with error except runt error are forwarded to memory */
+#define ENET_FORWARD_ERRFRAMES (ENET_DMA_CTL_FERF << 2U) /*!< the function that all frame received with error except runt error are forwarded to memory */
-#define ENET_FORWARD_UNDERSZ_GOODFRAMES_ENABLE (ENET_DMA_CTL_FUF<<2) /*!< forward undersized good frames */
-#define ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE ((uint32_t)0x00000000) /*!< RxFIFO drops all frames whose length is less than 64 bytes */
-#define ENET_FORWARD_UNDERSZ_GOODFRAMES (ENET_DMA_CTL_FUF<<2) /*!< the function that forwarding undersized good frames */
+#define ENET_FORWARD_UNDERSZ_GOODFRAMES_ENABLE (ENET_DMA_CTL_FUF << 2U) /*!< forward undersized good frames */
+#define ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE ((uint32_t)0x00000000U) /*!< RxFIFO drops all frames whose length is less than 64 bytes */
+#define ENET_FORWARD_UNDERSZ_GOODFRAMES (ENET_DMA_CTL_FUF << 2U) /*!< the function that forwarding undersized good frames */
-#define ENET_SECONDFRAME_OPT_ENABLE ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame mode enable*/
-#define ENET_SECONDFRAME_OPT_DISABLE ((uint32_t)0x00000000) /*!< TxDMA controller operate on second frame mode disable */
-#define ENET_SECONDFRAME_OPT ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame function */
+#define ENET_SECONDFRAME_OPT_ENABLE ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame mode enable*/
+#define ENET_SECONDFRAME_OPT_DISABLE ((uint32_t)0x00000000U) /*!< TxDMA controller operate on second frame mode disable */
+#define ENET_SECONDFRAME_OPT ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame function */
/* dma_mfbocnt register value */
-#define GET_DMA_MFBOCNT_MSFC(regval) GET_BITS((regval),0,15) /*!< get value of ENET_DMA_MFBOCNT_MSFC bit field */
+#define GET_DMA_MFBOCNT_MSFC(regval) GET_BITS((regval), 0U, 15U) /*!< get value of ENET_DMA_MFBOCNT_MSFC bit field */
-#define GET_DMA_MFBOCNT_MSFA(regval) GET_BITS((regval),17,27) /*!< get value of ENET_DMA_MFBOCNT_MSFA bit field */
+#define GET_DMA_MFBOCNT_MSFA(regval) GET_BITS((regval), 17U, 27U) /*!< get value of ENET_DMA_MFBOCNT_MSFA bit field */
/* dma tx descriptor tdes0 register value */
-#define TDES0_CONT(regval) (BITS(3,6) & ((uint32_t)(regval) << 3)) /*!< write value to ENET DMA TDES0 CONT bit field */
-#define GET_TDES0_COCNT(regval) GET_BITS((regval),3,6) /*!< get value of ENET DMA TDES0 CONT bit field */
+#define TDES0_CONT(regval) (BITS(3,6) & ((uint32_t)(regval) << 3U)) /*!< write value to ENET DMA TDES0 CONT bit field */
+#define GET_TDES0_COCNT(regval) GET_BITS((regval), 3U, 6U) /*!< get value of ENET DMA TDES0 CONT bit field */
-#define TDES0_CM(regval) (BITS(22,23) & ((uint32_t)(regval) << 22)) /*!< write value to ENET DMA TDES0 CM bit field */
-#define ENET_CHECKSUM_DISABLE TDES0_CM(0) /*!< checksum insertion disabled */
-#define ENET_CHECKSUM_IPV4HEADER TDES0_CM(1) /*!< only IP header checksum calculation and insertion are enabled */
-#define ENET_CHECKSUM_TCPUDPICMP_SEGMENT TDES0_CM(2) /*!< TCP/UDP/ICMP checksum insertion calculated but pseudo-header */
-#define ENET_CHECKSUM_TCPUDPICMP_FULL TDES0_CM(3) /*!< TCP/UDP/ICMP checksum insertion fully calculated */
+#define TDES0_CM(regval) (BITS(22,23) & ((uint32_t)(regval) << 22U)) /*!< write value to ENET DMA TDES0 CM bit field */
+#define ENET_CHECKSUM_DISABLE TDES0_CM(0) /*!< checksum insertion disabled */
+#define ENET_CHECKSUM_IPV4HEADER TDES0_CM(1) /*!< only IP header checksum calculation and insertion are enabled */
+#define ENET_CHECKSUM_TCPUDPICMP_SEGMENT TDES0_CM(2) /*!< TCP/UDP/ICMP checksum insertion calculated but pseudo-header */
+#define ENET_CHECKSUM_TCPUDPICMP_FULL TDES0_CM(3) /*!< TCP/UDP/ICMP checksum insertion fully calculated */
/* dma tx descriptor tdes1 register value */
-#define TDES1_TB1S(regval) (BITS(0,12) & ((uint32_t)(regval) << 0)) /*!< write value to ENET DMA TDES1 TB1S bit field */
+#define TDES1_TB1S(regval) (BITS(0,12) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET DMA TDES1 TB1S bit field */
-#define TDES1_TB2S(regval) (BITS(16,28) & ((uint32_t)(regval) << 16)) /*!< write value to ENET DMA TDES1 TB2S bit field */
+#define TDES1_TB2S(regval) (BITS(16,28) & ((uint32_t)(regval) << 16U)) /*!< write value to ENET DMA TDES1 TB2S bit field */
/* dma rx descriptor rdes0 register value */
-#define RDES0_FRML(regval) (BITS(16,29) & ((uint32_t)(regval) << 16)) /*!< write value to ENET DMA RDES0 FRML bit field */
-#define GET_RDES0_FRML(regval) GET_BITS((regval),16,29) /*!< get value of ENET DMA RDES0 FRML bit field */
+#define RDES0_FRML(regval) (BITS(16,29) & ((uint32_t)(regval) << 16U)) /*!< write value to ENET DMA RDES0 FRML bit field */
+#define GET_RDES0_FRML(regval) GET_BITS((regval), 16U, 29U) /*!< get value of ENET DMA RDES0 FRML bit field */
/* dma rx descriptor rdes1 register value */
-#define ENET_RECEIVE_COMPLETE_INT_ENABLE ((uint32_t)0x00000000U) /*!< RS bit immediately set after Rx completed */
-#define ENET_RECEIVE_COMPLETE_INT_DISABLE ENET_RDES1_DINTC /*!< RS bit not immediately set after Rx completed */
+#define ENET_RECEIVE_COMPLETE_INT_ENABLE ((uint32_t)0x00000000U) /*!< RS bit immediately set after Rx completed */
+#define ENET_RECEIVE_COMPLETE_INT_DISABLE ENET_RDES1_DINTC /*!< RS bit not immediately set after Rx completed */
-#define GET_RDES1_RB1S(regval) GET_BITS((regval),0,12) /*!< get value of ENET DMA RDES1 RB1S bit field */
+#define GET_RDES1_RB1S(regval) GET_BITS((regval), 0U, 12U) /*!< get value of ENET DMA RDES1 RB1S bit field */
-#define GET_RDES1_RB2S(regval) GET_BITS((regval),16,28) /*!< get value of ENET DMA RDES1 RB2S bit field */
+#define GET_RDES1_RB2S(regval) GET_BITS((regval), 16U, 28U) /*!< get value of ENET DMA RDES1 RB2S bit field */
/* dma rx descriptor rdes4 register value */
-#define RDES4_IPPLDT(regval) (BITS(0,2) & ((uint32_t)(regval) << 0)) /*!< write value to ENET DMA RDES4 IPPLDT bit field */
-#define GET_RDES4_IPPLDT(regval) GET_BITS((regval),0,2) /*!< get value of ENET DMA RDES4 IPPLDT bit field */
+#define RDES4_IPPLDT(regval) (BITS(0,2) & ((uint32_t)(regval) << 0U)) /*!< write value to ENET DMA RDES4 IPPLDT bit field */
+#define GET_RDES4_IPPLDT(regval) GET_BITS((regval),0,2) /*!< get value of ENET DMA RDES4 IPPLDT bit field */
-#define RDES4_PTPMT(regval) (BITS(8,11) & ((uint32_t)(regval) << 8)) /*!< write value to ENET DMA RDES4 PTPMT bit field */
-#define GET_RDES4_PTPMT(regval) GET_BITS((regval),8,11) /*!< get value of ENET DMA RDES4 PTPMT bit field */
+#define RDES4_PTPMT(regval) (BITS(8,11) & ((uint32_t)(regval) << 8U)) /*!< write value to ENET DMA RDES4 PTPMT bit field */
+#define GET_RDES4_PTPMT(regval) GET_BITS((regval),8,11) /*!< get value of ENET DMA RDES4 PTPMT bit field */
/* ENET register mask value */
#define MAC_CFG_MASK ((uint32_t)0xFD30810FU) /*!< ENET_MAC_CFG register mask */
@@ -1270,23 +1247,23 @@ typedef struct
#define DMA_CTL_MASK ((uint32_t)0xF8DE3F23U) /*!< ENET_DMA_CTL register mask */
#define DMA_BCTL_MASK ((uint32_t)0xF800007DU) /*!< ENET_DMA_BCTL register mask */
-#define ETH_DMATXDESC_SIZE 0x10U /*!< TxDMA descriptor size */
-#define ETH_DMARXDESC_SIZE 0x10U /*!< RxDMA descriptor size */
+#define ETH_DMATXDESC_SIZE 0x00000010U /*!< TxDMA descriptor size */
+#define ETH_DMARXDESC_SIZE 0x00000010U /*!< RxDMA descriptor size */
-typedef enum{
+typedef enum {
ENET_PTP_SYSTIME_INIT = ENET_PTP_TSCTL_TMSSTI, /*!< timestamp initialize */
- ENET_PTP_SYSTIME_UPDATE = ENET_PTP_TSCTL_TMSSTU, /*!< timestamp update */
+ ENET_PTP_SYSTIME_UPDATE = ENET_PTP_TSCTL_TMSSTU, /*!< timestamp update */
ENET_PTP_ADDEND_UPDATE = ENET_PTP_TSCTL_TMSARU, /*!< addend register update */
- ENET_PTP_FINEMODE = (int32_t)(ENET_PTP_TSCTL_TMSFCU| BIT(31)), /*!< the system timestamp uses the fine method for updating */
+ ENET_PTP_FINEMODE = (int32_t)(ENET_PTP_TSCTL_TMSFCU | BIT(31)), /*!< the system timestamp uses the fine method for updating */
ENET_PTP_COARSEMODE = ENET_PTP_TSCTL_TMSFCU, /*!< the system timestamp uses the coarse method for updating */
-}enet_ptp_function_enum;
+} enet_ptp_function_enum;
/* ENET remote wake-up frame register length */
#define ETH_WAKEUP_REGISTER_LENGTH 8U /*!< remote wake-up frame register length */
-/* ENET frame size */
-#define ENET_MAX_FRAME_SIZE 1524U /*!< header + frame_extra + payload + CRC */
+/* ENET frame size */
+#define ENET_MAX_FRAME_SIZE 1524U /*!< header + frame_extra + payload + CRC */
/* ENET delay timeout */
#define ENET_DELAY_TO ((uint32_t)0x0004FFFFU) /*!< ENET delay timeout */
@@ -1319,27 +1296,14 @@ ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length);
/* configure the transmit IP frame checksum offload calculation and insertion */
void enet_transmit_checksum_config(enet_descriptors_struct *desc, uint32_t checksum);
/* ENET Tx and Rx function enable (include MAC and DMA module) */
-void enet_enable(void);
+void enet_enable(void);
/* ENET Tx and Rx function disable (include MAC and DMA module) */
void enet_disable(void);
/* configure MAC address */
void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[]);
-/* get MAC address */
+/* get MAC address */
void enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[]);
-/* get the ENET MAC/MSC/PTP/DMA status flag */
-FlagStatus enet_flag_get(enet_flag_enum enet_flag);
-/* clear the ENET DMA status flag */
-void enet_flag_clear(enet_flag_clear_enum enet_flag);
-/* enable ENET MAC/MSC/DMA interrupt */
-void enet_interrupt_enable(enet_int_enum enet_int);
-/* disable ENET MAC/MSC/DMA interrupt */
-void enet_interrupt_disable(enet_int_enum enet_int);
-/* get ENET MAC/MSC/DMA interrupt flag */
-FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag);
-/* clear ENET DMA interrupt flag */
-void enet_interrupt_flag_clear(enet_int_flag_clear_enum int_flag_clear);
-
/* MAC function */
/* ENET Tx function enable (include MAC and DMA module) */
void enet_tx_enable(void);
@@ -1392,7 +1356,7 @@ void enet_flowcontrol_feature_disable(uint32_t feature);
/* DMA function */
/* get the dma transmit/receive process state */
-uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction);
+uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction);
/* poll the dma transmission/reception enable */
void enet_dmaprocess_resume(enet_dmadirection_enum direction);
/* check and recover the Rx process */
@@ -1412,7 +1376,7 @@ FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag)
/* set the bit flag of ENET dma tx descriptor */
void enet_desc_flag_set(enet_descriptors_struct *desc, uint32_t desc_flag);
/* clear the bit flag of ENET dma tx descriptor */
-void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag);
+void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag);
/* when receiving the completed, set RS bit in ENET_DMA_STAT register will set */
void enet_desc_receive_complete_bit_enable(enet_descriptors_struct *desc);
/* when receiving the completed, set RS bit in ENET_DMA_STAT register will not set */
@@ -1450,11 +1414,11 @@ void enet_wum_feature_disable(uint32_t feature);
/* MSC function */
/* reset the MAC statistics counters */
void enet_msc_counters_reset(void);
-/* enable the MAC statistics counter features */
+/* enable the MAC statistics counter features */
void enet_msc_feature_enable(uint32_t feature);
-/* disable the MAC statistics counter features */
+/* disable the MAC statistics counter features */
void enet_msc_feature_disable(uint32_t feature);
-/* get MAC statistics counter */
+/* get MAC statistics counter */
uint32_t enet_msc_counters_get(enet_msc_counter_enum counter);
/* PTP function */
@@ -1485,7 +1449,7 @@ void enet_ptp_finecorrection_adjfreq(int32_t carry_cfg);
/* update system time in coarse method */
void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct *systime_struct);
/* set system time in fine method */
-void enet_ptp_finecorrection_settime(enet_ptp_systime_struct * systime_struct);
+void enet_ptp_finecorrection_settime(enet_ptp_systime_struct *systime_struct);
/* get the ptp flag status */
FlagStatus enet_ptp_flag_get(uint32_t flag);
@@ -1496,7 +1460,7 @@ void enet_initpara_reset(void);
static void enet_default_init(void);
#ifdef USE_DELAY
/* user can provide more timing precise _ENET_DELAY_ function */
-#define _ENET_DELAY_ delay_ms
+#define _ENET_DELAY_ delay_ms
#else
/* insert a delay time */
static void enet_delay(uint32_t ncount);
@@ -1504,4 +1468,17 @@ static void enet_delay(uint32_t ncount);
#define _ENET_DELAY_ enet_delay
#endif
+/* get the ENET MAC/MSC/PTP/DMA status flag */
+FlagStatus enet_flag_get(enet_flag_enum enet_flag);
+/* clear the ENET DMA status flag */
+void enet_flag_clear(enet_flag_clear_enum enet_flag);
+/* enable ENET MAC/MSC/DMA interrupt */
+void enet_interrupt_enable(enet_int_enum enet_int);
+/* disable ENET MAC/MSC/DMA interrupt */
+void enet_interrupt_disable(enet_int_enum enet_int);
+/* get ENET MAC/MSC/DMA interrupt flag */
+FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag);
+/* clear ENET DMA interrupt flag */
+void enet_interrupt_flag_clear(enet_int_flag_clear_enum int_flag_clear);
+
#endif /* GD32F20X_ENET_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exmc.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exmc.h
index 691e835..0f05d11 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exmc.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exmc.h
@@ -2,36 +2,33 @@
\file gd32f20x_exmc.h
\brief definitions for the EXMC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,66 +39,66 @@ OF SUCH DAMAGE.
/* EXMC definitions */
#define EXMC (EXMC_BASE) /*!< EXMC register base address */
-#define EXMC_NOR_PSRAM (EXMC_BASE - 0x40000000) /*!< EXMC NOR/PSRAM base address */
-#define EXMC_NAND (EXMC_BASE - 0x30000000) /*!< EXMC NAND base address */
-#define EXMC_PCCARD (EXMC_BASE - 0x10000000) /*!< EXMC PC card base address */
-#define EXMC_SDRAM (EXMC_BASE + 0x20000000) /*!< EXMC SDRAM base address */
+#define EXMC_NOR_PSRAM (EXMC_BASE - 0x40000000U) /*!< EXMC NOR/PSRAM base address */
+#define EXMC_NAND (EXMC_BASE - 0x30000000U) /*!< EXMC NAND base address */
+#define EXMC_PCCARD (EXMC_BASE - 0x10000000U) /*!< EXMC PC card base address */
+#define EXMC_SDRAM (EXMC_BASE + 0x20000000U) /*!< EXMC SDRAM base address */
/* registers definitions */
/* NOR/PSRAM */
-#define EXMC_SNCTL0 REG32(EXMC + 0x00U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG0 REG32(EXMC + 0x04U) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG0 REG32(EXMC + 0x104U) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL0 REG32(EXMC + 0x00000000U) /*!< EXMC SRAM/NOR flash control register */
+#define EXMC_SNTCFG0 REG32(EXMC + 0x00000004U) /*!< EXMC SRAM/NOR flash timing configuration register */
+#define EXMC_SNWTCFG0 REG32(EXMC + 0x00000104U) /*!< EXMC SRAM/NOR flash write timing configuration register */
-#define EXMC_SNCTL1 REG32(EXMC + 0x08U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG1 REG32(EXMC + 0x0CU) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG1 REG32(EXMC + 0x10CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL1 REG32(EXMC + 0x00000008U) /*!< EXMC SRAM/NOR flash control register */
+#define EXMC_SNTCFG1 REG32(EXMC + 0x0000000CU) /*!< EXMC SRAM/NOR flash timing configuration register */
+#define EXMC_SNWTCFG1 REG32(EXMC + 0x0000010CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
-#define EXMC_SNCTL2 REG32(EXMC + 0x10U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG2 REG32(EXMC + 0x14U) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG2 REG32(EXMC + 0x114U) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL2 REG32(EXMC + 0x00000010U) /*!< EXMC SRAM/NOR flash control register */
+#define EXMC_SNTCFG2 REG32(EXMC + 0x00000014U) /*!< EXMC SRAM/NOR flash timing configuration register */
+#define EXMC_SNWTCFG2 REG32(EXMC + 0x00000114U) /*!< EXMC SRAM/NOR flash write timing configuration register */
-#define EXMC_SNCTL3 REG32(EXMC + 0x18U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG3 REG32(EXMC + 0x1CU) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG3 REG32(EXMC + 0x11CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL3 REG32(EXMC + 0x00000018U) /*!< EXMC SRAM/NOR flash control register */
+#define EXMC_SNTCFG3 REG32(EXMC + 0x0000001CU) /*!< EXMC SRAM/NOR flash timing configuration register */
+#define EXMC_SNWTCFG3 REG32(EXMC + 0x0000011CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
/* NAND/PC card */
-#define EXMC_NPCTL1 REG32(EXMC + 0x60U) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN1 REG32(EXMC + 0x64U) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG1 REG32(EXMC + 0x68U) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG1 REG32(EXMC + 0x6CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_NECC1 REG32(EXMC + 0x74U) /*!< EXMC NAND ECC register */
-
-#define EXMC_NPCTL2 REG32(EXMC + 0x80U) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN2 REG32(EXMC + 0x84U) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG2 REG32(EXMC + 0x88U) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG2 REG32(EXMC + 0x8CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_NECC2 REG32(EXMC + 0x94U) /*!< EXMC NAND ECC register */
-
-#define EXMC_NPCTL3 REG32(EXMC + 0xA0U) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN3 REG32(EXMC + 0xA4U) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG3 REG32(EXMC + 0xA8U) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG3 REG32(EXMC + 0xACU) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_PIOTCFG3 REG32(EXMC + 0xB0U) /*!< EXMC PC card I/O space timing configuration register */
+#define EXMC_NPCTL1 REG32(EXMC + 0x00000060U) /*!< EXMC NAND/PC card control register */
+#define EXMC_NPINTEN1 REG32(EXMC + 0x00000064U) /*!< EXMC NAND/PC card interrupt enable register */
+#define EXMC_NPCTCFG1 REG32(EXMC + 0x00000068U) /*!< EXMC NAND/PC card common space timing configuration register */
+#define EXMC_NPATCFG1 REG32(EXMC + 0x0000006CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
+#define EXMC_NECC1 REG32(EXMC + 0x00000074U) /*!< EXMC NAND ECC register */
+
+#define EXMC_NPCTL2 REG32(EXMC + 0x00000080U) /*!< EXMC NAND/PC card control register */
+#define EXMC_NPINTEN2 REG32(EXMC + 0x00000084U) /*!< EXMC NAND/PC card interrupt enable register */
+#define EXMC_NPCTCFG2 REG32(EXMC + 0x00000088U) /*!< EXMC NAND/PC card common space timing configuration register */
+#define EXMC_NPATCFG2 REG32(EXMC + 0x0000008CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
+#define EXMC_NECC2 REG32(EXMC + 0x00000094U) /*!< EXMC NAND ECC register */
+
+#define EXMC_NPCTL3 REG32(EXMC + 0x000000A0U) /*!< EXMC NAND/PC card control register */
+#define EXMC_NPINTEN3 REG32(EXMC + 0x000000A4U) /*!< EXMC NAND/PC card interrupt enable register */
+#define EXMC_NPCTCFG3 REG32(EXMC + 0x000000A8U) /*!< EXMC NAND/PC card common space timing configuration register */
+#define EXMC_NPATCFG3 REG32(EXMC + 0x000000ACU) /*!< EXMC NAND/PC card attribute space timing configuration register */
+#define EXMC_PIOTCFG3 REG32(EXMC + 0x000000B0U) /*!< EXMC PC card I/O space timing configuration register */
/* SDRAM */
-#define EXMC_SDCTL0 REG32(EXMC + 0x140U) /*!< EXMC SDRAM control register */
-#define EXMC_SDTCFG0 REG32(EXMC + 0x148U) /*!< EXMC SDRAM timing configuration register register */
+#define EXMC_SDCTL0 REG32(EXMC + 0x000000140U) /*!< EXMC SDRAM control register */
+#define EXMC_SDTCFG0 REG32(EXMC + 0x000000148U) /*!< EXMC SDRAM timing configuration register register */
-#define EXMC_SDCTL1 REG32(EXMC + 0x144U) /*!< EXMC SDRAM control register */
-#define EXMC_SDTCFG1 REG32(EXMC + 0x14CU) /*!< EXMC SDRAM timing configuration register register */
+#define EXMC_SDCTL1 REG32(EXMC + 0x00000144U) /*!< EXMC SDRAM control register */
+#define EXMC_SDTCFG1 REG32(EXMC + 0x0000014CU) /*!< EXMC SDRAM timing configuration register register */
-#define EXMC_SDCMD REG32(EXMC + 0x150U) /*!< EXMC SDRAM command register */
-#define EXMC_SDARI REG32(EXMC + 0x154U) /*!< EXMC SDRAM auto-refresh interval register */
-#define EXMC_SDSTAT REG32(EXMC + 0x158U) /*!< EXMC SDRAM status register */
-#define EXMC_SDRSCTL REG32(EXMC + 0x180U) /*!< EXMC SDRAM read sample control register */
+#define EXMC_SDCMD REG32(EXMC + 0x00000150U) /*!< EXMC SDRAM command register */
+#define EXMC_SDARI REG32(EXMC + 0x00000154U) /*!< EXMC SDRAM auto-refresh interval register */
+#define EXMC_SDSTAT REG32(EXMC + 0x00000158U) /*!< EXMC SDRAM status register */
+#define EXMC_SDRSCTL REG32(EXMC + 0x00000180U) /*!< EXMC SDRAM read sample control register */
/* SQPI PSRAM */
-#define EXMC_SINIT REG32(EXMC + 0x310U) /*!< EXMC SPI initialization register */
-#define EXMC_SRCMD REG32(EXMC + 0x320U) /*!< EXMC SPI read command register */
-#define EXMC_SWCMD REG32(EXMC + 0x330U) /*!< EXMC SPI write command register */
-#define EXMC_SIDL REG32(EXMC + 0x340U) /*!< EXMC SPI ID low register */
-#define EXMC_SIDH REG32(EXMC + 0x350U) /*!< EXMC SPI ID high register */
+#define EXMC_SINIT REG32(EXMC + 0x00000310U) /*!< EXMC SPI initialization register */
+#define EXMC_SRCMD REG32(EXMC + 0x00000320U) /*!< EXMC SPI read command register */
+#define EXMC_SWCMD REG32(EXMC + 0x00000330U) /*!< EXMC SPI write command register */
+#define EXMC_SIDL REG32(EXMC + 0x00000340U) /*!< EXMC SPI ID low register */
+#define EXMC_SIDH REG32(EXMC + 0x00000350U) /*!< EXMC SPI ID high register */
/* bits definitions */
/* NOR/PSRAM */
@@ -250,234 +247,227 @@ OF SUCH DAMAGE.
/* constants definitions */
/* EXMC NOR/SRAM timing initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t asyn_access_mode; /*!< asynchronous access mode */
-
+
uint32_t syn_data_latency; /*!< configure the data latency */
- /*!< the range is EXMC_DATALAT_2_CLK to EXMC_DATALAT_17_CLK */
-
+ /*!< the range is EXMC_DATALAT_2_CLK to EXMC_DATALAT_17_CLK */
+
uint32_t syn_clk_division; /*!< configure the clock divide ratio */
- /*!< the range is EXMC_SYN_CLOCK_RATIO_2_CLK to EXMC_SYN_CLOCK_RATIO_16_CLK */
-
+ /*!< the range is EXMC_SYN_CLOCK_RATIO_2_CLK to EXMC_SYN_CLOCK_RATIO_16_CLK */
+
uint32_t bus_latency; /*!< configure the bus latency */
- /*!< the range is 1 to 16 HCLK */
-
+ /*!< the range is 1 to 16 HCLK */
+
uint32_t asyn_data_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
- /*!< the range is 2 to 256 HCLK */
-
+ /*!< the range is 2 to 256 HCLK */
+
uint32_t asyn_address_holdtime; /*!< configure the address hold time,asynchronous access mode valid */
- /*!< the range is 2 to 16 HCLK */
-
+ /*!< the range is 2 to 16 HCLK */
+
uint32_t asyn_address_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
- /*!< the range is 1 to 16 HCLK */
-}exmc_norsram_timing_parameter_struct;
+ /*!< the range is 1 to 16 HCLK */
+} exmc_norsram_timing_parameter_struct;
/* EXMC NOR/SRAM initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t norsram_region; /*!< select the region of EXMC NOR/SRAM bank */
- /*!< norsram_region: EXMC_BANK0_NORSRAM_REGIONx,x=0..3 */
-
+ /*!< norsram_region: EXMC_BANK0_NORSRAM_REGIONx,x=0..3 */
+
uint32_t write_mode; /*!< the write mode, synchronous mode or asynchronous mode */
- /*!< write_mode: EXMC_ASYN_WRITE or EXMC_SYN_WRITE */
-
+ /*!< write_mode: EXMC_ASYN_WRITE or EXMC_SYN_WRITE */
+
uint32_t extended_mode; /*!< enable or disable the extended mode */
- /*!< extended_mode: ENABLE or DISABLE */
-
+ /*!< extended_mode: ENABLE or DISABLE */
+
uint32_t asyn_wait; /*!< enable or disable the asynchronous wait function */
- /*!< asyn_wait: ENABLE or DISABLE */
-
+ /*!< asyn_wait: ENABLE or DISABLE */
+
uint32_t nwait_signal; /*!< enable or disable the NWAIT signal while in synchronous bust mode */
- /*!< nwait_signal: ENABLE or DISABLE */
-
+ /*!< nwait_signal: ENABLE or DISABLE */
+
uint32_t memory_write; /*!< enable or disable the write operation */
- /*!< memory_write: ENABLE or DISABLE */
-
+ /*!< memory_write: ENABLE or DISABLE */
+
uint32_t nwait_config; /*!< NWAIT signal configuration */
- /*!< nwait_config: EXMC_NWAIT_CONFIG_BEFORE or EXMC_NWAIT_CONFIG_DURING */
-
+ /*!< nwait_config: EXMC_NWAIT_CONFIG_BEFORE or EXMC_NWAIT_CONFIG_DURING */
+
uint32_t wrap_burst_mode; /*!< enable or disable the wrap burst mode */
- /*!< wrap_burst_mode: ENABLE or DISABLE */
-
+ /*!< wrap_burst_mode: ENABLE or DISABLE */
+
uint32_t nwait_polarity; /*!< specifies the polarity of NWAIT signal from memory */
- /*!< nwait_polarity: EXMC_NWAIT_POLARITY_LOW or EXMC_NWAIT_POLARITY_HIGH */
-
+ /*!< nwait_polarity: EXMC_NWAIT_POLARITY_LOW or EXMC_NWAIT_POLARITY_HIGH */
+
uint32_t burst_mode; /*!< enable or disable the burst mode */
- /*!< burst_mode: ENABLE or DISABLE */
-
+ /*!< burst_mode: ENABLE or DISABLE */
+
uint32_t databus_width; /*!< specifies the databus width of external memory */
- /*!< databus_width: EXMC_NOR_DATABUS_WIDTH_8B or EXMC_NOR_DATABUS_WIDTH_16B */
-
+ /*!< databus_width: EXMC_NOR_DATABUS_WIDTH_8B or EXMC_NOR_DATABUS_WIDTH_16B */
+
uint32_t memory_type; /*!< specifies the type of external memory */
- /*!< memory_type: EXMC_MEMORY_TYPE_SRAM / EXMC_MEMORY_TYPE_PSRAM / EXMC_MEMORY_TYPE_NOR */
-
+ /*!< memory_type: EXMC_MEMORY_TYPE_SRAM / EXMC_MEMORY_TYPE_PSRAM / EXMC_MEMORY_TYPE_NOR */
+
uint32_t address_data_mux; /*!< specifies whether the data bus and address bus are multiplexed */
- /*!< address_data_mux: ENABLE or DISABLE */
-
- exmc_norsram_timing_parameter_struct* read_write_timing; /*!< timing parameters for read and write if the extendedmode is not used or the timing
+ /*!< address_data_mux: ENABLE or DISABLE */
+
+ exmc_norsram_timing_parameter_struct
+ *read_write_timing; /*!< timing parameters for read and write if the extendedmode is not used or the timing
parameters for read if the extendedmode is used. */
-
- exmc_norsram_timing_parameter_struct* write_timing; /*!< timing parameters for write when the extendedmode is used. */
-}exmc_norsram_parameter_struct;
+
+ exmc_norsram_timing_parameter_struct *write_timing; /*!< timing parameters for write when the extendedmode is used. */
+} exmc_norsram_parameter_struct;
/* EXMC NAND/PC card timing initialize struct */
-typedef struct
-{
- uint32_t databus_hiztime; /*!< configure the dadtabus HiZ time for write operation */
- /*!< the range is 1 to 256 HCLK */
-
+typedef struct {
+ uint32_t databus_hiztime; /*!< configure the databus HiZ time for write operation */
+ /*!< the range is 1 to 256 HCLK */
+
uint32_t holdtime; /*!< configure the address hold time(or the data hold time for write operation) */
- /*!< the range is 1 to 255 HCLK */
-
+ /*!< the range is 1 to 255 HCLK */
+
uint32_t waittime; /*!< configure the minimum wait time */
- /*!< the range is 2 to 256 HCLK (+NWAIT active cycles) */
-
+ /*!< the range is 2 to 256 HCLK (+NWAIT active cycles) */
+
uint32_t setuptime; /*!< configure the address setup time */
- /*!< the range is 1 to 256 HCLK */
-}exmc_nand_pccard_timing_parameter_struct;
+ /*!< the range is 1 to 256 HCLK */
+} exmc_nand_pccard_timing_parameter_struct;
/* EXMC NAND initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t nand_bank; /*!< select the bank of NAND */
- /*!< nand_bank: EXMC_BANK1_NAND or EXMC_BANK2_NAND */
-
+ /*!< nand_bank: EXMC_BANK1_NAND or EXMC_BANK2_NAND */
+
uint32_t ecc_size; /*!< the page size for the ECC calculation */
- /*!< ecc_size: EXMC_ECC_SIZE_xBYTES,x=256,512,1024,2048,4096 */
-
- uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
- /*!< atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16 */
-
+ /*!< ecc_size: EXMC_ECC_SIZE_xBYTES,x=256,512,1024,2048,4096 */
+
+ uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
+ /*!< atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16 */
+
uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
- /*!< ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16 */
-
+ /*!< ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16 */
+
uint32_t ecc_logic; /*!< enable or disable the ECC calculation logic */
- /*!< ecc_logic: ENABLE or DISABLE */
-
+ /*!< ecc_logic: ENABLE or DISABLE */
+
uint32_t databus_width; /*!< the NAND flash databus width */
- /*!< databus_width: EXMC_NAND_DATABUS_WIDTH_8B or EXMC_NAND_DATABUS_WIDTH_16B */
-
- uint32_t wait_feature; /*!< enables or disables the wait feature */
- /*!< wait_feature: ENABLE or DISABLE */
-
- exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash Common Space */
-
- exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash Attribute Space */
-}exmc_nand_parameter_struct;
+ /*!< databus_width: EXMC_NAND_DATABUS_WIDTH_8B or EXMC_NAND_DATABUS_WIDTH_16B */
+
+ uint32_t wait_feature; /*!< enable or disable the wait feature */
+ /*!< wait_feature: ENABLE or DISABLE */
+
+ exmc_nand_pccard_timing_parameter_struct *common_space_timing; /*!< the timing parameters for NAND flash common space */
+
+ exmc_nand_pccard_timing_parameter_struct *attribute_space_timing; /*!< the timing parameters for NAND flash attribute space */
+} exmc_nand_parameter_struct;
/* EXMC PC card initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
- /*!< atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16 */
-
+ /*!< atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16 */
+
uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
- /*!< ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16 */
-
- uint32_t wait_feature; /*!< enables or disables the Wait feature */
- /*!< wait_feature: ENABLE or DISABLE */
-
- exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash Common Space */
-
- exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash Attribute Space */
-
- exmc_nand_pccard_timing_parameter_struct* io_space_timing; /*!< the timing parameters for NAND flash IO Space */
-}exmc_pccard_parameter_struct;
+ /*!< ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16 */
+
+ uint32_t wait_feature; /*!< enable or disable the wait feature */
+ /*!< wait_feature: ENABLE or DISABLE */
+
+ exmc_nand_pccard_timing_parameter_struct *common_space_timing; /*!< the timing parameters for NAND flash common space */
+
+ exmc_nand_pccard_timing_parameter_struct *attribute_space_timing; /*!< the timing parameters for NAND flash attribute space */
+
+ exmc_nand_pccard_timing_parameter_struct *io_space_timing; /*!< the timing parameters for NAND flash IO Space */
+} exmc_pccard_parameter_struct;
/* EXMC SDRAM timing initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t row_to_column_delay; /*!< configure the row to column delay */
- /*!< the range is 1 to 16 cycles */
-
+ /*!< the range is 1 to 16 cycles */
+
uint32_t row_precharge_delay; /*!< configure the row precharge delay */
- /*!< the range is 1 to 16 cycles */
-
+ /*!< the range is 1 to 16 cycles */
+
uint32_t write_recovery_delay; /*!< configure the write recovery delay */
- /*!< the range is 1 to 16 cycles */
-
- uint32_t auto_refresh_delay; /*!< configure the auto refresh delay */
- /*!< the range is 1 to 16 cycles */
-
+ /*!< the range is 1 to 16 cycles */
+
+ uint32_t auto_refresh_delay; /*!< configure the auto refresh delay */
+ /*!< the range is 1 to 16 cycles */
+
uint32_t row_address_select_delay; /*!< configure the row address select delay */
- /*!< the range is 1 to 16 cycles */
-
+ /*!< the range is 1 to 16 cycles */
+
uint32_t exit_selfrefresh_delay; /*!< configure the exit self-refresh delay */
- /*!< the range is 1 to 16 cycles */
-
+ /*!< the range is 1 to 16 cycles */
+
uint32_t load_mode_register_delay; /*!< configure the load mode register delay */
- /*!< the range is 1 to 16 cycles */
-}exmc_sdram_timing_parameter_struct;
+ /*!< the range is 1 to 16 cycles */
+} exmc_sdram_timing_parameter_struct;
/* EXMC SDRAM initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t sdram_device; /*!< device of SDRAM */
- /*!< sdram_device: EXMC_SDRAM_DEVICE0 or EXMC_SDRAM_DEVICE1 */
-
+ /*!< sdram_device: EXMC_SDRAM_DEVICE0 or EXMC_SDRAM_DEVICE1 */
+
uint32_t pipeline_read_delay; /*!< the delay for reading data after CAS latency in HCLK clock cycles */
- /*!< pipeline_read_delay: EXMC_PIPELINE_DELAY_x_HCLK, x=0..2 */
-
- uint32_t brust_read_switch; /*!< enable or disable the burst read */
- /*!< brust_read_switch: ENABLE or DISABLE */
-
+ /*!< pipeline_read_delay: EXMC_PIPELINE_DELAY_x_HCLK, x=0..2 */
+
+ uint32_t burst_read_switch; /*!< enable or disable the burst read */
+ /*!< burst_read_switch: ENABLE or DISABLE */
+
uint32_t sdclock_config; /*!< the SDCLK memory clock for both SDRAM banks */
- /*!< sdclock_config: EXMC_SDCLK_DISABLE,EXMC_SDCLK_PERIODS_2_HCLK,EXMC_SDCLK_PERIODS_3_HCLK */
-
+ /*!< sdclock_config: EXMC_SDCLK_DISABLE,EXMC_SDCLK_PERIODS_2_HCLK,EXMC_SDCLK_PERIODS_3_HCLK */
+
uint32_t write_protection; /*!< enable or disable SDRAM bank write protection function */
- /*!< write_protection: ENABLE or DISABLE */
-
+ /*!< write_protection: ENABLE or DISABLE */
+
uint32_t cas_latency; /*!< configure the SDRAM CAS latency */
- /*!< cas_latency: EXMC_CAS_LATENCY_x_SDCLK, x=1..3 */
-
+ /*!< cas_latency: EXMC_CAS_LATENCY_x_SDCLK, x=1..3 */
+
uint32_t internal_bank_number; /*!< the number internal banks */
- /*!< internal_bank_number: EXMC_SDRAM_2_INTER_BANK or EXMC_SDRAM_4_INTER_BANK */
-
+ /*!< internal_bank_number: EXMC_SDRAM_2_INTER_BANK or EXMC_SDRAM_4_INTER_BANK */
+
uint32_t data_width; /*!< the databus width of SDRAM memory */
- /*!< data_width: EXMC_SDRAM_DATABUS_WIDTH_8B,EXMC_SDRAM_DATABUS_WIDTH_16B,EXMC_SDRAM_DATABUS_WIDTH_32B */
-
+ /*!< data_width: EXMC_SDRAM_DATABUS_WIDTH_8B,EXMC_SDRAM_DATABUS_WIDTH_16B,EXMC_SDRAM_DATABUS_WIDTH_32B */
+
uint32_t row_address_width; /*!< the bit width of a row address */
- /*!< row_address_width: EXMC_SDRAM_ROW_ADDRESS_x, x=11..13 */
-
+ /*!< row_address_width: EXMC_SDRAM_ROW_ADDRESS_x, x=11..13 */
+
uint32_t column_address_width; /*!< the bit width of a column address */
- /*!< column_address_width: EXMC_SDRAM_COW_ADDRESS_x, x=8..11 */
-
- exmc_sdram_timing_parameter_struct* timing; /*!< the timing parameters for write and read SDRAM */
-}exmc_sdram_parameter_struct;
+ /*!< column_address_width: EXMC_SDRAM_COW_ADDRESS_x, x=8..11 */
+
+ exmc_sdram_timing_parameter_struct *timing; /*!< the timing parameters for write and read SDRAM */
+} exmc_sdram_parameter_struct;
/* EXMC SDRAM command initialize structure */
-typedef struct
-{
+typedef struct {
uint32_t mode_register_content; /*!< the SDRAM mode register content */
- /*!< mode_register_content: */
-
+ /*!< mode_register_content: */
+
uint32_t auto_refresh_number; /*!< the number of successive auto-refresh cycles will be send when CMD = 011 */
- /*!< auto_refresh_number: EXMC_SDRAM_AUTO_REFLESH_x_SDCLK, x=1..15 */
-
+ /*!< auto_refresh_number: EXMC_SDRAM_AUTO_REFLESH_x_SDCLK, x=1..15 */
+
uint32_t bank_select; /*!< the bank which command will be sent to */
- /*!< bank_select: EXMC_SDRAM_DEVICE0_SELECT, EXMC_SDRAM_DEVICE1_SELECT, EXMC_SDRAM_DEVICE0_1_SELECT */
-
+ /*!< bank_select: EXMC_SDRAM_DEVICE0_SELECT, EXMC_SDRAM_DEVICE1_SELECT, EXMC_SDRAM_DEVICE0_1_SELECT */
+
uint32_t command; /*!< the commands that will be sent to SDRAM */
- /*!< command: EXMC_SDRAM_NORMAL_OPERATION, EXMC_SDRAM_CLOCK_ENABLE, EXMC_SDRAM_PRECHARGE_ALL,
- EXMC_SDRAM_AUTO_REFRESH, EXMC_SDRAM_LOAD_MODE_REGISTER, EXMC_SDRAM_SELF_REFRESH,
- EXMC_SDRAM_POWERDOWN_ENTRY */
-}exmc_sdram_command_parameter_struct;
+ /*!< command: EXMC_SDRAM_NORMAL_OPERATION, EXMC_SDRAM_CLOCK_ENABLE, EXMC_SDRAM_PRECHARGE_ALL,
+ EXMC_SDRAM_AUTO_REFRESH, EXMC_SDRAM_LOAD_MODE_REGISTER, EXMC_SDRAM_SELF_REFRESH,
+ EXMC_SDRAM_POWERDOWN_ENTRY */
+} exmc_sdram_command_parameter_struct;
/* EXMC SQPISRAM initialize structure */
-typedef struct{
+typedef struct {
uint32_t sample_polarity; /*!< read data sample polarity */
- /*!< sample_polarity: EXMC_SDRAM_SAMPLE_RISING_EDGE,EXMC_SDRAM_SAMPLE_FALLING_EDGE */
-
+ /*!< sample_polarity: EXMC_SDRAM_SAMPLE_RISING_EDGE,EXMC_SDRAM_SAMPLE_FALLING_EDGE */
+
uint32_t id_length; /*!< SPI PSRAM ID length */
- /*!< id_length: EXMC_SQPIPSRAM_ID_LENGTH_xB,x=8,16,32,64 */
-
+ /*!< id_length: EXMC_SQPIPSRAM_ID_LENGTH_xB,x=8,16,32,64 */
+
uint32_t address_bits; /*!< bit number of SPI PSRAM address phase */
- /*!< address_bits: EXMC_SQPIPSRAM_ADDR_LENGTH_xB,x=1..26 */
-
+ /*!< address_bits: EXMC_SQPIPSRAM_ADDR_LENGTH_xB,x=1..26 */
+
uint32_t command_bits; /*!< bit number of SPI PSRAM command phase */
- /*!< command_bits: EXMC_SQPIPSRAM_COMMAND_LENGTH_xB,x=4,8,16 */
-}exmc_sqpipsram_parameter_struct;
+ /*!< command_bits: EXMC_SQPIPSRAM_COMMAND_LENGTH_xB,x=4,8,16 */
+} exmc_sqpipsram_parameter_struct;
/* EXMC NOR/SRAM bank region definition */
#define EXMC_BANK0_NORSRAM_REGION0 ((uint32_t)0x00000000U) /*!< bank0 NOR/SRAM region0 */
@@ -548,21 +538,23 @@ typedef struct{
/* synchronous clock divide ratio */
#define SNTCFG_CKDIV(regval) (BITS(20,23) & ((uint32_t)(regval) << 20))
-#define EXMC_SYN_CLOCK_RATIO_2_CLK SNTCFG_CKDIV(1) /*!< EXMC_CLK = 2*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_3_CLK SNTCFG_CKDIV(2) /*!< EXMC_CLK = 3*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_4_CLK SNTCFG_CKDIV(3) /*!< EXMC_CLK = 4*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_5_CLK SNTCFG_CKDIV(4) /*!< EXMC_CLK = 5*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_6_CLK SNTCFG_CKDIV(5) /*!< EXMC_CLK = 6*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_7_CLK SNTCFG_CKDIV(6) /*!< EXMC_CLK = 7*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_8_CLK SNTCFG_CKDIV(7) /*!< EXMC_CLK = 8*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_9_CLK SNTCFG_CKDIV(8) /*!< EXMC_CLK = 9*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_10_CLK SNTCFG_CKDIV(9) /*!< EXMC_CLK = 10*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_11_CLK SNTCFG_CKDIV(10) /*!< EXMC_CLK = 11*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_12_CLK SNTCFG_CKDIV(11) /*!< EXMC_CLK = 12*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_13_CLK SNTCFG_CKDIV(12) /*!< EXMC_CLK = 13*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_14_CLK SNTCFG_CKDIV(13) /*!< EXMC_CLK = 14*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_15_CLK SNTCFG_CKDIV(14) /*!< EXMC_CLK = 15*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_16_CLK SNTCFG_CKDIV(15) /*!< EXMC_CLK = 16*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_DISABLE SNTCFG_CKDIV(0) /*!< EXMC_CLK disable */
+#define EXMC_SYN_CLOCK_RATIO_2_CLK SNTCFG_CKDIV(1) /*!< EXMC_CLK = HCLK/2 */
+#define EXMC_SYN_CLOCK_RATIO_3_CLK SNTCFG_CKDIV(2) /*!< EXMC_CLK = HCLK/3 */
+#define EXMC_SYN_CLOCK_RATIO_4_CLK SNTCFG_CKDIV(3) /*!< EXMC_CLK = HCLK/4 */
+#define EXMC_SYN_CLOCK_RATIO_5_CLK SNTCFG_CKDIV(4) /*!< EXMC_CLK = HCLK/5 */
+#define EXMC_SYN_CLOCK_RATIO_6_CLK SNTCFG_CKDIV(5) /*!< EXMC_CLK = HCLK/6 */
+#define EXMC_SYN_CLOCK_RATIO_7_CLK SNTCFG_CKDIV(6) /*!< EXMC_CLK = HCLK/7 */
+#define EXMC_SYN_CLOCK_RATIO_8_CLK SNTCFG_CKDIV(7) /*!< EXMC_CLK = HCLK/8 */
+#define EXMC_SYN_CLOCK_RATIO_9_CLK SNTCFG_CKDIV(8) /*!< EXMC_CLK = HCLK/9 */
+#define EXMC_SYN_CLOCK_RATIO_10_CLK SNTCFG_CKDIV(9) /*!< EXMC_CLK = HCLK/10 */
+#define EXMC_SYN_CLOCK_RATIO_11_CLK SNTCFG_CKDIV(10) /*!< EXMC_CLK = HCLK/11 */
+#define EXMC_SYN_CLOCK_RATIO_12_CLK SNTCFG_CKDIV(11) /*!< EXMC_CLK = HCLK/12 */
+#define EXMC_SYN_CLOCK_RATIO_13_CLK SNTCFG_CKDIV(12) /*!< EXMC_CLK = HCLK/13 */
+#define EXMC_SYN_CLOCK_RATIO_14_CLK SNTCFG_CKDIV(13) /*!< EXMC_CLK = HCLK/14 */
+#define EXMC_SYN_CLOCK_RATIO_15_CLK SNTCFG_CKDIV(14) /*!< EXMC_CLK = HCLK/15 */
+#define EXMC_SYN_CLOCK_RATIO_16_CLK SNTCFG_CKDIV(15) /*!< EXMC_CLK = HCLK/16 */
+
/* EXMC NOR/SRAM write mode */
#define EXMC_ASYN_WRITE ((uint32_t)0x00000000U) /*!< asynchronous write mode */
#define EXMC_SYN_WRITE EXMC_SNCTL_SYNCWR /*!< synchronous write mode */
@@ -578,50 +570,50 @@ typedef struct{
/* NAND/PC card */
/* ECC size */
#define NPCTL_ECCSZ(regval) (BITS(17,19) & ((uint32_t)(regval) << 17))
-#define EXMC_ECC_SIZE_256BYTES NPCTL_ECCSZ(0) /* 256 bytes */
-#define EXMC_ECC_SIZE_512BYTES NPCTL_ECCSZ(1) /* 512 bytes */
-#define EXMC_ECC_SIZE_1024BYTES NPCTL_ECCSZ(2) /* 1024 bytes */
-#define EXMC_ECC_SIZE_2048BYTES NPCTL_ECCSZ(3) /* 2048 bytes */
-#define EXMC_ECC_SIZE_4096BYTES NPCTL_ECCSZ(4) /* 4096 bytes */
-#define EXMC_ECC_SIZE_8192BYTES NPCTL_ECCSZ(5) /* 8192 bytes */
+#define EXMC_ECC_SIZE_256BYTES NPCTL_ECCSZ(0) /*!< ECC size is 256 bytes */
+#define EXMC_ECC_SIZE_512BYTES NPCTL_ECCSZ(1) /*!< ECC size is 512 bytes */
+#define EXMC_ECC_SIZE_1024BYTES NPCTL_ECCSZ(2) /*!< ECC size is 1024 bytes */
+#define EXMC_ECC_SIZE_2048BYTES NPCTL_ECCSZ(3) /*!< ECC size is 2048 bytes */
+#define EXMC_ECC_SIZE_4096BYTES NPCTL_ECCSZ(4) /*!< ECC size is 4096 bytes */
+#define EXMC_ECC_SIZE_8192BYTES NPCTL_ECCSZ(5) /*!< ECC size is 8192 bytes */
/* ALE to RE delay */
#define NPCTL_ATR(regval) (BITS(13,16) & ((uint32_t)(regval) << 13))
-#define EXMC_ALE_RE_DELAY_1_HCLK NPCTL_ATR(0) /* ALE to RE delay = 1*HCLK */
-#define EXMC_ALE_RE_DELAY_2_HCLK NPCTL_ATR(1) /* ALE to RE delay = 2*HCLK */
-#define EXMC_ALE_RE_DELAY_3_HCLK NPCTL_ATR(2) /* ALE to RE delay = 3*HCLK */
-#define EXMC_ALE_RE_DELAY_4_HCLK NPCTL_ATR(3) /* ALE to RE delay = 4*HCLK */
-#define EXMC_ALE_RE_DELAY_5_HCLK NPCTL_ATR(4) /* ALE to RE delay = 5*HCLK */
-#define EXMC_ALE_RE_DELAY_6_HCLK NPCTL_ATR(5) /* ALE to RE delay = 6*HCLK */
-#define EXMC_ALE_RE_DELAY_7_HCLK NPCTL_ATR(6) /* ALE to RE delay = 7*HCLK */
-#define EXMC_ALE_RE_DELAY_8_HCLK NPCTL_ATR(7) /* ALE to RE delay = 8*HCLK */
-#define EXMC_ALE_RE_DELAY_9_HCLK NPCTL_ATR(8) /* ALE to RE delay = 9*HCLK */
-#define EXMC_ALE_RE_DELAY_10_HCLK NPCTL_ATR(9) /* ALE to RE delay = 10*HCLK */
-#define EXMC_ALE_RE_DELAY_11_HCLK NPCTL_ATR(10) /* ALE to RE delay = 11*HCLK */
-#define EXMC_ALE_RE_DELAY_12_HCLK NPCTL_ATR(11) /* ALE to RE delay = 12*HCLK */
-#define EXMC_ALE_RE_DELAY_13_HCLK NPCTL_ATR(12) /* ALE to RE delay = 13*HCLK */
-#define EXMC_ALE_RE_DELAY_14_HCLK NPCTL_ATR(13) /* ALE to RE delay = 14*HCLK */
-#define EXMC_ALE_RE_DELAY_15_HCLK NPCTL_ATR(14) /* ALE to RE delay = 15*HCLK */
-#define EXMC_ALE_RE_DELAY_16_HCLK NPCTL_ATR(15) /* ALE to RE delay = 16*HCLK */
+#define EXMC_ALE_RE_DELAY_1_HCLK NPCTL_ATR(0) /*!< ALE to RE delay = 1*HCLK */
+#define EXMC_ALE_RE_DELAY_2_HCLK NPCTL_ATR(1) /*!< ALE to RE delay = 2*HCLK */
+#define EXMC_ALE_RE_DELAY_3_HCLK NPCTL_ATR(2) /*!< ALE to RE delay = 3*HCLK */
+#define EXMC_ALE_RE_DELAY_4_HCLK NPCTL_ATR(3) /*!< ALE to RE delay = 4*HCLK */
+#define EXMC_ALE_RE_DELAY_5_HCLK NPCTL_ATR(4) /*!< ALE to RE delay = 5*HCLK */
+#define EXMC_ALE_RE_DELAY_6_HCLK NPCTL_ATR(5) /*!< ALE to RE delay = 6*HCLK */
+#define EXMC_ALE_RE_DELAY_7_HCLK NPCTL_ATR(6) /*!< ALE to RE delay = 7*HCLK */
+#define EXMC_ALE_RE_DELAY_8_HCLK NPCTL_ATR(7) /*!< ALE to RE delay = 8*HCLK */
+#define EXMC_ALE_RE_DELAY_9_HCLK NPCTL_ATR(8) /*!< ALE to RE delay = 9*HCLK */
+#define EXMC_ALE_RE_DELAY_10_HCLK NPCTL_ATR(9) /*!< ALE to RE delay = 10*HCLK */
+#define EXMC_ALE_RE_DELAY_11_HCLK NPCTL_ATR(10) /*!< ALE to RE delay = 11*HCLK */
+#define EXMC_ALE_RE_DELAY_12_HCLK NPCTL_ATR(11) /*!< ALE to RE delay = 12*HCLK */
+#define EXMC_ALE_RE_DELAY_13_HCLK NPCTL_ATR(12) /*!< ALE to RE delay = 13*HCLK */
+#define EXMC_ALE_RE_DELAY_14_HCLK NPCTL_ATR(13) /*!< ALE to RE delay = 14*HCLK */
+#define EXMC_ALE_RE_DELAY_15_HCLK NPCTL_ATR(14) /*!< ALE to RE delay = 15*HCLK */
+#define EXMC_ALE_RE_DELAY_16_HCLK NPCTL_ATR(15) /*!< ALE to RE delay = 16*HCLK */
/* CLE to RE delay */
#define NPCTL_CTR(regval) (BITS(9,12) & ((uint32_t)(regval) << 9))
-#define EXMC_CLE_RE_DELAY_1_HCLK NPCTL_CTR(0) /* CLE to RE delay = 1*HCLK */
-#define EXMC_CLE_RE_DELAY_2_HCLK NPCTL_CTR(1) /* CLE to RE delay = 2*HCLK */
-#define EXMC_CLE_RE_DELAY_3_HCLK NPCTL_CTR(2) /* CLE to RE delay = 3*HCLK */
-#define EXMC_CLE_RE_DELAY_4_HCLK NPCTL_CTR(3) /* CLE to RE delay = 4*HCLK */
-#define EXMC_CLE_RE_DELAY_5_HCLK NPCTL_CTR(4) /* CLE to RE delay = 5*HCLK */
-#define EXMC_CLE_RE_DELAY_6_HCLK NPCTL_CTR(5) /* CLE to RE delay = 6*HCLK */
-#define EXMC_CLE_RE_DELAY_7_HCLK NPCTL_CTR(6) /* CLE to RE delay = 7*HCLK */
-#define EXMC_CLE_RE_DELAY_8_HCLK NPCTL_CTR(7) /* CLE to RE delay = 8*HCLK */
-#define EXMC_CLE_RE_DELAY_9_HCLK NPCTL_CTR(8) /* CLE to RE delay = 9*HCLK */
-#define EXMC_CLE_RE_DELAY_10_HCLK NPCTL_CTR(9) /* CLE to RE delay = 10*HCLK */
-#define EXMC_CLE_RE_DELAY_11_HCLK NPCTL_CTR(10) /* CLE to RE delay = 11*HCLK */
-#define EXMC_CLE_RE_DELAY_12_HCLK NPCTL_CTR(11) /* CLE to RE delay = 12*HCLK */
-#define EXMC_CLE_RE_DELAY_13_HCLK NPCTL_CTR(12) /* CLE to RE delay = 13*HCLK */
-#define EXMC_CLE_RE_DELAY_14_HCLK NPCTL_CTR(13) /* CLE to RE delay = 14*HCLK */
-#define EXMC_CLE_RE_DELAY_15_HCLK NPCTL_CTR(14) /* CLE to RE delay = 15*HCLK */
-#define EXMC_CLE_RE_DELAY_16_HCLK NPCTL_CTR(15) /* CLE to RE delay = 16*HCLK */
+#define EXMC_CLE_RE_DELAY_1_HCLK NPCTL_CTR(0) /*!< CLE to RE delay = 1*HCLK */
+#define EXMC_CLE_RE_DELAY_2_HCLK NPCTL_CTR(1) /*!< CLE to RE delay = 2*HCLK */
+#define EXMC_CLE_RE_DELAY_3_HCLK NPCTL_CTR(2) /*!< CLE to RE delay = 3*HCLK */
+#define EXMC_CLE_RE_DELAY_4_HCLK NPCTL_CTR(3) /*!< CLE to RE delay = 4*HCLK */
+#define EXMC_CLE_RE_DELAY_5_HCLK NPCTL_CTR(4) /*!< CLE to RE delay = 5*HCLK */
+#define EXMC_CLE_RE_DELAY_6_HCLK NPCTL_CTR(5) /*!< CLE to RE delay = 6*HCLK */
+#define EXMC_CLE_RE_DELAY_7_HCLK NPCTL_CTR(6) /*!< CLE to RE delay = 7*HCLK */
+#define EXMC_CLE_RE_DELAY_8_HCLK NPCTL_CTR(7) /*!< CLE to RE delay = 8*HCLK */
+#define EXMC_CLE_RE_DELAY_9_HCLK NPCTL_CTR(8) /*!< CLE to RE delay = 9*HCLK */
+#define EXMC_CLE_RE_DELAY_10_HCLK NPCTL_CTR(9) /*!< CLE to RE delay = 10*HCLK */
+#define EXMC_CLE_RE_DELAY_11_HCLK NPCTL_CTR(10) /*!< CLE to RE delay = 11*HCLK */
+#define EXMC_CLE_RE_DELAY_12_HCLK NPCTL_CTR(11) /*!< CLE to RE delay = 12*HCLK */
+#define EXMC_CLE_RE_DELAY_13_HCLK NPCTL_CTR(12) /*!< CLE to RE delay = 13*HCLK */
+#define EXMC_CLE_RE_DELAY_14_HCLK NPCTL_CTR(13) /*!< CLE to RE delay = 14*HCLK */
+#define EXMC_CLE_RE_DELAY_15_HCLK NPCTL_CTR(14) /*!< CLE to RE delay = 15*HCLK */
+#define EXMC_CLE_RE_DELAY_16_HCLK NPCTL_CTR(15) /*!< CLE to RE delay = 16*HCLK */
/* NAND bank memory data bus width */
#define NPCTL_NDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
@@ -713,7 +705,7 @@ typedef struct{
#define EXMC_SDRAM_14_DELAY_CELL SDRSCTL_SDSC(14) /*!< select the clock after 14 delay cell */
#define EXMC_SDRAM_15_DELAY_CELL SDRSCTL_SDSC(15) /*!< select the clock after 15 delay cell */
- /* EXMC SDRAM internal banks */
+/* EXMC SDRAM internal banks */
#define EXMC_SDRAM_2_INTER_BANK ((uint32_t)0x00000000U) /*!< 2 internal banks */
#define EXMC_SDRAM_4_INTER_BANK EXMC_SDCTL_NBK /*!< 4 internal banks */
@@ -821,57 +813,62 @@ typedef struct{
#define EXMC_SDRAM_INT_FLAG_REFRESH EXMC_SDARI_REIE /*!< interrupt refresh error enable */
/* function declarations */
-/* function configuration */
+/* NOR/SRAM */
/* deinitialize EXMC NOR/SRAM region */
void exmc_norsram_deinit(uint32_t exmc_norsram_region);
-/* exmc_norsram_parameter_struct parameter initialize */
-void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
+/* initialize exmc_norsram_parameter_struct with the default values */
+void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct *exmc_norsram_init_struct);
/* initialize EXMC NOR/SRAM region */
-void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
-/* EXMC NOR/SRAM bank enable */
+void exmc_norsram_init(exmc_norsram_parameter_struct *exmc_norsram_init_struct);
+/* enable EXMC NOR/SRAM bank region */
void exmc_norsram_enable(uint32_t exmc_norsram_region);
-/* EXMC NOR/SRAM bank disable */
+/* disable EXMC NOR/SRAM bank region */
void exmc_norsram_disable(uint32_t exmc_norsram_region);
+/* NAND */
/* deinitialize EXMC NAND bank */
void exmc_nand_deinit(uint32_t exmc_nand_bank);
-/* exmc_nand_init_struct parameter initialize */
-void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
+/* initialize exmc_nand_parameter_struct with the default values */
+void exmc_nand_struct_para_init(exmc_nand_parameter_struct *exmc_nand_init_struct);
/* initialize EXMC NAND bank */
-void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
-/* EXMC NAND bank enable */
+void exmc_nand_init(exmc_nand_parameter_struct *exmc_nand_init_struct);
+/* enable EXMC NAND bank */
void exmc_nand_enable(uint32_t exmc_nand_bank);
-/* EXMC NAND bank disable */
+/* disable EXMC NAND bank */
void exmc_nand_disable(uint32_t exmc_nand_bank);
/* enable or disable the EXMC NAND ECC function */
void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue);
/* get the EXMC ECC value */
uint32_t exmc_ecc_get(uint32_t exmc_nand_bank);
+/* PC card */
/* deinitialize EXMC PC card bank */
void exmc_pccard_deinit(void);
+/* initialize exmc_pccard_parameter_struct with the default values */
+void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct *exmc_pccard_init_struct);
/* initialize EXMC PC card bank */
-void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
-/* exmc_pccard_parameter_struct parameter initialize */
-void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
-/* EXMC PC card bank enable */
+void exmc_pccard_init(exmc_pccard_parameter_struct *exmc_pccard_init_struct);
+/* enable EXMC PC card bank */
void exmc_pccard_enable(void);
-/* EXMC PC card bank disable */
+/* disable EXMC PC card bank */
void exmc_pccard_disable(void);
+/* SDRAM */
/* deinitialize EXMC SDRAM device */
void exmc_sdram_deinit(uint32_t exmc_sdram_device);
+/* initialize exmc_sdram_init_struct with the default values */
+void exmc_sdram_struct_para_init(exmc_sdram_parameter_struct *exmc_sdram_init_struct);
/* initialize EXMC SDRAM device */
-void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
-/* exmc_sdram_parameter_struct parameter initialize */
-void exmc_sdram_parameter_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
+void exmc_sdram_init(exmc_sdram_parameter_struct *exmc_sdram_init_struct);
+/* initialize exmc_sdram_command_parameter_struct with the default values */
+void exmc_sdram_struct_command_para_init(exmc_sdram_command_parameter_struct *exmc_sdram_command_init_struct);
/* configure the SDRAM memory command */
-void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct);
+void exmc_sdram_command_config(exmc_sdram_command_parameter_struct *exmc_sdram_command_init_struct);
/* set auto-refresh interval */
void exmc_sdram_refresh_count_set(uint32_t exmc_count);
/* set the number of successive auto-refresh command */
void exmc_sdram_autorefresh_number_set(uint32_t exmc_number);
-/* config the write protection function */
+/* configure the write protection function */
void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue);
/* get the status of SDRAM device0 or device1 */
uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device);
@@ -882,12 +879,13 @@ void exmc_sdram_readsample_enable(void);
/* disable read sample */
void exmc_sdram_readsample_disable(void);
+/* SQPIPSARM */
/* deinitialize EXMC SQPIPSRAM */
void exmc_sqpipsram_deinit(void);
+/* initialize exmc_sqpipsram_init_struct with the default values */
+void exmc_sqpipsram_struct_para_init(exmc_sqpipsram_parameter_struct *exmc_sqpipsram_init_struct);
/* initialize EXMC SQPIPSRAM */
-void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
-/* exmc_sqpipsram_parameter_struct parameter initialize */
-void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
+void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct *exmc_sqpipsram_init_struct);
/* set the read command */
void exmc_sqpipsram_read_command_set(uint32_t read_command_mode, uint32_t read_wait_cycle, uint32_t read_command_code);
/* set the write command */
@@ -904,17 +902,17 @@ uint32_t exmc_sqpipsram_high_id_get(void);
FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag);
/* interrupt & flag functions */
-/* check EXMC flag is set or not */
+/* get EXMC flag status */
FlagStatus exmc_flag_get(uint32_t bank, uint32_t flag);
-/* clear EXMC flag */
+/* clear EXMC flag status */
void exmc_flag_clear(uint32_t bank, uint32_t flag);
-/* check EXMC flag is set or not */
-FlagStatus exmc_interrupt_flag_get(uint32_t bank, uint32_t interrupt_source);
-/* clear EXMC flag */
-void exmc_interrupt_flag_clear(uint32_t bank, uint32_t interrupt_source);
/* enable EXMC interrupt */
-void exmc_interrupt_enable(uint32_t bank, uint32_t interrupt_source);
+void exmc_interrupt_enable(uint32_t bank, uint32_t interrupt);
/* disable EXMC interrupt */
-void exmc_interrupt_disable(uint32_t bank, uint32_t interrupt_source);
+void exmc_interrupt_disable(uint32_t bank, uint32_t interrupt);
+/* get EXMC interrupt flag */
+FlagStatus exmc_interrupt_flag_get(uint32_t bank, uint32_t interrupt);
+/* clear EXMC interrupt flag */
+void exmc_interrupt_flag_clear(uint32_t bank, uint32_t interrupt);
#endif /* GD32F20X_EXMC_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exti.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exti.h
index 34ff397..79c4f43 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exti.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_exti.h
@@ -2,36 +2,33 @@
\file gd32f20x_exti.h
\brief definitions for the EXTI
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -44,12 +41,12 @@ OF SUCH DAMAGE.
#define EXTI EXTI_BASE
/* registers definitions */
-#define EXTI_INTEN REG32(EXTI + 0x00U) /*!< interrupt enable register */
-#define EXTI_EVEN REG32(EXTI + 0x04U) /*!< event enable register */
-#define EXTI_RTEN REG32(EXTI + 0x08U) /*!< rising edge trigger enable register */
-#define EXTI_FTEN REG32(EXTI + 0x0CU) /*!< falling trigger enable register */
-#define EXTI_SWIEV REG32(EXTI + 0x10U) /*!< software interrupt event register */
-#define EXTI_PD REG32(EXTI + 0x14U) /*!< pending register */
+#define EXTI_INTEN REG32(EXTI + 0x00000000U) /*!< interrupt enable register */
+#define EXTI_EVEN REG32(EXTI + 0x00000004U) /*!< event enable register */
+#define EXTI_RTEN REG32(EXTI + 0x00000008U) /*!< rising edge trigger enable register */
+#define EXTI_FTEN REG32(EXTI + 0x0000000CU) /*!< falling edge trigger enable register */
+#define EXTI_SWIEV REG32(EXTI + 0x00000010U) /*!< software interrupt event register */
+#define EXTI_PD REG32(EXTI + 0x00000014U) /*!< pending register */
/* bits definitions */
/* EXTI_INTEN */
@@ -163,31 +160,30 @@ OF SUCH DAMAGE.
#define EXTI_SWIEV_SWIEV19 BIT(19) /*!< software interrupt/event request from line 19 */
/* EXTI_PD */
-#define EXTI_PD_PD0 BIT(0) /*!< interrupt/event pending status from line 0 */
-#define EXTI_PD_PD1 BIT(1) /*!< interrupt/event pending status from line 1 */
-#define EXTI_PD_PD2 BIT(2) /*!< interrupt/event pending status from line 2 */
-#define EXTI_PD_PD3 BIT(3) /*!< interrupt/event pending status from line 3 */
-#define EXTI_PD_PD4 BIT(4) /*!< interrupt/event pending status from line 4 */
-#define EXTI_PD_PD5 BIT(5) /*!< interrupt/event pending status from line 5 */
-#define EXTI_PD_PD6 BIT(6) /*!< interrupt/event pending status from line 6 */
-#define EXTI_PD_PD7 BIT(7) /*!< interrupt/event pending status from line 7 */
-#define EXTI_PD_PD8 BIT(8) /*!< interrupt/event pending status from line 8 */
-#define EXTI_PD_PD9 BIT(9) /*!< interrupt/event pending status from line 9 */
-#define EXTI_PD_PD10 BIT(10) /*!< interrupt/event pending status from line 10 */
-#define EXTI_PD_PD11 BIT(11) /*!< interrupt/event pending status from line 11 */
-#define EXTI_PD_PD12 BIT(12) /*!< interrupt/event pending status from line 12 */
-#define EXTI_PD_PD13 BIT(13) /*!< interrupt/event pending status from line 13 */
-#define EXTI_PD_PD14 BIT(14) /*!< interrupt/event pending status from line 14 */
-#define EXTI_PD_PD15 BIT(15) /*!< interrupt/event pending status from line 15 */
-#define EXTI_PD_PD16 BIT(16) /*!< interrupt/event pending status from line 16 */
-#define EXTI_PD_PD17 BIT(17) /*!< interrupt/event pending status from line 17 */
-#define EXTI_PD_PD18 BIT(18) /*!< interrupt/event pending status from line 18 */
-#define EXTI_PD_PD19 BIT(19) /*!< interrupt/event pending status from line 19 */
+#define EXTI_PD_PD0 BIT(0) /*!< interrupt pending status from line 0 */
+#define EXTI_PD_PD1 BIT(1) /*!< interrupt pending status from line 1 */
+#define EXTI_PD_PD2 BIT(2) /*!< interrupt pending status from line 2 */
+#define EXTI_PD_PD3 BIT(3) /*!< interrupt pending status from line 3 */
+#define EXTI_PD_PD4 BIT(4) /*!< interrupt pending status from line 4 */
+#define EXTI_PD_PD5 BIT(5) /*!< interrupt pending status from line 5 */
+#define EXTI_PD_PD6 BIT(6) /*!< interrupt pending status from line 6 */
+#define EXTI_PD_PD7 BIT(7) /*!< interrupt pending status from line 7 */
+#define EXTI_PD_PD8 BIT(8) /*!< interrupt pending status from line 8 */
+#define EXTI_PD_PD9 BIT(9) /*!< interrupt pending status from line 9 */
+#define EXTI_PD_PD10 BIT(10) /*!< interrupt pending status from line 10 */
+#define EXTI_PD_PD11 BIT(11) /*!< interrupt pending status from line 11 */
+#define EXTI_PD_PD12 BIT(12) /*!< interrupt pending status from line 12 */
+#define EXTI_PD_PD13 BIT(13) /*!< interrupt pending status from line 13 */
+#define EXTI_PD_PD14 BIT(14) /*!< interrupt pending status from line 14 */
+#define EXTI_PD_PD15 BIT(15) /*!< interrupt pending status from line 15 */
+#define EXTI_PD_PD16 BIT(16) /*!< interrupt pending status from line 16 */
+#define EXTI_PD_PD17 BIT(17) /*!< interrupt pending status from line 17 */
+#define EXTI_PD_PD18 BIT(18) /*!< interrupt pending status from line 18 */
+#define EXTI_PD_PD19 BIT(19) /*!< interrupt pending status from line 19 */
/* constants definitions */
/* EXTI line number */
-typedef enum
-{
+typedef enum {
EXTI_0 = BIT(0), /*!< EXTI line 0 */
EXTI_1 = BIT(1), /*!< EXTI line 1 */
EXTI_2 = BIT(2), /*!< EXTI line 2 */
@@ -207,52 +203,50 @@ typedef enum
EXTI_16 = BIT(16), /*!< EXTI line 16 */
EXTI_17 = BIT(17), /*!< EXTI line 17 */
EXTI_18 = BIT(18), /*!< EXTI line 18 */
- EXTI_19 = BIT(19), /*!< EXTI line 19 */
-}exti_line_enum;
+ EXTI_19 = BIT(19) /*!< EXTI line 19 */
+} exti_line_enum;
/* external interrupt and event */
-typedef enum
-{
+typedef enum {
EXTI_INTERRUPT = 0, /*!< EXTI interrupt mode */
EXTI_EVENT /*!< EXTI event mode */
-}exti_mode_enum;
+} exti_mode_enum;
-/* interrupt trigger mode */
-typedef enum
-{
+/* interrupt and event trigger mode */
+typedef enum {
EXTI_TRIG_RISING = 0, /*!< EXTI rising edge trigger */
EXTI_TRIG_FALLING, /*!< EXTI falling edge trigger */
- EXTI_TRIG_BOTH /*!< EXTI rising and falling edge trigger */
-}exti_trig_type_enum;
+ EXTI_TRIG_BOTH, /*!< EXTI rising and falling edge trigger */
+ EXTI_TRIG_NONE /*!< without rising edge or falling edge trigger */
+} exti_trig_type_enum;
/* function declarations */
/* initialization, EXTI lines configuration functions */
/* deinitialize the EXTI */
void exti_deinit(void);
-/* enable the configuration of EXTI initialize */
+/* initialize the EXTI line x */
void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum trig_type);
/* enable the interrupts from EXTI line x */
void exti_interrupt_enable(exti_line_enum linex);
-/* enable the events from EXTI line x */
-void exti_event_enable(exti_line_enum linex);
/* disable the interrupts from EXTI line x */
void exti_interrupt_disable(exti_line_enum linex);
+/* enable the events from EXTI line x */
+void exti_event_enable(exti_line_enum linex);
/* disable the events from EXTI line x */
void exti_event_disable(exti_line_enum linex);
+/* enable the software interrupt event from EXTI line x */
+void exti_software_interrupt_enable(exti_line_enum linex);
+/* disable the software interrupt event from EXTI line x */
+void exti_software_interrupt_disable(exti_line_enum linex);
/* interrupt & flag functions */
-/* get EXTI lines pending flag */
+/* get EXTI line x interrupt pending flag */
FlagStatus exti_flag_get(exti_line_enum linex);
-/* clear EXTI lines pending flag */
+/* clear EXTI line x interrupt pending flag */
void exti_flag_clear(exti_line_enum linex);
-/* get EXTI lines flag when the interrupt flag is set */
+/* get EXTI line x interrupt pending flag */
FlagStatus exti_interrupt_flag_get(exti_line_enum linex);
-/* clear EXTI lines pending flag */
+/* clear EXTI line x interrupt pending flag */
void exti_interrupt_flag_clear(exti_line_enum linex);
-/* enable the EXTI software interrupt event */
-void exti_software_interrupt_enable(exti_line_enum linex);
-/* disable the EXTI software interrupt event */
-void exti_software_interrupt_disable(exti_line_enum linex);
#endif /* GD32F20X_EXTI_H */
-
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fmc.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fmc.h
index f070ffe..585ed65 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fmc.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fmc.h
@@ -2,36 +2,33 @@
\file gd32f20x_fmc.h
\brief definitions for the FMC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -45,27 +42,27 @@ OF SUCH DAMAGE.
#define OB OB_BASE /*!< option bytes base address */
/* registers definitions */
-#define FMC_WS REG32((FMC) + 0x00U) /*!< FMC wait state register */
-#define FMC_KEY0 REG32((FMC) + 0x04U) /*!< FMC unlock key register 0 */
-#define FMC_OBKEY REG32((FMC) + 0x08U) /*!< FMC option bytes unlock key register */
-#define FMC_STAT0 REG32((FMC) + 0x0CU) /*!< FMC status register 0 */
-#define FMC_CTL0 REG32((FMC) + 0x10U) /*!< FMC control register 0 */
-#define FMC_ADDR0 REG32((FMC) + 0x14U) /*!< FMC address register 0 */
-#define FMC_OBSTAT REG32((FMC) + 0x1CU) /*!< FMC option bytes status register */
-#define FMC_WP REG32((FMC) + 0x20U) /*!< FMC erase/program protection register */
-#define FMC_KEY1 REG32((FMC) + 0x44U) /*!< FMC unlock key register 1 */
-#define FMC_STAT1 REG32((FMC) + 0x4CU) /*!< FMC status register 1 */
-#define FMC_CTL1 REG32((FMC) + 0x50U) /*!< FMC control register 1 */
-#define FMC_ADDR1 REG32((FMC) + 0x54U) /*!< FMC address register 1 */
-#define FMC_WSEN REG32((FMC) + 0xFCU) /*!< FMC wait state enable register */
-#define FMC_PID REG32((FMC) + 0x100U) /*!< FMC product ID register */
-
-#define OB_SPC REG16((OB) + 0x00U) /*!< option byte security protection value */
-#define OB_USER REG16((OB) + 0x02U) /*!< option byte user value*/
-#define OB_WP0 REG16((OB) + 0x08U) /*!< option byte write protection 0 */
-#define OB_WP1 REG16((OB) + 0x0AU) /*!< option byte write protection 1 */
-#define OB_WP2 REG16((OB) + 0x0CU) /*!< option byte write protection 2 */
-#define OB_WP3 REG16((OB) + 0x0EU) /*!< option byte write protection 3 */
+#define FMC_WS REG32((FMC) + 0x00000000U) /*!< FMC wait state register */
+#define FMC_KEY0 REG32((FMC) + 0x00000004U) /*!< FMC unlock key register 0 */
+#define FMC_OBKEY REG32((FMC) + 0x00000008U) /*!< FMC option bytes unlock key register */
+#define FMC_STAT0 REG32((FMC) + 0x0000000CU) /*!< FMC status register 0 */
+#define FMC_CTL0 REG32((FMC) + 0x00000010U) /*!< FMC control register 0 */
+#define FMC_ADDR0 REG32((FMC) + 0x00000014U) /*!< FMC address register 0 */
+#define FMC_OBSTAT REG32((FMC) + 0x0000001CU) /*!< FMC option bytes status register */
+#define FMC_WP REG32((FMC) + 0x00000020U) /*!< FMC erase/program protection register */
+#define FMC_KEY1 REG32((FMC) + 0x00000044U) /*!< FMC unlock key register 1 */
+#define FMC_STAT1 REG32((FMC) + 0x0000004CU) /*!< FMC status register 1 */
+#define FMC_CTL1 REG32((FMC) + 0x00000050U) /*!< FMC control register 1 */
+#define FMC_ADDR1 REG32((FMC) + 0x00000054U) /*!< FMC address register 1 */
+#define FMC_WSEN REG32((FMC) + 0x000000FCU) /*!< FMC wait state enable register */
+#define FMC_PID REG32((FMC) + 0x00000100U) /*!< FMC product ID register */
+
+#define OB_SPC REG16((OB) + 0x0000U) /*!< option byte security protection value */
+#define OB_USER REG16((OB) + 0x0002U) /*!< option byte user value*/
+#define OB_WP0 REG16((OB) + 0x0008U) /*!< option byte write protection 0 */
+#define OB_WP1 REG16((OB) + 0x000AU) /*!< option byte write protection 1 */
+#define OB_WP2 REG16((OB) + 0x000CU) /*!< option byte write protection 2 */
+#define OB_WP3 REG16((OB) + 0x000EU) /*!< option byte write protection 3 */
/* bits definitions */
/* FMC_WS */
@@ -96,7 +93,7 @@ OF SUCH DAMAGE.
#define FMC_CTL0_ENDIE BIT(12) /*!< end of operation interrupt enable bit */
/* FMC_ADDR0 */
-#define FMC_ADDR0_ADDR BITS(0,31) /*!< Flash erase/program command address bits */
+#define FMC_ADDR0_ADDR BITS(0,31) /*!< flash erase/program command address bits */
/* FMC_OBSTAT */
#define FMC_OBSTAT_OBERR BIT(0) /*!< option bytes read error bit. */
@@ -126,7 +123,7 @@ OF SUCH DAMAGE.
#define FMC_CTL1_ENDIE BIT(12) /*!< end of operation interrupt enable bit */
/* FMC_ADDR1 */
-#define FMC_ADDR1_ADDR BITS(0,31) /*!< Flash erase/program command address bits */
+#define FMC_ADDR1_ADDR BITS(0,31) /*!< flash erase/program command address bits */
/* FMC_WSEN */
#define FMC_WSEN_WSEN BIT(0) /*!< FMC wait state enable bit */
@@ -146,34 +143,31 @@ OF SUCH DAMAGE.
#define FMC_REG_OFFSET_GET(flag) ((uint32_t)(flag) >> 12)
/* configuration register */
-#define FMC_STAT0_REG_OFFSET 0x0CU /*!< status register 0 offset */
-#define FMC_CTL0_REG_OFFSET 0x10U /*!< control register 0 offset */
-#define FMC_STAT1_REG_OFFSET 0x4CU /*!< status register 1 offset */
-#define FMC_CTL1_REG_OFFSET 0x50U /*!< control register 1 offset */
-#define FMC_OBSTAT_REG_OFFSET 0x1CU /*!< option byte status register offset */
+#define FMC_STAT0_REG_OFFSET ((uint32_t)0x0000000CU) /*!< status register 0 offset */
+#define FMC_CTL0_REG_OFFSET ((uint32_t)0x00000010U) /*!< control register 0 offset */
+#define FMC_STAT1_REG_OFFSET ((uint32_t)0x0000004CU) /*!< status register 1 offset */
+#define FMC_CTL1_REG_OFFSET ((uint32_t)0x00000050U) /*!< control register 1 offset */
+#define FMC_OBSTAT_REG_OFFSET ((uint32_t)0x0000001CU) /*!< option byte status register offset */
/* fmc state */
-typedef enum
-{
- FMC_READY, /*!< the operation has been completed */
- FMC_BUSY, /*!< the operation is in progress */
- FMC_PGERR, /*!< program error */
- FMC_WPERR, /*!< erase/program protection error */
- FMC_TOERR, /*!< timeout error */
-}fmc_state_enum;
-
-/* FMC interrupt enable */
-typedef enum
-{
- FMC_INT_BANK0_END = FMC_REGIDX_BIT(FMC_CTL0_REG_OFFSET, 12U), /*!< enable FMC end of program interrupt */
- FMC_INT_BANK0_ERR = FMC_REGIDX_BIT(FMC_CTL0_REG_OFFSET, 10U), /*!< enable FMC error interrupt */
- FMC_INT_BANK1_END = FMC_REGIDX_BIT(FMC_CTL1_REG_OFFSET, 12U), /*!< enable FMC bank1 end of program interrupt */
- FMC_INT_BANK1_ERR = FMC_REGIDX_BIT(FMC_CTL1_REG_OFFSET, 10U), /*!< enable FMC bank1 error interrupt */
-}fmc_int_enum;
+typedef enum {
+ FMC_READY = 0, /*!< the operation has been completed */
+ FMC_BUSY, /*!< the operation is in progress */
+ FMC_PGERR, /*!< program error */
+ FMC_WPERR, /*!< erase/program protection error */
+ FMC_TOERR /*!< timeout error */
+} fmc_state_enum;
+
+/* FMC interrupt */
+typedef enum {
+ FMC_INT_BANK0_END = FMC_REGIDX_BIT(FMC_CTL0_REG_OFFSET, 12U), /*!< FMC bank0 end of program interrupt */
+ FMC_INT_BANK0_ERR = FMC_REGIDX_BIT(FMC_CTL0_REG_OFFSET, 10U), /*!< FMC bank0 error interrupt */
+ FMC_INT_BANK1_END = FMC_REGIDX_BIT(FMC_CTL1_REG_OFFSET, 12U), /*!< FMC bank1 end of program interrupt */
+ FMC_INT_BANK1_ERR = FMC_REGIDX_BIT(FMC_CTL1_REG_OFFSET, 10U) /*!< FMC bank1 error interrupt */
+} fmc_interrupt_enum;
/* FMC flags */
-typedef enum
-{
+typedef enum {
FMC_FLAG_BANK0_BUSY = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 0U), /*!< FMC bank0 busy flag */
FMC_FLAG_BANK0_PGERR = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 2U), /*!< FMC bank0 operation error flag bit */
FMC_FLAG_BANK0_WPERR = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 4U), /*!< FMC bank0 erase/program protection error flag bit */
@@ -182,114 +176,114 @@ typedef enum
FMC_FLAG_BANK1_BUSY = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 0U), /*!< FMC bank1 busy flag */
FMC_FLAG_BANK1_PGERR = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 2U), /*!< FMC bank1 operation error flag bit */
FMC_FLAG_BANK1_WPERR = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 4U), /*!< FMC bank1 erase/program protection error flag bit */
- FMC_FLAG_BANK1_END = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 5U), /*!< FMC bank1 end of operation flag bit */
-}fmc_flag_enum;
+ FMC_FLAG_BANK1_END = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 5U) /*!< FMC bank1 end of operation flag bit */
+} fmc_flag_enum;
/* FMC interrupt flags */
-typedef enum
-{
+typedef enum {
FMC_INT_FLAG_BANK0_PGERR = FMC_REGIDX_BITS(FMC_STAT0_REG_OFFSET, 2U, 10U), /*!< FMC bank0 operation error interrupt flag bit */
FMC_INT_FLAG_BANK0_WPERR = FMC_REGIDX_BITS(FMC_STAT0_REG_OFFSET, 4U, 10U), /*!< FMC bank0 erase/program protection error interrupt flag bit */
FMC_INT_FLAG_BANK0_END = FMC_REGIDX_BITS(FMC_STAT0_REG_OFFSET, 5U, 12U), /*!< FMC bank0 end of operation interrupt flag bit */
FMC_INT_FLAG_BANK1_PGERR = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 2U, 10U), /*!< FMC bank1 operation error interrupt flag bit */
FMC_INT_FLAG_BANK1_WPERR = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 4U, 10U), /*!< FMC bank1 erase/program protection error interrupt flag bit */
- FMC_INT_FLAG_BANK1_END = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 5U, 12U), /*!< FMC bank1 end of operation interrupt flag bit */
-}fmc_interrupt_flag_enum;
+ FMC_INT_FLAG_BANK1_END = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 5U, 12U) /*!< FMC bank1 end of operation interrupt flag bit */
+} fmc_interrupt_flag_enum;
/* unlock key */
-#define UNLOCK_KEY0 ((uint32_t)0x45670123U) /*!< unlock key 0 */
-#define UNLOCK_KEY1 ((uint32_t)0xCDEF89ABU) /*!< unlock key 1 */
+#define UNLOCK_KEY0 ((uint32_t)0x45670123U) /*!< unlock key 0 */
+#define UNLOCK_KEY1 ((uint32_t)0xCDEF89ABU) /*!< unlock key 1 */
/* FMC wait state counter */
#define WS_WSCNT(regval) (BITS(0,2) & ((uint32_t)(regval)))
-#define WS_WSCNT_0 WS_WSCNT(0) /*!< FMC 0 wait */
-#define WS_WSCNT_1 WS_WSCNT(1) /*!< FMC 1 wait */
-#define WS_WSCNT_2 WS_WSCNT(2) /*!< FMC 2 wait */
+#define WS_WSCNT_0 WS_WSCNT(0) /*!< FMC 0 wait */
+#define WS_WSCNT_1 WS_WSCNT(1) /*!< FMC 1 wait */
+#define WS_WSCNT_2 WS_WSCNT(2) /*!< FMC 2 wait */
-/* option bytes software/hardware free watch dog timer */
-#define OB_FWDGT_SW ((uint8_t)0x01U) /*!< software free watchdog */
-#define OB_FWDGT_HW ((uint8_t)0x00U) /*!< hardware free watchdog */
+/* option bytes software/hardware free watch dog timer */
+#define OB_FWDGT_SW ((uint8_t)0x01U) /*!< software free watchdog */
+#define OB_FWDGT_HW ((uint8_t)0x00U) /*!< hardware free watchdog */
/* option bytes reset or not entering deep sleep mode */
-#define OB_DEEPSLEEP_NRST ((uint8_t)0x02U) /*!< no reset when entering deepsleep mode */
-#define OB_DEEPSLEEP_RST ((uint8_t)0x00U) /*!< generate a reset instead of entering deepsleep mode */
+#define OB_DEEPSLEEP_NRST ((uint8_t)0x02U) /*!< no reset when entering deepsleep mode */
+#define OB_DEEPSLEEP_RST ((uint8_t)0x00U) /*!< generate a reset instead of entering deepsleep mode */
/* option bytes reset or not entering standby mode */
-#define OB_STDBY_NRST ((uint8_t)0x04U) /*!< no reset when entering deepsleep mode */
-#define OB_STDBY_RST ((uint8_t)0x00U) /*!< generate a reset instead of entering standby mode */
+#define OB_STDBY_NRST ((uint8_t)0x04U) /*!< no reset when entering deepsleep mode */
+#define OB_STDBY_RST ((uint8_t)0x00U) /*!< generate a reset instead of entering standby mode */
/* option bytes boot bank value */
-#define OB_BOOT_B0 ((uint8_t)0x08U) /*!< boot from bank0 */
-#define OB_BOOT_B1 ((uint8_t)0x00U) /*!< boot from bank1 */
+#define OB_BOOT_B0 ((uint8_t)0x08U) /*!< boot from bank0 */
+#define OB_BOOT_B1 ((uint8_t)0x00U) /*!< boot from bank1 */
-#define OB_USER_MASK ((uint8_t)0xF0U) /*!< MASK value */
+#define OB_USER_MASK ((uint8_t)0xF0U) /*!< mask value */
/* read protect configure */
-#define FMC_NSPC ((uint8_t)0xA5U) /*!< no security protection */
-#define FMC_USPC ((uint8_t)0xBBU) /*!< under security protection */
+#define FMC_NSPC ((uint8_t)0xA5U) /*!< no security protection */
+#define FMC_USPC ((uint8_t)0xBBU) /*!< under security protection */
/* OB_SPC */
-#define OB_SPC_SPC ((uint32_t)0x000000FFU) /*!< option byte security protection value */
-#define OB_SPC_SPC_N ((uint32_t)0x0000FF00U) /*!< option byte security protection complement value */
+#define OB_SPC_SPC ((uint32_t)0x000000FFU) /*!< option byte security protection value */
+#define OB_SPC_SPC_N ((uint32_t)0x0000FF00U) /*!< option byte security protection complement value */
/* OB_USER */
-#define OB_USER_USER ((uint32_t)0x00FF0000U) /*!< user option value */
-#define OB_USER_USER_N ((uint32_t)0xFF000000U) /*!< user option complement value */
+#define OB_USER_USER ((uint32_t)0x00FF0000U) /*!< user option value */
+#define OB_USER_USER_N ((uint32_t)0xFF000000U) /*!< user option complement value */
/* OB_WP0 */
-#define OB_WP0_WP0 ((uint32_t)0x000000FFU) /*!< FMC write protection option value */
+#define OB_WP0_WP0 ((uint32_t)0x000000FFU) /*!< FMC write protection option value */
/* OB_WP1 */
-#define OB_WP1_WP1 ((uint32_t)0x0000FF00U) /*!< FMC write protection option complement value */
+#define OB_WP1_WP1 ((uint32_t)0x0000FF00U) /*!< FMC write protection option complement value */
/* OB_WP2 */
-#define OB_WP2_WP2 ((uint32_t)0x00FF0000U) /*!< FMC write protection option value */
+#define OB_WP2_WP2 ((uint32_t)0x00FF0000U) /*!< FMC write protection option value */
/* OB_WP3 */
-#define OB_WP3_WP3 ((uint32_t)0xFF000000U) /*!< FMC write protection option complement value */
+#define OB_WP3_WP3 ((uint32_t)0xFF000000U) /*!< FMC write protection option complement value */
/* option bytes write protection */
-#define OB_WP_0 ((uint32_t)0x00000001U) /*!< erase/program protection of sector 0 */
-#define OB_WP_1 ((uint32_t)0x00000002U) /*!< erase/program protection of sector 1 */
-#define OB_WP_2 ((uint32_t)0x00000004U) /*!< erase/program protection of sector 2 */
-#define OB_WP_3 ((uint32_t)0x00000008U) /*!< erase/program protection of sector 3 */
-#define OB_WP_4 ((uint32_t)0x00000010U) /*!< erase/program protection of sector 4 */
-#define OB_WP_5 ((uint32_t)0x00000020U) /*!< erase/program protection of sector 5 */
-#define OB_WP_6 ((uint32_t)0x00000040U) /*!< erase/program protection of sector 6 */
-#define OB_WP_7 ((uint32_t)0x00000080U) /*!< erase/program protection of sector 7 */
-#define OB_WP_8 ((uint32_t)0x00000100U) /*!< erase/program protection of sector 8 */
-#define OB_WP_9 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 9 */
-#define OB_WP_10 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 10 */
-#define OB_WP_11 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 11 */
-#define OB_WP_12 ((uint32_t)0x00001000U) /*!< erase/program protection of sector 12 */
-#define OB_WP_13 ((uint32_t)0x00002000U) /*!< erase/program protection of sector 13 */
-#define OB_WP_14 ((uint32_t)0x00004000U) /*!< erase/program protection of sector 14 */
-#define OB_WP_15 ((uint32_t)0x00008000U) /*!< erase/program protection of sector 15 */
-#define OB_WP_16 ((uint32_t)0x00010000U) /*!< erase/program protection of sector 16 */
-#define OB_WP_17 ((uint32_t)0x00020000U) /*!< erase/program protection of sector 17 */
-#define OB_WP_18 ((uint32_t)0x00040000U) /*!< erase/program protection of sector 18 */
-#define OB_WP_19 ((uint32_t)0x00080000U) /*!< erase/program protection of sector 19 */
-#define OB_WP_20 ((uint32_t)0x00100000U) /*!< erase/program protection of sector 20 */
-#define OB_WP_21 ((uint32_t)0x00200000U) /*!< erase/program protection of sector 21 */
-#define OB_WP_22 ((uint32_t)0x00400000U) /*!< erase/program protection of sector 22 */
-#define OB_WP_23 ((uint32_t)0x00800000U) /*!< erase/program protection of sector 23 */
-#define OB_WP_24 ((uint32_t)0x01000000U) /*!< erase/program protection of sector 24 */
-#define OB_WP_25 ((uint32_t)0x02000000U) /*!< erase/program protection of sector 25 */
-#define OB_WP_26 ((uint32_t)0x04000000U) /*!< erase/program protection of sector 26 */
-#define OB_WP_27 ((uint32_t)0x08000000U) /*!< erase/program protection of sector 27 */
-#define OB_WP_28 ((uint32_t)0x10000000U) /*!< erase/program protection of sector 28 */
-#define OB_WP_29 ((uint32_t)0x20000000U) /*!< erase/program protection of sector 29 */
-#define OB_WP_30 ((uint32_t)0x40000000U) /*!< erase/program protection of sector 30 */
-#define OB_WP_31 ((uint32_t)0x80000000U) /*!< erase/program protection of sector 31 */
-#define OB_WP_ALL ((uint32_t)0xFFFFFFFFU) /*!< erase/program protection of all sectors */
+#define OB_WP_NONE ((uint32_t)0x00000000U) /*!< disable all erase/program protection */
+#define OB_WP_0 ((uint32_t)0x00000001U) /*!< erase/program protection of sector 0 */
+#define OB_WP_1 ((uint32_t)0x00000002U) /*!< erase/program protection of sector 1 */
+#define OB_WP_2 ((uint32_t)0x00000004U) /*!< erase/program protection of sector 2 */
+#define OB_WP_3 ((uint32_t)0x00000008U) /*!< erase/program protection of sector 3 */
+#define OB_WP_4 ((uint32_t)0x00000010U) /*!< erase/program protection of sector 4 */
+#define OB_WP_5 ((uint32_t)0x00000020U) /*!< erase/program protection of sector 5 */
+#define OB_WP_6 ((uint32_t)0x00000040U) /*!< erase/program protection of sector 6 */
+#define OB_WP_7 ((uint32_t)0x00000080U) /*!< erase/program protection of sector 7 */
+#define OB_WP_8 ((uint32_t)0x00000100U) /*!< erase/program protection of sector 8 */
+#define OB_WP_9 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 9 */
+#define OB_WP_10 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 10 */
+#define OB_WP_11 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 11 */
+#define OB_WP_12 ((uint32_t)0x00001000U) /*!< erase/program protection of sector 12 */
+#define OB_WP_13 ((uint32_t)0x00002000U) /*!< erase/program protection of sector 13 */
+#define OB_WP_14 ((uint32_t)0x00004000U) /*!< erase/program protection of sector 14 */
+#define OB_WP_15 ((uint32_t)0x00008000U) /*!< erase/program protection of sector 15 */
+#define OB_WP_16 ((uint32_t)0x00010000U) /*!< erase/program protection of sector 16 */
+#define OB_WP_17 ((uint32_t)0x00020000U) /*!< erase/program protection of sector 17 */
+#define OB_WP_18 ((uint32_t)0x00040000U) /*!< erase/program protection of sector 18 */
+#define OB_WP_19 ((uint32_t)0x00080000U) /*!< erase/program protection of sector 19 */
+#define OB_WP_20 ((uint32_t)0x00100000U) /*!< erase/program protection of sector 20 */
+#define OB_WP_21 ((uint32_t)0x00200000U) /*!< erase/program protection of sector 21 */
+#define OB_WP_22 ((uint32_t)0x00400000U) /*!< erase/program protection of sector 22 */
+#define OB_WP_23 ((uint32_t)0x00800000U) /*!< erase/program protection of sector 23 */
+#define OB_WP_24 ((uint32_t)0x01000000U) /*!< erase/program protection of sector 24 */
+#define OB_WP_25 ((uint32_t)0x02000000U) /*!< erase/program protection of sector 25 */
+#define OB_WP_26 ((uint32_t)0x04000000U) /*!< erase/program protection of sector 26 */
+#define OB_WP_27 ((uint32_t)0x08000000U) /*!< erase/program protection of sector 27 */
+#define OB_WP_28 ((uint32_t)0x10000000U) /*!< erase/program protection of sector 28 */
+#define OB_WP_29 ((uint32_t)0x20000000U) /*!< erase/program protection of sector 29 */
+#define OB_WP_30 ((uint32_t)0x40000000U) /*!< erase/program protection of sector 30 */
+#define OB_WP_31 ((uint32_t)0x80000000U) /*!< erase/program protection of sector 31 */
+#define OB_WP_ALL ((uint32_t)0xFFFFFFFFU) /*!< erase/program protection of all sectors */
/* FMC timeout */
-#define FMC_TIMEOUT_COUNT ((uint32_t)0x000F0000U) /*!< FMC timeout count value */
+#define FMC_TIMEOUT_COUNT ((uint32_t)0x000F0000U) /*!< FMC timeout count value */
/* FMC BANK address */
-#define FMC_BANK0_END_ADDRESS ((uint32_t)0x0807FFFFU) /*!< FMC bank0 end address */
-#define FMC_BANK0_SIZE ((uint32_t)0x00000200U) /*!< FMC bank0 size */
-#define FMC_SIZE (*(uint16_t *)0x1FFFF7E0U) /*!< FMC size */
+#define FMC_BANK0_END_ADDRESS ((uint32_t)0x0807FFFFU) /*!< FMC bank0 end address */
+#define FMC_BANK0_SIZE ((uint32_t)0x00000200U) /*!< FMC bank0 size */
+#define FMC_SIZE (*(uint16_t *)0x1FFFF7E0U) /*!< FMC size */
/* function declarations */
/* FMC main memory programming functions */
@@ -307,17 +301,17 @@ void fmc_lock(void);
void fmc_bank0_lock(void);
/* lock the bank1 FMC operation */
void fmc_bank1_lock(void);
-/* FMC erase page */
+/* erase page */
fmc_state_enum fmc_page_erase(uint32_t page_address);
-/* FMC erase whole chip */
+/* erase whole chip */
fmc_state_enum fmc_mass_erase(void);
-/* FMC erase whole bank0 */
+/* erase whole bank0 */
fmc_state_enum fmc_bank0_erase(void);
-/* FMC erase whole bank1 */
+/* erase whole bank1 */
fmc_state_enum fmc_bank1_erase(void);
-/* FMC program a word at the corresponding address */
+/* program a word at the corresponding address */
fmc_state_enum fmc_word_program(uint32_t address, uint32_t data);
-/* FMC program a half word at the corresponding address */
+/* program a half word at the corresponding address */
fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data);
/* FMC option bytes programming functions */
@@ -327,17 +321,17 @@ void ob_unlock(void);
void ob_lock(void);
/* erase the option byte */
fmc_state_enum ob_erase(void);
-/* enable write protect */
+/* enable write protection */
fmc_state_enum ob_write_protection_enable(uint32_t ob_wp);
/* configure the option byte security protection */
fmc_state_enum ob_security_protection_config(uint8_t ob_spc);
-/* write the FMC option byte */
+/* program option bytes user */
fmc_state_enum ob_user_write(uint8_t ob_fwdgt, uint8_t ob_deepsleep, uint8_t ob_stdby, uint8_t ob_boot);
/* program option bytes data */
fmc_state_enum ob_data_program(uint32_t address, uint8_t data);
-/* get the FMC option byte user */
+/* get the FMC option bytes user */
uint8_t ob_user_get(void);
-/* get OB_DATA in register FMC_OBSTAT */
+/* get the FMC option bytes data */
uint16_t ob_data_get(void);
/* get the FMC option byte write protection */
uint32_t ob_write_protection_get(void);
@@ -345,25 +339,17 @@ uint32_t ob_write_protection_get(void);
FlagStatus ob_spc_get(void);
/* FMC interrupts and flags management functions */
-/* enable FMC interrupt */
-void fmc_interrupt_enable(uint32_t interrupt);
-/* disable FMC interrupt */
-void fmc_interrupt_disable(uint32_t interrupt);
/* check flag is set or not */
FlagStatus fmc_flag_get(uint32_t flag);
/* clear the FMC flag */
void fmc_flag_clear(uint32_t flag);
+/* enable FMC interrupt */
+void fmc_interrupt_enable(fmc_interrupt_enum interrupt);
+/* disable FMC interrupt */
+void fmc_interrupt_disable(fmc_interrupt_enum interrupt);
/* get FMC interrupt flag state */
-FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag);
+FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum int_flag);
/* clear FMC interrupt flag state */
-void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag);
-/* return the FMC bank0 state */
-fmc_state_enum fmc_bank0_state_get(void);
-/* return the FMC bank1 state */
-fmc_state_enum fmc_bank1_state_get(void);
-/* check FMC bank0 ready or not */
-fmc_state_enum fmc_bank0_ready_wait(uint32_t timeout);
-/* check FMC bank1 ready or not */
-fmc_state_enum fmc_bank1_ready_wait(uint32_t timeout);
+void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum int_flag);
#endif /* GD32F20X_FMC_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fwdgt.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fwdgt.h
index 1cc6c00..b5f4b1e 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fwdgt.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_fwdgt.h
@@ -2,36 +2,33 @@
\file gd32f20x_fwdgt.h
\brief definitions for the FWDGT
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -88,12 +85,10 @@ OF SUCH DAMAGE.
#define FWDGT_FLAG_PUD FWDGT_STAT_PUD /*!< FWDGT prescaler divider value update flag */
#define FWDGT_FLAG_RUD FWDGT_STAT_RUD /*!< FWDGT counter reload value update flag */
-#ifdef __cplusplus
- extern "C" {
-#endif
+/* write value to FWDGT_RLD_RLD bit field */
+#define RLD_RLD(regval) (BITS(0,11) & ((uint32_t)(regval) << 0))
/* function declarations */
-/* function configuration */
/* enable write access to FWDGT_PSC and FWDGT_RLD */
void fwdgt_write_enable(void);
/* disable write access to FWDGT_PSC and FWDGT_RLD */
@@ -101,16 +96,16 @@ void fwdgt_write_disable(void);
/* start the free watchdog timer counter */
void fwdgt_enable(void);
+/* configure the free watchdog timer counter prescaler value */
+ErrStatus fwdgt_prescaler_value_config(uint16_t prescaler_value);
+/* configure the free watchdog timer counter reload value */
+ErrStatus fwdgt_reload_value_config(uint16_t reload_value);
/* reload the counter of FWDGT */
void fwdgt_counter_reload(void);
/* configure counter reload value, and prescaler divider value */
ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div);
-/* interrupt & flag functions */
/* get flag state of FWDGT */
FlagStatus fwdgt_flag_get(uint16_t flag);
-#ifdef __cplusplus
-}
-#endif
#endif /* GD32F20X_FWDGT_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_gpio.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_gpio.h
index dc24990..5b6f8f0 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_gpio.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_gpio.h
@@ -2,36 +2,33 @@
\file gd32f20x_gpio.h
\brief definitions for the GPIO
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,45 +38,45 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* GPIOx(x=A,B,C,D,E,F,G,H,I) definitions */
-#define GPIOA (GPIO_BASE + 0x00000000U)
-#define GPIOB (GPIO_BASE + 0x00000400U)
-#define GPIOC (GPIO_BASE + 0x00000800U)
-#define GPIOD (GPIO_BASE + 0x00000C00U)
-#define GPIOE (GPIO_BASE + 0x00001000U)
-#define GPIOF (GPIO_BASE + 0x00001400U)
-#define GPIOG (GPIO_BASE + 0x00001800U)
-#define GPIOH (GPIO_BASE + 0x00006C00U)
-#define GPIOI (GPIO_BASE + 0x00007000U)
+#define GPIOA (GPIO_BASE + 0x00000000U) /*!< GPIOA bsae address */
+#define GPIOB (GPIO_BASE + 0x00000400U) /*!< GPIOB bsae address */
+#define GPIOC (GPIO_BASE + 0x00000800U) /*!< GPIOC bsae address */
+#define GPIOD (GPIO_BASE + 0x00000C00U) /*!< GPIOD bsae address */
+#define GPIOE (GPIO_BASE + 0x00001000U) /*!< GPIOE bsae address */
+#define GPIOF (GPIO_BASE + 0x00001400U) /*!< GPIOF bsae address */
+#define GPIOG (GPIO_BASE + 0x00001800U) /*!< GPIOG bsae address */
+#define GPIOH (GPIO_BASE + 0x00006C00U) /*!< GPIOH bsae address */
+#define GPIOI (GPIO_BASE + 0x00007000U) /*!< GPIOI bsae address */
/* AFIO definitions */
-#define AFIO AFIO_BASE
+#define AFIO AFIO_BASE /*!< AFIO bsae address */
/* registers definitions */
/* GPIO registers definitions */
-#define GPIO_CTL0(gpiox) REG32((gpiox) + 0x00U) /*!< GPIO port control register 0 */
-#define GPIO_CTL1(gpiox) REG32((gpiox) + 0x04U) /*!< GPIO port control register 1 */
-#define GPIO_ISTAT(gpiox) REG32((gpiox) + 0x08U) /*!< GPIO port input status register */
-#define GPIO_OCTL(gpiox) REG32((gpiox) + 0x0CU) /*!< GPIO port output control register */
-#define GPIO_BOP(gpiox) REG32((gpiox) + 0x10U) /*!< GPIO port bit operation register */
-#define GPIO_BC(gpiox) REG32((gpiox) + 0x14U) /*!< GPIO bit clear register */
-#define GPIO_LOCK(gpiox) REG32((gpiox) + 0x18U) /*!< GPIO port configuration lock register */
+#define GPIO_CTL0(gpiox) REG32((gpiox) + 0x00000000U) /*!< GPIO port control register 0 */
+#define GPIO_CTL1(gpiox) REG32((gpiox) + 0x00000004U) /*!< GPIO port control register 1 */
+#define GPIO_ISTAT(gpiox) REG32((gpiox) + 0x00000008U) /*!< GPIO port input status register */
+#define GPIO_OCTL(gpiox) REG32((gpiox) + 0x0000000CU) /*!< GPIO port output control register */
+#define GPIO_BOP(gpiox) REG32((gpiox) + 0x00000010U) /*!< GPIO port bit operation register */
+#define GPIO_BC(gpiox) REG32((gpiox) + 0x00000014U) /*!< GPIO bit clear register */
+#define GPIO_LOCK(gpiox) REG32((gpiox) + 0x00000018U) /*!< GPIO port configuration lock register */
/* AFIO registers definitions */
-#define AFIO_EC REG32(AFIO + 0x00U) /*!< AFIO event control register */
-#define AFIO_PCF0 REG32(AFIO + 0x04U) /*!< AFIO port configuration register 0 */
-#define AFIO_EXTISS0 REG32(AFIO + 0x08U) /*!< AFIO port EXTI sources selection register 0 */
-#define AFIO_EXTISS1 REG32(AFIO + 0x0CU) /*!< AFIO port EXTI sources selection register 1 */
-#define AFIO_EXTISS2 REG32(AFIO + 0x10U) /*!< AFIO port EXTI sources selection register 2 */
-#define AFIO_EXTISS3 REG32(AFIO + 0x14U) /*!< AFIO port EXTI sources selection register 3 */
-#define AFIO_PCF1 REG32(AFIO + 0x1CU) /*!< AFIO port configuration register 1 */
-#define AFIO_PCF2 REG32(AFIO + 0x3CU) /*!< AFIO port configuration register 2 */
-#define AFIO_PCF3 REG32(AFIO + 0x40U) /*!< AFIO port configuration register 3 */
-#define AFIO_PCF4 REG32(AFIO + 0x44U) /*!< AFIO port configuration register 4 */
-#define AFIO_PCF5 REG32(AFIO + 0x48U) /*!< AFIO port configuration register 5 */
+#define AFIO_EC REG32(AFIO + 0x00000000U) /*!< AFIO event control register */
+#define AFIO_PCF0 REG32(AFIO + 0x00000004U) /*!< AFIO port configuration register 0 */
+#define AFIO_EXTISS0 REG32(AFIO + 0x00000008U) /*!< AFIO port EXTI sources selection register 0 */
+#define AFIO_EXTISS1 REG32(AFIO + 0x0000000CU) /*!< AFIO port EXTI sources selection register 1 */
+#define AFIO_EXTISS2 REG32(AFIO + 0x00000010U) /*!< AFIO port EXTI sources selection register 2 */
+#define AFIO_EXTISS3 REG32(AFIO + 0x00000014U) /*!< AFIO port EXTI sources selection register 3 */
+#define AFIO_PCF1 REG32(AFIO + 0x0000001CU) /*!< AFIO port configuration register 1 */
+#define AFIO_PCF2 REG32(AFIO + 0x0000003CU) /*!< AFIO port configuration register 2 */
+#define AFIO_PCF3 REG32(AFIO + 0x00000040U) /*!< AFIO port configuration register 3 */
+#define AFIO_PCF4 REG32(AFIO + 0x00000044U) /*!< AFIO port configuration register 4 */
+#define AFIO_PCF5 REG32(AFIO + 0x00000048U) /*!< AFIO port configuration register 5 */
/* bits definitions */
/* GPIO_CTL0 */
-#define GPIO_CTL0_MD0 BITS(0,1) /*!< port 0 mode bits */
+#define GPIO_CTL0_MD0 BITS(0,1) /*!< port 0 mode bits */
#define GPIO_CTL0_CTL0 BITS(2,3) /*!< pin 0 configuration bits */
#define GPIO_CTL0_MD1 BITS(4,5) /*!< port 1 mode bits */
#define GPIO_CTL0_CTL1 BITS(6,7) /*!< pin 1 configuration bits */
@@ -97,7 +94,7 @@ OF SUCH DAMAGE.
#define GPIO_CTL0_CTL7 BITS(30,31) /*!< pin 7 configuration bits */
/* GPIO_CTL1 */
-#define GPIO_CTL1_MD8 BITS(0,1) /*!< port 8 mode bits */
+#define GPIO_CTL1_MD8 BITS(0,1) /*!< port 8 mode bits */
#define GPIO_CTL1_CTL8 BITS(2,3) /*!< pin 8 configuration bits */
#define GPIO_CTL1_MD9 BITS(4,5) /*!< port 9 mode bits */
#define GPIO_CTL1_CTL9 BITS(6,7) /*!< pin 9 configuration bits */
@@ -636,7 +633,7 @@ typedef FlagStatus bit_status;
#define GPIO_PCF5_SPI1_NSCK_REMAP0 ((uint32_t)0x00000400U) /*!< SPI1 NSS/SCK remapping 0 */
#define GPIO_PCF5_SPI1_NSCK_REMAP1 ((uint32_t)0x00000600U) /*!< SPI1 NSS/SCK remapping 1 */
#define GPIO_PCF5_SPI1_IO_REMAP0 ((uint32_t)0x00000800U) /*!< SPI1 MISO/MOSI remapping 0 */
-#define GPIO_PCF5_SPI1_IO_REMAP1 ((uint32_t)0x00001800U) /*!< SPI1 MISO/MOSI remapping 1 */
+#define GPIO_PCF5_SPI1_IO_REMAP1 ((uint32_t)0x00001000U) /*!< SPI1 MISO/MOSI remapping 1 */
#define GPIO_PCF5_UART3_REMAP ((uint32_t)0x00002000U) /*!< UART3 remapping */
#define GPIO_PCF5_TIMER11_REMAP ((uint32_t)0x00004000U) /*!< TIMER11 remapping */
#define GPIO_PCF5_CAN0_ADD_REMAP ((uint32_t)0x00008000U) /*!< CAN0 addition remapping */
@@ -677,9 +674,9 @@ void gpio_afio_deinit(void);
void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed, uint32_t pin);
/* function configuration */
-/* set GPIO pin bit */
+/* set GPIO pin */
void gpio_bit_set(uint32_t gpio_periph, uint32_t pin);
-/* reset GPIO pin bit */
+/* reset GPIO pin */
void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin);
/* write data to the specified GPIO pin */
void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value);
@@ -696,10 +693,13 @@ FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin);
uint16_t gpio_output_port_get(uint32_t gpio_periph);
/* configure GPIO pin remap */
-void gpio_pin_remap_config(uint32_t gpio_remap, ControlStatus newvalue);
+void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue);
/* configure GPIO pin remap1 */
void gpio_pin_remap1_config(uint8_t remap_reg, uint32_t remap, ControlStatus newvalue);
+/* select ethernet MII or RMII PHY */
+void gpio_ethernet_phy_select(uint32_t enet_sel);
+
/* select GPIO pin exti sources */
void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin);
/* configure GPIO pin event output */
@@ -712,7 +712,4 @@ void gpio_event_output_disable(void);
/* lock GPIO pin bit */
void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin);
-/* select ethernet MII or RMII PHY */
-void gpio_ethernet_phy_select(uint32_t enet_sel);
-
#endif /* GD32F20X_GPIO_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_hau.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_hau.h
index 043342c..2d7e9c2 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_hau.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_hau.h
@@ -2,36 +2,33 @@
\file gd32f20x_hau.h
\brief definitions for the HAU
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,22 +38,22 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* HAU definitions */
-#define HAU HAU_BASE
+#define HAU HAU_BASE /*!< HAU base address */
/* registers definitions */
-#define HAU_CTL REG32(HAU + 0x00U) /*!< control register */
-#define HAU_DI REG32(HAU + 0x04U) /*!< data input register */
-#define HAU_CFG REG32(HAU + 0x08U) /*!< configuration register */
-#define HAU_DO0 REG32(HAU + 0x0CU) /*!< data output register 0 */
-#define HAU_DO1 REG32(HAU + 0x10U) /*!< data output register 1 */
-#define HAU_DO2 REG32(HAU + 0x14U) /*!< data output register 2 */
-#define HAU_DO3 REG32(HAU + 0x18U) /*!< data output register 3 */
-#define HAU_DO4 REG32(HAU + 0x1CU) /*!< data output register 4 */
-#define HAU_DO5 REG32(HAU + 0x324U) /*!< data output register 5 */
-#define HAU_DO6 REG32(HAU + 0x328U) /*!< data output register 6 */
-#define HAU_DO7 REG32(HAU + 0x32CU) /*!< data output register 7 */
-#define HAU_INTEN REG32(HAU + 0x20U) /*!< interrupt enable register */
-#define HAU_STAT REG32(HAU + 0x24U) /*!< status and interrupt flag register */
+#define HAU_CTL REG32(HAU + 0x00000000U) /*!< control register */
+#define HAU_DI REG32(HAU + 0x00000004U) /*!< data input register */
+#define HAU_CFG REG32(HAU + 0x00000008U) /*!< configuration register */
+#define HAU_DO0 REG32(HAU + 0x0000000CU) /*!< data output register 0 */
+#define HAU_DO1 REG32(HAU + 0x00000010U) /*!< data output register 1 */
+#define HAU_DO2 REG32(HAU + 0x00000014U) /*!< data output register 2 */
+#define HAU_DO3 REG32(HAU + 0x00000018U) /*!< data output register 3 */
+#define HAU_DO4 REG32(HAU + 0x0000001CU) /*!< data output register 4 */
+#define HAU_DO5 REG32(HAU + 0x00000324U) /*!< data output register 5 */
+#define HAU_DO6 REG32(HAU + 0x00000328U) /*!< data output register 6 */
+#define HAU_DO7 REG32(HAU + 0x0000032CU) /*!< data output register 7 */
+#define HAU_INTEN REG32(HAU + 0x00000020U) /*!< interrupt enable register */
+#define HAU_STAT REG32(HAU + 0x00000024U) /*!< status and interrupt flag register */
/* bits definitions */
/* HAU_CTL */
@@ -92,28 +89,26 @@ OF SUCH DAMAGE.
#define HAU_STAT_BUSY BIT(3) /*!< busy bit */
/* constants definitions */
-/* structure for initialization of the hau */
-typedef struct
-{
+/* structure for initialization of the hau */
+typedef struct {
uint32_t algo; /*!< algorithm selection */
uint32_t mode; /*!< HAU mode selection */
uint32_t datatype; /*!< data type mode */
uint32_t keytype; /*!< key length mode */
-}hau_init_parameter_struct;
+} hau_init_parameter_struct;
/* structure for message digest result of the hau */
-typedef struct
-{
+typedef struct {
uint32_t out[8]; /* message digest result 0-7 */
-}hau_digest_parameter_struct;
+} hau_digest_parameter_struct;
-/* hau_ctl register value */
+/* hau_ctl register value */
#define HAU_ALGO_SHA1 ((uint32_t)0x00000000U) /*!< HAU function is SHA1 */
#define HAU_ALGO_SHA224 HAU_CTL_ALGM_1 /*!< HAU function is SHA224 */
#define HAU_ALGO_SHA256 (HAU_CTL_ALGM_1 | HAU_CTL_ALGM_0) /*!< HAU function is SHA256 */
#define HAU_ALGO_MD5 HAU_CTL_ALGM_0 /*!< HAU function is MD5 */
-#define HAU_MODE_HASH ((uint32_t)0x00000000U) /*!< HAU mode is HASH */
+#define HAU_MODE_HASH ((uint32_t)0x00000000U) /*!< HAU mode is HASH */
#define HAU_MODE_HMAC HAU_CTL_HMS /*!< HAU mode is HMAC */
#define CTL_DATAM_1(regval) (BITS(4,5) & ((uint32_t)(regval) << 4)) /*!< write value to HAU_CTL_DATAM bit field */
@@ -141,7 +136,7 @@ typedef struct
#define HAU_FLAG_CALCULATION_COMPLETE HAU_STAT_CINT /*!< digest calculation is completed */
#define HAU_FLAG_DMA HAU_STAT_DMAS /*!< DMA is enabled (DMAE =1) or a transfer is processing */
#define HAU_FLAG_BUSY HAU_STAT_BUSY /*!< data block is in process */
-#define HAU_FLAG_INFIFO_NO_EMPTY HAU_CTL_DINE /*!< the input FIFO is not empty */
+#define HAU_FLAG_INFIFO_NO_EMPTY HAU_CTL_DINE /*!< the input FIFO is not empty */
#define HAU_INT_FLAG_DATA_INPUT HAU_STAT_DINT /*!< there is enough space (16 bytes) in the input FIFO */
#define HAU_INT_FLAG_CALCULATION_COMPLETE HAU_STAT_CINT /*!< digest calculation is completed */
@@ -151,9 +146,9 @@ typedef struct
/* reset the HAU peripheral */
void hau_deinit(void);
/* initialize the HAU peripheral parameters */
-void hau_init(hau_init_parameter_struct* initpara);
+void hau_init(hau_init_parameter_struct *initpara);
/* initialize the structure hau_initpara */
-void hau_init_parameter_init(hau_init_parameter_struct* initpara);
+void hau_init_struct_para_init(hau_init_parameter_struct *initpara);
/* reset the HAU processor core */
void hau_reset(void);
/* configure the number of valid bits in last word of the message */
@@ -163,7 +158,7 @@ void hau_data_write(uint32_t data);
/* return the number of words already written into the IN FIFO */
uint32_t hau_infifo_words_num_get(void);
/* read the message digest result */
-void hau_digest_read(hau_digest_parameter_struct* digestpara);
+void hau_digest_read(hau_digest_parameter_struct *digestpara);
/* enable digest calculation */
void hau_digest_calculation_enable(void);
/* configure single or multiple DMA is used, and digest calculation at the end of a DMA transfer or not */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_i2c.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_i2c.h
index 414e089..f9404c2 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_i2c.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_i2c.h
@@ -2,37 +2,33 @@
\file gd32f20x_i2c.h
\brief definitions for the I2C
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
- \version 2019-04-16, V2.1.1, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,228 +38,221 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* I2Cx(x=0,1,2) definitions */
-#define I2C0 I2C_BASE /*!< I2C0 base address */
-#define I2C1 (I2C_BASE + 0x00000400U) /*!< I2C1 base address */
-#define I2C2 (I2C_BASE + 0x00006C00U) /*!< I2C2 base address */
+#define I2C0 I2C_BASE /*!< I2C0 base address */
+#define I2C1 (I2C_BASE + 0x00000400U) /*!< I2C1 base address */
+#define I2C2 (I2C_BASE + 0x00006C00U) /*!< I2C2 base address */
/* registers definitions */
-#define I2C_CTL0(i2cx) REG32((i2cx) + 0x00U) /*!< I2C control register 0 */
-#define I2C_CTL1(i2cx) REG32((i2cx) + 0x04U) /*!< I2C control register 1 */
-#define I2C_SADDR0(i2cx) REG32((i2cx) + 0x08U) /*!< I2C slave address register 0*/
-#define I2C_SADDR1(i2cx) REG32((i2cx) + 0x0CU) /*!< I2C slave address register */
-#define I2C_DATA(i2cx) REG32((i2cx) + 0x10U) /*!< I2C transfer buffer register */
-#define I2C_STAT0(i2cx) REG32((i2cx) + 0x14U) /*!< I2C transfer status register 0 */
-#define I2C_STAT1(i2cx) REG32((i2cx) + 0x18U) /*!< I2C transfer status register */
-#define I2C_CKCFG(i2cx) REG32((i2cx) + 0x1CU) /*!< I2C clock configure register */
-#define I2C_RT(i2cx) REG32((i2cx) + 0x20U) /*!< I2C rise time register */
+#define I2C_CTL0(i2cx) REG32((i2cx) + 0x00000000U) /*!< I2C control register 0 */
+#define I2C_CTL1(i2cx) REG32((i2cx) + 0x00000004U) /*!< I2C control register 1 */
+#define I2C_SADDR0(i2cx) REG32((i2cx) + 0x00000008U) /*!< I2C slave address register 0 */
+#define I2C_SADDR1(i2cx) REG32((i2cx) + 0x0000000CU) /*!< I2C slave address register 1 */
+#define I2C_DATA(i2cx) REG32((i2cx) + 0x00000010U) /*!< I2C transfer buffer register */
+#define I2C_STAT0(i2cx) REG32((i2cx) + 0x00000014U) /*!< I2C transfer status register 0 */
+#define I2C_STAT1(i2cx) REG32((i2cx) + 0x00000018U) /*!< I2C transfer status register */
+#define I2C_CKCFG(i2cx) REG32((i2cx) + 0x0000001CU) /*!< I2C clock configure register */
+#define I2C_RT(i2cx) REG32((i2cx) + 0x00000020U) /*!< I2C rise time register */
/* bits definitions */
/* I2Cx_CTL0 */
-#define I2C_CTL0_I2CEN BIT(0) /*!< peripheral enable */
-#define I2C_CTL0_SMBEN BIT(1) /*!< SMBus mode */
-#define I2C_CTL0_SMBSEL BIT(3) /*!< SMBus type */
-#define I2C_CTL0_ARPEN BIT(4) /*!< ARP enable */
-#define I2C_CTL0_PECEN BIT(5) /*!< PEC enable */
-#define I2C_CTL0_GCEN BIT(6) /*!< general call enable */
-#define I2C_CTL0_DISSTRC BIT(7) /*!< clock stretching disable (slave mode) */
-#define I2C_CTL0_START BIT(8) /*!< start generation */
-#define I2C_CTL0_STOP BIT(9) /*!< stop generation */
-#define I2C_CTL0_ACKEN BIT(10) /*!< acknowledge enable */
-#define I2C_CTL0_POAP BIT(11) /*!< acknowledge/PEC position (for data reception) */
-#define I2C_CTL0_PECTRANS BIT(12) /*!< packet error checking */
-#define I2C_CTL0_SALT BIT(13) /*!< SMBus alert */
-#define I2C_CTL0_SRESET BIT(15) /*!< software reset */
+#define I2C_CTL0_I2CEN BIT(0) /*!< peripheral enable */
+#define I2C_CTL0_SMBEN BIT(1) /*!< SMBus mode */
+#define I2C_CTL0_SMBSEL BIT(3) /*!< SMBus type */
+#define I2C_CTL0_ARPEN BIT(4) /*!< ARP enable */
+#define I2C_CTL0_PECEN BIT(5) /*!< PEC enable */
+#define I2C_CTL0_GCEN BIT(6) /*!< general call enable */
+#define I2C_CTL0_SS BIT(7) /*!< clock stretching disable (slave mode) */
+#define I2C_CTL0_START BIT(8) /*!< start generation */
+#define I2C_CTL0_STOP BIT(9) /*!< stop generation */
+#define I2C_CTL0_ACKEN BIT(10) /*!< acknowledge enable */
+#define I2C_CTL0_POAP BIT(11) /*!< acknowledge/PEC position (for data reception) */
+#define I2C_CTL0_PECTRANS BIT(12) /*!< packet error checking */
+#define I2C_CTL0_SALT BIT(13) /*!< SMBus alert */
+#define I2C_CTL0_SRESET BIT(15) /*!< software reset */
/* I2Cx_CTL1 */
-#define I2C_CTL1_I2CCLK BITS(0,5) /*!< I2CCLK[5:0] bits (peripheral clock frequency) */
-#define I2C_CTL1_ERRIE BIT(8) /*!< error interrupt enable */
-#define I2C_CTL1_EVIE BIT(9) /*!< event interrupt enable */
-#define I2C_CTL1_BUFIE BIT(10) /*!< buffer interrupt enable */
-#define I2C_CTL1_DMAON BIT(11) /*!< DMA requests enable */
-#define I2C_CTL1_DMALST BIT(12) /*!< DMA last transfer */
+#define I2C_CTL1_I2CCLK BITS(0,5) /*!< I2CCLK[5:0] bits (peripheral clock frequency) */
+#define I2C_CTL1_ERRIE BIT(8) /*!< error interrupt enable */
+#define I2C_CTL1_EVIE BIT(9) /*!< event interrupt enable */
+#define I2C_CTL1_BUFIE BIT(10) /*!< buffer interrupt enable */
+#define I2C_CTL1_DMAON BIT(11) /*!< DMA requests enable */
+#define I2C_CTL1_DMALST BIT(12) /*!< DMA last transfer */
/* I2Cx_SADDR0 */
-#define I2C_SADDR0_ADDRESS0 BIT(0) /*!< bit 0 of a 10-bit address */
-#define I2C_SADDR0_ADDRESS BITS(1,7) /*!< 7-bit address or bits 7:1 of a 10-bit address */
-#define I2C_SADDR0_ADDRESS_H BITS(8,9) /*!< highest two bits of a 10-bit address */
-#define I2C_SADDR0_ADDFORMAT BIT(15) /*!< address mode for the I2C slave */
+#define I2C_SADDR0_ADDRESS0 BIT(0) /*!< bit 0 of a 10-bit address */
+#define I2C_SADDR0_ADDRESS BITS(1,7) /*!< 7-bit address or bits 7:1 of a 10-bit address */
+#define I2C_SADDR0_ADDRESS_H BITS(8,9) /*!< highest two bits of a 10-bit address */
+#define I2C_SADDR0_ADDFORMAT BIT(15) /*!< address mode for the I2C slave */
/* I2Cx_SADDR1 */
-#define I2C_SADDR1_DUADEN BIT(0) /*!< aual-address mode switch */
-#define I2C_SADDR1_ADDRESS2 BITS(1,7) /*!< second I2C address for the slave in dual-address mode */
+#define I2C_SADDR1_DUADEN BIT(0) /*!< aual-address mode switch */
+#define I2C_SADDR1_ADDRESS2 BITS(1,7) /*!< second I2C address for the slave in dual-address mode */
/* I2Cx_DATA */
-#define I2C_DATA_TRB BITS(0,7) /*!< 8-bit data register */
+#define I2C_DATA_TRB BITS(0,7) /*!< 8-bit data register */
/* I2Cx_STAT0 */
-#define I2C_STAT0_SBSEND BIT(0) /*!< start bit (master mode) */
-#define I2C_STAT0_ADDSEND BIT(1) /*!< address sent (master mode)/matched (slave mode) */
-#define I2C_STAT0_BTC BIT(2) /*!< byte transfer finished */
-#define I2C_STAT0_ADD10SEND BIT(3) /*!< 10-bit header sent (master mode) */
-#define I2C_STAT0_STPDET BIT(4) /*!< stop detection (slave mode) */
-#define I2C_STAT0_RBNE BIT(6) /*!< data register not empty (receivers) */
-#define I2C_STAT0_TBE BIT(7) /*!< data register empty (transmitters) */
-#define I2C_STAT0_BERR BIT(8) /*!< bus error */
-#define I2C_STAT0_LOSTARB BIT(9) /*!< arbitration lost (master mode) */
-#define I2C_STAT0_AERR BIT(10) /*!< acknowledge failure */
-#define I2C_STAT0_OUERR BIT(11) /*!< overrun/underrun */
-#define I2C_STAT0_PECERR BIT(12) /*!< PEC error in reception */
-#define I2C_STAT0_SMBTO BIT(14) /*!< timeout signal in SMBus mode */
-#define I2C_STAT0_SMBALT BIT(15) /*!< SMBus alert status */
+#define I2C_STAT0_SBSEND BIT(0) /*!< start bit (master mode) */
+#define I2C_STAT0_ADDSEND BIT(1) /*!< address sent (master mode)/matched (slave mode) */
+#define I2C_STAT0_BTC BIT(2) /*!< byte transfer finished */
+#define I2C_STAT0_ADD10SEND BIT(3) /*!< 10-bit header sent (master mode) */
+#define I2C_STAT0_STPDET BIT(4) /*!< stop detection (slave mode) */
+#define I2C_STAT0_RBNE BIT(6) /*!< data register not empty (receivers) */
+#define I2C_STAT0_TBE BIT(7) /*!< data register empty (transmitters) */
+#define I2C_STAT0_BERR BIT(8) /*!< bus error */
+#define I2C_STAT0_LOSTARB BIT(9) /*!< arbitration lost (master mode) */
+#define I2C_STAT0_AERR BIT(10) /*!< acknowledge failure */
+#define I2C_STAT0_OUERR BIT(11) /*!< overrun/underrun */
+#define I2C_STAT0_PECERR BIT(12) /*!< PEC error in reception */
+#define I2C_STAT0_SMBTO BIT(14) /*!< timeout signal in SMBus mode */
+#define I2C_STAT0_SMBALT BIT(15) /*!< SMBus alert status */
/* I2Cx_STAT1 */
-#define I2C_STAT1_MASTER BIT(0) /*!< master/slave */
-#define I2C_STAT1_I2CBSY BIT(1) /*!< bus busy */
-#define I2C_STAT1_TRS BIT(2) /*!< transmitter/receiver */
-#define I2C_STAT1_RXGC BIT(4) /*!< general call address (slave mode) */
-#define I2C_STAT1_DEFSMB BIT(5) /*!< SMBus device default address (slave mode) */
-#define I2C_STAT1_HSTSMB BIT(6) /*!< SMBus host header (slave mode) */
-#define I2C_STAT1_DUMODF BIT(7) /*!< dual flag (slave mode) */
-#define I2C_STAT1_ECV BITS(8,15) /*!< packet error checking register */
+#define I2C_STAT1_MASTER BIT(0) /*!< master/slave */
+#define I2C_STAT1_I2CBSY BIT(1) /*!< bus busy */
+#define I2C_STAT1_TR BIT(2) /*!< transmitter/receiver */
+#define I2C_STAT1_RXGC BIT(4) /*!< general call address (slave mode) */
+#define I2C_STAT1_DEFSMB BIT(5) /*!< SMBus device default address (slave mode) */
+#define I2C_STAT1_HSTSMB BIT(6) /*!< SMBus host header (slave mode) */
+#define I2C_STAT1_DUMODF BIT(7) /*!< dual flag (slave mode) */
+#define I2C_STAT1_PECV BITS(8,15) /*!< packet error checking value */
/* I2Cx_CKCFG */
-#define I2C_CKCFG_CLKC BITS(0,11) /*!< clock control register in fast/standard mode (master mode) */
-#define I2C_CKCFG_DTCY BIT(14) /*!< fast mode duty cycle */
-#define I2C_CKCFG_FAST BIT(15) /*!< I2C speed selection in master mode */
+#define I2C_CKCFG_CLKC BITS(0,11) /*!< clock control register in fast/standard mode (master mode) */
+#define I2C_CKCFG_DTCY BIT(14) /*!< fast mode duty cycle */
+#define I2C_CKCFG_FAST BIT(15) /*!< I2C speed selection in master mode */
/* I2Cx_RT */
-#define I2C_RT_RISETIME BITS(0,5) /*!< maximum rise time in fast/standard mode (Master mode) */
+#define I2C_RT_RISETIME BITS(0,5) /*!< maximum rise time in fast/standard mode (Master mode) */
/* constants definitions */
/* define the I2C bit position and its register index offset */
#define I2C_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
-#define I2C_REG_VAL(i2cx, offset) (REG32((i2cx) + (((uint32_t)(offset) & 0xFFFFU) >> 6)))
-#define I2C_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+#define I2C_REG_VAL(i2cx, offset) (REG32((i2cx) + (((uint32_t)(offset) & 0x0000FFFFU) >> 6)))
+#define I2C_BIT_POS(val) ((uint32_t)(val) & 0x0000001FU)
#define I2C_REGIDX_BIT2(regidx, bitpos, regidx2, bitpos2) (((uint32_t)(regidx2) << 22) | (uint32_t)((bitpos2) << 16)\
- | (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos)))
+ | (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos)))
#define I2C_REG_VAL2(i2cx, offset) (REG32((i2cx) + ((uint32_t)(offset) >> 22)))
-#define I2C_BIT_POS2(val) (((uint32_t)(val) & 0x1F0000U) >> 16)
+#define I2C_BIT_POS2(val) (((uint32_t)(val) & 0x001F0000U) >> 16)
/* register offset */
-#define I2C_CTL1_REG_OFFSET 0x04U /*!< CTL1 register offset */
-#define I2C_STAT0_REG_OFFSET 0x14U /*!< STAT0 register offset */
-#define I2C_STAT1_REG_OFFSET 0x18U /*!< STAT1 register offset */
-#define I2C_SAMCS_REG_OFFSET 0x80U /*!< SAMCS register offset */
+#define I2C_CTL1_REG_OFFSET ((uint32_t)0x00000004U) /*!< CTL1 register offset */
+#define I2C_STAT0_REG_OFFSET ((uint32_t)0x00000014U) /*!< STAT0 register offset */
+#define I2C_STAT1_REG_OFFSET ((uint32_t)0x00000018U) /*!< STAT1 register offset */
+#define I2C_SAMCS_REG_OFFSET ((uint32_t)0x00000080U) /*!< SAMCS register offset */
/* I2C flags */
-typedef enum
-{
+typedef enum {
/* flags in STAT0 register */
- I2C_FLAG_SBSEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 0U), /*!< start condition sent out in master mode */
- I2C_FLAG_ADDSEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 1U), /*!< address is sent in master mode or received and matches in slave mode */
- I2C_FLAG_BTC = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 2U), /*!< byte transmission finishes */
- I2C_FLAG_ADD10SEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 3U), /*!< header of 10-bit address is sent in master mode */
- I2C_FLAG_STPDET = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 4U), /*!< stop condition detected in slave mode */
- I2C_FLAG_RBNE = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 6U), /*!< I2C_DATA is not Empty during receiving */
- I2C_FLAG_TBE = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 7U), /*!< I2C_DATA is empty during transmitting */
- I2C_FLAG_BERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 8U), /*!< a bus error occurs indication a unexpected start or stop condition on I2C bus */
- I2C_FLAG_LOSTARB = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 9U), /*!< arbitration lost in master mode */
- I2C_FLAG_AERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 10U), /*!< acknowledge error */
- I2C_FLAG_OUERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 11U), /*!< over-run or under-run situation occurs in slave mode */
- I2C_FLAG_PECERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 12U), /*!< PEC error when receiving data */
- I2C_FLAG_SMBTO = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 14U), /*!< timeout signal in SMBus mode */
- I2C_FLAG_SMBALT = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 15U), /*!< SMBus alert status */
+ I2C_FLAG_SBSEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 0U), /*!< start condition sent out in master mode */
+ I2C_FLAG_ADDSEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 1U), /*!< address is sent in master mode or received and matches in slave mode */
+ I2C_FLAG_BTC = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 2U), /*!< byte transmission finishes */
+ I2C_FLAG_ADD10SEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 3U), /*!< header of 10-bit address is sent in master mode */
+ I2C_FLAG_STPDET = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 4U), /*!< stop condition detected in slave mode */
+ I2C_FLAG_RBNE = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 6U), /*!< I2C_DATA is not empty during receiving */
+ I2C_FLAG_TBE = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 7U), /*!< I2C_DATA is empty during transmitting */
+ I2C_FLAG_BERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 8U), /*!< a bus error occurs indication a unexpected start or stop condition on I2C bus */
+ I2C_FLAG_LOSTARB = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 9U), /*!< arbitration lost in master mode */
+ I2C_FLAG_AERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 10U), /*!< acknowledge error */
+ I2C_FLAG_OUERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 11U), /*!< over-run or under-run situation occurs in slave mode */
+ I2C_FLAG_PECERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 12U), /*!< PEC error when receiving data */
+ I2C_FLAG_SMBTO = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 14U), /*!< timeout signal in SMBus mode */
+ I2C_FLAG_SMBALT = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 15U), /*!< SMBus alert status */
/* flags in STAT1 register */
- I2C_FLAG_MASTER = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 0U), /*!< a flag indicating whether I2C block is in master or slave mode */
- I2C_FLAG_I2CBSY = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 1U), /*!< busy flag */
- I2C_FLAG_TRS = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 2U), /*!< whether the I2C is a transmitter or a receiver */
- I2C_FLAG_RXGC = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 4U), /*!< general call address (00h) received */
- I2C_FLAG_DEFSMB = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 5U), /*!< default address of SMBus device */
- I2C_FLAG_HSTSMB = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 6U), /*!< SMBus host header detected in slave mode */
- I2C_FLAG_DUMOD = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 7U) /*!< dual flag in slave mode indicating which address is matched in dual-address mode */
-}i2c_flag_enum;
+ I2C_FLAG_MASTER = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 0U), /*!< a flag indicating whether I2C block is in master or slave mode */
+ I2C_FLAG_I2CBSY = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 1U), /*!< busy flag */
+ I2C_FLAG_TR = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 2U), /*!< whether the I2C is a transmitter or a receiver */
+ I2C_FLAG_RXGC = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 4U), /*!< general call address (00h) received */
+ I2C_FLAG_DEFSMB = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 5U), /*!< default address of SMBus device */
+ I2C_FLAG_HSTSMB = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 6U), /*!< SMBus host header detected in slave mode */
+ I2C_FLAG_DUMOD = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 7U) /*!< dual flag in slave mode indicating which address is matched in dual-address mode */
+} i2c_flag_enum;
/* I2C interrupt flags */
-typedef enum
-{
+typedef enum {
/* interrupt flags in CTL1 register */
I2C_INT_FLAG_SBSEND = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 0U), /*!< start condition sent out in master mode interrupt flag */
I2C_INT_FLAG_ADDSEND = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 1U), /*!< address is sent in master mode or received and matches in slave mode interrupt flag */
- I2C_INT_FLAG_BTC = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 2U), /*!< byte transmission finishes */
+ I2C_INT_FLAG_BTC = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 2U), /*!< byte transmission finishes interrupt flag */
I2C_INT_FLAG_ADD10SEND = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 3U), /*!< header of 10-bit address is sent in master mode interrupt flag */
I2C_INT_FLAG_STPDET = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 4U), /*!< stop condition detected in slave mode interrupt flag */
I2C_INT_FLAG_RBNE = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 6U), /*!< I2C_DATA is not Empty during receiving interrupt flag */
- I2C_INT_FLAG_TBE = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 7U), /*!< I2C_DATA is empty during transmitting interrupt flag */
+ I2C_INT_FLAG_TBE = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 7U), /*!< I2C_DATA is empty during transmitting interrupt flag */
I2C_INT_FLAG_BERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 8U), /*!< a bus error occurs indication a unexpected start or stop condition on I2C bus interrupt flag */
I2C_INT_FLAG_LOSTARB = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 9U), /*!< arbitration lost in master mode interrupt flag */
I2C_INT_FLAG_AERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 10U), /*!< acknowledge error interrupt flag */
I2C_INT_FLAG_OUERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 11U), /*!< over-run or under-run situation occurs in slave mode interrupt flag */
I2C_INT_FLAG_PECERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 12U), /*!< PEC error when receiving data interrupt flag */
I2C_INT_FLAG_SMBTO = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 14U), /*!< timeout signal in SMBus mode interrupt flag */
- I2C_INT_FLAG_SMBALT = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 15U), /*!< SMBus Alert status interrupt flag */
-}i2c_interrupt_flag_enum;
+ I2C_INT_FLAG_SMBALT = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 15U), /*!< SMBus alert status interrupt flag */
+} i2c_interrupt_flag_enum;
-/* I2C interrupt enable or disable */
-typedef enum
-{
+/* I2C interrupt */
+typedef enum {
/* interrupt in CTL1 register */
- I2C_INT_ERR = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 8U), /*!< error interrupt enable */
- I2C_INT_EV = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 9U), /*!< event interrupt enable */
- I2C_INT_BUF = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 10U), /*!< buffer interrupt enable */
-}i2c_interrupt_enum;
+ I2C_INT_ERR = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 8U), /*!< error interrupt */
+ I2C_INT_EV = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 9U), /*!< event interrupt */
+ I2C_INT_BUF = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 10U), /*!< buffer interrupt */
+} i2c_interrupt_enum;
/* SMBus/I2C mode switch and SMBus type selection */
-#define I2C_I2CMODE_ENABLE ((uint32_t)0x00000000U) /*!< I2C mode */
-#define I2C_SMBUSMODE_ENABLE I2C_CTL0_SMBEN /*!< SMBus mode */
+#define I2C_I2CMODE_ENABLE ((uint32_t)0x00000000U) /*!< I2C mode */
+#define I2C_SMBUSMODE_ENABLE I2C_CTL0_SMBEN /*!< SMBus mode */
/* SMBus/I2C mode switch and SMBus type selection */
-#define I2C_SMBUS_DEVICE ((uint32_t)0x00000000U) /*!< SMBus mode device type */
-#define I2C_SMBUS_HOST I2C_CTL0_SMBSEL /*!< SMBus mode host type */
+#define I2C_SMBUS_DEVICE ((uint32_t)0x00000000U) /*!< SMBus mode device type */
+#define I2C_SMBUS_HOST I2C_CTL0_SMBSEL /*!< SMBus mode host type */
/* I2C transfer direction */
-#define I2C_RECEIVER ((uint32_t)0x00000001U) /*!< receiver */
-#define I2C_TRANSMITTER ((uint32_t)0xFFFFFFFEU) /*!< transmitter */
+#define I2C_RECEIVER ((uint32_t)0x00000001U) /*!< receiver */
+#define I2C_TRANSMITTER ((uint32_t)0xFFFFFFFEU) /*!< transmitter */
/* whether or not to send an ACK */
-#define I2C_ACK_DISABLE ((uint32_t)0x00000000U) /*!< ACK will be not sent */
-#define I2C_ACK_ENABLE ((uint32_t)0x00000001U) /*!< ACK will be sent */
+#define I2C_ACK_DISABLE ((uint32_t)0x00000000U) /*!< ACK will be not sent */
+#define I2C_ACK_ENABLE I2C_CTL0_ACKEN /*!< ACK will be sent */
/* I2C POAP position*/
-#define I2C_ACKPOS_NEXT ((uint32_t)0x00000000U) /*!< ACKEN bit decides whether or not to send ACK for the next byte */
-#define I2C_ACKPOS_CURRENT ((uint32_t)0x00000001U) /*!< ACKEN bit decides whether or not to send ACK or not for the current byte */
-
-/* I2C dual-address mode switch */
-#define I2C_DUADEN_DISABLE ((uint32_t)0x00000000U) /*!< dual-address mode disabled */
-#define I2C_DUADEN_ENABLE ((uint32_t)0x00000001U) /*!< dual-address mode enabled */
+#define I2C_ACKPOS_CURRENT ((uint32_t)0x00000000U) /*!< ACKEN bit decides whether or not to send ACK or not for the current byte */
+#define I2C_ACKPOS_NEXT I2C_CTL0_POAP /*!< ACKEN bit decides whether or not to send ACK for the next byte */
/* whether or not to stretch SCL low */
-#define I2C_SCLSTRETCH_DISABLE ((uint32_t)0x00000000U) /*!< SCL stretching is disabled */
-#define I2C_SCLSTRETCH_ENABLE I2C_CTL0_DISSTRC /*!< SCL stretching is enabled */
+#define I2C_SCLSTRETCH_ENABLE ((uint32_t)0x00000000U) /*!< enable SCL stretching */
+#define I2C_SCLSTRETCH_DISABLE I2C_CTL0_SS /*!< disable SCL stretching */
/* whether or not to response to a general call */
-#define I2C_GCEN_ENABLE I2C_CTL0_GCEN /*!< slave will response to a general call */
-#define I2C_GCEN_DISABLE ((uint32_t)0x00000000U) /*!< slave will not response to a general call */
+#define I2C_GCEN_ENABLE I2C_CTL0_GCEN /*!< slave will response to a general call */
+#define I2C_GCEN_DISABLE ((uint32_t)0x00000000U) /*!< slave will not response to a general call */
/* software reset I2C */
-#define I2C_SRESET_SET I2C_CTL0_SRESET /*!< I2C is under reset */
-#define I2C_SRESET_RESET ((uint32_t)0x00000000U) /*!< I2C is not under reset */
+#define I2C_SRESET_RESET ((uint32_t)0x00000000U) /*!< I2C is not under reset */
+#define I2C_SRESET_SET I2C_CTL0_SRESET /*!< I2C is under reset */
/* I2C DMA mode configure */
/* DMA mode switch */
-#define I2C_DMA_ON I2C_CTL1_DMAON /*!< DMA mode enabled */
-#define I2C_DMA_OFF ((uint32_t)0x00000000U) /*!< DMA mode disabled */
+#define I2C_DMA_OFF ((uint32_t)0x00000000U) /*!< disable DMA mode */
+#define I2C_DMA_ON I2C_CTL1_DMAON /*!< enable DMA mode */
/* flag indicating DMA last transfer */
-#define I2C_DMALST_ON I2C_CTL1_DMALST /*!< next DMA EOT is the last transfer */
-#define I2C_DMALST_OFF ((uint32_t)0x00000000U) /*!< next DMA EOT is not the last transfer */
+#define I2C_DMALST_OFF ((uint32_t)0x00000000U) /*!< next DMA EOT is not the last transfer */
+#define I2C_DMALST_ON I2C_CTL1_DMALST /*!< next DMA EOT is the last transfer */
/* I2C PEC configure */
/* PEC enable */
-#define I2C_PEC_ENABLE I2C_CTL0_PECEN /*!< PEC calculation on */
-#define I2C_PEC_DISABLE ((uint32_t)0x00000000U) /*!< PEC calculation off */
+#define I2C_PEC_DISABLE ((uint32_t)0x00000000U) /*!< PEC calculation off */
+#define I2C_PEC_ENABLE I2C_CTL0_PECEN /*!< PEC calculation on */
/* PEC transfer */
-#define I2C_PECTRANS_ENABLE I2C_CTL0_PECTRANS /*!< transfer PEC */
-#define I2C_PECTRANS_DISABLE ((uint32_t)0x00000000U) /*!< not transfer PEC value */
+#define I2C_PECTRANS_DISABLE ((uint32_t)0x00000000U) /*!< not transfer PEC value */
+#define I2C_PECTRANS_ENABLE I2C_CTL0_PECTRANS /*!< transfer PEC value */
/* I2C SMBus configure */
/* issue or not alert through SMBA pin */
-#define I2C_SALTSEND_ENABLE I2C_CTL0_SALT /*!< issue alert through SMBA pin */
-#define I2C_SALTSEND_DISABLE ((uint32_t)0x00000000U) /*!< not issue alert through SMBA */
+#define I2C_SALTSEND_DISABLE ((uint32_t)0x00000000U) /*!< not issue alert through SMBA */
+#define I2C_SALTSEND_ENABLE I2C_CTL0_SALT /*!< issue alert through SMBA pin */
/* ARP protocol in SMBus switch */
-#define I2C_ARP_ENABLE I2C_CTL0_ARPEN /*!< ARP is enabled */
-#define I2C_ARP_DISABLE ((uint32_t)0x00000000U) /*!< ARP is disabled */
+#define I2C_ARP_DISABLE ((uint32_t)0x00000000U) /*!< disable ARP */
+#define I2C_ARP_ENABLE I2C_CTL0_ARPEN /*!< enable ARP */
/* transmit I2C data */
#define DATA_TRANS(regval) (BITS(0,7) & ((uint32_t)(regval) << 0))
@@ -272,12 +261,12 @@ typedef enum
#define DATA_RECV(regval) GET_BITS((uint32_t)(regval), 0, 7)
/* I2C duty cycle in fast mode */
-#define I2C_DTCY_2 ((uint32_t)0x00000000U) /*!< I2C fast mode Tlow/Thigh = 2 */
-#define I2C_DTCY_16_9 I2C_CKCFG_DTCY /*!< I2C fast mode Tlow/Thigh = 16/9 */
+#define I2C_DTCY_2 ((uint32_t)0x00000000U) /*!< T_low/T_high = 2 in fast mode */
+#define I2C_DTCY_16_9 I2C_CKCFG_DTCY /*!< T_low/T_high = 16/9 in fast mode */
/* address mode for the I2C slave */
-#define I2C_ADDFORMAT_7BITS ((uint32_t)0x00000000U) /*!< address:7 bits */
-#define I2C_ADDFORMAT_10BITS I2C_SADDR0_ADDFORMAT /*!< address:10 bits */
+#define I2C_ADDFORMAT_7BITS ((uint32_t)0x00000000U) /*!< address format is 7 bits */
+#define I2C_ADDFORMAT_10BITS I2C_SADDR0_ADDFORMAT /*!< address format is 10 bits */
/* function declarations */
/* initialization functions */
@@ -287,7 +276,9 @@ void i2c_deinit(uint32_t i2c_periph);
void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc);
/* configure I2C address */
void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode, uint32_t addformat, uint32_t addr);
-/* SMBus type selection */
+
+/* application function declarations */
+/* select SMBus type */
void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type);
/* whether or not to send an ACK */
void i2c_ack_config(uint32_t i2c_periph, uint32_t ack);
@@ -299,8 +290,6 @@ void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr, uint32_t trandire
void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr);
/* disable dual-address mode */
void i2c_dualaddr_disable(uint32_t i2c_periph);
-
-/* function configuration */
/* enable I2C */
void i2c_enable(uint32_t i2c_periph);
/* disable I2C */
@@ -313,40 +302,39 @@ void i2c_stop_on_bus(uint32_t i2c_periph);
void i2c_data_transmit(uint32_t i2c_periph, uint8_t data);
/* I2C receive data function */
uint8_t i2c_data_receive(uint32_t i2c_periph);
-/* enable I2C DMA mode */
-void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate);
+/* configure I2C DMA mode */
+void i2c_dma_config(uint32_t i2c_periph, uint32_t dmastate);
/* configure whether next DMA EOT is DMA last transfer or not */
void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast);
/* whether to stretch SCL low when data is not ready in slave mode */
void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara);
/* whether or not to response to a general call */
void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara);
-/* software reset I2C */
+/* configure software reset of I2C */
void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset);
-
-/* I2C PEC calculation on or off */
-void i2c_pec_enable(uint32_t i2c_periph, uint32_t pecstate);
-/* I2C whether to transfer PEC value */
-void i2c_pec_transfer_enable(uint32_t i2c_periph, uint32_t pecpara);
-/* packet error checking value */
+/* configure I2C PEC calculation */
+void i2c_pec_config(uint32_t i2c_periph, uint32_t pecstate);
+/* configure whether to transfer PEC value */
+void i2c_pec_transfer_config(uint32_t i2c_periph, uint32_t pecpara);
+/* get packet error checking value */
uint8_t i2c_pec_value_get(uint32_t i2c_periph);
-/* I2C issue alert through SMBA pin */
-void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara);
-/* I2C ARP protocol in SMBus switch */
-void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate);
+/* configure I2C alert through SMBA pin */
+void i2c_smbus_alert_config(uint32_t i2c_periph, uint32_t smbuspara);
+/* configure I2C ARP protocol in SMBus */
+void i2c_smbus_arp_config(uint32_t i2c_periph, uint32_t arpstate);
/* interrupt & flag functions */
-/* check I2C flag is set or not */
+/* get I2C flag status */
FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag);
-/* clear I2C flag */
+/* clear I2C flag status */
void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag);
/* enable I2C interrupt */
void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt);
/* disable I2C interrupt */
void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt);
-/* check I2C interrupt flag */
+/* get I2C interrupt flag status */
FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag);
-/* clear I2C interrupt flag */
+/* clear I2C interrupt flag status */
void i2c_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag);
#endif /* GD32F20X_I2C_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_misc.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_misc.h
index 93bdc82..640da18 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_misc.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_misc.h
@@ -2,36 +2,33 @@
\file gd32f20x_misc.h
\brief definitions for the MISC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,26 +39,26 @@ OF SUCH DAMAGE.
/* constants definitions */
/* set the RAM and FLASH base address */
-#define NVIC_VECTTAB_RAM ((uint32_t)0x20000000) /*!< RAM base address */
-#define NVIC_VECTTAB_FLASH ((uint32_t)0x08000000) /*!< Flash base address */
+#define NVIC_VECTTAB_RAM ((uint32_t)0x20000000U) /*!< RAM base address */
+#define NVIC_VECTTAB_FLASH ((uint32_t)0x08000000U) /*!< Flash base address */
/* set the NVIC vector table offset mask */
-#define NVIC_VECTTAB_OFFSET_MASK ((uint32_t)0x1FFFFF80) /*!< NVIC vector table offset mask */
+#define NVIC_VECTTAB_OFFSET_MASK ((uint32_t)0x1FFFFF80U) /*!< NVIC vector table offset mask */
/* the register key mask, if you want to do the write operation, you should write 0x5FA to VECTKEY bits */
-#define NVIC_AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) /*!< NVIC VECTKEY mask */
+#define NVIC_AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000U) /*!< NVIC VECTKEY mask */
/* priority group - define the pre-emption priority and the subpriority */
-#define NVIC_PRIGROUP_PRE0_SUB4 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 4 bits for subpriority */
-#define NVIC_PRIGROUP_PRE1_SUB3 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 3 bits for subpriority */
-#define NVIC_PRIGROUP_PRE2_SUB2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 2 bits for subpriority */
-#define NVIC_PRIGROUP_PRE3_SUB1 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 1 bits for subpriority */
-#define NVIC_PRIGROUP_PRE4_SUB0 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 0 bits for subpriority */
+#define NVIC_PRIGROUP_PRE0_SUB4 ((uint32_t)0x00000700U) /*!< 0 bits for pre-emption priority, 4 bits for subpriority */
+#define NVIC_PRIGROUP_PRE1_SUB3 ((uint32_t)0x00000600U) /*!< 1 bits for pre-emption priority, 3 bits for subpriority */
+#define NVIC_PRIGROUP_PRE2_SUB2 ((uint32_t)0x00000500U) /*!< 2 bits for pre-emption priority, 2 bits for subpriority */
+#define NVIC_PRIGROUP_PRE3_SUB1 ((uint32_t)0x00000400U) /*!< 3 bits for pre-emption priority, 1 bits for subpriority */
+#define NVIC_PRIGROUP_PRE4_SUB0 ((uint32_t)0x00000300U) /*!< 4 bits for pre-emption priority, 0 bits for subpriority */
-/* choose the method to enter or exit the lowpower mode */
-#define SCB_SCR_SLEEPONEXIT ((uint8_t)0x02) /*!< choose the the system whether enter low power mode by exiting from ISR */
-#define SCB_SCR_SLEEPDEEP ((uint8_t)0x04) /*!< choose the the system enter the DEEPSLEEP mode or SLEEP mode */
-#define SCB_SCR_SEVONPEND ((uint8_t)0x10) /*!< choose the interrupt source that can wake up the lowpower mode */
+/* choose the method to enter or exit the low power mode */
+#define SCB_SCR_SLEEPONEXIT ((uint8_t)0x02U) /*!< choose the system whether enter low power mode by exiting from ISR */
+#define SCB_SCR_SLEEPDEEP ((uint8_t)0x04U) /*!< choose the system enter the DEEPSLEEP mode or SLEEP mode */
+#define SCB_SCR_SEVONPEND ((uint8_t)0x10U) /*!< choose the interrupt source that can wake up the low power mode */
#define SCB_LPM_SLEEP_EXIT_ISR SCB_SCR_SLEEPONEXIT /*!< low power mode by exiting from ISR */
#define SCB_LPM_DEEPSLEEP SCB_SCR_SLEEPDEEP /*!< DEEPSLEEP mode or SLEEP mode */
@@ -72,25 +69,20 @@ OF SUCH DAMAGE.
#define SYSTICK_CLKSOURCE_HCLK ((uint32_t)0x00000004U) /*!< systick clock source is from HCLK */
/* function declarations */
-/* function configuration */
/* set the priority group */
void nvic_priority_group_set(uint32_t nvic_prigroup);
-/* enable NVIC request */
+/* enable NVIC interrupt request */
void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority, uint8_t nvic_irq_sub_priority);
-/* disable NVIC request */
+/* disable NVIC interrupt request */
void nvic_irq_disable(uint8_t nvic_irq);
-
/* set the NVIC vector table base address */
void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset);
-
/* set the state of the low power mode */
void system_lowpower_set(uint8_t lowpower_mode);
/* reset the state of the low power mode */
void system_lowpower_reset(uint8_t lowpower_mode);
-
/* set the systick clock source */
void systick_clksource_set(uint32_t systick_clksource);
#endif /* GD32F20X_MISC_H */
-
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_pmu.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_pmu.h
index 5648728..839bc67 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_pmu.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_pmu.h
@@ -2,36 +2,33 @@
\file gd32f20x_pmu.h
\brief definitions for the PMU
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -64,6 +61,10 @@ OF SUCH DAMAGE.
#define PMU_CS_WUPEN BIT(8) /*!< wakeup pin enable */
/* constants definitions */
+/* PMU ldo definitions */
+#define PMU_LDO_NORMAL ((uint32_t)0x00000000U) /*!< LDO normal work when PMU enter deepsleep mode */
+#define PMU_LDO_LOWPOWER PMU_CTL_LDOLP /*!< LDO work at low power status when PMU enter deepsleep mode */
+
/* PMU low voltage detector threshold definitions */
#define CTL_LVDT(regval) (BITS(5,7)&((uint32_t)(regval) << 5))
#define PMU_LVDT_0 CTL_LVDT(0) /*!< voltage threshold is 2.2V */
@@ -80,10 +81,6 @@ OF SUCH DAMAGE.
#define PMU_FLAG_STANDBY PMU_CS_STBF /*!< standby flag status */
#define PMU_FLAG_LVD PMU_CS_LVDF /*!< lvd flag status */
-/* PMU ldo definitions */
-#define PMU_LDO_NORMAL ((uint32_t)0x00000000U) /*!< LDO normal work when PMU enter deepsleep mode */
-#define PMU_LDO_LOWPOWER PMU_CTL_LDOLP /*!< LDO work at low power status when PMU enter deepsleep mode */
-
/* PMU flag reset definitions */
#define PMU_FLAG_RESET_WAKEUP ((uint8_t)0x00U) /*!< wakeup flag reset */
#define PMU_FLAG_RESET_STANDBY ((uint8_t)0x01U) /*!< standby flag reset */
@@ -93,22 +90,22 @@ OF SUCH DAMAGE.
#define WFE_CMD ((uint8_t)0x01U) /*!< use WFE command */
/* function declarations */
-/* initialization functions */
/* reset PMU registers */
void pmu_deinit(void);
+/* LVD functions */
/* select low voltage detector threshold */
void pmu_lvd_select(uint32_t lvdt_n);
/* disable PMU lvd */
void pmu_lvd_disable(void);
/* set PMU mode */
-/* PMU work at sleep mode */
+/* PMU work in sleep mode */
void pmu_to_sleepmode(uint8_t sleepmodecmd);
-/* PMU work at deepsleep mode */
+/* PMU work in deepsleep mode */
void pmu_to_deepsleepmode(uint32_t ldo, uint8_t deepsleepmodecmd);
-/* PMU work at standby mode */
-void pmu_to_standbymode(uint8_t standbymodecmd);
+/* PMU work in standby mode */
+void pmu_to_standbymode(void);
/* enable PMU wakeup pin */
void pmu_wakeup_pin_enable(void);
/* disable PMU wakeup pin */
@@ -124,6 +121,6 @@ void pmu_backup_write_disable(void);
/* get flag state */
FlagStatus pmu_flag_get(uint32_t flag);
/* clear flag bit */
-void pmu_flag_clear(uint32_t flag_reset);
+void pmu_flag_clear(uint32_t flag);
#endif /* GD32F20X_PMU_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rcu.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rcu.h
index 4ac9bfa..4b94875 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rcu.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rcu.h
@@ -2,36 +2,33 @@
\file gd32f20x_rcu.h
\brief definitions for the RCU
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -359,8 +356,7 @@ OF SUCH DAMAGE.
#define PLLTCFG_REG_OFFSET 0x98U /*!< PLLT configuration register offset */
/* peripheral clock enable */
-typedef enum
-{
+typedef enum {
/* AHB peripherals */
RCU_DMA0 = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 0U), /*!< DMA0 clock */
RCU_DMA1 = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 1U), /*!< DMA1 clock */
@@ -371,12 +367,12 @@ typedef enum
RCU_ENET = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 14U), /*!< ENET clock */
RCU_ENETTX = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 15U), /*!< ENETTX clock */
RCU_ENETRX = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 16U), /*!< ENETRX clock */
-
+
RCU_DCI = RCU_REGIDX_BIT(AHB2EN_REG_OFFSET, 0U), /*!< DCI clock */
RCU_CAU = RCU_REGIDX_BIT(AHB2EN_REG_OFFSET, 4U), /*!< CAU clock */
RCU_HAU = RCU_REGIDX_BIT(AHB2EN_REG_OFFSET, 5U), /*!< HAU clock */
RCU_TRNG = RCU_REGIDX_BIT(AHB2EN_REG_OFFSET, 6U), /*!< TRNG clock */
-
+
/* APB1 peripherals */
RCU_TIMER1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 0U), /*!< TIMER1 clock */
RCU_TIMER2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 1U), /*!< TIMER2 clock */
@@ -401,13 +397,13 @@ typedef enum
RCU_BKPI = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 27U), /*!< BKPI clock */
RCU_PMU = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 28U), /*!< PMU clock */
RCU_DAC = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 29U), /*!< DAC clock */
-
+
RCU_RTC = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 15U), /*!< RTC clock */
-
+
RCU_I2C2 = RCU_REGIDX_BIT(ADD_APB1EN_REG_OFFSET, 23U), /*!< I2C2 clock */
RCU_UART6 = RCU_REGIDX_BIT(ADD_APB1EN_REG_OFFSET, 30U), /*!< UART6 clock */
RCU_UART7 = RCU_REGIDX_BIT(ADD_APB1EN_REG_OFFSET, 31U), /*!< UART7 clock */
-
+
/* APB2 peripherals */
RCU_AF = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 0U), /*!< alternate function clock */
RCU_GPIOA = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 2U), /*!< GPIOA clock */
@@ -427,34 +423,32 @@ typedef enum
RCU_TIMER8 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 19U), /*!< TIMER8 clock */
RCU_TIMER9 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 20U), /*!< TIMER9 clock */
RCU_TIMER10 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 21U), /*!< TIMER10 clock */
-
+
RCU_USART5 = RCU_REGIDX_BIT(ADD_APB2EN_REG_OFFSET, 24U), /*!< USART5 clock */
RCU_TLI = RCU_REGIDX_BIT(ADD_APB2EN_REG_OFFSET, 26U), /*!< TLI clock */
RCU_GPIOH = RCU_REGIDX_BIT(ADD_APB2EN_REG_OFFSET, 30U), /*!< GPIOH clock */
RCU_GPIOI = RCU_REGIDX_BIT(ADD_APB2EN_REG_OFFSET, 31U), /*!< GPIOI clock */
-}rcu_periph_enum;
+} rcu_periph_enum;
/* peripheral clock enable when sleep mode*/
-typedef enum
-{
+typedef enum {
/* AHB peripherals */
RCU_SRAM_SLP = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 2U), /*!< SRAM clock */
RCU_FMC_SLP = RCU_REGIDX_BIT(AHB1EN_REG_OFFSET, 4U), /*!< FMC clock */
-}rcu_periph_sleep_enum;
+} rcu_periph_sleep_enum;
/* peripherals reset */
-typedef enum
-{
+typedef enum {
/* AHB peripherals */
RCU_USBFSRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 12U), /*!< USBFS clock reset */
RCU_ENETRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 14U), /*!< ENET clock reset */
-
+
RCU_DCIRST = RCU_REGIDX_BIT(AHB2RST_REG_OFFSET, 0U), /*!< DCI clock reset */
RCU_CAURST = RCU_REGIDX_BIT(AHB2RST_REG_OFFSET, 4U), /*!< CAU clock reset */
RCU_HAURST = RCU_REGIDX_BIT(AHB2RST_REG_OFFSET, 5U), /*!< HAU clock reset */
RCU_TRNGRST = RCU_REGIDX_BIT(AHB2RST_REG_OFFSET, 6U), /*!< TRNG clock reset */
-
+
/* APB1 peripherals */
RCU_TIMER1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 0U), /*!< TIMER1 clock reset */
RCU_TIMER2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 1U), /*!< TIMER2 clock reset */
@@ -479,7 +473,7 @@ typedef enum
RCU_BKPIRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 27U), /*!< BKPI clock reset */
RCU_PMURST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 28U), /*!< PMU clock reset */
RCU_DACRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 29U), /*!< DAC clock reset */
-
+
RCU_I2C2RST = RCU_REGIDX_BIT(ADD_APB1RST_REG_OFFSET, 23U), /*!< I2C2 clock reset */
RCU_UART6RST = RCU_REGIDX_BIT(ADD_APB1RST_REG_OFFSET, 30U), /*!< UART6 clock reset */
RCU_UART7RST = RCU_REGIDX_BIT(ADD_APB1RST_REG_OFFSET, 31U), /*!< UART7 clock reset */
@@ -509,11 +503,10 @@ typedef enum
RCU_GPIOHRST = RCU_REGIDX_BIT(ADD_APB2RST_REG_OFFSET, 30U), /*!< GPIOH clock reset */
RCU_GPIOIRST = RCU_REGIDX_BIT(ADD_APB2RST_REG_OFFSET, 31U), /*!< GPIOI clock reset */
-}rcu_periph_reset_enum;
+} rcu_periph_reset_enum;
/* clock stabilization and peripheral reset flags */
-typedef enum
-{
+typedef enum {
/* clock stabilization flags */
RCU_FLAG_IRC8MSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 1U), /*!< IRC8M stabilization flags */
RCU_FLAG_HXTALSTB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 17U), /*!< HXTAL stabilization flags */
@@ -522,7 +515,7 @@ typedef enum
RCU_FLAG_PLL2STB = RCU_REGIDX_BIT(CTL_REG_OFFSET, 29U), /*!< PLL2 stabilization flags */
RCU_FLAG_LXTALSTB = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 1U), /*!< LXTAL stabilization flags */
-
+
RCU_FLAG_IRC40KSTB = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 1U), /*!< IRC40K stabilization flags */
RCU_FLAG_PLLTSTB = RCU_REGIDX_BIT(PLLTCTL_REG_OFFSET, 29U), /*!< PLLT stabilization flags */
@@ -534,11 +527,10 @@ typedef enum
RCU_FLAG_FWDGTRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 29U), /*!< FWDGT reset flags */
RCU_FLAG_WWDGTRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 30U), /*!< WWDGT reset flags */
RCU_FLAG_LPRST = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 31U), /*!< low-power reset flags */
-}rcu_flag_enum;
+} rcu_flag_enum;
/* clock stabilization and ckm interrupt flags */
-typedef enum
-{
+typedef enum {
RCU_INT_FLAG_IRC40KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 0U), /*!< IRC40K stabilization interrupt flag */
RCU_INT_FLAG_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 1U), /*!< LXTAL stabilization interrupt flag */
RCU_INT_FLAG_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 2U), /*!< IRC8M stabilization interrupt flag */
@@ -548,11 +540,10 @@ typedef enum
RCU_INT_FLAG_PLL2STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 6U), /*!< PLL2 stabilization interrupt flag */
RCU_INT_FLAG_CKM = RCU_REGIDX_BIT(INT_REG_OFFSET, 7U), /*!< HXTAL clock stuck interrupt flag */
RCU_INT_FLAG_PLLTSTB = RCU_REGIDX_BIT(PLLTINT_REG_OFFSET, 6U), /*!< PLLT stabilization interrupt flag */
-}rcu_int_flag_enum;
+} rcu_int_flag_enum;
/* clock stabilization and stuck interrupt flags clear */
-typedef enum
-{
+typedef enum {
RCU_INT_FLAG_IRC40KSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 16U), /*!< IRC40K stabilization interrupt flags clear */
RCU_INT_FLAG_LXTALSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 17U), /*!< LXTAL stabilization interrupt flags clear */
RCU_INT_FLAG_IRC8MSTB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 18U), /*!< IRC8M stabilization interrupt flags clear */
@@ -562,11 +553,10 @@ typedef enum
RCU_INT_FLAG_PLL2STB_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 22U), /*!< PLL2 stabilization interrupt flags clear */
RCU_INT_FLAG_CKM_CLR = RCU_REGIDX_BIT(INT_REG_OFFSET, 23U), /*!< CKM interrupt flags clear */
RCU_INT_FLAG_PLLTSTB_CLR = RCU_REGIDX_BIT(PLLTINT_REG_OFFSET, 22U), /*!< PLLT stabilization interrupt clear */
-}rcu_int_flag_clear_enum;
+} rcu_int_flag_clear_enum;
/* clock stabilization interrupt enable or disable */
-typedef enum
-{
+typedef enum {
RCU_INT_IRC40KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 8U), /*!< IRC40K stabilization interrupt */
RCU_INT_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 9U), /*!< LXTAL stabilization interrupt */
RCU_INT_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 10U), /*!< IRC8M stabilization interrupt */
@@ -575,33 +565,31 @@ typedef enum
RCU_INT_PLL1STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 13U), /*!< PLL1 stabilization interrupt */
RCU_INT_PLL2STB = RCU_REGIDX_BIT(INT_REG_OFFSET, 14U), /*!< PLL2 stabilization interrupt */
RCU_INT_PLLTSTB = RCU_REGIDX_BIT(PLLTINT_REG_OFFSET, 14U), /*!< PLLT stabilization interrupt */
-}rcu_int_enum;
+} rcu_int_enum;
/* oscillator types */
-typedef enum
-{
+typedef enum {
RCU_IRC8M = RCU_REGIDX_BIT(CTL_REG_OFFSET, 0U), /*!< IRC8M */
RCU_HXTAL = RCU_REGIDX_BIT(CTL_REG_OFFSET, 16U), /*!< HXTAL */
RCU_PLL_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 24U), /*!< PLL */
RCU_PLL1_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 26U), /*!< PLL1 */
RCU_PLL2_CK = RCU_REGIDX_BIT(CTL_REG_OFFSET, 28U), /*!< PLL2 */
-
+
RCU_LXTAL = RCU_REGIDX_BIT(BDCTL_REG_OFFSET, 0U), /*!< LXTAL */
RCU_IRC40K = RCU_REGIDX_BIT(RSTSCK_REG_OFFSET, 0U), /*!< IRC40K */
RCU_PLLT_CK = RCU_REGIDX_BIT(PLLTCTL_REG_OFFSET, 28U), /*!< PLLT */
-}rcu_osci_type_enum;
+} rcu_osci_type_enum;
/* rcu clock frequency */
-typedef enum
-{
+typedef enum {
CK_SYS = 0, /*!< system clock */
CK_AHB, /*!< AHB clock */
CK_APB1, /*!< APB1 clock */
CK_APB2, /*!< APB2 clock */
-}rcu_clock_freq_enum;
+} rcu_clock_freq_enum;
/* RCU_CFG0 register bit define */
/* system clock source selection */
@@ -975,10 +963,6 @@ typedef enum
#define RCU_PLLTSRC_IRC8M ((uint32_t)0x00000000U) /*!< IRC8M selected as source clock of PLLT */
#define RCU_PLLTSRC_HXTAL RCU_PLLTCFG_PLLTSEL /*!< HXTAL selected as source clock of PLLT */
-#ifdef __cplusplus
- extern "C" {
-#endif
-
/* function declarations */
/* initialization, peripheral clock enable/disable functions */
/* deinitialize the RCU */
@@ -1018,7 +1002,7 @@ void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div);
void rcu_ckout1_config(uint32_t ckout1_src, uint32_t ckout1_div);
/* configure the PLL clock source selection and PLL multiply factor */
-void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul);
+void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul);
/* configure the PREDV0 division factor and clock source */
void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div);
@@ -1048,19 +1032,6 @@ ErrStatus rcu_pllt_vco_config(uint32_t pllt_psc, uint32_t pllt_mul, uint32_t ppl
/* configure the TLI prescaler factor */
void rcu_tli_clock_config(uint32_t tli_psc);
-/* get the clock stabilization and periphral reset flags */
-FlagStatus rcu_flag_get(rcu_flag_enum flag);
-/* clear the reset flag */
-void rcu_all_reset_flag_clear(void);
-/* get the clock stabilization interrupt and ckm flags */
-FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
-/* clear the interrupt flags */
-void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear);
-/* enable the stabilization interrupt */
-void rcu_interrupt_enable(rcu_int_enum stab_int);
-/* disable the stabilization interrupt */
-void rcu_interrupt_disable(rcu_int_enum stab_int);
-
/* configure the LXTAL drive capability */
void rcu_lxtal_drive_capability_config(uint32_t lxtal_dricap);
/* wait for oscillator stabilization flags is SET or oscillator startup is timeout */
@@ -1077,17 +1048,24 @@ void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci);
void rcu_hxtal_clock_monitor_enable(void);
/* disable the HXTAL clock monitor */
void rcu_hxtal_clock_monitor_disable(void);
-
/* set the IRC8M adjust value */
void rcu_irc8m_adjust_value_set(uint8_t irc8m_adjval);
-
/* set the deep sleep mode voltage */
void rcu_deepsleep_voltage_set(uint32_t dsvol);
-
/* get the system clock, bus and peripheral clock frequency */
uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock);
-#ifdef __cplusplus
-}
-#endif
+/* get the clock stabilization and peripheral reset flags */
+FlagStatus rcu_flag_get(rcu_flag_enum flag);
+/* clear the reset flag */
+void rcu_all_reset_flag_clear(void);
+/* enable the stabilization interrupt */
+void rcu_interrupt_enable(rcu_int_enum stab_int);
+/* disable the stabilization interrupt */
+void rcu_interrupt_disable(rcu_int_enum stab_int);
+/* get the clock stabilization interrupt and ckm flags */
+FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
+/* clear the interrupt flags */
+void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear);
+
#endif /* GD32F20X_RCU_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rtc.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rtc.h
index 3f7bab1..6d45c3d 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rtc.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_rtc.h
@@ -2,36 +2,33 @@
\file gd32f20x_rtc.h
\brief definitions for the RTC
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,19 +38,19 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* RTC definitions */
-#define RTC RTC_BASE
+#define RTC RTC_BASE /*!< RTC base address */
/* registers definitions */
-#define RTC_INTEN REG32(RTC + 0x00U) /*!< interrupt enable register */
-#define RTC_CTL REG32(RTC + 0x04U) /*!< control register */
-#define RTC_PSCH REG32(RTC + 0x08U) /*!< prescaler high register */
-#define RTC_PSCL REG32(RTC + 0x0CU) /*!< prescaler low register */
-#define RTC_DIVH REG32(RTC + 0x10U) /*!< divider high register */
-#define RTC_DIVL REG32(RTC + 0x14U) /*!< divider low register */
-#define RTC_CNTH REG32(RTC + 0x18U) /*!< counter high register */
-#define RTC_CNTL REG32(RTC + 0x1CU) /*!< counter low register */
-#define RTC_ALRMH REG32(RTC + 0x20U) /*!< alarm high register */
-#define RTC_ALRML REG32(RTC + 0x24U) /*!< alarm low register */
+#define RTC_INTEN REG32(RTC + 0x00000000U) /*!< interrupt enable register */
+#define RTC_CTL REG32(RTC + 0x00000004U) /*!< control register */
+#define RTC_PSCH REG32(RTC + 0x00000008U) /*!< prescaler high register */
+#define RTC_PSCL REG32(RTC + 0x0000000CU) /*!< prescaler low register */
+#define RTC_DIVH REG32(RTC + 0x00000010U) /*!< divider high register */
+#define RTC_DIVL REG32(RTC + 0x00000014U) /*!< divider low register */
+#define RTC_CNTH REG32(RTC + 0x00000018U) /*!< counter high register */
+#define RTC_CNTL REG32(RTC + 0x0000001CU) /*!< counter low register */
+#define RTC_ALRMH REG32(RTC + 0x00000020U) /*!< alarm high register */
+#define RTC_ALRML REG32(RTC + 0x00000024U) /*!< alarm low register */
/* bits definitions */
/* RTC_INTEN */
@@ -69,28 +66,20 @@ OF SUCH DAMAGE.
#define RTC_CTL_CMF BIT(4) /*!< configuration mode flag */
#define RTC_CTL_LWOFF BIT(5) /*!< last write operation finished flag */
-/* RTC_PSCH */
+/* RTC_PSC */
#define RTC_PSCH_PSC BITS(0,3) /*!< prescaler high value */
-
-/* RTC_PSCL */
#define RTC_PSCL_PSC BITS(0,15) /*!< prescaler low value */
-/* RTC_DIVH */
+/* RTC_DIV */
#define RTC_DIVH_DIV BITS(0,3) /*!< divider high value */
-
-/* RTC_DIVL */
#define RTC_DIVL_DIV BITS(0,15) /*!< divider low value */
-/* RTC_CNTH */
+/* RTC_CNT */
#define RTC_CNTH_CNT BITS(0,15) /*!< counter high value */
-
-/* RTC_CNTL */
#define RTC_CNTL_CNT BITS(0,15) /*!< counter low value */
-/* RTC_ALRMH */
+/* RTC_ALRM */
#define RTC_ALRMH_ALRM BITS(0,15) /*!< alarm high value */
-
-/* RTC_ALRML */
#define RTC_ALRML_ALRM BITS(0,15) /*!< alarm low value */
/* constants definitions */
@@ -99,11 +88,6 @@ OF SUCH DAMAGE.
#define RTC_INT_ALARM RTC_INTEN_ALRMIE /*!< alarm interrupt enable */
#define RTC_INT_OVERFLOW RTC_INTEN_OVIE /*!< overflow interrupt enable */
-/* RTC interrupt flag definitions */
-#define RTC_INT_FLAG_SECOND RTC_CTL_SCIF /*!< second interrupt flag */
-#define RTC_INT_FLAG_ALARM RTC_CTL_ALRMIF /*!< alarm interrupt flag */
-#define RTC_INT_FLAG_OVERFLOW RTC_CTL_OVIF /*!< overflow interrupt flag */
-
/* RTC flag definitions */
#define RTC_FLAG_SECOND RTC_CTL_SCIF /*!< second interrupt flag */
#define RTC_FLAG_ALARM RTC_CTL_ALRMIF /*!< alarm interrupt flag */
@@ -112,40 +96,36 @@ OF SUCH DAMAGE.
#define RTC_FLAG_LWOF RTC_CTL_LWOFF /*!< last write operation finished flag */
/* function declarations */
-/* initialization functions */
/* enter RTC configuration mode */
void rtc_configuration_mode_enter(void);
/* exit RTC configuration mode */
void rtc_configuration_mode_exit(void);
-/* set RTC counter value */
-void rtc_counter_set(uint32_t cnt);
-/* set RTC prescaler value */
-void rtc_prescaler_set(uint32_t psc);
/* operation functions */
/* wait RTC last write operation finished flag set */
void rtc_lwoff_wait(void);
/* wait RTC registers synchronized flag set */
void rtc_register_sync_wait(void);
-/* set RTC alarm value */
-void rtc_alarm_config(uint32_t alarm);
+
/* get RTC counter value */
uint32_t rtc_counter_get(void);
+/* set RTC counter value */
+void rtc_counter_set(uint32_t cnt);
+/* set RTC prescaler value */
+void rtc_prescaler_set(uint32_t psc);
+/* set RTC alarm value */
+void rtc_alarm_config(uint32_t alarm);
/* get RTC divider value */
uint32_t rtc_divider_get(void);
+/* enable RTC interrupt */
+void rtc_interrupt_enable(uint32_t interrupt);
+/* disable RTC interrupt */
+void rtc_interrupt_disable(uint32_t interrupt);
/* flag & interrupt functions */
/* get RTC flag status */
FlagStatus rtc_flag_get(uint32_t flag);
/* clear RTC flag status */
void rtc_flag_clear(uint32_t flag);
-/* get RTC interrupt flag status */
-FlagStatus rtc_interrupt_flag_get(uint32_t flag);
-/* clear RTC interrupt flag status */
-void rtc_interrupt_flag_clear(uint32_t flag);
-/* enable RTC interrupt */
-void rtc_interrupt_enable(uint32_t interrupt);
-/* disable RTC interrupt */
-void rtc_interrupt_disable(uint32_t interrupt);
#endif /* GD32F20X_RTC_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_sdio.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_sdio.h
index d33510b..6e85d25 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_sdio.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_sdio.h
@@ -2,36 +2,33 @@
\file gd32f20x_sdio.h
\brief definitions for the SDIO
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_spi.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_spi.h
index bf27bfe..80d03c7 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_spi.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_spi.h
@@ -2,36 +2,33 @@
\file gd32f20x_spi.h
\brief definitions for the SPI
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -45,17 +42,17 @@ OF SUCH DAMAGE.
#define SPI1 SPI_BASE
#define SPI2 (SPI_BASE + 0x00000400U)
-/* SPI registers definitions */
-#define SPI_CTL0(spix) REG32((spix) + 0x00U) /*!< SPI control register 0 */
-#define SPI_CTL1(spix) REG32((spix) + 0x04U) /*!< SPI control register 1*/
-#define SPI_STAT(spix) REG32((spix) + 0x08U) /*!< SPI status register */
-#define SPI_DATA(spix) REG32((spix) + 0x0CU) /*!< SPI data register */
-#define SPI_CRCPOLY(spix) REG32((spix) + 0x10U) /*!< SPI CRC polynomial register */
-#define SPI_RCRC(spix) REG32((spix) + 0x14U) /*!< SPI receive CRC register */
-#define SPI_TCRC(spix) REG32((spix) + 0x18U) /*!< SPI transmit CRC register */
-#define SPI_I2SCTL(spix) REG32((spix) + 0x1CU) /*!< SPI I2S control register */
-#define SPI_I2SPSC(spix) REG32((spix) + 0x20U) /*!< SPI I2S clock prescaler register */
-#define SPI_QCTL(spix) REG32((spix) + 0x80U) /*!< SPI quad mode control register(only SPI0) */
+/* registers definitions */
+#define SPI_CTL0(spix) REG32((spix) + 0x00000000U) /*!< SPI control register 0 */
+#define SPI_CTL1(spix) REG32((spix) + 0x00000004U) /*!< SPI control register 1*/
+#define SPI_STAT(spix) REG32((spix) + 0x00000008U) /*!< SPI status register */
+#define SPI_DATA(spix) REG32((spix) + 0x0000000CU) /*!< SPI data register */
+#define SPI_CRCPOLY(spix) REG32((spix) + 0x00000010U) /*!< SPI CRC polynomial register */
+#define SPI_RCRC(spix) REG32((spix) + 0x00000014U) /*!< SPI receive CRC register */
+#define SPI_TCRC(spix) REG32((spix) + 0x00000018U) /*!< SPI transmit CRC register */
+#define SPI_I2SCTL(spix) REG32((spix) + 0x0000001CU) /*!< SPI I2S control register */
+#define SPI_I2SPSC(spix) REG32((spix) + 0x00000020U) /*!< SPI I2S clock prescaler register */
+#define SPI_QCTL(spix) REG32((spix) + 0x00000080U) /*!< SPI quad mode control register(only available in SPI0) */
/* bits definitions */
/* SPI_CTL0 */
@@ -75,8 +72,8 @@ OF SUCH DAMAGE.
#define SPI_CTL0_BDEN BIT(15) /*!< bidirectional enable */
/* SPI_CTL1 */
-#define SPI_CTL1_DMAREN BIT(0) /*!< receive buffer dma enable */
-#define SPI_CTL1_DMATEN BIT(1) /*!< transmit buffer dma enable */
+#define SPI_CTL1_DMAREN BIT(0) /*!< receive buffer DMA enable */
+#define SPI_CTL1_DMATEN BIT(1) /*!< transmit buffer DMA enable */
#define SPI_CTL1_NSSDRV BIT(2) /*!< drive NSS output */
#define SPI_CTL1_ERRIE BIT(5) /*!< errors interrupt enable */
#define SPI_CTL1_RBNEIE BIT(6) /*!< receive buffer not empty interrupt enable */
@@ -119,15 +116,14 @@ OF SUCH DAMAGE.
#define SPI_I2SPSC_OF BIT(8) /*!< odd factor for the prescaler */
#define SPI_I2SPSC_MCKOEN BIT(9) /*!< I2S MCK output enable */
-/* SPI_QCTL(only for SPI0) */
+/* SPI_QCTL(only available in SPI0) */
#define SPI_QCTL_QMOD BIT(0) /*!< quad-SPI mode enable */
#define SPI_QCTL_QRD BIT(1) /*!< quad-SPI mode read select */
#define SPI_QCTL_IO23_DRV BIT(2) /*!< drive SPI_IO2 and SPI_IO3 enable */
/* constants definitions */
/* SPI and I2S parameter struct definitions */
-typedef struct
-{
+typedef struct {
uint32_t device_mode; /*!< SPI master or slave */
uint32_t trans_mode; /*!< SPI transfer type */
uint32_t frame_size; /*!< SPI frame size */
@@ -135,7 +131,7 @@ typedef struct
uint32_t endian; /*!< SPI big endian or little endian */
uint32_t clock_polarity_phase; /*!< SPI clock phase and polarity */
uint32_t prescale; /*!< SPI prescaler factor */
-}spi_parameter_struct;
+} spi_parameter_struct;
/* SPI mode definitions */
#define SPI_MASTER (SPI_CTL0_MSTMOD | SPI_CTL0_SWNSS) /*!< SPI as master */
@@ -143,7 +139,7 @@ typedef struct
/* SPI bidirectional transfer direction */
#define SPI_BIDIRECTIONAL_TRANSMIT SPI_CTL0_BDOEN /*!< SPI work in transmit-only mode */
-#define SPI_BIDIRECTIONAL_RECEIVE ~SPI_CTL0_BDOEN /*!< SPI work in receive-only mode */
+#define SPI_BIDIRECTIONAL_RECEIVE (~SPI_CTL0_BDOEN) /*!< SPI work in receive-only mode */
/* SPI transmit type */
#define SPI_TRANSMODE_FULLDUPLEX ((uint32_t)0x00000000U) /*!< SPI receive and send data at fullduplex communication */
@@ -169,16 +165,16 @@ typedef struct
#define SPI_CK_PL_LOW_PH_2EDGE SPI_CTL0_CKPH /*!< SPI clock polarity is low level and phase is second edge */
#define SPI_CK_PL_HIGH_PH_2EDGE (SPI_CTL0_CKPL | SPI_CTL0_CKPH) /*!< SPI clock polarity is high level and phase is second edge */
-/* SPI clock prescale factor */
+/* SPI clock prescaler factor */
#define CTL0_PSC(regval) (BITS(3,5) & ((uint32_t)(regval) << 3))
-#define SPI_PSC_2 CTL0_PSC(0) /*!< SPI clock prescale factor is 2 */
-#define SPI_PSC_4 CTL0_PSC(1) /*!< SPI clock prescale factor is 4 */
-#define SPI_PSC_8 CTL0_PSC(2) /*!< SPI clock prescale factor is 8 */
-#define SPI_PSC_16 CTL0_PSC(3) /*!< SPI clock prescale factor is 16 */
-#define SPI_PSC_32 CTL0_PSC(4) /*!< SPI clock prescale factor is 32 */
-#define SPI_PSC_64 CTL0_PSC(5) /*!< SPI clock prescale factor is 64 */
-#define SPI_PSC_128 CTL0_PSC(6) /*!< SPI clock prescale factor is 128 */
-#define SPI_PSC_256 CTL0_PSC(7) /*!< SPI clock prescale factor is 256 */
+#define SPI_PSC_2 CTL0_PSC(0) /*!< SPI clock prescaler factor is 2 */
+#define SPI_PSC_4 CTL0_PSC(1) /*!< SPI clock prescaler factor is 4 */
+#define SPI_PSC_8 CTL0_PSC(2) /*!< SPI clock prescaler factor is 8 */
+#define SPI_PSC_16 CTL0_PSC(3) /*!< SPI clock prescaler factor is 16 */
+#define SPI_PSC_32 CTL0_PSC(4) /*!< SPI clock prescaler factor is 32 */
+#define SPI_PSC_64 CTL0_PSC(5) /*!< SPI clock prescaler factor is 64 */
+#define SPI_PSC_128 CTL0_PSC(6) /*!< SPI clock prescaler factor is 128 */
+#define SPI_PSC_256 CTL0_PSC(7) /*!< SPI clock prescaler factor is 256 */
/* I2S audio sample rate */
#define I2S_AUDIOSAMPLE_8K ((uint32_t)8000U) /*!< I2S audio sample rate is 8KHz */
@@ -221,7 +217,7 @@ typedef struct
#define I2S_CKPL_LOW ((uint32_t)0x00000000U) /*!< I2S clock polarity low level */
#define I2S_CKPL_HIGH SPI_I2SCTL_CKPL /*!< I2S clock polarity high level */
-/* SPI DMA constants definitions */
+/* SPI DMA constants definitions */
#define SPI_DMA_TRANSMIT ((uint8_t)0x00U) /*!< SPI transmit data use DMA */
#define SPI_DMA_RECEIVE ((uint8_t)0x01U) /*!< SPI receive data use DMA */
@@ -230,9 +226,9 @@ typedef struct
#define SPI_CRC_RX ((uint8_t)0x01U) /*!< SPI receive CRC value */
/* SPI/I2S interrupt enable/disable constants definitions */
-#define SPI_I2S_INT_TBE ((uint8_t)0x00U) /*!< transmit buffer empty interrupt */
-#define SPI_I2S_INT_RBNE ((uint8_t)0x01U) /*!< receive buffer not empty interrupt */
-#define SPI_I2S_INT_ERR ((uint8_t)0x02U) /*!< error interrupt */
+#define SPI_I2S_INT_TBE SPI_CTL1_TBEIE /*!< transmit buffer empty interrupt */
+#define SPI_I2S_INT_RBNE SPI_CTL1_RBNEIE /*!< receive buffer not empty interrupt */
+#define SPI_I2S_INT_ERR SPI_CTL1_ERRIE /*!< error interrupt */
/* SPI/I2S interrupt flag constants definitions */
#define SPI_I2S_INT_FLAG_TBE ((uint8_t)0x00U) /*!< transmit buffer empty interrupt flag */
@@ -242,7 +238,7 @@ typedef struct
#define SPI_INT_FLAG_CRCERR ((uint8_t)0x04U) /*!< CRC error interrupt flag */
#define I2S_INT_FLAG_TXURERR ((uint8_t)0x05U) /*!< underrun error interrupt flag */
-/* SPI/I2S flag definitions */
+/* SPI/I2S flag definitions */
#define SPI_FLAG_RBNE SPI_STAT_RBNE /*!< receive buffer not empty flag */
#define SPI_FLAG_TBE SPI_STAT_TBE /*!< transmit buffer empty flag */
#define SPI_FLAG_CRCERR SPI_STAT_CRCERR /*!< CRC error flag */
@@ -257,18 +253,19 @@ typedef struct
#define I2S_FLAG_TRANS SPI_STAT_TRANS /*!< transmit on-going flag */
/* function declarations */
-/* SPI/I2S deinitialization and initialization functions */
+/* SPI deinitialization and initialization functions */
/* reset SPI and I2S */
void spi_i2s_deinit(uint32_t spi_periph);
/* initialize the parameters of SPI structure with the default values */
-void spi_struct_para_init(spi_parameter_struct* spi_struct);
-/* initialize SPI parameter */
-void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct);
+void spi_struct_para_init(spi_parameter_struct *spi_struct);
+/* initialize SPI parameters */
+void spi_init(uint32_t spi_periph, spi_parameter_struct *spi_struct);
/* enable SPI */
void spi_enable(uint32_t spi_periph);
/* disable SPI */
void spi_disable(uint32_t spi_periph);
+/* I2S initialization functions */
/* initialize I2S parameter */
void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ckpl);
/* configure I2S prescaler */
@@ -288,21 +285,21 @@ void spi_nss_internal_high(uint32_t spi_periph);
/* SPI NSS pin low level in software mode */
void spi_nss_internal_low(uint32_t spi_periph);
-/* DMA communication */
+/* DMA functions */
/* enable SPI DMA */
void spi_dma_enable(uint32_t spi_periph, uint8_t dma);
/* disable SPI DMA */
void spi_dma_disable(uint32_t spi_periph, uint8_t dma);
-/* normal mode communication */
-/* configure SPI/I2S data frame format */
+/* communication functions */
+/* configure SPI data frame format */
void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format);
+/* configure SPI bidirectional transfer direction */
+void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction);
/* SPI transmit data */
void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data);
/* SPI receive data */
uint16_t spi_i2s_data_receive(uint32_t spi_periph);
-/* configure SPI bidirectional transfer direction */
-void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction);
/* SPI CRC functions */
/* set SPI CRC polynomial */
@@ -317,30 +314,31 @@ void spi_crc_off(uint32_t spi_periph);
void spi_crc_next(uint32_t spi_periph);
/* get SPI CRC send value or receive value */
uint16_t spi_crc_get(uint32_t spi_periph, uint8_t crc);
+/* clear SPI CRC error flag status */
+void spi_crc_error_clear(uint32_t spi_periph);
+
+/* quad wire SPI functions */
+/* enable quad wire SPI */
+void spi_quad_enable(uint32_t spi_periph);
+/* disable quad wire SPI */
+void spi_quad_disable(uint32_t spi_periph);
+/* enable quad wire SPI write */
+void spi_quad_write_enable(uint32_t spi_periph);
+/* enable quad wire SPI read */
+void spi_quad_read_enable(uint32_t spi_periph);
+/* enable SPI_IO2 and SPI_IO3 pin output */
+void spi_quad_io23_output_enable(uint32_t spi_periph);
+/* disable SPI_IO2 and SPI_IO3 pin output */
+void spi_quad_io23_output_disable(uint32_t spi_periph);
/* flag and interrupt functions */
+/* get SPI and I2S flag status */
+FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag);
/* enable SPI and I2S interrupt */
void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt);
/* disable SPI and I2S interrupt */
void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt);
/* get SPI and I2S interrupt status */
FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt);
-/* get SPI and I2S flag status */
-FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag);
-/* clear SPI CRC error flag status */
-void spi_crc_error_clear(uint32_t spi_periph);
-
-/* enable quad wire SPI */
-void qspi_enable(uint32_t spi_periph);
-/* disable quad wire SPI */
-void qspi_disable(uint32_t spi_periph);
-/* enable quad wire SPI write */
-void qspi_write_enable(uint32_t spi_periph);
-/* enable quad wire SPI read */
-void qspi_read_enable(uint32_t spi_periph);
-/* enable quad wire SPI_IO2 and SPI_IO3 pin output */
-void qspi_io23_output_enable(uint32_t spi_periph);
-/* disable quad wire SPI_IO2 and SPI_IO3 pin output */
-void qspi_io23_output_disable(uint32_t spi_periph);
#endif /* GD32F20X_SPI_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_timer.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_timer.h
index d83f771..a04b85a 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_timer.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_timer.h
@@ -2,36 +2,33 @@
\file gd32f20x_timer.h
\brief definitions for the TIMER
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -74,7 +71,7 @@ OF SUCH DAMAGE.
#define TIMER_CH1CV(timerx) REG32((timerx) + 0x38U) /*!< TIMER channel 1 capture/compare value register */
#define TIMER_CH2CV(timerx) REG32((timerx) + 0x3CU) /*!< TIMER channel 2 capture/compare value register */
#define TIMER_CH3CV(timerx) REG32((timerx) + 0x40U) /*!< TIMER channel 3 capture/compare value register */
-#define TIMER_CCHP(timerx) REG32((timerx) + 0x44U) /*!< TIMER channel complementary protection register */
+#define TIMER_CCHP(timerx) REG32((timerx) + 0x44U) /*!< TIMER complementary channel protection register */
#define TIMER_DMACFG(timerx) REG32((timerx) + 0x48U) /*!< TIMER DMA configuration register */
#define TIMER_DMATB(timerx) REG32((timerx) + 0x4CU) /*!< TIMER DMA transfer buffer register */
@@ -111,7 +108,7 @@ OF SUCH DAMAGE.
#define TIMER_SMCFG_ETPSC BITS(12,13) /*!< external trigger prescaler */
#define TIMER_SMCFG_SMC1 BIT(14) /*!< part of SMC for enable external clock mode 1 */
#define TIMER_SMCFG_ETP BIT(15) /*!< external trigger polarity */
-
+
/* TIMER_DMAINTEN */
#define TIMER_DMAINTEN_UPIE BIT(0) /*!< update interrupt enable */
#define TIMER_DMAINTEN_CH0IE BIT(1) /*!< channel 0 capture/compare interrupt enable */
@@ -122,10 +119,10 @@ OF SUCH DAMAGE.
#define TIMER_DMAINTEN_TRGIE BIT(6) /*!< trigger interrupt enable */
#define TIMER_DMAINTEN_BRKIE BIT(7) /*!< break interrupt enable */
#define TIMER_DMAINTEN_UPDEN BIT(8) /*!< update DMA request enable */
-#define TIMER_DMAINTEN_CH0DEN BIT(9) /*!< channel 0 capture/compare DMA request enable */
-#define TIMER_DMAINTEN_CH1DEN BIT(10) /*!< channel 1 capture/compare DMA request enable */
-#define TIMER_DMAINTEN_CH2DEN BIT(11) /*!< channel 2 capture/compare DMA request enable */
-#define TIMER_DMAINTEN_CH3DEN BIT(12) /*!< channel 3 capture/compare DMA request enable */
+#define TIMER_DMAINTEN_CH0DEN BIT(9) /*!< channel 0 DMA request enable */
+#define TIMER_DMAINTEN_CH1DEN BIT(10) /*!< channel 1 DMA request enable */
+#define TIMER_DMAINTEN_CH2DEN BIT(11) /*!< channel 2 DMA request enable */
+#define TIMER_DMAINTEN_CH3DEN BIT(12) /*!< channel 3 DMA request enable */
#define TIMER_DMAINTEN_CMTDEN BIT(13) /*!< commutation DMA request enable */
#define TIMER_DMAINTEN_TRGDEN BIT(14) /*!< trigger DMA request enable */
@@ -248,19 +245,17 @@ OF SUCH DAMAGE.
/* constants definitions */
/* TIMER init parameter structure definitions */
-typedef struct
-{
+typedef struct {
uint16_t prescaler; /*!< prescaler value */
uint16_t alignedmode; /*!< aligned mode */
uint16_t counterdirection; /*!< counter direction */
uint32_t period; /*!< period value */
uint16_t clockdivision; /*!< clock division value */
uint8_t repetitioncounter; /*!< the counter repetition value */
-}timer_parameter_struct;
+} timer_parameter_struct;
/* break parameter structure definitions*/
-typedef struct
-{
+typedef struct {
uint16_t runoffstate; /*!< run mode off-state */
uint16_t ideloffstate; /*!< idle mode off-state */
uint16_t deadtime; /*!< dead time */
@@ -268,27 +263,25 @@ typedef struct
uint16_t outputautostate; /*!< output automatic enable */
uint16_t protectmode; /*!< complementary register protect control */
uint16_t breakstate; /*!< break enable */
-}timer_break_parameter_struct;
+} timer_break_parameter_struct;
/* channel output parameter structure definitions */
-typedef struct
-{
+typedef struct {
uint16_t outputstate; /*!< channel output state */
uint16_t outputnstate; /*!< channel complementary output state */
uint16_t ocpolarity; /*!< channel output polarity */
uint16_t ocnpolarity; /*!< channel complementary output polarity */
uint16_t ocidlestate; /*!< idle state of channel output */
uint16_t ocnidlestate; /*!< idle state of channel complementary output */
-}timer_oc_parameter_struct;
+} timer_oc_parameter_struct;
/* channel input parameter structure definitions */
-typedef struct
-{
+typedef struct {
uint16_t icpolarity; /*!< channel input polarity */
uint16_t icselection; /*!< channel input mode selection */
uint16_t icprescaler; /*!< channel input capture prescaler */
uint16_t icfilter; /*!< channel input capture filter control */
-}timer_ic_parameter_struct;
+} timer_ic_parameter_struct;
/* TIMER interrupt enable or disable */
#define TIMER_INT_UP TIMER_DMAINTEN_UPIE /*!< update interrupt */
@@ -296,20 +289,10 @@ typedef struct
#define TIMER_INT_CH1 TIMER_DMAINTEN_CH1IE /*!< channel 1 interrupt */
#define TIMER_INT_CH2 TIMER_DMAINTEN_CH2IE /*!< channel 2 interrupt */
#define TIMER_INT_CH3 TIMER_DMAINTEN_CH3IE /*!< channel 3 interrupt */
-#define TIMER_INT_CMT TIMER_DMAINTEN_CMTIE /*!< channel commutation interrupt flag */
+#define TIMER_INT_CMT TIMER_DMAINTEN_CMTIE /*!< channel commutation interrupt */
#define TIMER_INT_TRG TIMER_DMAINTEN_TRGIE /*!< trigger interrupt */
#define TIMER_INT_BRK TIMER_DMAINTEN_BRKIE /*!< break interrupt */
-/* TIMER interrupt flag */
-#define TIMER_INT_FLAG_UP TIMER_INT_UP /*!< update interrupt */
-#define TIMER_INT_FLAG_CH0 TIMER_INT_CH0 /*!< channel 0 interrupt */
-#define TIMER_INT_FLAG_CH1 TIMER_INT_CH1 /*!< channel 1 interrupt */
-#define TIMER_INT_FLAG_CH2 TIMER_INT_CH2 /*!< channel 2 interrupt */
-#define TIMER_INT_FLAG_CH3 TIMER_INT_CH3 /*!< channel 3 interrupt */
-#define TIMER_INT_FLAG_CMT TIMER_INT_CMT /*!< channel commutation interrupt flag */
-#define TIMER_INT_FLAG_TRG TIMER_INT_TRG /*!< trigger interrupt */
-#define TIMER_INT_FLAG_BRK TIMER_INT_BRK
-
/* TIMER flag */
#define TIMER_FLAG_UP TIMER_INTF_UPIF /*!< update flag */
#define TIMER_FLAG_CH0 TIMER_INTF_CH0IF /*!< channel 0 flag */
@@ -324,6 +307,16 @@ typedef struct
#define TIMER_FLAG_CH2O TIMER_INTF_CH2OF /*!< channel 2 overcapture flag */
#define TIMER_FLAG_CH3O TIMER_INTF_CH3OF /*!< channel 3 overcapture flag */
+/* TIMER interrupt flag */
+#define TIMER_INT_FLAG_UP TIMER_INTF_UPIF /*!< update interrupt flag */
+#define TIMER_INT_FLAG_CH0 TIMER_INTF_CH0IF /*!< channel 0 interrupt flag */
+#define TIMER_INT_FLAG_CH1 TIMER_INTF_CH1IF /*!< channel 1 interrupt flag */
+#define TIMER_INT_FLAG_CH2 TIMER_INTF_CH2IF /*!< channel 2 interrupt flag */
+#define TIMER_INT_FLAG_CH3 TIMER_INTF_CH3IF /*!< channel 3 interrupt flag */
+#define TIMER_INT_FLAG_CMT TIMER_INTF_CMTIF /*!< channel commutation interrupt flag */
+#define TIMER_INT_FLAG_TRG TIMER_INTF_TRGIF /*!< trigger interrupt flag */
+#define TIMER_INT_FLAG_BRK TIMER_INTF_BRKIF /*!< break interrupt */
+
/* TIMER DMA source enable */
#define TIMER_DMA_UPD ((uint16_t)TIMER_DMAINTEN_UPDEN) /*!< update DMA enable */
#define TIMER_DMA_CH0D ((uint16_t)TIMER_DMAINTEN_CH0DEN) /*!< channel 0 DMA enable */
@@ -333,12 +326,12 @@ typedef struct
#define TIMER_DMA_CMTD ((uint16_t)TIMER_DMAINTEN_CMTDEN) /*!< commutation DMA request enable */
#define TIMER_DMA_TRGD ((uint16_t)TIMER_DMAINTEN_TRGDEN) /*!< trigger DMA enable */
-/* channel DMA request source selection */
-#define TIMER_DMAREQUEST_UPDATEEVENT TIMER_CTL1_DMAS /*!< DMA request of channel n is sent when update event occurs */
-#define TIMER_DMAREQUEST_CHANNELEVENT ((uint32_t)0x00000000U) /*!< DMA request of channel n is sent when channel n event occurs */
+/* channel DMA request source selection */
+#define TIMER_DMAREQUEST_UPDATEEVENT ((uint32_t)0x00000000U) /*!< DMA request of channel y is sent when update event occurs */
+#define TIMER_DMAREQUEST_CHANNELEVENT ((uint32_t)0x00000001U) /*!< DMA request of channel y is sent when channel y event occurs */
/* DMA access base address */
-#define DMACFG_DMATA(regval) (BITS(0, 4) & ((uint32_t)(regval) << 0U))
+#define DMACFG_DMATA(regval) (BITS(0,4) & ((uint32_t)(regval) << 0U))
#define TIMER_DMACFG_DMATA_CTL0 DMACFG_DMATA(0) /*!< DMA transfer address is TIMER_CTL0 */
#define TIMER_DMACFG_DMATA_CTL1 DMACFG_DMATA(1) /*!< DMA transfer address is TIMER_CTL1 */
#define TIMER_DMACFG_DMATA_SMCFG DMACFG_DMATA(2) /*!< DMA transfer address is TIMER_SMCFG */
@@ -361,7 +354,7 @@ typedef struct
#define TIMER_DMACFG_DMATA_DMATB DMACFG_DMATA(19) /*!< DMA transfer address is TIMER_DMATB */
/* DMA access burst length */
-#define DMACFG_DMATC(regval) (BITS(8, 12) & ((uint32_t)(regval) << 8U))
+#define DMACFG_DMATC(regval) (BITS(8,12) & ((uint32_t)(regval) << 8U))
#define TIMER_DMACFG_DMATC_1TRANSFER DMACFG_DMATC(0) /*!< DMA transfer 1 time */
#define TIMER_DMACFG_DMATC_2TRANSFER DMACFG_DMATC(1) /*!< DMA transfer 2 times */
#define TIMER_DMACFG_DMATC_3TRANSFER DMACFG_DMATC(2) /*!< DMA transfer 3 times */
@@ -392,39 +385,39 @@ typedef struct
#define TIMER_EVENT_SRC_BRKG ((uint16_t)0x0080U) /*!< break event generation */
/* center-aligned mode selection */
-#define CTL0_CAM(regval) ((uint16_t)(BITS(5, 6) & ((uint32_t)(regval) << 5U)))
+#define CTL0_CAM(regval) ((uint16_t)(BITS(5,6) & ((uint32_t)(regval) << 5U)))
#define TIMER_COUNTER_EDGE CTL0_CAM(0) /*!< edge-aligned mode */
#define TIMER_COUNTER_CENTER_DOWN CTL0_CAM(1) /*!< center-aligned and counting down assert mode */
#define TIMER_COUNTER_CENTER_UP CTL0_CAM(2) /*!< center-aligned and counting up assert mode */
#define TIMER_COUNTER_CENTER_BOTH CTL0_CAM(3) /*!< center-aligned and counting up/down assert mode */
/* TIMER prescaler reload mode */
-#define TIMER_PSC_RELOAD_NOW TIMER_SWEVG_UPG /*!< the prescaler is loaded right now */
-#define TIMER_PSC_RELOAD_UPDATE ((uint32_t)0x00000000U) /*!< the prescaler is loaded at the next update event */
+#define TIMER_PSC_RELOAD_NOW ((uint32_t)0x00000000U) /*!< the prescaler is loaded right now */
+#define TIMER_PSC_RELOAD_UPDATE ((uint32_t)0x00000001U) /*!< the prescaler is loaded at the next update event */
/* count direction */
#define TIMER_COUNTER_UP ((uint16_t)0x0000U) /*!< counter up direction */
#define TIMER_COUNTER_DOWN ((uint16_t)TIMER_CTL0_DIR) /*!< counter down direction */
/* specify division ratio between TIMER clock and dead-time and sampling clock */
-#define CTL0_CKDIV(regval) ((uint16_t)(BITS(8, 9) & ((uint32_t)(regval) << 8U)))
+#define CTL0_CKDIV(regval) ((uint16_t)(BITS(8,9) & ((uint32_t)(regval) << 8U)))
#define TIMER_CKDIV_DIV1 CTL0_CKDIV(0) /*!< clock division value is 1,fDTS=fTIMER_CK */
#define TIMER_CKDIV_DIV2 CTL0_CKDIV(1) /*!< clock division value is 2,fDTS= fTIMER_CK/2 */
#define TIMER_CKDIV_DIV4 CTL0_CKDIV(2) /*!< clock division value is 4, fDTS= fTIMER_CK/4 */
/* single pulse mode */
-#define TIMER_SP_MODE_SINGLE TIMER_CTL0_SPM /*!< single pulse mode */
-#define TIMER_SP_MODE_REPETITIVE ((uint32_t)0x00000000U) /*!< repetitive pulse mode */
+#define TIMER_SP_MODE_SINGLE ((uint32_t)0x00000000U) /*!< single pulse mode */
+#define TIMER_SP_MODE_REPETITIVE ((uint32_t)0x00000001U) /*!< repetitive pulse mode */
/* update source */
-#define TIMER_UPDATE_SRC_REGULAR TIMER_CTL0_UPS /*!< update generate only by counter overflow/underflow */
-#define TIMER_UPDATE_SRC_GLOBAL ((uint32_t)0x00000000U) /*!< update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger */
+#define TIMER_UPDATE_SRC_REGULAR ((uint32_t)0x00000000U) /*!< update generate only by counter overflow/underflow */
+#define TIMER_UPDATE_SRC_GLOBAL ((uint32_t)0x00000001U) /*!< update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger */
/* run mode off-state configure */
#define TIMER_ROS_STATE_ENABLE ((uint16_t)TIMER_CCHP_ROS) /*!< when POEN bit is set, the channel output signals(CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
#define TIMER_ROS_STATE_DISABLE ((uint16_t)0x0000U) /*!< when POEN bit is set, the channel output signals(CHx_O/CHx_ON) are disabled */
-/* idle mode off-state configure */
+/* idle mode off-state configure */
#define TIMER_IOS_STATE_ENABLE ((uint16_t)TIMER_CCHP_IOS) /*!< when POEN bit is reset, he channel output signals(CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
#define TIMER_IOS_STATE_DISABLE ((uint16_t)0x0000U) /*!< when POEN bit is reset, the channel output signals(CHx_O/CHx_ON) are disabled */
@@ -437,7 +430,7 @@ typedef struct
#define TIMER_OUTAUTO_DISABLE ((uint16_t)0x0000U) /*!< output automatic disable */
/* complementary register protect control */
-#define CCHP_PROT(regval) ((uint16_t)(BITS(8, 9) & ((uint32_t)(regval) << 8U)))
+#define CCHP_PROT(regval) ((uint16_t)(BITS(8,9) & ((uint32_t)(regval) << 8U)))
#define TIMER_CCHP_PROT_OFF CCHP_PROT(0) /*!< protect disable */
#define TIMER_CCHP_PROT_0 CCHP_PROT(1) /*!< PROT mode 0 */
#define TIMER_CCHP_PROT_1 CCHP_PROT(2) /*!< PROT mode 1 */
@@ -469,19 +462,19 @@ typedef struct
#define TIMER_OCN_POLARITY_HIGH ((uint16_t)0x0000U) /*!< channel complementary output polarity is high */
#define TIMER_OCN_POLARITY_LOW ((uint16_t)0x0008U) /*!< channel complementary output polarity is low */
-/* idle state of channel output */
+/* idle state of channel output */
#define TIMER_OC_IDLE_STATE_HIGH ((uint16_t)0x0100) /*!< idle state of channel output is high */
#define TIMER_OC_IDLE_STATE_LOW ((uint16_t)0x0000) /*!< idle state of channel output is low */
-/* idle state of channel complementary output */
+/* idle state of channel complementary output */
#define TIMER_OCN_IDLE_STATE_HIGH ((uint16_t)0x0200U) /*!< idle state of channel complementary output is high */
#define TIMER_OCN_IDLE_STATE_LOW ((uint16_t)0x0000U) /*!< idle state of channel complementary output is low */
/* channel output compare mode */
-#define TIMER_OC_MODE_TIMING ((uint16_t)0x0000U) /*!< frozen mode */
-#define TIMER_OC_MODE_ACTIVE ((uint16_t)0x0010U) /*!< set the channel output */
-#define TIMER_OC_MODE_INACTIVE ((uint16_t)0x0020U) /*!< clear the channel output */
-#define TIMER_OC_MODE_TOGGLE ((uint16_t)0x0030U) /*!< toggle on match */
+#define TIMER_OC_MODE_TIMING ((uint16_t)0x0000U) /*!< timing mode */
+#define TIMER_OC_MODE_ACTIVE ((uint16_t)0x0010U) /*!< active mode */
+#define TIMER_OC_MODE_INACTIVE ((uint16_t)0x0020U) /*!< inactive mode */
+#define TIMER_OC_MODE_TOGGLE ((uint16_t)0x0030U) /*!< toggle mode */
#define TIMER_OC_MODE_LOW ((uint16_t)0x0040U) /*!< force low mode */
#define TIMER_OC_MODE_HIGH ((uint16_t)0x0050U) /*!< force high mode */
#define TIMER_OC_MODE_PWM0 ((uint16_t)0x0060U) /*!< PWM0 mode */
@@ -499,16 +492,16 @@ typedef struct
#define TIMER_OC_CLEAR_ENABLE ((uint16_t)0x0080U) /*!< channel output clear function enable */
#define TIMER_OC_CLEAR_DISABLE ((uint16_t)0x0000U) /*!< channel output clear function disable */
-/* channel control shadow register update control */
-#define TIMER_UPDATECTL_CCU ((uint32_t)0x00000000U) /*!< the shadow registers update by when CMTG bit is set */
-#define TIMER_UPDATECTL_CCUTRI TIMER_CTL1_CCUC /*!< the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs */
+/* channel control shadow register update control */
+#define TIMER_UPDATECTL_CCU ((uint32_t)0x00000000U) /*!< the shadow registers are updated when CMTG bit is set */
+#define TIMER_UPDATECTL_CCUTRI ((uint32_t)0x00000001U) /*!< the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs */
/* channel input capture polarity */
#define TIMER_IC_POLARITY_RISING ((uint16_t)0x0000U) /*!< input capture rising edge */
#define TIMER_IC_POLARITY_FALLING ((uint16_t)0x0002U) /*!< input capture falling edge */
#define TIMER_IC_POLARITY_BOTH_EDGE ((uint16_t)0x000AU) /*!< input capture both edge */
-/* timer input capture selection */
+/* TIMER input capture selection */
#define TIMER_IC_SELECTION_DIRECTTI ((uint16_t)0x0001U) /*!< channel y is configured as input and icy is mapped on CIy */
#define TIMER_IC_SELECTION_INDIRECTTI ((uint16_t)0x0002U) /*!< channel y is configured as input and icy is mapped on opposite input */
#define TIMER_IC_SELECTION_ITS ((uint16_t)0x0003U) /*!< channel y is configured as input and icy is mapped on ITS */
@@ -520,7 +513,7 @@ typedef struct
#define TIMER_IC_PSC_DIV8 ((uint16_t)0x000CU) /*!< divided by 8 */
/* trigger selection */
-#define SMCFG_TRGSEL(regval) (BITS(4, 6) & ((uint32_t)(regval) << 4U))
+#define SMCFG_TRGSEL(regval) (BITS(4,6) & ((uint32_t)(regval) << 4U))
#define TIMER_SMCFG_TRGSEL_ITI0 SMCFG_TRGSEL(0) /*!< internal trigger 0 */
#define TIMER_SMCFG_TRGSEL_ITI1 SMCFG_TRGSEL(1) /*!< internal trigger 1 */
#define TIMER_SMCFG_TRGSEL_ITI2 SMCFG_TRGSEL(2) /*!< internal trigger 2 */
@@ -528,10 +521,10 @@ typedef struct
#define TIMER_SMCFG_TRGSEL_CI0F_ED SMCFG_TRGSEL(4) /*!< TI0 Edge Detector */
#define TIMER_SMCFG_TRGSEL_CI0FE0 SMCFG_TRGSEL(5) /*!< filtered TIMER input 0 */
#define TIMER_SMCFG_TRGSEL_CI1FE1 SMCFG_TRGSEL(6) /*!< filtered TIMER input 1 */
-#define TIMER_SMCFG_TRGSEL_ETIFP SMCFG_TRGSEL(7) /*!< external trigger */
+#define TIMER_SMCFG_TRGSEL_ETIFP SMCFG_TRGSEL(7) /*!< filtered external trigger input */
/* master mode control */
-#define CTL1_MMC(regval) (BITS(4, 6) & ((uint32_t)(regval) << 4U))
+#define CTL1_MMC(regval) (BITS(4,6) & ((uint32_t)(regval) << 4U))
#define TIMER_TRI_OUT_SRC_RESET CTL1_MMC(0) /*!< the UPG bit as trigger output */
#define TIMER_TRI_OUT_SRC_ENABLE CTL1_MMC(1) /*!< the counter enable signal TIMER_CTL0_CEN as trigger output */
#define TIMER_TRI_OUT_SRC_UPDATE CTL1_MMC(2) /*!< update event as trigger output */
@@ -542,22 +535,22 @@ typedef struct
#define TIMER_TRI_OUT_SRC_O3CPRE CTL1_MMC(7) /*!< O3CPRE as trigger output */
/* slave mode control */
-#define SMCFG_SMC(regval) (BITS(0, 2) & ((uint32_t)(regval) << 0U))
+#define SMCFG_SMC(regval) (BITS(0,2) & ((uint32_t)(regval) << 0U))
#define TIMER_SLAVE_MODE_DISABLE SMCFG_SMC(0) /*!< slave mode disable */
-#define TIMER_ENCODER_MODE0 SMCFG_SMC(1) /*!< encoder mode 0 */
-#define TIMER_ENCODER_MODE1 SMCFG_SMC(2) /*!< encoder mode 1 */
-#define TIMER_ENCODER_MODE2 SMCFG_SMC(3) /*!< encoder mode 2 */
+#define TIMER_QUAD_DECODER_MODE0 SMCFG_SMC(1) /*!< quadrature decoder mode 0 */
+#define TIMER_QUAD_DECODER_MODE1 SMCFG_SMC(2) /*!< quadrature decoder mode 1 */
+#define TIMER_QUAD_DECODER_MODE2 SMCFG_SMC(3) /*!< quadrature decoder mode 2 */
#define TIMER_SLAVE_MODE_RESTART SMCFG_SMC(4) /*!< restart mode */
#define TIMER_SLAVE_MODE_PAUSE SMCFG_SMC(5) /*!< pause mode */
#define TIMER_SLAVE_MODE_EVENT SMCFG_SMC(6) /*!< event mode */
#define TIMER_SLAVE_MODE_EXTERNAL0 SMCFG_SMC(7) /*!< external clock mode 0 */
-/* master slave mode selection */
-#define TIMER_MASTER_SLAVE_MODE_ENABLE TIMER_SMCFG_MSM /*!< master slave mode enable */
-#define TIMER_MASTER_SLAVE_MODE_DISABLE ((uint32_t)0x00000000U) /*!< master slave mode disable */
+/* master slave mode selection */
+#define TIMER_MASTER_SLAVE_MODE_ENABLE ((uint32_t)0x00000000U) /*!< master slave mode enable */
+#define TIMER_MASTER_SLAVE_MODE_DISABLE ((uint32_t)0x00000001U) /*!< master slave mode disable */
/* external trigger prescaler */
-#define SMCFG_ETPSC(regval) (BITS(12, 13) & ((uint32_t)(regval) << 12U))
+#define SMCFG_ETPSC(regval) (BITS(12,13) & ((uint32_t)(regval) << 12U))
#define TIMER_EXT_TRI_PSC_OFF SMCFG_ETPSC(0) /*!< no divided */
#define TIMER_EXT_TRI_PSC_DIV2 SMCFG_ETPSC(1) /*!< divided by 2 */
#define TIMER_EXT_TRI_PSC_DIV4 SMCFG_ETPSC(2) /*!< divided by 4 */
@@ -567,22 +560,18 @@ typedef struct
#define TIMER_ETP_FALLING TIMER_SMCFG_ETP /*!< active low or falling edge active */
#define TIMER_ETP_RISING ((uint32_t)0x00000000U) /*!< active high or rising edge active */
-/* channel 0 trigger input selection */
-#define TIMER_HALLINTERFACE_ENABLE TIMER_CTL1_TI0S /*!< TIMER hall sensor mode enable */
-#define TIMER_HALLINTERFACE_DISABLE ((uint32_t)0x00000000U) /*!< TIMER hall sensor mode disable */
-
-/* TIMERx(x=0..4,7..13) write CHxVAL register selection */
-#define TIMER_CHVSEL_ENABLE ((uint16_t)TIMER_CFG_OUTSEL) /*!< write CHxVAL register selection enable */
-#define TIMER_CHVSEL_DISABLE ((uint16_t)0x0000U) /*!< write CHxVAL register selection disable */
+/* channel 0 trigger input selection */
+#define TIMER_HALLINTERFACE_ENABLE ((uint32_t)0x00000000U) /*!< TIMER hall sensor mode enable */
+#define TIMER_HALLINTERFACE_DISABLE ((uint32_t)0x00000001U) /*!< TIMER hall sensor mode disable */
/* function declarations */
/* TIMER timebase */
/* deinit a TIMER */
void timer_deinit(uint32_t timer_periph);
/* initialize TIMER init parameter structure */
-void timer_struct_para_init(timer_parameter_struct* initpara);
+void timer_struct_para_init(timer_parameter_struct *initpara);
/* initialize TIMER counter */
-void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara);
+void timer_init(uint32_t timer_periph, timer_parameter_struct *initpara);
/* enable a TIMER */
void timer_enable(uint32_t timer_periph);
/* disable a TIMER */
@@ -604,7 +593,7 @@ void timer_counter_down_direction(uint32_t timer_periph);
/* configure TIMER prescaler */
void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t pscreload);
/* configure TIMER repetition register value */
-void timer_repetition_value_config(uint32_t timer_periph, uint8_t repetition);
+void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition);
/* configure TIMER autoreload register value */
void timer_autoreload_value_config(uint32_t timer_periph, uint32_t autoreload);
/* configure TIMER counter register value */
@@ -618,7 +607,7 @@ void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode);
/* configure TIMER update source */
void timer_update_source_config(uint32_t timer_periph, uint32_t update);
-/* timer DMA and event */
+/* TIMER DMA and event */
/* enable the TIMER DMA */
void timer_dma_enable(uint32_t timer_periph, uint16_t dma);
/* disable the TIMER DMA */
@@ -632,9 +621,9 @@ void timer_event_software_generate(uint32_t timer_periph, uint16_t event);
/* TIMER channel complementary protection */
/* initialize TIMER break parameter struct */
-void timer_break_struct_para_init(timer_break_parameter_struct* breakpara);
+void timer_break_struct_para_init(timer_break_parameter_struct *breakpara);
/* configure TIMER break function */
-void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara);
+void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct *breakpara);
/* enable TIMER break function */
void timer_break_enable(uint32_t timer_periph);
/* disable TIMER break function */
@@ -652,13 +641,13 @@ void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint32_t
/* TIMER channel output */
/* initialize TIMER channel output parameter struct */
-void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara);
+void timer_channel_output_struct_para_init(timer_oc_parameter_struct *ocpara);
/* configure TIMER channel output function */
-void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct* ocpara);
+void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct *ocpara);
/* configure TIMER channel output compare mode */
void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode);
/* configure TIMER channel output pulse value */
-void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint16_t pulse);
+void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse);
/* configure TIMER channel output shadow function */
void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow);
/* configure TIMER channel output fast function */
@@ -676,15 +665,15 @@ void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint
/* TIMER channel input */
/* initialize TIMER channel input parameter structure */
-void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara);
+void timer_channel_input_struct_para_init(timer_ic_parameter_struct *icpara);
/* configure TIMER input capture parameter */
-void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpara);
+void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpara);
/* configure TIMER channel input capture prescaler value */
void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler);
/* read TIMER channel capture compare register value */
uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel);
/* configure TIMER input pwm capture function */
-void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm);
+void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpwm);
/* configure TIMER hall sensor mode */
void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode);
@@ -698,7 +687,7 @@ void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode);
/* configure TIMER master slave mode */
void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave);
/* configure TIMER external trigger input */
-void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint8_t extfilter);
+void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter);
/* configure TIMER quadrature decoder mode */
void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity);
/* configure TIMER internal clock mode */
@@ -706,26 +695,26 @@ void timer_internal_clock_config(uint32_t timer_periph);
/* configure TIMER the internal trigger as external clock input */
void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger);
/* configure TIMER the external trigger as external clock input */
-void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint8_t extfilter);
+void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint32_t extfilter);
/* configure TIMER the external clock mode 0 */
-void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint8_t extfilter);
+void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter);
/* configure TIMER the external clock mode 1 */
-void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint8_t extfilter);
+void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter);
/* disable TIMER the external clock mode 1 */
void timer_external_clock_mode1_disable(uint32_t timer_periph);
/* TIMER interrupt and flag */
+/* get TIMER flags */
+FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag);
+/* clear TIMER flags */
+void timer_flag_clear(uint32_t timer_periph, uint32_t flag);
/* enable the TIMER interrupt */
void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt);
/* disable the TIMER interrupt */
void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt);
-/* get TIMER interrupt flag */
-FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt);
-/* clear TIMER interrupt flag */
-void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt);
-/* get TIMER flag */
-FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag);
-/* clear TIMER flag */
-void timer_flag_clear(uint32_t timer_periph, uint32_t flag);
+/* get TIMER interrupt flags */
+FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t int_flag);
+/* clear TIMER interrupt flags */
+void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t int_flag);
#endif /* GD32F20X_TIMER_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_tli.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_tli.h
index 55bfc90..00efc28 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_tli.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_tli.h
@@ -2,36 +2,33 @@
\file gd32f20x_tli.h
\brief definitions for the TLI
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -193,12 +190,11 @@ OF SUCH DAMAGE.
/* constants definitions */
/* TLI parameter structure definitions */
-typedef struct
-{
- uint32_t synpsz_vpsz; /*!< size of the vertical synchronous pulse */
- uint32_t synpsz_hpsz; /*!< size of the horizontal synchronous pulse */
- uint32_t backpsz_vbpsz; /*!< size of the vertical back porch plus synchronous pulse */
- uint32_t backpsz_hbpsz; /*!< size of the horizontal back porch plus synchronous pulse */
+typedef struct {
+ uint16_t synpsz_vpsz; /*!< size of the vertical synchronous pulse */
+ uint16_t synpsz_hpsz; /*!< size of the horizontal synchronous pulse */
+ uint16_t backpsz_vbpsz; /*!< size of the vertical back porch plus synchronous pulse */
+ uint16_t backpsz_hbpsz; /*!< size of the horizontal back porch plus synchronous pulse */
uint32_t activesz_vasz; /*!< size of the vertical active area width plus back porch and synchronous pulse */
uint32_t activesz_hasz; /*!< size of the horizontal active area width plus back porch and synchronous pulse */
uint32_t totalsz_vtsz; /*!< vertical total size of the display */
@@ -210,49 +206,46 @@ typedef struct
uint32_t signalpolarity_vs; /*!< vertical pulse polarity selection */
uint32_t signalpolarity_de; /*!< data enable polarity selection */
uint32_t signalpolarity_pixelck; /*!< pixel clock polarity selection */
-}tli_parameter_struct;
+} tli_parameter_struct;
/* TLI layer parameter structure definitions */
-typedef struct
-{
- uint32_t layer_window_rightpos; /*!< window right position */
- uint32_t layer_window_leftpos; /*!< window left position */
- uint32_t layer_window_bottompos; /*!< window bottom position */
- uint32_t layer_window_toppos; /*!< window top position */
+typedef struct {
+ uint16_t layer_window_rightpos; /*!< window right position */
+ uint16_t layer_window_leftpos; /*!< window left position */
+ uint16_t layer_window_bottompos; /*!< window bottom position */
+ uint16_t layer_window_toppos; /*!< window top position */
uint32_t layer_ppf; /*!< packeted pixel format */
- uint32_t layer_sa; /*!< specified alpha */
- uint32_t layer_default_alpha; /*!< the default color alpha */
- uint32_t layer_default_red; /*!< the default color red */
- uint32_t layer_default_green; /*!< the default color green */
- uint32_t layer_default_blue; /*!< the default color blue */
+ uint8_t layer_sa; /*!< specified alpha */
+ uint8_t layer_default_alpha; /*!< the default color alpha */
+ uint8_t layer_default_red; /*!< the default color red */
+ uint8_t layer_default_green; /*!< the default color green */
+ uint8_t layer_default_blue; /*!< the default color blue */
uint32_t layer_acf1; /*!< alpha calculation factor 1 of blending method */
uint32_t layer_acf2; /*!< alpha calculation factor 2 of blending method */
uint32_t layer_frame_bufaddr; /*!< frame buffer base address */
- uint32_t layer_frame_buf_stride_offset; /*!< frame buffer stride offset */
- uint32_t layer_frame_line_length; /*!< frame line length */
- uint32_t layer_frame_total_line_number; /*!< frame total line number */
-}tli_layer_parameter_struct;
+ uint16_t layer_frame_buf_stride_offset; /*!< frame buffer stride offset */
+ uint16_t layer_frame_line_length; /*!< frame line length */
+ uint16_t layer_frame_total_line_number; /*!< frame total line number */
+} tli_layer_parameter_struct;
/* TLI layer LUT parameter structure definitions */
-typedef struct
-{
+typedef struct {
uint32_t layer_table_addr; /*!< look up table write address */
- uint32_t layer_lut_channel_red; /*!< red channel of a LUT entry */
- uint32_t layer_lut_channel_green; /*!< green channel of a LUT entry */
- uint32_t layer_lut_channel_blue; /*!< blue channel of a LUT entry */
-}tli_layer_lut_parameter_struct;
+ uint8_t layer_lut_channel_red; /*!< red channel of a LUT entry */
+ uint8_t layer_lut_channel_green; /*!< green channel of a LUT entry */
+ uint8_t layer_lut_channel_blue; /*!< blue channel of a LUT entry */
+} tli_layer_lut_parameter_struct;
/* packeted pixel format */
-typedef enum
-{
- LAYER_PPF_ARGB8888, /*!< layerx packeted pixel format ARGB8888 */
- LAYER_PPF_RGB888, /*!< layerx packeted pixel format RGB888 */
- LAYER_PPF_RGB565, /*!< layerx packeted pixel format RGB565 */
- LAYER_PPF_ARGB1555, /*!< layerx packeted pixel format ARGB1555 */
- LAYER_PPF_ARGB4444, /*!< layerx packeted pixel format ARGB4444 */
- LAYER_PPF_L8, /*!< layerx packeted pixel format L8 */
- LAYER_PPF_AL44, /*!< layerx packeted pixel format AL44 */
- LAYER_PPF_AL88 /*!< layerx packeted pixel format AL88 */
+typedef enum {
+ LAYER_PPF_ARGB8888 = 0U, /*!< layerx packeted pixel format ARGB8888 */
+ LAYER_PPF_RGB888, /*!< layerx packeted pixel format RGB888 */
+ LAYER_PPF_RGB565, /*!< layerx packeted pixel format RGB565 */
+ LAYER_PPF_ARGB1555, /*!< layerx packeted pixel format ARGB1555 */
+ LAYER_PPF_ARGB4444, /*!< layerx packeted pixel format ARGB4444 */
+ LAYER_PPF_L8, /*!< layerx packeted pixel format L8 */
+ LAYER_PPF_AL44, /*!< layerx packeted pixel format AL44 */
+ LAYER_PPF_AL88 /*!< layerx packeted pixel format AL88 */
} tli_layer_ppf_enum;
/* TLI flags and states */
@@ -288,10 +281,12 @@ typedef enum
/* horizontal pulse polarity selection */
#define TLI_HSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< horizontal synchronous pulse active low */
#define TLI_HSYN_ACTLIVE_HIGHT TLI_CTL_HPPS /*!< horizontal synchronous pulse active high */
+#define TLI_HSYN_ACTLIVE_HIGH TLI_HSYN_ACTLIVE_HIGHT /*!< horizontal synchronous pulse active high */
/* vertical pulse polarity selection */
#define TLI_VSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< vertical synchronous pulse active low */
#define TLI_VSYN_ACTLIVE_HIGHT TLI_CTL_VPPS /*!< vertical synchronous pulse active high */
+#define TLI_VSYN_ACTLIVE_HIGH TLI_VSYN_ACTLIVE_HIGHT /*!< vertical synchronous pulse active high */
/* pixel clock polarity selection */
#define TLI_PIXEL_CLOCK_TLI ((uint32_t)0x00000000U) /*!< pixel clock is TLI clock */
@@ -300,69 +295,79 @@ typedef enum
/* data enable polarity selection */
#define TLI_DE_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< data enable active low */
#define TLI_DE_ACTLIVE_HIGHT TLI_CTL_DEPS /*!< data enable active high */
+#define TLI_DE_ACTLIVE_HIGH TLI_DE_ACTLIVE_HIGHT /*!< data enable active high */
/* alpha calculation factor 1 of blending method */
-#define LxBLEND_ACF1(regval) (BITS(8,10) & ((regval)<<8))
+#define LxBLEND_ACF1(regval) (BITS(8,10) & ((uint32_t)(regval)<<8))
#define LAYER_ACF1_SA LxBLEND_ACF1(4) /*!< normalization specified alpha */
#define LAYER_ACF1_PASA LxBLEND_ACF1(6) /*!< normalization pixel alpha * normalization specified alpha */
/* alpha calculation factor 2 of blending method */
-#define LxBLEND_ACF2(regval) (BITS(0,2) & ((regval)))
+#define LxBLEND_ACF2(regval) (BITS(0,2) & ((uint32_t)(regval)))
#define LAYER_ACF2_SA LxBLEND_ACF2(5) /*!< normalization specified alpha */
#define LAYER_ACF2_PASA LxBLEND_ACF2(7) /*!< normalization pixel alpha * normalization specified alpha */
/* function declarations */
/* initialization functions */
-/* deinitialize TLI */
+/* deinitialize TLI registers */
void tli_deinit(void);
-/* initialize TLI */
+/* initialize the parameters of TLI parameter structure with the default values, it is suggested
+ that call this function after a tli_parameter_struct structure is defined */
+void tli_struct_para_init(tli_parameter_struct *tli_struct);
+/* initialize TLI display timing parameters */
void tli_init(tli_parameter_struct *tli_struct);
/* configure TLI dither function */
-void tli_dither_config(uint8_t ditherstat);
+void tli_dither_config(uint8_t dither_stat);
/* enable TLI */
void tli_enable(void);
/* disable TLI */
void tli_disable(void);
/* configure TLI reload mode */
-void tli_reload_config(uint8_t reloadmode);
-
-/* set line mark value */
-void tli_line_mark_set(uint32_t linenum);
-/* get current displayed position */
-uint32_t tli_current_pos_get(void);
-
-/* function configuration */
-/* TLI layer enable */
+void tli_reload_config(uint8_t reload_mod);
+
+/* TLI layer configuration functions */
+/* initialize the parameters of TLI layer structure with the default values, it is suggested
+ that call this function after a tli_layer_parameter_struct structure is defined */
+void tli_layer_struct_para_init(tli_layer_parameter_struct *layer_struct);
+/* initialize TLI layer */
+void tli_layer_init(uint32_t layerx, tli_layer_parameter_struct *layer_struct);
+/* reconfigure window position */
+void tli_layer_window_offset_modify(uint32_t layerx, uint16_t offset_x, uint16_t offset_y);
+/* initialize the parameters of TLI layer LUT structure with the default values, it is suggested
+ that call this function after a tli_layer_lut_parameter_struct structure is defined */
+void tli_lut_struct_para_init(tli_layer_lut_parameter_struct *lut_struct);
+/* initialize TLI layer LUT */
+void tli_lut_init(uint32_t layerx, tli_layer_lut_parameter_struct *lut_struct);
+/* initialize TLI layer color key */
+void tli_color_key_init(uint32_t layerx, uint8_t redkey, uint8_t greenkey, uint8_t bluekey);
+/* enable TLI layer */
void tli_layer_enable(uint32_t layerx);
-/* TLI layer disable */
+/* disable TLI layer */
void tli_layer_disable(uint32_t layerx);
-/* TLI layer color keying enable */
+/* enable TLI layer color keying */
void tli_color_key_enable(uint32_t layerx);
-/* TLI layer color keying disable */
+/* disable TLI layer color keying */
void tli_color_key_disable(uint32_t layerx);
-/* TLI layer LUT enable */
+/* enable TLI layer LUT */
void tli_lut_enable(uint32_t layerx);
-/* TLI layer LUT disable */
+/* disable TLI layer LUT */
void tli_lut_disable(uint32_t layerx);
-/* TLI layer initialize */
-void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct);
-/* TLI layer initialize */
-void tli_layer_window_offset_modify(uint32_t layerx,uint32_t offset_x,uint32_t offset_y);
-/* TLI layer LUT initialize */
-void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct);
-/* TLI layer key initialize */
-void tli_ckey_init(uint32_t layerx,uint32_t redkey,uint32_t greenkey,uint32_t bluekey);
-
-/* interrupt & flag functions */
-/* get TLI flag or state */
-FlagStatus tli_flag_get(uint32_t flag);
+
+/* set line mark value */
+void tli_line_mark_set(uint16_t line_num);
+/* get current displayed position */
+uint32_t tli_current_pos_get(void);
+
+/* flag and interrupt functions */
/* enable TLI interrupt */
-void tli_interrupt_enable(uint32_t interrupt);
+void tli_interrupt_enable(uint32_t int_flag);
/* disable TLI interrupt */
-void tli_interrupt_disable(uint32_t interrupt);
+void tli_interrupt_disable(uint32_t int_flag);
/* get TLI interrupt flag */
FlagStatus tli_interrupt_flag_get(uint32_t int_flag);
/* clear TLI interrupt flag */
void tli_interrupt_flag_clear(uint32_t int_flag);
+/* get TLI flag or state in TLI_INTF register or TLI_STAT register */
+FlagStatus tli_flag_get(uint32_t flag);
#endif /* GD32F20X_TLI_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_trng.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_trng.h
index da2edeb..3db15e4 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_trng.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_trng.h
@@ -2,36 +2,33 @@
\file gd32f20x_trng.h
\brief definitions for the TRNG
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -41,17 +38,17 @@ OF SUCH DAMAGE.
#include "gd32f20x.h"
/* TRNG definitions */
-#define TRNG TRNG_BASE
+#define TRNG TRNG_BASE /*!< TRNG base address */
/* registers definitions */
-#define TRNG_CTL REG32(TRNG + 0x00U) /*!< control register */
-#define TRNG_STAT REG32(TRNG + 0x04U) /*!< status register */
-#define TRNG_DATA REG32(TRNG + 0x08U) /*!< data register */
+#define TRNG_CTL REG32(TRNG + 0x00000000U) /*!< control register */
+#define TRNG_STAT REG32(TRNG + 0x00000004U) /*!< status register */
+#define TRNG_DATA REG32(TRNG + 0x00000008U) /*!< data register */
/* bits definitions */
/* TRNG_CTL */
#define TRNG_CTL_TRNGEN BIT(2) /*!< TRNG enable bit */
-#define TRNG_CTL_IE BIT(3) /*!< interrupt enable bit */
+#define TRNG_CTL_TRNGIE BIT(3) /*!< interrupt enable bit */
/* TRNG_STAT */
#define TRNG_STAT_DRDY BIT(0) /*!< random data ready status bit */
@@ -60,46 +57,41 @@ OF SUCH DAMAGE.
#define TRNG_STAT_CEIF BIT(5) /*!< clock error interrupt flag */
#define TRNG_STAT_SEIF BIT(6) /*!< seed error interrupt flag */
-/* TRNG_DATA */
-#define TRNG_DATA_TRNDATA BITS(0,31) /*!< 32-Bit Random data */
-
/* constants definitions */
/* trng status flag */
-typedef enum
-{
+typedef enum {
TRNG_FLAG_DRDY = TRNG_STAT_DRDY, /*!< random Data ready status */
TRNG_FLAG_CECS = TRNG_STAT_CECS, /*!< clock error current status */
TRNG_FLAG_SECS = TRNG_STAT_SECS /*!< seed error current status */
-}trng_flag_enum;
+} trng_flag_enum;
/* trng inerrupt flag */
-typedef enum
-{
- TRNG_INT_FLAG_CE = TRNG_STAT_CEIF, /*!< clock error interrupt flag */
- TRNG_INT_FLAG_SE = TRNG_STAT_SEIF /*!< seed error interrupt flag */
-}trng_int_flag_enum;
+typedef enum {
+ TRNG_INT_FLAG_CE = TRNG_STAT_CEIF, /*!< clock error interrupt flag */
+ TRNG_INT_FLAG_SE = TRNG_STAT_SEIF /*!< seed error interrupt flag */
+} trng_int_flag_enum;
/* function declarations */
/* initialization functions */
-/* deinitialize the TRNG */
+/* reset TRNG */
void trng_deinit(void);
-/* enable the TRNG interface */
+/* enable TRNG */
void trng_enable(void);
-/* disable the TRNG interface */
+/* disable TRNG */
void trng_disable(void);
/* get the true random data */
uint32_t trng_get_true_random_data(void);
/* interrupt & flag functions */
-/* get the trng status flags */
+/* get TRNG status flags */
FlagStatus trng_flag_get(trng_flag_enum flag);
-/* the trng interrupt enable */
+/* enable TRNG interrupt */
void trng_interrupt_enable(void);
-/* the trng interrupt disable */
+/* disable TRNG interrupt */
void trng_interrupt_disable(void);
-/* get the trng interrupt flags */
+/* get TRNG interrupt flag status */
FlagStatus trng_interrupt_flag_get(trng_int_flag_enum int_flag);
-/* clear the trng interrupt flags */
+/* clear TRNG interrupt flag status */
void trng_interrupt_flag_clear(trng_int_flag_enum int_flag);
#endif /* GD32F20X_TRNG_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_usart.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_usart.h
index 01c43fc..114eb53 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_usart.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_usart.h
@@ -2,36 +2,33 @@
\file gd32f20x_usart.h
\brief definitions for the USART
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,108 +39,108 @@ OF SUCH DAMAGE.
/* USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7) definitions */
#define USART1 USART_BASE /*!< USART1 base address */
-#define USART2 (USART_BASE+0x00000400U) /*!< USART2 base address */
-#define UART3 (USART_BASE+0x00000800U) /*!< UART3 base address */
-#define UART4 (USART_BASE+0x00000C00U) /*!< UART4 base address */
-#define UART6 (USART_BASE+0x00003400U) /*!< UART6 base address */
-#define UART7 (USART_BASE+0x00003800U) /*!< UART7 base address */
-#define USART0 (USART_BASE+0x0000F400U) /*!< USART0 base address */
-#define USART5 (USART_BASE+0x00012C00U) /*!< USART5 base address */
+#define USART2 (USART_BASE + 0x00000400U) /*!< USART2 base address */
+#define UART3 (USART_BASE + 0x00000800U) /*!< UART3 base address */
+#define UART4 (USART_BASE + 0x00000C00U) /*!< UART4 base address */
+#define UART6 (USART_BASE + 0x00003400U) /*!< UART6 base address */
+#define UART7 (USART_BASE + 0x00003800U) /*!< UART7 base address */
+#define USART0 (USART_BASE + 0x0000F400U) /*!< USART0 base address */
+#define USART5 (USART_BASE + 0x00012C00U) /*!< USART5 base address */
/* registers definitions */
-#define USART_STAT0(usartx) REG32((usartx) + 0x00U) /*!< USART status register 0 */
-#define USART_DATA(usartx) REG32((usartx) + 0x04U) /*!< USART data register */
-#define USART_BAUD(usartx) REG32((usartx) + 0x08U) /*!< USART baud rate register */
-#define USART_CTL0(usartx) REG32((usartx) + 0x0CU) /*!< USART control register 0 */
-#define USART_CTL1(usartx) REG32((usartx) + 0x10U) /*!< USART control register 1 */
-#define USART_CTL2(usartx) REG32((usartx) + 0x14U) /*!< USART control register 2 */
-#define USART_GP(usartx) REG32((usartx) + 0x18U) /*!< USART guard time and prescaler register */
-#define USART_CTL3(usartx) REG32((usartx) + 0x80U) /*!< USART control register 3 */
-#define USART_RT(usartx) REG32((usartx) + 0x84U) /*!< USART receiver timeout register */
-#define USART_STAT1(usartx) REG32((usartx) + 0x88U) /*!< USART status register 1 */
+#define USART_STAT0(usartx) REG32((usartx) + 0x00000000U) /*!< USART status register 0 */
+#define USART_DATA(usartx) REG32((usartx) + 0x00000004U) /*!< USART data register */
+#define USART_BAUD(usartx) REG32((usartx) + 0x00000008U) /*!< USART baud rate register */
+#define USART_CTL0(usartx) REG32((usartx) + 0x0000000CU) /*!< USART control register 0 */
+#define USART_CTL1(usartx) REG32((usartx) + 0x00000010U) /*!< USART control register 1 */
+#define USART_CTL2(usartx) REG32((usartx) + 0x00000014U) /*!< USART control register 2 */
+#define USART_GP(usartx) REG32((usartx) + 0x00000018U) /*!< USART guard time and prescaler register */
+#define USART_CTL3(usartx) REG32((usartx) + 0x00000080U) /*!< USART control register 3 */
+#define USART_RT(usartx) REG32((usartx) + 0x00000084U) /*!< USART receiver timeout register */
+#define USART_STAT1(usartx) REG32((usartx) + 0x00000088U) /*!< USART status register 1 */
/* bits definitions */
/* USARTx_STAT0 */
-#define USART_STAT0_PERR BIT(0) /*!< parity error flag */
-#define USART_STAT0_FERR BIT(1) /*!< frame error flag */
-#define USART_STAT0_NERR BIT(2) /*!< noise error flag */
-#define USART_STAT0_ORERR BIT(3) /*!< overrun error */
-#define USART_STAT0_IDLEF BIT(4) /*!< IDLE frame detected flag */
-#define USART_STAT0_RBNE BIT(5) /*!< read data buffer not empty */
-#define USART_STAT0_TC BIT(6) /*!< transmission complete */
-#define USART_STAT0_TBE BIT(7) /*!< transmit data buffer empty */
-#define USART_STAT0_LBDF BIT(8) /*!< LIN break detected flag */
-#define USART_STAT0_CTSF BIT(9) /*!< CTS change flag */
+#define USART_STAT0_PERR BIT(0) /*!< parity error flag */
+#define USART_STAT0_FERR BIT(1) /*!< frame error flag */
+#define USART_STAT0_NERR BIT(2) /*!< noise error flag */
+#define USART_STAT0_ORERR BIT(3) /*!< overrun error */
+#define USART_STAT0_IDLEF BIT(4) /*!< IDLE frame detected flag */
+#define USART_STAT0_RBNE BIT(5) /*!< read data buffer not empty */
+#define USART_STAT0_TC BIT(6) /*!< transmission complete */
+#define USART_STAT0_TBE BIT(7) /*!< transmit data buffer empty */
+#define USART_STAT0_LBDF BIT(8) /*!< LIN break detected flag */
+#define USART_STAT0_CTSF BIT(9) /*!< CTS change flag */
/* USARTx_DATA */
-#define USART_DATA_DATA BITS(0,8) /*!< transmit or read data value */
+#define USART_DATA_DATA BITS(0,8) /*!< transmit or read data value */
/* USARTx_BAUD */
-#define USART_BAUD_FRADIV BITS(0,3) /*!< fraction part of baud-rate divider */
-#define USART_BAUD_INTDIV BITS(4,15) /*!< integer part of baud-rate divider */
+#define USART_BAUD_FRADIV BITS(0,3) /*!< fraction part of baud-rate divider */
+#define USART_BAUD_INTDIV BITS(4,15) /*!< integer part of baud-rate divider */
/* USARTx_CTL0 */
-#define USART_CTL0_SBKCMD BIT(0) /*!< send break command */
-#define USART_CTL0_RWU BIT(1) /*!< receiver wakeup from mute mode */
-#define USART_CTL0_REN BIT(2) /*!< receiver enable */
-#define USART_CTL0_TEN BIT(3) /*!< transmitter enable */
-#define USART_CTL0_IDLEIE BIT(4) /*!< idle line detected interrupt enable */
-#define USART_CTL0_RBNEIE BIT(5) /*!< read data buffer not empty interrupt and overrun error interrupt enable */
-#define USART_CTL0_TCIE BIT(6) /*!< transmission complete interrupt enable */
-#define USART_CTL0_TBEIE BIT(7) /*!< transmitter buffer empty interrupt enable */
-#define USART_CTL0_PERRIE BIT(8) /*!< parity error interrupt enable */
-#define USART_CTL0_PM BIT(9) /*!< parity mode */
-#define USART_CTL0_PCEN BIT(10) /*!< parity check function enable */
-#define USART_CTL0_WM BIT(11) /*!< wakeup method in mute mode */
-#define USART_CTL0_WL BIT(12) /*!< word length */
-#define USART_CTL0_UEN BIT(13) /*!< USART enable */
+#define USART_CTL0_SBKCMD BIT(0) /*!< send break command */
+#define USART_CTL0_RWU BIT(1) /*!< receiver wakeup from mute mode */
+#define USART_CTL0_REN BIT(2) /*!< enable receiver */
+#define USART_CTL0_TEN BIT(3) /*!< enable transmitter */
+#define USART_CTL0_IDLEIE BIT(4) /*!< enable idle line detected interrupt */
+#define USART_CTL0_RBNEIE BIT(5) /*!< enable read data buffer not empty interrupt and overrun error interrupt */
+#define USART_CTL0_TCIE BIT(6) /*!< enable transmission complete interrupt */
+#define USART_CTL0_TBEIE BIT(7) /*!< enable transmitter buffer empty interrupt */
+#define USART_CTL0_PERRIE BIT(8) /*!< enable parity error interrupt */
+#define USART_CTL0_PM BIT(9) /*!< parity mode */
+#define USART_CTL0_PCEN BIT(10) /*!< enable parity check function */
+#define USART_CTL0_WM BIT(11) /*!< wakeup method in mute mode */
+#define USART_CTL0_WL BIT(12) /*!< word length */
+#define USART_CTL0_UEN BIT(13) /*!< enable USART */
/* USARTx_CTL1 */
-#define USART_CTL1_ADDR BITS(0,3) /*!< address of USART */
-#define USART_CTL1_LBLEN BIT(5) /*!< LIN break frame length */
-#define USART_CTL1_LBDIE BIT(6) /*!< LIN break detected interrupt eanble */
-#define USART_CTL1_CLEN BIT(8) /*!< CK length */
-#define USART_CTL1_CPH BIT(9) /*!< CK phase */
-#define USART_CTL1_CPL BIT(10) /*!< CK polarity */
-#define USART_CTL1_CKEN BIT(11) /*!< CK pin enable */
-#define USART_CTL1_STB BITS(12,13) /*!< STOP bits length */
-#define USART_CTL1_LMEN BIT(14) /*!< LIN mode enable */
+#define USART_CTL1_ADDR BITS(0,3) /*!< address of USART */
+#define USART_CTL1_LBLEN BIT(5) /*!< LIN break frame length */
+#define USART_CTL1_LBDIE BIT(6) /*!< eanble LIN break detected interrupt */
+#define USART_CTL1_CLEN BIT(8) /*!< CK length */
+#define USART_CTL1_CPH BIT(9) /*!< CK phase */
+#define USART_CTL1_CPL BIT(10) /*!< CK polarity */
+#define USART_CTL1_CKEN BIT(11) /*!< enable CK pin */
+#define USART_CTL1_STB BITS(12,13) /*!< STOP bits length */
+#define USART_CTL1_LMEN BIT(14) /*!< enable LIN mode */
/* USARTx_CTL2 */
-#define USART_CTL2_ERRIE BIT(0) /*!< error interrupt enable */
-#define USART_CTL2_IREN BIT(1) /*!< IrDA mode enable */
-#define USART_CTL2_IRLP BIT(2) /*!< IrDA low-power */
-#define USART_CTL2_HDEN BIT(3) /*!< half-duplex enable */
-#define USART_CTL2_NKEN BIT(4) /*!< NACK enable in smartcard mode */
-#define USART_CTL2_SCEN BIT(5) /*!< smartcard mode enable */
-#define USART_CTL2_DENR BIT(6) /*!< DMA request enable for reception */
-#define USART_CTL2_DENT BIT(7) /*!< DMA request enable for transmission */
-#define USART_CTL2_RTSEN BIT(8) /*!< RTS enable */
-#define USART_CTL2_CTSEN BIT(9) /*!< CTS enable */
-#define USART_CTL2_CTSIE BIT(10) /*!< CTS interrupt enable */
+#define USART_CTL2_ERRIE BIT(0) /*!< enable error interrupt */
+#define USART_CTL2_IREN BIT(1) /*!< enable IrDA mode */
+#define USART_CTL2_IRLP BIT(2) /*!< IrDA low-power */
+#define USART_CTL2_HDEN BIT(3) /*!< enable half-duplex */
+#define USART_CTL2_NKEN BIT(4) /*!< mode NACK enable in smartcard */
+#define USART_CTL2_SCEN BIT(5) /*!< senable martcard mode */
+#define USART_CTL2_DENR BIT(6) /*!< enable DMA request for reception */
+#define USART_CTL2_DENT BIT(7) /*!< enable DMA request for transmission */
+#define USART_CTL2_RTSEN BIT(8) /*!< enable RTS */
+#define USART_CTL2_CTSEN BIT(9) /*!< enable CTS */
+#define USART_CTL2_CTSIE BIT(10) /*!< enable CTS interrupt */
/* USARTx_GP */
-#define USART_GP_PSC BITS(0,7) /*!< prescaler value for dividing the system clock */
-#define USART_GP_GUAT BITS(8,15) /*!< guard time value in smartcard mode */
-
+#define USART_GP_PSC BITS(0,7) /*!< prescaler value for dividing the system clock */
+#define USART_GP_GUAT BITS(8,15) /*!< guard time value in smartcard mode */
+
/* USARTx_CTL3 */
-#define USART_CTL3_RTEN BIT(0) /*!< receiver timeout enable */
-#define USART_CTL3_SCRTNUM BITS(1,3) /*!< smartcard auto-retry number */
-#define USART_CTL3_RTIE BIT(4) /*!< interrupt enable bit of receive timeout event */
-#define USART_CTL3_EBIE BIT(5) /*!< interrupt enable bit of end of block event */
-#define USART_CTL3_RINV BIT(8) /*!< RX pin level inversion */
-#define USART_CTL3_TINV BIT(9) /*!< TX pin level inversion */
-#define USART_CTL3_DINV BIT(10) /*!< data bit level inversion */
-#define USART_CTL3_MSBF BIT(11) /*!< most significant bit first */
+#define USART_CTL3_RTEN BIT(0) /*!< enable receiver timeout */
+#define USART_CTL3_SCRTNUM BITS(1,3) /*!< smartcard auto-retry number */
+#define USART_CTL3_RTIE BIT(4) /*!< interrupt enable bit of receive timeout event */
+#define USART_CTL3_EBIE BIT(5) /*!< interrupt enable bit of end of block event */
+#define USART_CTL3_RINV BIT(8) /*!< RX pin level inversion */
+#define USART_CTL3_TINV BIT(9) /*!< TX pin level inversion */
+#define USART_CTL3_DINV BIT(10) /*!< data bit level inversion */
+#define USART_CTL3_MSBF BIT(11) /*!< most significant bit first */
/* USARTx_RT */
-#define USART_RT_RT BITS(0,23) /*!< receiver timeout threshold */
-#define USART_RT_BL BITS(24,31) /*!< block length */
+#define USART_RT_RT BITS(0,23) /*!< receiver timeout threshold */
+#define USART_RT_BL BITS(24,31) /*!< block length */
/* USARTx_STAT1 */
-#define USART_STAT1_RTF BIT(11) /*!< receiver timeout flag */
-#define USART_STAT1_EBF BIT(12) /*!< end of block flag */
-#define USART_STAT1_BSY BIT(16) /*!< busy flag */
+#define USART_STAT1_RTF BIT(11) /*!< receiver timeout flag */
+#define USART_STAT1_EBF BIT(12) /*!< end of block flag */
+#define USART_STAT1_BSY BIT(16) /*!< busy flag */
/* constants definitions */
/* define the USART bit position and its register index offset */
@@ -156,36 +153,34 @@ OF SUCH DAMAGE.
#define USART_BIT_POS2(val) (((uint32_t)(val) & 0x1F0000U) >> 16)
/* register offset */
-#define USART_STAT0_REG_OFFSET 0x00U /*!< STAT0 register offset */
-#define USART_STAT1_REG_OFFSET 0x88U /*!< STAT1 register offset */
-#define USART_CTL0_REG_OFFSET 0x0CU /*!< CTL0 register offset */
-#define USART_CTL1_REG_OFFSET 0x10U /*!< CTL1 register offset */
-#define USART_CTL2_REG_OFFSET 0x14U /*!< CTL2 register offset */
-#define USART_CTL3_REG_OFFSET 0x80U /*!< CTL3 register offset */
+#define USART_STAT0_REG_OFFSET ((uint32_t)0x00000000U) /*!< STAT0 register offset */
+#define USART_STAT1_REG_OFFSET ((uint32_t)0x00000088U) /*!< STAT1 register offset */
+#define USART_CTL0_REG_OFFSET ((uint32_t)0x0000000CU) /*!< CTL0 register offset */
+#define USART_CTL1_REG_OFFSET ((uint32_t)0x00000010U) /*!< CTL1 register offset */
+#define USART_CTL2_REG_OFFSET ((uint32_t)0x00000014U) /*!< CTL2 register offset */
+#define USART_CTL3_REG_OFFSET ((uint32_t)0x00000080U) /*!< CTL3 register offset */
/* USART flags */
-typedef enum
-{
+typedef enum {
/* flags in STAT0 register */
- USART_FLAG_CTS = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 9U), /*!< CTS change flag */
- USART_FLAG_LBD = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 8U), /*!< LIN break detected flag */
- USART_FLAG_TBE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 7U), /*!< transmit data buffer empty */
- USART_FLAG_TC = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 6U), /*!< transmission complete */
- USART_FLAG_RBNE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty */
- USART_FLAG_IDLE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 4U), /*!< IDLE frame detected flag */
- USART_FLAG_ORERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 3U), /*!< overrun error */
- USART_FLAG_NERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 2U), /*!< noise error flag */
- USART_FLAG_FERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 1U), /*!< frame error flag */
- USART_FLAG_PERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 0U), /*!< parity error flag */
+ USART_FLAG_CTS = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 9U), /*!< CTS change flag */
+ USART_FLAG_LBD = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 8U), /*!< LIN break detected flag */
+ USART_FLAG_TBE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 7U), /*!< transmit data buffer empty */
+ USART_FLAG_TC = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 6U), /*!< transmission complete */
+ USART_FLAG_RBNE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty */
+ USART_FLAG_IDLE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 4U), /*!< IDLE frame detected flag */
+ USART_FLAG_ORERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 3U), /*!< overrun error */
+ USART_FLAG_NERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 2U), /*!< noise error flag */
+ USART_FLAG_FERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 1U), /*!< frame error flag */
+ USART_FLAG_PERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 0U), /*!< parity error flag */
/* flags in STAT1 register */
- USART_FLAG_BSY = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 16U), /*!< busy flag */
- USART_FLAG_EB = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 12U), /*!< end of block flag */
- USART_FLAG_RT = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 11U), /*!< receiver timeout flag */
-}usart_flag_enum;
+ USART_FLAG_BSY = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 16U), /*!< busy flag */
+ USART_FLAG_EB = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 12U), /*!< end of block flag */
+ USART_FLAG_RT = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 11U) /*!< receiver timeout flag */
+} usart_flag_enum;
/* USART interrupt flags */
-typedef enum
-{
+typedef enum {
/* interrupt flags in CTL0 register */
USART_INT_FLAG_PERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 8U, USART_STAT0_REG_OFFSET, 0U), /*!< parity error interrupt and flag */
USART_INT_FLAG_TBE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 7U, USART_STAT0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt and flag */
@@ -202,12 +197,11 @@ typedef enum
USART_INT_FLAG_ERR_FERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 1U), /*!< error interrupt and frame error flag */
/* interrupt flags in CTL3 register */
USART_INT_FLAG_EB = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 5U, USART_STAT1_REG_OFFSET, 12U), /*!< interrupt enable bit of end of block event and flag */
- USART_INT_FLAG_RT = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 4U, USART_STAT1_REG_OFFSET, 11U), /*!< interrupt enable bit of receive timeout event and flag */
-}usart_interrupt_flag_enum;
+ USART_INT_FLAG_RT = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 4U, USART_STAT1_REG_OFFSET, 11U) /*!< interrupt enable bit of receive timeout event and flag */
+} usart_interrupt_flag_enum;
/* USART interrupt enable or disable */
-typedef enum
-{
+typedef enum {
/* interrupt in CTL0 register */
USART_INT_PERR = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 8U), /*!< parity error interrupt */
USART_INT_TBE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt */
@@ -221,123 +215,115 @@ typedef enum
USART_INT_ERR = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 0U), /*!< error interrupt */
/* interrupt in CTL3 register */
USART_INT_EB = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 5U), /*!< end of block interrupt */
- USART_INT_RT = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 4U), /*!< receive timeout interrupt */
-}usart_interrupt_enum;
+ USART_INT_RT = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 4U) /*!< receive timeout interrupt */
+} usart_interrupt_enum;
-/* USART invert configure */
-typedef enum
-{
+/* configure USART invert */
+typedef enum {
/* data bit level inversion */
- USART_DINV_ENABLE, /*!< data bit level inversion */
- USART_DINV_DISABLE, /*!< data bit level not inversion */
+ USART_DINV_ENABLE, /*!< data bit level inversion */
+ USART_DINV_DISABLE, /*!< data bit level not inversion */
/* TX pin level inversion */
- USART_TXPIN_ENABLE, /*!< TX pin level inversion */
- USART_TXPIN_DISABLE, /*!< TX pin level not inversion */
+ USART_TXPIN_ENABLE, /*!< TX pin level inversion */
+ USART_TXPIN_DISABLE, /*!< TX pin level not inversion */
/* RX pin level inversion */
- USART_RXPIN_ENABLE, /*!< RX pin level inversion */
- USART_RXPIN_DISABLE, /*!< RX pin level not inversion */
-}usart_invert_enum;
+ USART_RXPIN_ENABLE, /*!< RX pin level inversion */
+ USART_RXPIN_DISABLE /*!< RX pin level not inversion */
+} usart_invert_enum;
-/* USART receiver configure */
+/* configure USART receiver */
#define CTL0_REN(regval) (BIT(2) & ((uint32_t)(regval) << 2))
-#define USART_RECEIVE_ENABLE CTL0_REN(1) /*!< enable receiver */
-#define USART_RECEIVE_DISABLE CTL0_REN(0) /*!< disable receiver */
+#define USART_RECEIVE_ENABLE CTL0_REN(1) /*!< enable receiver */
+#define USART_RECEIVE_DISABLE CTL0_REN(0) /*!< disable receiver */
-/* USART transmitter configure */
+/* configure USART transmitter */
#define CTL0_TEN(regval) (BIT(3) & ((uint32_t)(regval) << 3))
-#define USART_TRANSMIT_ENABLE CTL0_TEN(1) /*!< enable transmitter */
-#define USART_TRANSMIT_DISABLE CTL0_TEN(0) /*!< disable transmitter */
+#define USART_TRANSMIT_ENABLE CTL0_TEN(1) /*!< enable transmitter */
+#define USART_TRANSMIT_DISABLE CTL0_TEN(0) /*!< disable transmitter */
/* USART parity bits definitions */
#define CTL0_PM(regval) (BITS(9,10) & ((uint32_t)(regval) << 9))
-#define USART_PM_NONE CTL0_PM(0) /*!< no parity */
-#define USART_PM_EVEN CTL0_PM(2) /*!< even parity */
-#define USART_PM_ODD CTL0_PM(3) /*!< odd parity */
+#define USART_PM_NONE CTL0_PM(0) /*!< no parity */
+#define USART_PM_EVEN CTL0_PM(2) /*!< even parity */
+#define USART_PM_ODD CTL0_PM(3) /*!< odd parity */
/* USART wakeup method in mute mode */
#define CTL0_WM(regval) (BIT(11) & ((uint32_t)(regval) << 11))
-#define USART_WM_IDLE CTL0_WM(0) /*!< idle line */
-#define USART_WM_ADDR CTL0_WM(1) /*!< address match */
+#define USART_WM_IDLE CTL0_WM(0) /*!< idle line */
+#define USART_WM_ADDR CTL0_WM(1) /*!< address match */
/* USART word length definitions */
#define CTL0_WL(regval) (BIT(12) & ((uint32_t)(regval) << 12))
-#define USART_WL_8BIT CTL0_WL(0) /*!< 8 bits */
-#define USART_WL_9BIT CTL0_WL(1) /*!< 9 bits */
+#define USART_WL_8BIT CTL0_WL(0) /*!< 8 bits */
+#define USART_WL_9BIT CTL0_WL(1) /*!< 9 bits */
/* USART stop bits definitions */
#define CTL1_STB(regval) (BITS(12,13) & ((uint32_t)(regval) << 12))
-#define USART_STB_1BIT CTL1_STB(0) /*!< 1 bit */
-#define USART_STB_0_5BIT CTL1_STB(1) /*!< 0.5 bit */
-#define USART_STB_2BIT CTL1_STB(2) /*!< 2 bits */
-#define USART_STB_1_5BIT CTL1_STB(3) /*!< 1.5 bits */
+#define USART_STB_1BIT CTL1_STB(0) /*!< 1 bit */
+#define USART_STB_0_5BIT CTL1_STB(1) /*!< 0.5 bit */
+#define USART_STB_2BIT CTL1_STB(2) /*!< 2 bits */
+#define USART_STB_1_5BIT CTL1_STB(3) /*!< 1.5 bits */
/* USART LIN break frame length */
#define CTL1_LBLEN(regval) (BIT(5) & ((uint32_t)(regval) << 5))
-#define USART_LBLEN_10B CTL1_LBLEN(0) /*!< 10 bits */
-#define USART_LBLEN_11B CTL1_LBLEN(1) /*!< 11 bits */
+#define USART_LBLEN_10B CTL1_LBLEN(0) /*!< 10 bits */
+#define USART_LBLEN_11B CTL1_LBLEN(1) /*!< 11 bits */
/* USART CK length */
#define CTL1_CLEN(regval) (BIT(8) & ((uint32_t)(regval) << 8))
-#define USART_CLEN_NONE CTL1_CLEN(0) /*!< there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame */
-#define USART_CLEN_EN CTL1_CLEN(1) /*!< there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame */
+#define USART_CLEN_NONE CTL1_CLEN(0) /*!< there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame */
+#define USART_CLEN_EN CTL1_CLEN(1) /*!< there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame */
/* USART clock phase */
#define CTL1_CPH(regval) (BIT(9) & ((uint32_t)(regval) << 9))
-#define USART_CPH_1CK CTL1_CPH(0) /*!< first clock transition is the first data capture edge */
-#define USART_CPH_2CK CTL1_CPH(1) /*!< second clock transition is the first data capture edge */
+#define USART_CPH_1CK CTL1_CPH(0) /*!< first clock transition is the first data capture edge */
+#define USART_CPH_2CK CTL1_CPH(1) /*!< second clock transition is the first data capture edge */
/* USART clock polarity */
#define CTL1_CPL(regval) (BIT(10) & ((uint32_t)(regval) << 10))
-#define USART_CPL_LOW CTL1_CPL(0) /*!< steady low value on CK pin */
-#define USART_CPL_HIGH CTL1_CPL(1) /*!< steady high value on CK pin */
-
-/* USART DMA request for receive configure */
-#define CLT2_DENR(regval) (BIT(6) & ((uint32_t)(regval) << 6))
-#define USART_DENR_ENABLE CLT2_DENR(1) /*!< DMA request enable for reception */
-#define USART_DENR_DISABLE CLT2_DENR(0) /*!< DMA request disable for reception */
-
-/* USART DMA request for transmission configure */
-#define CLT2_DENT(regval) (BIT(7) & ((uint32_t)(regval) << 7))
-#define USART_DENT_ENABLE CLT2_DENT(1) /*!< DMA request enable for transmission */
-#define USART_DENT_DISABLE CLT2_DENT(0) /*!< DMA request disable for transmission */
-
-/* USART RTS configure */
+#define USART_CPL_LOW CTL1_CPL(0) /*!< steady low value on CK pin */
+#define USART_CPL_HIGH CTL1_CPL(1) /*!< steady high value on CK pin */
+
+/* configure USART DMA */
+#define CLT2_RECEIVE_DMAEN(regval) (BIT(6) & ((uint32_t)(regval) << 6))
+#define CTL2_TRANSMIT_DMAEN(regval) (BIT(7) & ((uint32_t)(regval) << 7))
+#define USART_RECEIVE_DMA_ENABLE CLT2_RECEIVE_DMAEN(1) /* enable DMA request for reception */
+#define USART_RECEIVE_DMA_DISABLE CLT2_RECEIVE_DMAEN(0) /* disable DMA request for reception */
+#define USART_TRANSMIT_DMA_ENABLE CTL2_TRANSMIT_DMAEN(1) /* enable DMA request for transmission */
+#define USART_TRANSMIT_DMA_DISABLE CTL2_TRANSMIT_DMAEN(0) /* disable DMA request for transmission */
+
+/* configure USART RTS */
#define CLT2_RTSEN(regval) (BIT(8) & ((uint32_t)(regval) << 8))
-#define USART_RTS_ENABLE CLT2_RTSEN(1) /*!< RTS enable */
-#define USART_RTS_DISABLE CLT2_RTSEN(0) /*!< RTS disable */
+#define USART_RTS_ENABLE CLT2_RTSEN(1) /*!< enable RTS */
+#define USART_RTS_DISABLE CLT2_RTSEN(0) /*!< disable RTS */
-/* USART CTS configure */
+/* configure USART CTS */
#define CLT2_CTSEN(regval) (BIT(9) & ((uint32_t)(regval) << 9))
-#define USART_CTS_ENABLE CLT2_CTSEN(1) /*!< CTS enable */
-#define USART_CTS_DISABLE CLT2_CTSEN(0) /*!< CTS disable */
+#define USART_CTS_ENABLE CLT2_CTSEN(1) /*!< enable CTS */
+#define USART_CTS_DISABLE CLT2_CTSEN(0) /*!< disable CTS */
-/* USART IrDA low-power enable */
+/* enable USART IrDA low-power */
#define CTL2_IRLP(regval) (BIT(2) & ((uint32_t)(regval) << 2))
-#define USART_IRLP_LOW CTL2_IRLP(1) /*!< low-power */
-#define USART_IRLP_NORMAL CTL2_IRLP(0) /*!< normal */
+#define USART_IRLP_LOW CTL2_IRLP(1) /*!< low-power */
+#define USART_IRLP_NORMAL CTL2_IRLP(0) /*!< normal */
/* USART data is transmitted/received with the LSB/MSB first */
#define CTL3_MSBF(regval) (BIT(11) & ((uint32_t)(regval) << 11))
-#define USART_MSBF_LSB CTL3_MSBF(0) /*!< LSB first */
-#define USART_MSBF_MSB CTL3_MSBF(1) /*!< MSB first */
-
-
+#define USART_MSBF_LSB CTL3_MSBF(0) /*!< LSB first */
+#define USART_MSBF_MSB CTL3_MSBF(1) /*!< MSB first */
/* function declarations */
/* initialization functions */
-/* reset USART */
+/* reset USART/UART */
void usart_deinit(uint32_t usart_periph);
/* configure USART baud rate value */
void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval);
-/* configure USART parity function */
+/* configure USART parity */
void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg);
/* configure USART word length */
void usart_word_length_set(uint32_t usart_periph, uint32_t wlen);
/* configure USART stop bit length */
void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen);
-
-/* function configuration */
-/* USART normal mode communication */
/* enable USART */
void usart_enable(uint32_t usart_periph);
/* disable USART */
@@ -346,9 +332,11 @@ void usart_disable(uint32_t usart_periph);
void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig);
/* configure USART receiver */
void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig);
+
+/* USART normal mode communication */
/* data is transmitted/received with the LSB/MSB first */
void usart_data_first_config(uint32_t usart_periph, uint32_t msbf);
-/* configure USART inverted */
+/* configure USART inversion */
void usart_invert_config(uint32_t usart_periph, usart_invert_enum invertpara);
/* enable receiver timeout */
void usart_receiver_timeout_enable(uint32_t usart_periph);
@@ -362,7 +350,7 @@ void usart_data_transmit(uint32_t usart_periph, uint16_t data);
uint16_t usart_data_receive(uint32_t usart_periph);
/* multi-processor communication */
-/* configure address of the USART */
+/* configure the address of the USART in wake up by address match mode */
void usart_address_config(uint32_t usart_periph, uint8_t addr);
/* enable mute mode */
void usart_mute_mode_enable(uint32_t usart_periph);
@@ -372,44 +360,44 @@ void usart_mute_mode_disable(uint32_t usart_periph);
void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod);
/* LIN mode communication */
-/* LIN mode enable */
+/* enable LIN mode */
void usart_lin_mode_enable(uint32_t usart_periph);
-/* LIN mode disable */
+/* disable LIN mode */
void usart_lin_mode_disable(uint32_t usart_periph);
-/* LIN break detection length */
+/* configure lin break frame length */
void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lblen);
/* send break frame */
void usart_send_break(uint32_t usart_periph);
/* half-duplex communication */
-/* half-duplex enable */
+/* enable half-duplex mode */
void usart_halfduplex_enable(uint32_t usart_periph);
-/* half-duplex disable */
+/* disable half-duplex mode */
void usart_halfduplex_disable(uint32_t usart_periph);
/* synchronous communication */
-/* clock enable */
+/* enable CK pin in synchronous mode */
void usart_synchronous_clock_enable(uint32_t usart_periph);
-/* clock disable */
+/* disable CK pin in synchronous mode */
void usart_synchronous_clock_disable(uint32_t usart_periph);
-/* configure usart synchronous mode parameters */
+/* configure USART synchronous mode parameters */
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl);
/* smartcard communication */
-/* guard time value configure in smartcard mode */
-void usart_guard_time_config(uint32_t usart_periph,uint32_t guat);
-/* smartcard mode enable */
+/* configure guard time value in smartcard mode */
+void usart_guard_time_config(uint32_t usart_periph, uint8_t guat);
+/* enable smartcard mode */
void usart_smartcard_mode_enable(uint32_t usart_periph);
-/* smartcard mode disable */
+/* disable smartcard mode */
void usart_smartcard_mode_disable(uint32_t usart_periph);
-/* NACK enable in smartcard mode */
+/* enable NACK in smartcard mode */
void usart_smartcard_mode_nack_enable(uint32_t usart_periph);
-/* NACK disable in smartcard mode */
+/* disable NACK in smartcard mode */
void usart_smartcard_mode_nack_disable(uint32_t usart_periph);
-/* smartcard auto-retry number configure */
-void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t scrtnum);
-/* block length configure */
-void usart_block_length_config(uint32_t usart_periph, uint32_t bl);
+/* configure smartcard auto-retry number */
+void usart_smartcard_autoretry_config(uint32_t usart_periph, uint8_t scrtnum);
+/* configure block length */
+void usart_block_length_config(uint32_t usart_periph, uint8_t bl);
/* IrDA communication */
/* enable IrDA mode */
@@ -427,23 +415,24 @@ void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig);
/* configure hardware flow control CTS */
void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig);
-/* configure USART DMA for reception */
-void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd);
-/* configure USART DMA for transmission */
-void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd);
+/* DMA communication */
+/* configure USART DMA reception */
+void usart_dma_receive_config(uint32_t usart_periph, uint8_t dmaconfig);
+/* configure USART DMA transmission */
+void usart_dma_transmit_config(uint32_t usart_periph, uint8_t dmaconfig);
-/* interrupt & flag functions */
+/* flag & interrupt functions */
/* get flag in STAT0/STAT1 register */
FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag);
/* clear flag in STAT0/STAT1 register */
void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag);
/* enable USART interrupt */
-void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag);
+void usart_interrupt_enable(uint32_t usart_periph, usart_interrupt_enum interrupt);
/* disable USART interrupt */
-void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag);
+void usart_interrupt_disable(uint32_t usart_periph, usart_interrupt_enum interrupt);
/* get USART interrupt and flag status */
-FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag);
-/* clear interrupt flag in STAT0/STAT1 register */
-void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t flag);
+FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, usart_interrupt_flag_enum int_flag);
+/* clear USART interrupt flag in STAT0/STAT1 register */
+void usart_interrupt_flag_clear(uint32_t usart_periph, usart_interrupt_flag_enum int_flag);
-#endif /* GD32F20X_USART_H */
+#endif /* GD32F20X_USART_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_wwdgt.h b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_wwdgt.h
index 84b2dd2..d483ffc 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_wwdgt.h
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Include/gd32f20x_wwdgt.h
@@ -1,37 +1,34 @@
/*!
\file gd32f20x_wwdgt.h
- \brief definitions for the WWDGT
+ \brief definitions for the WWDGT
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -68,24 +65,30 @@ OF SUCH DAMAGE.
#define WWDGT_CFG_PSC_DIV4 CFG_PSC(2) /*!< the time base of WWDGT = (PCLK1/4096)/4 */
#define WWDGT_CFG_PSC_DIV8 CFG_PSC(3) /*!< the time base of WWDGT = (PCLK1/4096)/8 */
+/* write value to WWDGT_CTL_CNT bit field */
+#define CTL_CNT(regval) (BITS(0,6) & ((uint32_t)(regval) << 0))
+/* write value to WWDGT_CFG_WIN bit field */
+#define CFG_WIN(regval) (BITS(0,6) & ((uint32_t)(regval) << 0))
+
/* function declarations */
/* initialization functions */
/* reset the window watchdog timer configuration */
void wwdgt_deinit(void);
/* start the window watchdog timer counter */
void wwdgt_enable(void);
-
/* configure the window watchdog timer counter value */
void wwdgt_counter_update(uint16_t counter_value);
/* configure counter value, window value, and prescaler divider value */
void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler);
/* interrupt & flag functions */
-/* enable early wakeup interrupt of WWDGT */
-void wwdgt_interrupt_enable(void);
-/* check early wakeup interrupt state of WWDGT */
+/* get early wakeup interrupt flag of WWDGT */
+FlagStatus wwdgt_interrupt_flag_get(void);
+/* get early wakeup flag of WWDGT */
FlagStatus wwdgt_flag_get(void);
/* clear early wakeup interrupt state of WWDGT */
void wwdgt_flag_clear(void);
+/* enable early wakeup interrupt of WWDGT */
+void wwdgt_interrupt_enable(void);
#endif /* GD32F20X_WWDGT_H */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_adc.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_adc.c
index 3e56361..5b6b209 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_adc.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_adc.c
@@ -2,36 +2,33 @@
\file gd32f20x_adc.c
\brief ADC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -60,14 +57,14 @@ OF SUCH DAMAGE.
#define ADC_OFFSET_SHIFT_LENGTH ((uint8_t)4U)
/*!
- \brief reset ADC
+ \brief reset ADC
\param[in] adc_periph: ADCx, x=0,1,2
\param[out] none
\retval none
*/
void adc_deinit(uint32_t adc_periph)
{
- switch(adc_periph){
+ switch(adc_periph) {
case ADC0:
/* reset ADC0 */
rcu_periph_reset_enable(RCU_ADC0RST);
@@ -125,33 +122,33 @@ void adc_mode_config(uint32_t mode)
*/
void adc_special_function_config(uint32_t adc_periph, uint32_t function, ControlStatus new_value)
{
- if(new_value){
- if(0U != (function & ADC_SCAN_MODE)){
+ if(new_value) {
+ if(0U != (function & ADC_SCAN_MODE)) {
/* enable ADC scan mode */
ADC_CTL0(adc_periph) |= ADC_SCAN_MODE;
}
- if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
+ if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)) {
/* enable ADC inserted channel group convert automatically */
ADC_CTL0(adc_periph) |= ADC_INSERTED_CHANNEL_AUTO;
}
- if(0U != (function & ADC_CONTINUOUS_MODE)){
+ if(0U != (function & ADC_CONTINUOUS_MODE)) {
/* enable ADC continuous mode */
ADC_CTL1(adc_periph) |= ADC_CONTINUOUS_MODE;
- }
- }else{
- if(0U != (function & ADC_SCAN_MODE)){
+ }
+ } else {
+ if(0U != (function & ADC_SCAN_MODE)) {
/* disable scan mode */
ADC_CTL0(adc_periph) &= ~ADC_SCAN_MODE;
}
- if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
+ if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)) {
/* disable ADC inserted channel group convert automatically */
ADC_CTL0(adc_periph) &= ~ADC_INSERTED_CHANNEL_AUTO;
}
- if(0U != (function & ADC_CONTINUOUS_MODE)){
+ if(0U != (function & ADC_CONTINUOUS_MODE)) {
/* disable ADC continuous mode */
ADC_CTL1(adc_periph) &= ~ADC_CONTINUOUS_MODE;
}
@@ -159,7 +156,7 @@ void adc_special_function_config(uint32_t adc_periph, uint32_t function, Control
}
/*!
- \brief configure ADC data alignment
+ \brief configure ADC data alignment
\param[in] adc_periph: ADCx, x=0,1,2
\param[in] data_alignment: data alignment select
only one parameter can be selected which is shown as below:
@@ -170,10 +167,10 @@ void adc_special_function_config(uint32_t adc_periph, uint32_t function, Control
*/
void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment)
{
- if(ADC_DATAALIGN_RIGHT != data_alignment){
+ if(ADC_DATAALIGN_RIGHT != data_alignment) {
/* MSB alignment */
ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
- }else{
+ } else {
/* LSB alignment */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DAL);
}
@@ -187,7 +184,7 @@ void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment)
*/
void adc_enable(uint32_t adc_periph)
{
- if(RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)){
+ if(RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)) {
/* enable ADC */
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
}
@@ -216,12 +213,12 @@ void adc_calibration_enable(uint32_t adc_periph)
/* reset the selected ADC calibration registers */
ADC_CTL1(adc_periph) |= (uint32_t) ADC_CTL1_RSTCLB;
/* check the RSTCLB bit state */
- while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)){
+ while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)) {
}
/* enable ADC calibration process */
ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
/* check the CLB bit state */
- while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)){
+ while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)) {
}
}
@@ -250,7 +247,7 @@ void adc_tempsensor_vrefint_disable(void)
}
/*!
- \brief enable DMA request
+ \brief enable DMA request
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[out] none
@@ -263,7 +260,7 @@ void adc_dma_mode_enable(uint32_t adc_periph)
}
/*!
- \brief disable DMA request
+ \brief disable DMA request
\param[in] adc_periph: ADCx, x=0,1,2
\param[out] none
\retval none
@@ -275,7 +272,7 @@ void adc_dma_mode_disable(uint32_t adc_periph)
}
/*!
- \brief configure ADC discontinuous mode
+ \brief configure ADC discontinuous mode
\param[in] adc_periph: ADCx, x=0,1,2
\param[in] adc_channel_group: select the channel group
only one parameter can be selected which is shown as below:
@@ -291,7 +288,7 @@ void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_grou
{
/* disable discontinuous mode of regular & inserted channel */
ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_DISRC | ADC_CTL0_DISIC));
- switch(adc_channel_group){
+ switch(adc_channel_group) {
case ADC_REGULAR_CHANNEL:
/* configure the number of conversions in discontinuous mode */
ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_DISNUM);
@@ -304,7 +301,7 @@ void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_grou
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISIC;
break;
case ADC_CHANNEL_DISCON_DISABLE:
- /* disable discontinuous mode of regular & inserted channel */
+ /* disable discontinuous mode of regular & inserted channel */
default:
break;
}
@@ -325,7 +322,7 @@ void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_grou
*/
void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t length)
{
- switch(adc_channel_group){
+ switch(adc_channel_group) {
case ADC_REGULAR_CHANNEL:
/* configure the length of regular channel group */
ADC_RSQ0(adc_periph) &= ~((uint32_t)ADC_RSQ0_RL);
@@ -348,7 +345,7 @@ void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, u
\param[in] rank: the regular group sequence rank,this parameter must be between 0 to 15
\param[in] adc_channel: the selected ADC channel
only one parameter can be selected which is shown as below:
- \arg ADC_CHANNEL_x(x=0..17)(x=16 and x=17 are only for ADC0): ADC Channelx
+ \arg ADC_CHANNEL_x(x=0..17)(x=16 and x=17 are only for ADC0): ADC Channelx
\param[in] sample_time: the sample time value
only one parameter can be selected which is shown as below:
\arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
@@ -364,56 +361,56 @@ void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, u
*/
void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
{
- uint32_t rsq,sampt;
-
+ uint32_t rsq, sampt;
+
/* configure ADC regular sequence */
- if(rank < ADC_REGULAR_CHANNEL_RANK_SIX){
+ if(rank < ADC_REGULAR_CHANNEL_RANK_SIX) {
/* the regular group sequence rank is smaller than six */
rsq = ADC_RSQ2(adc_periph);
rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH * rank)));
/* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH * rank));
ADC_RSQ2(adc_periph) = rsq;
- }else if(rank < ADC_REGULAR_CHANNEL_RANK_TWELVE){
+ } else if(rank < ADC_REGULAR_CHANNEL_RANK_TWELVE) {
/* the regular group sequence rank is smaller than twelve */
rsq = ADC_RSQ1(adc_periph);
rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH * (rank - ADC_REGULAR_CHANNEL_RANK_SIX))));
/* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH * (rank - ADC_REGULAR_CHANNEL_RANK_SIX)));
ADC_RSQ1(adc_periph) = rsq;
- }else if(rank < ADC_REGULAR_CHANNEL_RANK_SIXTEEN){
+ } else if(rank < ADC_REGULAR_CHANNEL_RANK_SIXTEEN) {
/* the regular group sequence rank is smaller than sixteen */
rsq = ADC_RSQ0(adc_periph);
rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH * (rank - ADC_REGULAR_CHANNEL_RANK_TWELVE))));
/* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH * (rank - ADC_REGULAR_CHANNEL_RANK_TWELVE)));
ADC_RSQ0(adc_periph) = rsq;
- }else{
+ } else {
/* illegal parameters */
}
-
+
/* configure ADC sampling time */
- if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
+ if(adc_channel < ADC_CHANNEL_SAMPLE_TEN) {
/* the regular group sequence rank is smaller than ten */
sampt = ADC_SAMPT1(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH * adc_channel)));
/* channel sample time set*/
sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH * adc_channel));
ADC_SAMPT1(adc_periph) = sampt;
- }else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN){
+ } else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN) {
/* the regular group sequence rank is smaller than eighteen */
sampt = ADC_SAMPT0(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH * (adc_channel - ADC_CHANNEL_SAMPLE_TEN))));
/* channel sample time set*/
sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH * (adc_channel - ADC_CHANNEL_SAMPLE_TEN)));
ADC_SAMPT0(adc_periph) = sampt;
- }else{
- /* illegal parameters */
+ } else {
+ /* illegal parameters */
}
}
/*!
- \brief configure ADC inserted channel
+ \brief configure ADC inserted channel
\param[in] adc_periph: ADCx,x=0,1,2
only one among these parameters can be selected
\param[in] rank: the inserted group sequencer rank,this parameter must be between 0 to 3
@@ -436,7 +433,7 @@ void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_c
void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
{
uint8_t inserted_length;
- uint32_t isq,sampt;
+ uint32_t isq, sampt;
/* get inserted channel group length */
inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph), 20U, 21U);
/* the channel number is written to these bits to select a channel as the nth conversion in the inserted channel group */
@@ -445,28 +442,28 @@ void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_
isq |= ((uint32_t)adc_channel << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH - (inserted_length - rank) * ADC_INSERTED_CHANNEL_RANK_LENGTH));
ADC_ISQ(adc_periph) = isq;
- /* ADC sampling time config */
- if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
+ /* ADC sampling time config */
+ if(adc_channel < ADC_CHANNEL_SAMPLE_TEN) {
/* the inserted group sequence rank is smaller than ten */
sampt = ADC_SAMPT1(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH * adc_channel)));
/* channel sample time set*/
sampt |= (uint32_t) sample_time << (ADC_CHANNEL_SAMPLE_LENGTH * adc_channel);
ADC_SAMPT1(adc_periph) = sampt;
- }else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN){
+ } else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN) {
/* the inserted group sequence rank is smaller than eighteen */
sampt = ADC_SAMPT0(adc_periph);
sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH * (adc_channel - ADC_CHANNEL_SAMPLE_TEN))));
/* channel sample time set*/
sampt |= ((uint32_t)sample_time << (ADC_CHANNEL_SAMPLE_LENGTH * (adc_channel - ADC_CHANNEL_SAMPLE_TEN)));
ADC_SAMPT0(adc_periph) = sampt;
- }else{
+ } else {
/* illegal parameters */
}
}
/*!
- \brief configure ADC inserted channel offset
+ \brief configure ADC inserted channel offset
\param[in] adc_periph: ADCx,x=0,1,2
only one among these parameters can be selected
\param[in] inserted_channel: insert channel select
@@ -486,8 +483,8 @@ void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_ch
inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph), 20U, 21U);
num = ((uint32_t)ADC_OFFSET_LENGTH - ((uint32_t)inserted_length - (uint32_t)inserted_channel));
-
- if(num <= ADC_OFFSET_LENGTH){
+
+ if(num <= ADC_OFFSET_LENGTH) {
/* calculate the offset of the register */
num = num * ADC_OFFSET_SHIFT_LENGTH;
/* configure the offset of the selected channels */
@@ -496,7 +493,7 @@ void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_ch
}
/*!
- \brief configure ADC external trigger source
+ \brief configure ADC external trigger source
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] adc_channel_group: select the channel group
@@ -518,7 +515,7 @@ void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_ch
\arg ADC2_EXTTRIG_REGULAR_T1_CH2: TIMER1 CH2 event select
\arg ADC2_EXTTRIG_REGULAR_T0_CH2: TIMER0 CH2 event select
\arg ADC2_EXTTRIG_REGULAR_T7_CH0: TIMER7 CH0 event select
- \arg ADC2_EXTTRIG_REGULAR_T7_TRGO: TIMER7 TRGO event select
+ \arg ADC2_EXTTRIG_REGULAR_T7_TRGO: TIMER7 TRGO event select
\arg ADC2_EXTTRIG_REGULAR_T4_CH0: TIMER4 CH0 event select
\arg ADC2_EXTTRIG_REGULAR_T4_CH2: TIMER4 CH2 event select
\arg ADC0_1_2_EXTTRIG_REGULAR_NONE: software trigger
@@ -543,8 +540,8 @@ void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_ch
\retval none
*/
void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t external_trigger_source)
-{
- switch(adc_channel_group){
+{
+ switch(adc_channel_group) {
case ADC_REGULAR_CHANNEL:
/* configure ADC regular group external trigger source */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSRC);
@@ -561,7 +558,7 @@ void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel
}
/*!
- \brief configure ADC external trigger
+ \brief configure ADC external trigger
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] adc_channel_group: select the channel group
@@ -574,23 +571,23 @@ void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel
*/
void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group, ControlStatus newvalue)
{
- if(newvalue){
- if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
+ if(newvalue) {
+ if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
/* external trigger enable for regular channel */
ADC_CTL1(adc_periph) |= ADC_CTL1_ETERC;
}
- if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
+ if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)) {
/* external trigger enable for inserted channel */
ADC_CTL1(adc_periph) |= ADC_CTL1_ETEIC;
}
- }else{
- if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
+ } else {
+ if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
/* external trigger disable for regular channel */
ADC_CTL1(adc_periph) &= ~ADC_CTL1_ETERC;
}
- if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
+ if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)) {
/* external trigger disable for inserted channel */
ADC_CTL1(adc_periph) &= ~ADC_CTL1_ETEIC;
}
@@ -598,7 +595,7 @@ void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group,
}
/*!
- \brief enable ADC software trigger
+ \brief enable ADC software trigger
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] adc_channel_group: select the channel group
@@ -610,19 +607,19 @@ void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group,
*/
void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group)
{
- if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
+ if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)) {
/* enable regular group channel software trigger */
ADC_CTL1(adc_periph) |= ADC_CTL1_SWRCST;
}
- if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
+ if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)) {
/* enable inserted channel group software trigger */
ADC_CTL1(adc_periph) |= ADC_CTL1_SWICST;
}
}
/*!
- \brief read ADC regular group data register
+ \brief read ADC regular group data register
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] none
@@ -635,7 +632,7 @@ uint16_t adc_regular_data_read(uint32_t adc_periph)
}
/*!
- \brief read ADC inserted group data register
+ \brief read ADC inserted group data register
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] inserted_channel: inserted channel select
@@ -651,7 +648,7 @@ uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel)
{
uint32_t idata;
/* read the data of the selected channel */
- switch(inserted_channel){
+ switch(inserted_channel) {
case ADC_INSERTED_CHANNEL_0:
/* read the data of channel 0 */
idata = ADC_IDATA0(adc_periph);
@@ -688,7 +685,7 @@ uint32_t adc_sync_mode_convert_value_read(void)
}
/*!
- \brief configure ADC analog watchdog single channel
+ \brief configure ADC analog watchdog single channel
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] adc_channel: the selected ADC channel
@@ -706,11 +703,11 @@ void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel
}
/*!
- \brief configure ADC analog watchdog group channel
+ \brief configure ADC analog watchdog group channel
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] adc_channel_group: the channel group use analog watchdog
- only one parameter can be selected which is shown as below:
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\arg ADC_REGULAR_INSERTED_CHANNEL: both regular and inserted group
@@ -721,7 +718,7 @@ void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_
{
ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
/* select the group */
- switch(adc_channel_group){
+ switch(adc_channel_group) {
case ADC_REGULAR_CHANNEL:
/* regular channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_RWDEN;
@@ -740,7 +737,7 @@ void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_
}
/*!
- \brief disable ADC analog watchdog
+ \brief disable ADC analog watchdog
\param[in] adc_periph: ADCx,x=0,1,2
only one among these parameters can be selected
\param[out] none
@@ -752,7 +749,7 @@ void adc_watchdog_disable(uint32_t adc_periph)
}
/*!
- \brief configure ADC analog watchdog threshold
+ \brief configure ADC analog watchdog threshold
\param[in] adc_periph: ADCx,x=0,1,2
only one among these parameters can be selected
\param[in] low_threshold: analog watchdog low threshold,0..4095
@@ -766,6 +763,95 @@ void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold,
ADC_WDHT(adc_periph) = (uint32_t)WDHT_WDHT(high_threshold);
}
+/*!
+ \brief configure ADC resolution
+ \param[in] adc_periph: ADCx,x=0,1,2
+ only one among these parameters can be selected
+ \param[in] resolution: ADC resolution
+ only one among these parameters can be selected
+ \arg ADC_RESOLUTION_12B: 12-bit ADC resolution
+ \arg ADC_RESOLUTION_10B: 10-bit ADC resolution
+ \arg ADC_RESOLUTION_8B: 8-bit ADC resolution
+ \arg ADC_RESOLUTION_6B: 6-bit ADC resolution
+ \param[out] none
+ \retval none
+*/
+void adc_resolution_config(uint32_t adc_periph, uint32_t resolution)
+{
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_DRES);
+ ADC_OVSAMPCTL(adc_periph) |= (uint32_t)resolution;
+}
+
+/*!
+ \brief configure ADC oversample mode
+ \param[in] adc_periph: ADCx, x=0,1,2
+ only one among these parameters can be selected
+ \param[in] mode: ADC oversampling mode
+ only oneparameter can be selected
+ \arg ADC_OVERSAMPLING_ALL_CONVERT: all oversampled conversions for a channel are done consecutively after a trigger
+ \arg ADC_OVERSAMPLING_ONE_CONVERT: each oversampled conversion for a channel needs a trigger
+ \param[in] shift: ADC oversampling shift
+ only oneparameter can be selected
+ \arg ADC_OVERSAMPLING_SHIFT_NONE: no oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_1B: 1-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_2B: 2-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_3B: 3-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_4B: 3-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_5B: 5-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_6B: 6-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_7B: 7-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_8B: 8-bit oversampling shift
+ \param[in] ratio: ADC oversampling ratio
+ only oneparameter can be selected
+ \arg ADC_OVERSAMPLING_RATIO_MUL2: oversampling ratio multiple 2
+ \arg ADC_OVERSAMPLING_RATIO_MUL4: oversampling ratio multiple 4
+ \arg ADC_OVERSAMPLING_RATIO_MUL8: oversampling ratio multiple 8
+ \arg ADC_OVERSAMPLING_RATIO_MUL16: oversampling ratio multiple 16
+ \arg ADC_OVERSAMPLING_RATIO_MUL32: oversampling ratio multiple 32
+ \arg ADC_OVERSAMPLING_RATIO_MUL64: oversampling ratio multiple 64
+ \arg ADC_OVERSAMPLING_RATIO_MUL128: oversampling ratio multiple 128
+ \arg ADC_OVERSAMPLING_RATIO_MUL256: oversampling ratio multiple 256
+ \param[out] none
+ \retval none
+*/
+void adc_oversample_mode_config(uint32_t adc_periph, uint8_t mode, uint16_t shift, uint8_t ratio)
+{
+ /* configure ADC oversampling mode */
+ if(ADC_OVERSAMPLING_ONE_CONVERT == mode) {
+ ADC_OVSAMPCTL(adc_periph) |= (uint32_t)ADC_OVSAMPCTL_TOVS;
+ } else {
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_TOVS);
+ }
+
+ /* configure the shift and ratio */
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)(ADC_OVSAMPCTL_OVSR | ADC_OVSAMPCTL_OVSS));
+ ADC_OVSAMPCTL(adc_periph) |= ((uint32_t)shift | (uint32_t)ratio);
+}
+
+/*!
+ \brief enable ADC oversample mode
+ \param[in] adc_periph: ADCx,x=0,1,2
+ only one among these parameters can be selected
+ \param[out] none
+ \retval none
+*/
+void adc_oversample_mode_enable(uint32_t adc_periph)
+{
+ ADC_OVSAMPCTL(adc_periph) |= ADC_OVSAMPCTL_OVSEN;
+}
+
+/*!
+ \brief disable ADC oversample mode
+ \param[in] adc_periph: ADCx,x=0,1,2
+ only one among these parameters can be selected
+ \param[out] none
+ \retval none
+*/
+void adc_oversample_mode_disable(uint32_t adc_periph)
+{
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_OVSEN);
+}
+
/*!
\brief get the ADC flag bits
\param[in] adc_periph: ADCx, x=0,1,2
@@ -783,7 +869,7 @@ void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold,
FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag)
{
FlagStatus reval = RESET;
- if(ADC_STAT(adc_periph) & adc_flag){
+ if(ADC_STAT(adc_periph) & adc_flag) {
reval = SET;
}
return reval;
@@ -809,70 +895,7 @@ void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag)
}
/*!
- \brief get the ADC interrupt flag
- \param[in] adc_periph: ADCx,x=0,1,2
- only one among these parameters can be selected
- \param[in] adc_interrupt: the adc interrupt bits
- only one parameter can be selected which is shown as below:
- \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
- \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
- \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt)
-{
- FlagStatus interrupt_flag = RESET;
- uint32_t state;
- /* check the interrupt bits */
- switch(adc_interrupt){
- case ADC_INT_FLAG_WDE:
- /* get the ADC analog watchdog interrupt bits */
- state = ADC_STAT(adc_periph) & ADC_STAT_WDE;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_WDEIE) && state){
- interrupt_flag = SET;
- }
- break;
- case ADC_INT_FLAG_EOC:
- /* get the ADC end of group conversion interrupt bits */
- state = ADC_STAT(adc_periph) & ADC_STAT_EOC;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_EOCIE) && state){
- interrupt_flag = SET;
- }
- break;
- case ADC_INT_FLAG_EOIC:
- /* get the ADC end of inserted group conversion interrupt bits */
- state = ADC_STAT(adc_periph) & ADC_STAT_EOIC;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_EOICIE) && state){
- interrupt_flag = SET;
- }
- break;
- default:
- break;
- }
-
- return interrupt_flag;
-}
-
-/*!
- \brief clear the ADC interrupt flag
- \param[in] adc_periph: ADCx, x=0,1,2
- only one among these parameters can be selected
- \param[in] adc_interrupt: the adc status flag
- one or more parameters can be selected which are shown as below:
- \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
- \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
- \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
- \param[out] none
- \retval none
-*/
-void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
-{
- ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
-}
-
-/*!
- \brief enable ADC interrupt
+ \brief enable ADC interrupt
\param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
\param[in] adc_interrupt: the adc interrupt
@@ -886,21 +909,21 @@ void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt)
{
/* enable ADC analog watchdog interrupt */
- if(0U != (adc_interrupt & ADC_INT_WDE)){
+ if(0U != (adc_interrupt & ADC_INT_WDE)) {
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_WDEIE;
- }
+ }
/* enable ADC end of group conversion interrupt */
- if(0U != (adc_interrupt & ADC_INT_EOC)){
+ if(0U != (adc_interrupt & ADC_INT_EOC)) {
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOCIE;
- }
+ }
/* enable ADC end of inserted group conversion interrupt */
- if(0U != (adc_interrupt & ADC_INT_EOIC)){
+ if(0U != (adc_interrupt & ADC_INT_EOIC)) {
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOICIE;
}
}
/*!
- \brief disable ADC interrupt
+ \brief disable ADC interrupt
\param[in] adc_periph: ADCx,x=0,1,2
only one among these parameters can be selected
\param[in] adc_interrupt: the adc interrupt flag
@@ -912,108 +935,81 @@ void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt)
\retval none
*/
void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt)
-{
+{
/* disable ADC analog watchdog interrupt */
- if(0U != (adc_interrupt & ADC_INT_WDE)){
+ if(0U != (adc_interrupt & ADC_INT_WDE)) {
ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_WDEIE;
- }
+ }
/* disable ADC end of group conversion interrupt */
- if(0U != (adc_interrupt & ADC_INT_EOC)){
+ if(0U != (adc_interrupt & ADC_INT_EOC)) {
ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_EOCIE;
- }
+ }
/* disable ADC end of inserted group conversion interrupt */
- if(0U != (adc_interrupt & ADC_INT_EOIC)){
+ if(0U != (adc_interrupt & ADC_INT_EOIC)) {
ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_EOICIE;
}
}
-
-
/*!
- \brief configure ADC resolution
+ \brief get the ADC interrupt flag
\param[in] adc_periph: ADCx,x=0,1,2
only one among these parameters can be selected
- \param[in] resolution: ADC resolution
- only one among these parameters can be selected
- \arg ADC_RESOLUTION_12B: 12-bit ADC resolution
- \arg ADC_RESOLUTION_10B: 10-bit ADC resolution
- \arg ADC_RESOLUTION_8B: 8-bit ADC resolution
- \arg ADC_RESOLUTION_6B: 6-bit ADC resolution
- \param[out] none
- \retval none
-*/
-void adc_resolution_config(uint32_t adc_periph, uint32_t resolution)
-{
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_DRES);
- ADC_OVSAMPCTL(adc_periph) |= (uint32_t)resolution;
-}
-
-/*!
- \brief configure ADC oversample mode
- \param[in] adc_periph: ADCx, x=0,1,2
- only one among these parameters can be selected
- \param[in] mode: ADC oversampling mode
- only oneparameter can be selected
- \arg ADC_OVERSAMPLING_ALL_CONVERT: all oversampled conversions for a channel are done consecutively after a trigger
- \arg ADC_OVERSAMPLING_ONE_CONVERT: each oversampled conversion for a channel needs a trigger
- \param[in] shift: ADC oversampling shift
- only oneparameter can be selected
- \arg ADC_OVERSAMPLING_SHIFT_NONE: no oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_1B: 1-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_2B: 2-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_3B: 3-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_4B: 3-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_5B: 5-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_6B: 6-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_7B: 7-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_8B: 8-bit oversampling shift
- \param[in] ratio: ADC oversampling ratio
- only oneparameter can be selected
- \arg ADC_OVERSAMPLING_RATIO_MUL2: oversampling ratio multiple 2
- \arg ADC_OVERSAMPLING_RATIO_MUL4: oversampling ratio multiple 4
- \arg ADC_OVERSAMPLING_RATIO_MUL8: oversampling ratio multiple 8
- \arg ADC_OVERSAMPLING_RATIO_MUL16: oversampling ratio multiple 16
- \arg ADC_OVERSAMPLING_RATIO_MUL32: oversampling ratio multiple 32
- \arg ADC_OVERSAMPLING_RATIO_MUL64: oversampling ratio multiple 64
- \arg ADC_OVERSAMPLING_RATIO_MUL128: oversampling ratio multiple 128
- \arg ADC_OVERSAMPLING_RATIO_MUL256: oversampling ratio multiple 256
+ \param[in] adc_interrupt: the adc interrupt bits
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
+ \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
+ \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void adc_oversample_mode_config(uint32_t adc_periph, uint8_t mode, uint16_t shift, uint8_t ratio)
+FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt)
{
- /* configure ADC oversampling mode */
- if(ADC_OVERSAMPLING_ONE_CONVERT == mode){
- ADC_OVSAMPCTL(adc_periph) |= (uint32_t)ADC_OVSAMPCTL_TOVS;
- }else{
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_TOVS);
+ FlagStatus interrupt_flag = RESET;
+ uint32_t state;
+ /* check the interrupt bits */
+ switch(adc_interrupt) {
+ case ADC_INT_FLAG_WDE:
+ /* get the ADC analog watchdog interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_WDE;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_WDEIE) && state) {
+ interrupt_flag = SET;
+ }
+ break;
+ case ADC_INT_FLAG_EOC:
+ /* get the ADC end of group conversion interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_EOC;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_EOCIE) && state) {
+ interrupt_flag = SET;
+ }
+ break;
+ case ADC_INT_FLAG_EOIC:
+ /* get the ADC end of inserted group conversion interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_EOIC;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_EOICIE) && state) {
+ interrupt_flag = SET;
+ }
+ break;
+ default:
+ break;
}
-
- /* configure the shift and ratio */
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)(ADC_OVSAMPCTL_OVSR | ADC_OVSAMPCTL_OVSS));
- ADC_OVSAMPCTL(adc_periph) |= ((uint32_t)shift | (uint32_t)ratio);
-}
-/*!
- \brief enable ADC oversample mode
- \param[in] adc_periph: ADCx,x=0,1,2
- only one among these parameters can be selected
- \param[out] none
- \retval none
-*/
-void adc_oversample_mode_enable(uint32_t adc_periph)
-{
- ADC_OVSAMPCTL(adc_periph) |= ADC_OVSAMPCTL_OVSEN;
+ return interrupt_flag;
}
/*!
- \brief disable ADC oversample mode
- \param[in] adc_periph: ADCx,x=0,1,2
+ \brief clear the ADC interrupt flag
+ \param[in] adc_periph: ADCx, x=0,1,2
only one among these parameters can be selected
+ \param[in] adc_interrupt: the adc status flag
+ one or more parameters can be selected which are shown as below:
+ \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
+ \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
+ \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
\param[out] none
\retval none
*/
-void adc_oversample_mode_disable(uint32_t adc_periph)
+void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
{
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_OVSEN);
+ ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
}
+
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_bkp.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_bkp.c
index c6081cc..687d446 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_bkp.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_bkp.c
@@ -2,43 +2,41 @@
\file gd32f20x_bkp.c
\brief BKP driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_bkp.h"
-#define TAMPER0_FLAG_SHIFT ((uint8_t)8U)
-#define TAMPER1_FLAG_SHIFT ((uint8_t)9U)
+#define TAMPER0_FLAG_SHIFT ((uint8_t)0x08U)
+#define TAMPER1_FLAG_SHIFT ((uint8_t)0x09U)
+#define TAMPER1_PIN_SHIFT ((uint8_t)0x08U)
/*!
\brief reset BKP registers
@@ -64,11 +62,11 @@ void bkp_deinit(void)
*/
void bkp_data_write(bkp_data_register_enum register_number, uint16_t data)
{
- if((register_number >= BKP_DATA_10) && (register_number <= BKP_DATA_41)){
+ if((register_number >= BKP_DATA_10) && (register_number <= BKP_DATA_41)) {
BKP_DATA10_41(register_number - 1U) = data;
- }else if((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_9)){
+ } else if((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_9)) {
BKP_DATA0_9(register_number - 1U) = data;
- }else{
+ } else {
/* illegal parameters */
}
}
@@ -84,13 +82,13 @@ void bkp_data_write(bkp_data_register_enum register_number, uint16_t data)
uint16_t bkp_data_read(bkp_data_register_enum register_number)
{
uint16_t data = 0U;
-
+
/* get the data from the BKP data register */
- if((register_number >= BKP_DATA_10) && (register_number <= BKP_DATA_41)){
+ if((register_number >= BKP_DATA_10) && (register_number <= BKP_DATA_41)) {
data = BKP_DATA10_41(register_number - 1U);
- }else if((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_9)){
+ } else if((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_9)) {
data = BKP_DATA0_9(register_number - 1U);
- }else{
+ } else {
/* illegal parameters */
}
return data;
@@ -152,7 +150,7 @@ void bkp_rtc_signal_output_disable(void)
void bkp_rtc_output_select(uint16_t outputsel)
{
uint16_t ctl = 0U;
-
+
ctl = BKP_OCTL;
ctl &= (uint16_t)~BKP_OCTL_ROSEL;
ctl |= outputsel;
@@ -160,8 +158,9 @@ void bkp_rtc_output_select(uint16_t outputsel)
}
/*!
- \brief select RTC clock output
+ \brief RTC clock output selection
\param[in] clocksel: RTC clock output selection
+ only one parameter can be selected which is shown as below:
\arg RTC_CLOCK_DIV64: RTC clock div 64
\arg RTC_CLOCK_DIV1: RTC clock
\param[out] none
@@ -170,7 +169,7 @@ void bkp_rtc_output_select(uint16_t outputsel)
void bkp_rtc_clock_output_select(uint16_t clocksel)
{
uint16_t ctl = 0U;
-
+
ctl = BKP_OCTL;
ctl &= (uint16_t)~BKP_OCTL_CCOSEL;
ctl |= clocksel;
@@ -180,7 +179,8 @@ void bkp_rtc_clock_output_select(uint16_t clocksel)
/*!
\brief RTC clock calibration direction
\param[in] direction: RTC clock calibration direction
- \arg RTC_CLOCK_SLOWED_DOWN: RTC clock slow down
+ only one parameter can be selected which is shown as below:
+ \arg RTC_CLOCK_SLOW_DOWN: RTC clock slow down
\arg RTC_CLOCK_SPEED_UP: RTC clock speed up
\param[out] none
\retval none
@@ -188,7 +188,7 @@ void bkp_rtc_clock_output_select(uint16_t clocksel)
void bkp_rtc_clock_calibration_direction(uint16_t direction)
{
uint16_t ctl = 0U;
-
+
ctl = BKP_OCTL;
ctl &= (uint16_t)~BKP_OCTL_CALDIR;
ctl |= direction;
@@ -196,7 +196,7 @@ void bkp_rtc_clock_calibration_direction(uint16_t direction)
}
/*!
- \brief set RTC clock calibration value
+ \brief set RTC clock calibration value
\param[in] value: RTC clock calibration value
\arg 0x00 - 0x7F
\param[out] none
@@ -205,7 +205,7 @@ void bkp_rtc_clock_calibration_direction(uint16_t direction)
void bkp_rtc_calibration_value_set(uint8_t value)
{
uint16_t ctl;
-
+
/* configure BKP_OCTL_RCCV with value */
ctl = BKP_OCTL;
ctl &= (uint16_t)OCTL_RCCV(0);
@@ -214,8 +214,9 @@ void bkp_rtc_calibration_value_set(uint8_t value)
}
/*!
- \brief enable tamper detection
- \param[in] tamperx
+ \brief enable tamper pin detection
+ \param[in] tamperx: BKP tamperx
+ only one parameter can be selected which is shown as below:
\arg TAMPER_0: BKP tamper0
\arg TAMPER_1: BKP tamper1
\param[out] none
@@ -223,16 +224,17 @@ void bkp_rtc_calibration_value_set(uint8_t value)
*/
void bkp_tamper_detection_enable(bkp_tamper_enum tamperx)
{
- if(TAMPER_0 == tamperx){
+ if(TAMPER_0 == tamperx) {
BKP_TPCTL0 |= (uint16_t)BKP_TPCTL0_TPEN0;
- }else{
+ } else {
BKP_TPCTL1 |= (uint16_t)BKP_TPCTL1_TPEN1;
}
}
/*!
- \brief disable tamper detection
- \param[in] tamperx
+ \brief disable tamper pin detection
+ \param[in] tamperx: BKP tamperx
+ only one parameter can be selected which is shown as below:
\arg TAMPER_0: BKP tamper0
\arg TAMPER_1: BKP tamper1
\param[out] none
@@ -240,19 +242,21 @@ void bkp_tamper_detection_enable(bkp_tamper_enum tamperx)
*/
void bkp_tamper_detection_disable(bkp_tamper_enum tamperx)
{
- if(TAMPER_0 == tamperx){
+ if(TAMPER_0 == tamperx) {
BKP_TPCTL0 &= (uint16_t)~BKP_TPCTL0_TPEN0;
- }else{
+ } else {
BKP_TPCTL1 &= (uint16_t)~BKP_TPCTL1_TPEN1;
}
}
/*!
\brief set tamper pin active level
- \param[in] tamperx
+ \param[in] tamperx: BKP tamperx
+ only one parameter can be selected which is shown as below:
\arg TAMPER_0: BKP tamper0
\arg TAMPER_1: BKP tamper1
- \param[in] level: tamper active level
+ \param[in] level: tamper pin active level
+ only one parameter can be selected which is shown as below:
\arg TAMPER_PIN_ACTIVE_HIGH: the tamper pin is active high
\arg TAMPER_PIN_ACTIVE_LOW: the tamper pin is active low
\param[out] none
@@ -262,69 +266,36 @@ void bkp_tamper_active_level_set(bkp_tamper_enum tamperx, uint16_t level)
{
uint16_t ctl = 0U;
- if(TAMPER_0 == tamperx){
+ if(TAMPER_0 == tamperx) {
ctl = BKP_TPCTL0;
ctl &= (uint16_t)~BKP_TPCTL0_TPAL0;
ctl |= level;
BKP_TPCTL0 = ctl;
- }else{
+ } else {
ctl = BKP_TPCTL1;
ctl &= (uint16_t)~BKP_TPCTL1_TPAL1;
- ctl |= level;
+ ctl |= (uint16_t)(level << TAMPER1_PIN_SHIFT);
BKP_TPCTL1 = ctl;
}
}
-/*!
- \brief enable tamper interrupt
- \param[in] tamperx
- \arg TAMPER_0: BKP tamper0
- \arg TAMPER_1: BKP tamper1
- \param[out] none
- \retval none
-*/
-void bkp_tamper_interrupt_enable(bkp_tamper_enum tamperx)
-{
- if(TAMPER_0 == tamperx){
- BKP_TPCS |= (uint16_t)BKP_TPCS_TPIE0;
- }else{
- BKP_TPCS |= (uint16_t)BKP_TPCS_TPIE1;
- }
-}
-
-/*!
- \brief disable tamper interrupt
- \param[in] tamperx
- \arg TAMPER_0: BKP tamper0
- \arg TAMPER_1: BKP tamper1
- \param[out] none
- \retval none
-*/
-void bkp_tamper_interrupt_disable(bkp_tamper_enum tamperx)
-{
- if(TAMPER_0 == tamperx){
- BKP_TPCS &= (uint16_t)~BKP_TPCS_TPIE0;
- }else{
- BKP_TPCS &= (uint16_t)~BKP_TPCS_TPIE1;
- }
-}
-
/*!
\brief waveform detect configure
- \param[in] waveform_detect_mode
+ \param[in] waveform_detect_mode:
+ only one parameter can be selected which is shown as below:
\arg BKP_WAVEFORM_DETECT_1: the first waveform detection
\arg BKP_WAVEFORM_DETECT_2: the second waveform detection
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
- \retval FlagStatus: SET or RESET
+ \retval none
*/
-void bkp_waveform_detect_enable(uint16_t waveform_detect_mode, ControlStatus newvalue)
+void bkp_waveform_detect_config(uint16_t waveform_detect_mode, ControlStatus newvalue)
{
uint16_t tpctl0 = 0U, tpctl1 = 0U, octl = 0U;
-
+
tpctl0 = BKP_TPCTL0;
tpctl1 = BKP_TPCTL1;
-
+
/* disable tamper0 and tamper1 */
tpctl0 &= (uint16_t)~BKP_TPCTL0_TPEN0;
tpctl1 &= (uint16_t)~BKP_TPCTL1_TPEN1;
@@ -339,54 +310,99 @@ void bkp_waveform_detect_enable(uint16_t waveform_detect_mode, ControlStatus new
BKP_TPCTL1 = tpctl1;
BKP_OCTL = octl;
- if(DISABLE != newvalue){
+ if(DISABLE != newvalue) {
/* enable the waveform detection function */
BKP_TPCTL1 |= waveform_detect_mode;
- }else{
+ } else {
/* disable the waveform detection function */
BKP_TPCTL1 &= (uint16_t)(~waveform_detect_mode);
}
}
/*!
- \brief get bkp flag state
- \param[in] flag
+ \brief get BKP flag
+ \param[in] flag:
+ only one parameter can be selected which is shown as below:
\arg BKP_FLAG_TAMPER0: tamper0 event flag
- \arg BKP_FLAG_TAMPER1_WAVEDETECT: tamper1/wavedetect event flag
+ \arg BKP_FLAG_TAMPER1_WAVEDETECT: tamper1/waveform detect event flag
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus bkp_flag_get(uint16_t flag)
{
- if(RESET != (BKP_TPCS & flag)){
+ if(RESET != (BKP_TPCS & flag)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear bkp flag state
- \param[in] flag
+ \brief clear BKP flag
+ \param[in] flag:
+ only one parameter can be selected which is shown as below:
\arg BKP_FLAG_TAMPER0: tamper0 event flag
- \arg BKP_FLAG_TAMPER1_WAVEDETECT: tamper1/wavedetect event flag
+ \arg BKP_FLAG_TAMPER1_WAVEDETECT: tamper1/waveform detect event flag
\param[out] none
\retval none
*/
void bkp_flag_clear(uint16_t flag)
{
- if(BKP_FLAG_TAMPER0 == flag){
+ if(BKP_FLAG_TAMPER0 == flag) {
BKP_TPCS |= (uint16_t)(flag >> TAMPER0_FLAG_SHIFT);
- }else if(BKP_FLAG_TAMPER1_WAVEDETECT == flag){
+ } else if(BKP_FLAG_TAMPER1_WAVEDETECT == flag) {
BKP_TPCS |= (uint16_t)(flag >> TAMPER1_FLAG_SHIFT);
- }else{
+ } else {
/* illegal parameters */
}
}
/*!
- \brief get bkp interrupt flag state
- \param[in] flag
+ \brief enable tamper interrupt
+ \param[in] bkp_interrupt: the BKP interrupt
+ only one parameter can be selected which is shown as below:
+ \arg BKP_INT_TAMPER0: BKP tamper0 interrupt
+ \arg BKP_INT_TAMPER1_WAVEDETECT: BKP tamper1/waveform detect interrupt
+ \param[out] none
+ \retval none
+*/
+void bkp_tamper_interrupt_enable(uint16_t bkp_interrupt)
+{
+ /* enable BKP tamper0 interrupt */
+ if(0U != (bkp_interrupt & BKP_TPCS_TPIE0)) {
+ BKP_TPCS |= (uint16_t) BKP_TPCS_TPIE0;
+ }
+ /* enable BKP tamper1/waveform detect interrupt */
+ if(0U != (bkp_interrupt & BKP_TPCS_TPIE1)) {
+ BKP_TPCS |= (uint16_t) BKP_TPCS_TPIE1;
+ }
+}
+
+/*!
+ \brief disable tamper interrupt
+ \param[in] bkp_interrupt: the BKP interrupt
+ only one parameter can be selected which is shown as below:
+ \arg BKP_INT_TAMPER0: BKP tamper0 interrupt
+ \arg BKP_INT_TAMPER1_WAVEDETECT: BKP tamper1/waveform detect interrupt
+ \param[out] none
+ \retval none
+*/
+void bkp_tamper_interrupt_disable(uint16_t bkp_interrupt)
+{
+ /* disable BKP tamper0 interrupt */
+ if(0U != (bkp_interrupt & BKP_TPCS_TPIE0)) {
+ BKP_TPCS &= (uint16_t)~BKP_TPCS_TPIE0;
+ }
+ /* disable BKP tamper1/waveform detect interrupt */
+ if(0U != (bkp_interrupt & BKP_TPCS_TPIE1)) {
+ BKP_TPCS &= (uint16_t)~BKP_TPCS_TPIE1;
+ }
+}
+
+/*!
+ \brief get BKP interrupt flag
+ \param[in] flag:
+ only one parameter can be selected which is shown as below:
\arg BKP_INT_FLAG_TAMPER0: tamper0 interrupt flag
\arg BKP_INT_FLAG_TAMPER1_WAVEDETECT: tamper1/waveform detect interrupt flag
\param[out] none
@@ -394,16 +410,17 @@ void bkp_flag_clear(uint16_t flag)
*/
FlagStatus bkp_interrupt_flag_get(uint16_t flag)
{
- if(RESET != (BKP_TPCS & flag)){
+ if(RESET != (BKP_TPCS & flag)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear bkp interrupt flag state
- \param[in] flag
+ \brief clear BKP interrupt flag
+ \param[in] flag:
+ only one parameter can be selected which is shown as below:
\arg BKP_INT_FLAG_TAMPER0: tamper0 interrupt flag
\arg BKP_INT_FLAG_TAMPER1_WAVEDETECT: tamper1/waveform detect interrupt flag
\param[out] none
@@ -411,11 +428,11 @@ FlagStatus bkp_interrupt_flag_get(uint16_t flag)
*/
void bkp_interrupt_flag_clear(uint16_t flag)
{
- if(BKP_INT_FLAG_TAMPER0 == flag){
+ if(BKP_INT_FLAG_TAMPER0 == flag) {
BKP_TPCS |= (uint16_t)(flag >> TAMPER0_FLAG_SHIFT);
- }else if(BKP_INT_FLAG_TAMPER1_WAVEDETECT == flag){
+ } else if(BKP_INT_FLAG_TAMPER1_WAVEDETECT == flag) {
BKP_TPCS |= (uint16_t)(flag >> TAMPER1_FLAG_SHIFT);
- }else{
+ } else {
/* illegal parameters */
}
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_can.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_can.c
index b1a3abe..c3fa007 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_can.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_can.c
@@ -2,61 +2,56 @@
\file gd32f20x_can.c
\brief CAN driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2019-11-27, V2.1.1, firmware for GD32F20x
- \version 2020-07-14, V2.1.2, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_can.h"
#define CAN_ERROR_HANDLE(s) do{}while(1)
-
-#define RFO1_CLEAR_VAL ((uint32_t)0x00000000U) /*!< RFO1 clear value */
-#define RFF1_CLEAR_VAL ((uint32_t)0x00000018U) /*!< RFF1 clear value */
+
+#define RFO1_CLEAR_VAL ((uint32_t)0x00000000U) /*!< RFO1 clear value */
+#define RFF1_CLEAR_VAL ((uint32_t)0x00000018U) /*!< RFF1 clear value */
/*!
- \brief deinitialize CAN
+ \brief deinitialize CAN
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[out] none
\retval none
*/
void can_deinit(uint32_t can_periph)
{
- if(CAN0 == can_periph){
+ if(CAN0 == can_periph) {
rcu_periph_reset_enable(RCU_CAN0RST);
rcu_periph_reset_disable(RCU_CAN0RST);
- }else{
+ } else {
rcu_periph_reset_enable(RCU_CAN1RST);
rcu_periph_reset_disable(RCU_CAN1RST);
}
@@ -64,7 +59,7 @@ void can_deinit(uint32_t can_periph)
/*!
\brief initialize CAN parameter struct with a default value
- \param[in] type: the type of CAN parameter struct
+ \param[in] type: the type of CAN parameter struct
only one parameter can be selected which is shown as below:
\arg CAN_INIT_STRUCT: the CAN initial struct
\arg CAN_FILTER_STRUCT: the CAN filter struct
@@ -77,67 +72,71 @@ void can_deinit(uint32_t can_periph)
void can_struct_para_init(can_struct_type_enum type, void* p_struct)
{
uint8_t i;
-
+
+ if(NULL == p_struct){
+ CAN_ERROR_HANDLE("struct parameter can not be NULL \r\n");
+ }
+
/* get type of the struct */
- switch(type){
- /* used for can_init() */
- case CAN_INIT_STRUCT:
- ((can_parameter_struct*)p_struct)->auto_bus_off_recovery = DISABLE;
- ((can_parameter_struct*)p_struct)->no_auto_retrans = DISABLE;
- ((can_parameter_struct*)p_struct)->auto_wake_up = DISABLE;
- ((can_parameter_struct*)p_struct)->prescaler = 0x03FFU;
- ((can_parameter_struct*)p_struct)->rec_fifo_overwrite = DISABLE;
- ((can_parameter_struct*)p_struct)->resync_jump_width = CAN_BT_SJW_1TQ;
- ((can_parameter_struct*)p_struct)->time_segment_1 = CAN_BT_BS1_3TQ;
- ((can_parameter_struct*)p_struct)->time_segment_2 = CAN_BT_BS2_1TQ;
- ((can_parameter_struct*)p_struct)->time_triggered = DISABLE;
- ((can_parameter_struct*)p_struct)->trans_fifo_order = DISABLE;
- ((can_parameter_struct*)p_struct)->working_mode = CAN_NORMAL_MODE;
-
- break;
- /* used for can_filter_init() */
- case CAN_FILTER_STRUCT:
- ((can_filter_parameter_struct*)p_struct)->filter_bits = CAN_FILTERBITS_32BIT;
- ((can_filter_parameter_struct*)p_struct)->filter_enable = DISABLE;
- ((can_filter_parameter_struct*)p_struct)->filter_fifo_number = CAN_FIFO0;
- ((can_filter_parameter_struct*)p_struct)->filter_list_high = 0x0000U;
- ((can_filter_parameter_struct*)p_struct)->filter_list_low = 0x0000U;
- ((can_filter_parameter_struct*)p_struct)->filter_mask_high = 0x0000U;
- ((can_filter_parameter_struct*)p_struct)->filter_mask_low = 0x0000U;
- ((can_filter_parameter_struct*)p_struct)->filter_mode = CAN_FILTERMODE_MASK;
- ((can_filter_parameter_struct*)p_struct)->filter_number = 0U;
-
- break;
- /* used for can_message_transmit() */
- case CAN_TX_MESSAGE_STRUCT:
- for(i = 0U; i < 8U; i++){
- ((can_trasnmit_message_struct*)p_struct)->tx_data[i] = 0U;
- }
-
- ((can_trasnmit_message_struct*)p_struct)->tx_dlen = 0u;
- ((can_trasnmit_message_struct*)p_struct)->tx_efid = 0U;
- ((can_trasnmit_message_struct*)p_struct)->tx_ff = (uint8_t)CAN_FF_STANDARD;
- ((can_trasnmit_message_struct*)p_struct)->tx_ft = (uint8_t)CAN_FT_DATA;
- ((can_trasnmit_message_struct*)p_struct)->tx_sfid = 0U;
-
- break;
- /* used for can_message_receive() */
- case CAN_RX_MESSAGE_STRUCT:
- for(i = 0U; i < 8U; i++){
- ((can_receive_message_struct*)p_struct)->rx_data[i] = 0U;
- }
-
- ((can_receive_message_struct*)p_struct)->rx_dlen = 0U;
- ((can_receive_message_struct*)p_struct)->rx_efid = 0U;
- ((can_receive_message_struct*)p_struct)->rx_ff = (uint8_t)CAN_FF_STANDARD;
- ((can_receive_message_struct*)p_struct)->rx_fi = 0U;
- ((can_receive_message_struct*)p_struct)->rx_ft = (uint8_t)CAN_FT_DATA;
- ((can_receive_message_struct*)p_struct)->rx_sfid = 0U;
-
- break;
-
- default:
- CAN_ERROR_HANDLE("parameter is invalid \r\n");
+ switch(type) {
+ /* used for can_init() */
+ case CAN_INIT_STRUCT:
+ ((can_parameter_struct *)p_struct)->auto_bus_off_recovery = DISABLE;
+ ((can_parameter_struct *)p_struct)->auto_retrans = DISABLE;
+ ((can_parameter_struct *)p_struct)->auto_wake_up = DISABLE;
+ ((can_parameter_struct *)p_struct)->prescaler = 0x03FFU;
+ ((can_parameter_struct *)p_struct)->rec_fifo_overwrite = DISABLE;
+ ((can_parameter_struct *)p_struct)->resync_jump_width = CAN_BT_SJW_1TQ;
+ ((can_parameter_struct *)p_struct)->time_segment_1 = CAN_BT_BS1_3TQ;
+ ((can_parameter_struct *)p_struct)->time_segment_2 = CAN_BT_BS2_1TQ;
+ ((can_parameter_struct *)p_struct)->time_triggered = DISABLE;
+ ((can_parameter_struct *)p_struct)->trans_fifo_order = DISABLE;
+ ((can_parameter_struct *)p_struct)->working_mode = CAN_NORMAL_MODE;
+
+ break;
+ /* used for can_filter_init() */
+ case CAN_FILTER_STRUCT:
+ ((can_filter_parameter_struct *)p_struct)->filter_bits = CAN_FILTERBITS_32BIT;
+ ((can_filter_parameter_struct *)p_struct)->filter_enable = DISABLE;
+ ((can_filter_parameter_struct *)p_struct)->filter_fifo_number = CAN_FIFO0;
+ ((can_filter_parameter_struct *)p_struct)->filter_list_high = 0x0000U;
+ ((can_filter_parameter_struct *)p_struct)->filter_list_low = 0x0000U;
+ ((can_filter_parameter_struct *)p_struct)->filter_mask_high = 0x0000U;
+ ((can_filter_parameter_struct *)p_struct)->filter_mask_low = 0x0000U;
+ ((can_filter_parameter_struct *)p_struct)->filter_mode = CAN_FILTERMODE_MASK;
+ ((can_filter_parameter_struct *)p_struct)->filter_number = 0U;
+
+ break;
+ /* used for can_message_transmit() */
+ case CAN_TX_MESSAGE_STRUCT:
+ for(i = 0U; i < 8U; i++) {
+ ((can_trasnmit_message_struct *)p_struct)->tx_data[i] = 0U;
+ }
+
+ ((can_trasnmit_message_struct *)p_struct)->tx_dlen = 0u;
+ ((can_trasnmit_message_struct *)p_struct)->tx_efid = 0U;
+ ((can_trasnmit_message_struct *)p_struct)->tx_ff = (uint8_t)CAN_FF_STANDARD;
+ ((can_trasnmit_message_struct *)p_struct)->tx_ft = (uint8_t)CAN_FT_DATA;
+ ((can_trasnmit_message_struct *)p_struct)->tx_sfid = 0U;
+
+ break;
+ /* used for can_message_receive() */
+ case CAN_RX_MESSAGE_STRUCT:
+ for(i = 0U; i < 8U; i++) {
+ ((can_receive_message_struct *)p_struct)->rx_data[i] = 0U;
+ }
+
+ ((can_receive_message_struct *)p_struct)->rx_dlen = 0U;
+ ((can_receive_message_struct *)p_struct)->rx_efid = 0U;
+ ((can_receive_message_struct *)p_struct)->rx_ff = (uint8_t)CAN_FF_STANDARD;
+ ((can_receive_message_struct *)p_struct)->rx_fi = 0U;
+ ((can_receive_message_struct *)p_struct)->rx_ft = (uint8_t)CAN_FT_DATA;
+ ((can_receive_message_struct *)p_struct)->rx_sfid = 0U;
+
+ break;
+
+ default:
+ CAN_ERROR_HANDLE("parameter is invalid \r\n");
}
}
@@ -153,7 +152,7 @@ void can_struct_para_init(can_struct_type_enum type, void* p_struct)
\arg time_triggered: ENABLE or DISABLE
\arg auto_bus_off_recovery: ENABLE or DISABLE
\arg auto_wake_up: ENABLE or DISABLE
- \arg no_auto_retrans: ENABLE or DISABLE
+ \arg auto_retrans: ENABLE or DISABLE
\arg rec_fifo_overwrite: ENABLE or DISABLE
\arg trans_fifo_order: ENABLE or DISABLE
\arg prescaler: 0x0001 - 0x0400
@@ -164,158 +163,159 @@ ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init
{
uint32_t timeout = CAN_TIMEOUT;
ErrStatus flag = ERROR;
-
+
/* disable sleep mode */
CAN_CTL(can_periph) &= ~CAN_CTL_SLPWMOD;
/* enable initialize mode */
CAN_CTL(can_periph) |= CAN_CTL_IWMOD;
/* wait ACK */
- while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)){
+ while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)) {
timeout--;
}
/* check initialize working success */
- if(CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)){
+ if(CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) {
flag = ERROR;
- }else{
+ } else {
/* set the bit timing register */
CAN_BT(can_periph) = (BT_MODE((uint32_t)can_parameter_init->working_mode) | \
BT_SJW((uint32_t)can_parameter_init->resync_jump_width) | \
BT_BS1((uint32_t)can_parameter_init->time_segment_1) | \
BT_BS2((uint32_t)can_parameter_init->time_segment_2) | \
BT_BAUDPSC(((uint32_t)(can_parameter_init->prescaler) - 1U)));
+
/* time trigger communication mode */
- if(ENABLE == can_parameter_init->time_triggered){
+ if(ENABLE == can_parameter_init->time_triggered) {
CAN_CTL(can_periph) |= CAN_CTL_TTC;
- }else{
+ } else {
CAN_CTL(can_periph) &= ~CAN_CTL_TTC;
}
- /* automatic bus-off managment */
- if(ENABLE == can_parameter_init->auto_bus_off_recovery){
+ /* automatic bus-off management */
+ if(ENABLE == can_parameter_init->auto_bus_off_recovery) {
CAN_CTL(can_periph) |= CAN_CTL_ABOR;
- }else{
+ } else {
CAN_CTL(can_periph) &= ~CAN_CTL_ABOR;
}
/* automatic wakeup mode */
- if(ENABLE == can_parameter_init->auto_wake_up){
+ if(ENABLE == can_parameter_init->auto_wake_up) {
CAN_CTL(can_periph) |= CAN_CTL_AWU;
- }else{
+ } else {
CAN_CTL(can_periph) &= ~CAN_CTL_AWU;
}
- /* automatic retransmission mode disable*/
- if(ENABLE == can_parameter_init->no_auto_retrans){
- CAN_CTL(can_periph) |= CAN_CTL_ARD;
- }else{
+ /* automatic retransmission mode disable */
+ if(ENABLE == can_parameter_init->auto_retrans) {
CAN_CTL(can_periph) &= ~CAN_CTL_ARD;
+ } else {
+ CAN_CTL(can_periph) |= CAN_CTL_ARD;
}
- /* receive fifo overwrite mode */
- if(ENABLE == can_parameter_init->rec_fifo_overwrite){
- CAN_CTL(can_periph) |= CAN_CTL_RFOD;
- }else{
+ /* receive fifo overwrite mode */
+ if(ENABLE == can_parameter_init->rec_fifo_overwrite) {
CAN_CTL(can_periph) &= ~CAN_CTL_RFOD;
- }
+ } else {
+ CAN_CTL(can_periph) |= CAN_CTL_RFOD;
+ }
/* transmit fifo order */
- if(ENABLE == can_parameter_init->trans_fifo_order){
+ if(ENABLE == can_parameter_init->trans_fifo_order) {
CAN_CTL(can_periph) |= CAN_CTL_TFO;
- }else{
+ } else {
CAN_CTL(can_periph) &= ~CAN_CTL_TFO;
- }
+ }
/* disable initialize mode */
CAN_CTL(can_periph) &= ~CAN_CTL_IWMOD;
timeout = CAN_TIMEOUT;
/* wait the ACK */
- while((CAN_STAT_IWS == (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)){
+ while((CAN_STAT_IWS == (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)) {
timeout--;
}
/* check exit initialize mode */
- if(0U != timeout){
+ if(0U != timeout) {
flag = SUCCESS;
}
- }
+ }
return flag;
}
/*!
- \brief initialize CAN filter
+ \brief initialize CAN filter
\param[in] can_filter_parameter_init: struct for CAN filter initialization
\arg filter_list_high: 0x0000 - 0xFFFF
\arg filter_list_low: 0x0000 - 0xFFFF
\arg filter_mask_high: 0x0000 - 0xFFFF
\arg filter_mask_low: 0x0000 - 0xFFFF
- \arg filter_fifo_number: CAN_FIFO0, CAN_FIFO1
+ \arg filter_fifo_number: CAN_FIFO0, CAN_FIFO1
\arg filter_number: 0 - 27
\arg filter_mode: CAN_FILTERMODE_MASK, CAN_FILTERMODE_LIST
- \arg filter_bits: CAN_FILTERBITS_32BIT, CAN_FILTERBITS_16BIT
+ \arg filter_bits: CAN_FILTERBITS_32BIT, CAN_FILTERBITS_16BIT
\arg filter_enable: ENABLE or DISABLE
\param[out] none
\retval none
*/
-void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
+void can_filter_init(can_filter_parameter_struct *can_filter_parameter_init)
{
uint32_t val = 0U;
-
+
val = ((uint32_t)1) << (can_filter_parameter_init->filter_number);
/* filter lock disable */
CAN_FCTL(CAN0) |= CAN_FCTL_FLD;
/* disable filter */
CAN_FW(CAN0) &= ~(uint32_t)val;
-
+
/* filter 16 bits */
- if(CAN_FILTERBITS_16BIT == can_filter_parameter_init->filter_bits){
+ if(CAN_FILTERBITS_16BIT == can_filter_parameter_init->filter_bits) {
/* set filter 16 bits */
CAN_FSCFG(CAN0) &= ~(uint32_t)val;
/* first 16 bits list and first 16 bits mask or first 16 bits list and second 16 bits list */
CAN_FDATA0(CAN0, can_filter_parameter_init->filter_number) = \
- FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS) | \
- FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
+ FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS) | \
+ FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
/* second 16 bits list and second 16 bits mask or third 16 bits list and fourth 16 bits list */
CAN_FDATA1(CAN0, can_filter_parameter_init->filter_number) = \
- FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) | \
- FDATA_MASK_LOW((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS);
+ FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) | \
+ FDATA_MASK_LOW((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS);
}
/* filter 32 bits */
- if(CAN_FILTERBITS_32BIT == can_filter_parameter_init->filter_bits){
+ if(CAN_FILTERBITS_32BIT == can_filter_parameter_init->filter_bits) {
/* set filter 32 bits */
CAN_FSCFG(CAN0) |= (uint32_t)val;
/* 32 bits list or first 32 bits list */
CAN_FDATA0(CAN0, can_filter_parameter_init->filter_number) = \
- FDATA_MASK_HIGH((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS) |
- FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
+ FDATA_MASK_HIGH((can_filter_parameter_init->filter_list_high) & CAN_FILTER_MASK_16BITS) |
+ FDATA_MASK_LOW((can_filter_parameter_init->filter_list_low) & CAN_FILTER_MASK_16BITS);
/* 32 bits mask or second 32 bits list */
CAN_FDATA1(CAN0, can_filter_parameter_init->filter_number) = \
- FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) |
- FDATA_MASK_LOW((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS);
+ FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) |
+ FDATA_MASK_LOW((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS);
}
-
+
/* filter mode */
- if(CAN_FILTERMODE_MASK == can_filter_parameter_init->filter_mode){
+ if(CAN_FILTERMODE_MASK == can_filter_parameter_init->filter_mode) {
/* mask mode */
CAN_FMCFG(CAN0) &= ~(uint32_t)val;
- }else{
+ } else {
/* list mode */
CAN_FMCFG(CAN0) |= (uint32_t)val;
}
-
+
/* filter FIFO */
- if(CAN_FIFO0 == (can_filter_parameter_init->filter_fifo_number)){
+ if(CAN_FIFO0 == (can_filter_parameter_init->filter_fifo_number)) {
/* FIFO0 */
CAN_FAFIFO(CAN0) &= ~(uint32_t)val;
- }else{
+ } else {
/* FIFO1 */
CAN_FAFIFO(CAN0) |= (uint32_t)val;
}
-
+
/* filter working */
- if(ENABLE == can_filter_parameter_init->filter_enable){
-
+ if(ENABLE == can_filter_parameter_init->filter_enable) {
+
CAN_FW(CAN0) |= (uint32_t)val;
}
-
+
/* filter lock enable */
CAN_FCTL(CAN0) &= ~CAN_FCTL_FLD;
}
/*!
- \brief set CAN1 fliter start bank number
+ \brief set CAN1 filter start bank number
\param[in] start_bank: CAN1 start bank number
only one parameter can be selected which is shown as below:
\arg (1..27)
@@ -329,14 +329,14 @@ void can1_filter_start_bank(uint8_t start_bank)
/* set CAN1 filter start number */
CAN_FCTL(CAN0) &= ~(uint32_t)CAN_FCTL_HBC1F;
CAN_FCTL(CAN0) |= FCTL_HBC1F(start_bank);
- /* filter lock enaable */
+ /* filter lock enable */
CAN_FCTL(CAN0) &= ~CAN_FCTL_FLD;
}
/*!
\brief enable CAN debug freeze
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[out] none
\retval none
*/
@@ -345,9 +345,9 @@ void can_debug_freeze_enable(uint32_t can_periph)
/* set DFZ bit */
CAN_CTL(can_periph) |= CAN_CTL_DFZ;
- if(CAN0 == can_periph){
+ if(CAN0 == can_periph) {
dbg_periph_enable(DBG_CAN0_HOLD);
- }else{
+ } else {
dbg_periph_enable(DBG_CAN1_HOLD);
}
}
@@ -364,9 +364,9 @@ void can_debug_freeze_disable(uint32_t can_periph)
/* set DFZ bit */
CAN_CTL(can_periph) &= ~CAN_CTL_DFZ;
- if(CAN0 == can_periph){
+ if(CAN0 == can_periph) {
dbg_periph_disable(DBG_CAN0_HOLD);
- }else{
+ } else {
dbg_periph_disable(DBG_CAN1_HOLD);
}
}
@@ -381,11 +381,11 @@ void can_debug_freeze_disable(uint32_t can_periph)
void can_time_trigger_mode_enable(uint32_t can_periph)
{
uint8_t mailbox_number;
-
- /* enable the tcc mode */
+
+ /* enable the TTC mode */
CAN_CTL(can_periph) |= CAN_CTL_TTC;
/* enable time stamp */
- for(mailbox_number=0U; mailbox_number<3U; mailbox_number++){
+ for(mailbox_number = 0U; mailbox_number < 3U; mailbox_number++) {
CAN_TMP(can_periph, mailbox_number) |= CAN_TMP_TSEN;
}
}
@@ -399,20 +399,20 @@ void can_time_trigger_mode_enable(uint32_t can_periph)
*/
void can_time_trigger_mode_disable(uint32_t can_periph)
{
- uint8_t mailbox_number;
-
- /* disable the TCC mode */
+ uint8_t mailbox_number;
+
+ /* disable the TTC mode */
CAN_CTL(can_periph) &= ~CAN_CTL_TTC;
/* reset TSEN bits */
- for(mailbox_number=0U; mailbox_number<3U; mailbox_number++){
+ for(mailbox_number = 0U; mailbox_number < 3U; mailbox_number++) {
CAN_TMP(can_periph, mailbox_number) &= ~CAN_TMP_TSEN;
}
}
/*!
- \brief transmit CAN message
+ \brief transmit CAN message
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[in] transmit_message: struct for CAN transmit message
\arg tx_sfid: 0x00000000 - 0x000007FF
\arg tx_efid: 0x00000000 - 0x1FFFFFFF
@@ -423,48 +423,48 @@ void can_time_trigger_mode_disable(uint32_t can_periph)
\param[out] none
\retval mailbox_number
*/
-uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* transmit_message)
+uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct *transmit_message)
{
uint8_t mailbox_number = CAN_MAILBOX0;
/* select one empty mailbox */
- if(CAN_TSTAT_TME0 == (CAN_TSTAT(can_periph)&CAN_TSTAT_TME0)){
+ if(CAN_TSTAT_TME0 == (CAN_TSTAT(can_periph)&CAN_TSTAT_TME0)) {
mailbox_number = CAN_MAILBOX0;
- }else if(CAN_TSTAT_TME1 == (CAN_TSTAT(can_periph)&CAN_TSTAT_TME1)){
+ } else if(CAN_TSTAT_TME1 == (CAN_TSTAT(can_periph)&CAN_TSTAT_TME1)) {
mailbox_number = CAN_MAILBOX1;
- }else if(CAN_TSTAT_TME2 == (CAN_TSTAT(can_periph)&CAN_TSTAT_TME2)){
+ } else if(CAN_TSTAT_TME2 == (CAN_TSTAT(can_periph)&CAN_TSTAT_TME2)) {
mailbox_number = CAN_MAILBOX2;
- }else{
+ } else {
mailbox_number = CAN_NOMAILBOX;
}
/* return no mailbox empty */
- if(CAN_NOMAILBOX == mailbox_number){
+ if(CAN_NOMAILBOX == mailbox_number) {
return CAN_NOMAILBOX;
}
-
+
CAN_TMI(can_periph, mailbox_number) &= CAN_TMI_TEN;
- if(CAN_FF_STANDARD == transmit_message->tx_ff){
+ if(CAN_FF_STANDARD == transmit_message->tx_ff) {
/* set transmit mailbox standard identifier */
CAN_TMI(can_periph, mailbox_number) |= (uint32_t)(TMI_SFID(transmit_message->tx_sfid) | \
- transmit_message->tx_ft);
- }else{
+ transmit_message->tx_ft);
+ } else {
/* set transmit mailbox extended identifier */
CAN_TMI(can_periph, mailbox_number) |= (uint32_t)(TMI_EFID(transmit_message->tx_efid) | \
- transmit_message->tx_ff | \
- transmit_message->tx_ft);
+ transmit_message->tx_ff | \
+ transmit_message->tx_ft);
}
/* set the data length */
- CAN_TMP(can_periph, mailbox_number) &= ((uint32_t)~CAN_TMP_DLENC);
+ CAN_TMP(can_periph, mailbox_number) &= ~CAN_TMP_DLENC;
CAN_TMP(can_periph, mailbox_number) |= transmit_message->tx_dlen;
/* set the data */
CAN_TMDATA0(can_periph, mailbox_number) = TMDATA0_DB3(transmit_message->tx_data[3]) | \
- TMDATA0_DB2(transmit_message->tx_data[2]) | \
- TMDATA0_DB1(transmit_message->tx_data[1]) | \
- TMDATA0_DB0(transmit_message->tx_data[0]);
+ TMDATA0_DB2(transmit_message->tx_data[2]) | \
+ TMDATA0_DB1(transmit_message->tx_data[1]) | \
+ TMDATA0_DB0(transmit_message->tx_data[0]);
CAN_TMDATA1(can_periph, mailbox_number) = TMDATA1_DB7(transmit_message->tx_data[7]) | \
- TMDATA1_DB6(transmit_message->tx_data[6]) | \
- TMDATA1_DB5(transmit_message->tx_data[5]) | \
- TMDATA1_DB4(transmit_message->tx_data[4]);
+ TMDATA1_DB6(transmit_message->tx_data[6]) | \
+ TMDATA1_DB5(transmit_message->tx_data[5]) | \
+ TMDATA1_DB4(transmit_message->tx_data[4]);
/* enable transmission */
CAN_TMI(can_periph, mailbox_number) |= CAN_TMI_TEN;
@@ -472,7 +472,7 @@ uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* t
}
/*!
- \brief get CAN transmit state
+ \brief get CAN transmit state
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] mailbox_number
@@ -485,9 +485,9 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
{
can_transmit_state_enum state = CAN_TRANSMIT_FAILED;
uint32_t val = 0U;
-
- /* check selected mailbox state */
- switch(mailbox_number){
+
+ /* check selected mailbox state */
+ switch(mailbox_number) {
/* mailbox0 */
case CAN_MAILBOX0:
val = CAN_TSTAT(can_periph) & (CAN_TSTAT_MTF0 | CAN_TSTAT_MTFNERR0 | CAN_TSTAT_TME0);
@@ -504,26 +504,26 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
val = CAN_TRANSMIT_FAILED;
break;
}
-
- switch(val){
- /* transmit pending */
- case (CAN_STATE_PENDING):
+
+ switch(val) {
+ /* transmit pending */
+ case(CAN_STATE_PENDING):
state = CAN_TRANSMIT_PENDING;
break;
- /* mailbox0 transmit succeeded */
- case (CAN_TSTAT_MTF0 | CAN_TSTAT_MTFNERR0 | CAN_TSTAT_TME0):
+ /* mailbox0 transmit succeeded */
+ case(CAN_TSTAT_MTF0 | CAN_TSTAT_MTFNERR0 | CAN_TSTAT_TME0):
state = CAN_TRANSMIT_OK;
break;
- /* mailbox1 transmit succeeded */
- case (CAN_TSTAT_MTF1 | CAN_TSTAT_MTFNERR1 | CAN_TSTAT_TME1):
+ /* mailbox1 transmit succeeded */
+ case(CAN_TSTAT_MTF1 | CAN_TSTAT_MTFNERR1 | CAN_TSTAT_TME1):
state = CAN_TRANSMIT_OK;
break;
- /* mailbox2 transmit succeeded */
- case (CAN_TSTAT_MTF2 | CAN_TSTAT_MTFNERR2 | CAN_TSTAT_TME2):
+ /* mailbox2 transmit succeeded */
+ case(CAN_TSTAT_MTF2 | CAN_TSTAT_MTFNERR2 | CAN_TSTAT_TME2):
state = CAN_TRANSMIT_OK;
break;
- /* transmit failed */
- default:
+ /* transmit failed */
+ default:
state = CAN_TRANSMIT_FAILED;
break;
}
@@ -542,19 +542,19 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
*/
void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
{
- if(CAN_MAILBOX0 == mailbox_number){
+ if(CAN_MAILBOX0 == mailbox_number) {
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST0;
- while(CAN_TSTAT_MST0 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST0)){
+ while(CAN_TSTAT_MST0 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST0)) {
}
- }else if(CAN_MAILBOX1 == mailbox_number){
+ } else if(CAN_MAILBOX1 == mailbox_number) {
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST1;
- while(CAN_TSTAT_MST1 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST1)){
+ while(CAN_TSTAT_MST1 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST1)) {
}
- }else if(CAN_MAILBOX2 == mailbox_number){
+ } else if(CAN_MAILBOX2 == mailbox_number) {
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST2;
- while(CAN_TSTAT_MST2 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST2)){
+ while(CAN_TSTAT_MST2 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST2)) {
}
- }else{
+ } else {
/* illegal parameters */
}
}
@@ -562,7 +562,7 @@ void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
/*!
\brief CAN receive message
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[in] fifo_number
\arg CAN_FIFOx(x=0,1)
\param[out] receive_message: struct for CAN receive message
@@ -575,24 +575,24 @@ void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
\arg rx_fi: 0 - 27
\retval none
*/
-void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct* receive_message)
+void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct *receive_message)
{
/* get the frame format */
receive_message->rx_ff = (uint8_t)(CAN_RFIFOMI_FF & CAN_RFIFOMI(can_periph, fifo_number));
- if(CAN_FF_STANDARD == receive_message->rx_ff){
+ if(CAN_FF_STANDARD == receive_message->rx_ff) {
/* get standard identifier */
- receive_message -> rx_sfid = (uint32_t)(GET_RFIFOMI_SFID(CAN_RFIFOMI(can_periph, fifo_number)));
- }else{
+ receive_message->rx_sfid = (uint32_t)(GET_RFIFOMI_SFID(CAN_RFIFOMI(can_periph, fifo_number)));
+ } else {
/* get extended identifier */
- receive_message -> rx_efid = (uint32_t)(GET_RFIFOMI_EFID(CAN_RFIFOMI(can_periph, fifo_number)));
+ receive_message->rx_efid = (uint32_t)(GET_RFIFOMI_EFID(CAN_RFIFOMI(can_periph, fifo_number)));
}
/* get frame type */
- receive_message -> rx_ft = (uint8_t)(CAN_RFIFOMI_FT & CAN_RFIFOMI(can_periph, fifo_number));
- /* get recevie data length */
- receive_message -> rx_dlen = (uint8_t)(GET_RFIFOMP_DLENC(CAN_RFIFOMP(can_periph, fifo_number)));
+ receive_message->rx_ft = (uint8_t)(CAN_RFIFOMI_FT & CAN_RFIFOMI(can_periph, fifo_number));
/* filtering index */
- receive_message -> rx_fi = (uint8_t)(GET_RFIFOMP_FI(CAN_RFIFOMP(can_periph, fifo_number)));
+ receive_message->rx_fi = (uint8_t)(GET_RFIFOMP_FI(CAN_RFIFOMP(can_periph, fifo_number)));
+ /* get receive data length */
+ receive_message->rx_dlen = (uint8_t)(GET_RFIFOMP_DLENC(CAN_RFIFOMP(can_periph, fifo_number)));
/* receive data */
receive_message -> rx_data[0] = (uint8_t)(GET_RFIFOMDATA0_DB0(CAN_RFIFOMDATA0(can_periph, fifo_number)));
@@ -605,15 +605,15 @@ void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_m
receive_message -> rx_data[7] = (uint8_t)(GET_RFIFOMDATA1_DB7(CAN_RFIFOMDATA1(can_periph, fifo_number)));
/* release FIFO */
- if(CAN_FIFO0 == fifo_number){
+ if(CAN_FIFO0 == fifo_number) {
CAN_RFIFO0(can_periph) |= CAN_RFIFO0_RFD0;
- }else{
+ } else {
CAN_RFIFO1(can_periph) |= CAN_RFIFO1_RFD1;
}
}
/*!
- \brief release FIFO0
+ \brief release FIFO
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] fifo_number
@@ -624,11 +624,11 @@ void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_m
*/
void can_fifo_release(uint32_t can_periph, uint8_t fifo_number)
{
- if(CAN_FIFO0 == fifo_number){
+ if(CAN_FIFO0 == fifo_number) {
CAN_RFIFO0(can_periph) |= CAN_RFIFO0_RFD0;
- }else if(CAN_FIFO1 == fifo_number){
+ } else if(CAN_FIFO1 == fifo_number) {
CAN_RFIFO1(can_periph) |= CAN_RFIFO1_RFD1;
- }else{
+ } else {
/* illegal parameters */
CAN_ERROR_HANDLE("CAN FIFO NUM is invalid \r\n");
}
@@ -640,21 +640,21 @@ void can_fifo_release(uint32_t can_periph, uint8_t fifo_number)
\arg CANx(x=0,1)
\param[in] fifo_number
only one parameter can be selected which is shown as below:
- \arg CAN_FIFOx(x=0,1)
+ \arg CAN_FIFOx(x=0,1)
\param[out] none
\retval message length
*/
uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number)
{
uint8_t val = 0U;
-
- if(CAN_FIFO0 == fifo_number){
+
+ if(CAN_FIFO0 == fifo_number) {
/* FIFO0 */
val = (uint8_t)(CAN_RFIFO0(can_periph) & CAN_RFIF_RFL_MASK);
- }else if(CAN_FIFO1 == fifo_number){
+ } else if(CAN_FIFO1 == fifo_number) {
/* FIFO1 */
val = (uint8_t)(CAN_RFIFO1(can_periph) & CAN_RFIF_RFL_MASK);
- }else{
+ } else {
/* illegal parameters */
}
return val;
@@ -663,7 +663,7 @@ uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number)
/*!
\brief set CAN working mode
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[in] can_working_mode
only one parameter can be selected which is shown as below:
\arg CAN_MODE_INITIALIZE
@@ -676,49 +676,49 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
{
ErrStatus flag = ERROR;
/* timeout for IWS or also for SLPWS bits */
- uint32_t timeout = CAN_TIMEOUT;
-
- if(CAN_MODE_INITIALIZE == working_mode){
+ uint32_t timeout = CAN_TIMEOUT;
+
+ if(CAN_MODE_INITIALIZE == working_mode) {
/* disable sleep mode */
CAN_CTL(can_periph) &= (~(uint32_t)CAN_CTL_SLPWMOD);
/* set initialize mode */
CAN_CTL(can_periph) |= (uint8_t)CAN_CTL_IWMOD;
/* wait the acknowledge */
- while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)){
+ while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)) {
timeout--;
}
- if(CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)){
+ if(CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) {
flag = ERROR;
- }else{
+ } else {
flag = SUCCESS;
}
- }else if(CAN_MODE_NORMAL == working_mode){
+ } else if(CAN_MODE_NORMAL == working_mode) {
/* enter normal mode */
CAN_CTL(can_periph) &= ~(uint32_t)(CAN_CTL_SLPWMOD | CAN_CTL_IWMOD);
/* wait the acknowledge */
- while((0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))) && (0U != timeout)){
+ while((0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))) && (0U != timeout)) {
timeout--;
}
- if(0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))){
+ if(0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))) {
flag = ERROR;
- }else{
+ } else {
flag = SUCCESS;
}
- }else if(CAN_MODE_SLEEP == working_mode){
+ } else if(CAN_MODE_SLEEP == working_mode) {
/* disable initialize mode */
CAN_CTL(can_periph) &= (~(uint32_t)CAN_CTL_IWMOD);
/* set sleep mode */
CAN_CTL(can_periph) |= (uint8_t)CAN_CTL_SLPWMOD;
/* wait the acknowledge */
- while((CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (0U != timeout)){
+ while((CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (0U != timeout)) {
timeout--;
}
- if(CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)){
+ if(CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) {
flag = ERROR;
- }else{
+ } else {
flag = SUCCESS;
}
- }else{
+ } else {
flag = ERROR;
}
return flag;
@@ -727,7 +727,7 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
/*!
\brief wake up CAN
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -735,17 +735,17 @@ ErrStatus can_wakeup(uint32_t can_periph)
{
ErrStatus flag = ERROR;
uint32_t timeout = CAN_TIMEOUT;
-
+
/* wakeup */
CAN_CTL(can_periph) &= ~CAN_CTL_SLPWMOD;
-
- while((0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (0x00U != timeout)){
+
+ while((0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (0x00U != timeout)) {
timeout--;
}
/* check state */
- if(0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)){
+ if(0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) {
flag = ERROR;
- }else{
+ } else {
flag = SUCCESS;
}
return flag;
@@ -770,7 +770,7 @@ can_error_enum can_error_get(uint32_t can_periph)
{
can_error_enum error;
error = CAN_ERROR_NONE;
-
+
/* get error type */
error = (can_error_enum)(GET_ERR_ERRN(CAN_ERR(can_periph)));
return error;
@@ -779,14 +779,14 @@ can_error_enum can_error_get(uint32_t can_periph)
/*!
\brief get CAN receive error number
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[out] none
\retval error number
*/
uint8_t can_receive_error_number_get(uint32_t can_periph)
{
uint8_t val;
-
+
/* get error count */
val = (uint8_t)(GET_ERR_RECNT(CAN_ERR(can_periph)));
return val;
@@ -795,74 +795,18 @@ uint8_t can_receive_error_number_get(uint32_t can_periph)
/*!
\brief get CAN transmit error number
\param[in] can_periph
- \arg CANx(x=0,1)
+ \arg CANx(x=0,1)
\param[out] none
\retval error number
*/
uint8_t can_transmit_error_number_get(uint32_t can_periph)
{
uint8_t val;
-
+
val = (uint8_t)(GET_ERR_TECNT(CAN_ERR(can_periph)));
return val;
}
-/*!
- \brief enable CAN interrupt
- \param[in] can_periph
- \arg CANx(x=0,1)
- \param[in] interrupt
- one or more parameters can be selected which are shown as below:
- \arg CAN_INT_TME: transmit mailbox empty interrupt enable
- \arg CAN_INT_RFNE0: receive FIFO0 not empty interrupt enable
- \arg CAN_INT_RFF0: receive FIFO0 full interrupt enable
- \arg CAN_INT_RFO0: receive FIFO0 overfull interrupt enable
- \arg CAN_INT_RFNE1: receive FIFO1 not empty interrupt enable
- \arg CAN_INT_RFF1: receive FIFO1 full interrupt enable
- \arg CAN_INT_RFO1: receive FIFO1 overfull interrupt enable
- \arg CAN_INT_WERR: warning error interrupt enable
- \arg CAN_INT_PERR: passive error interrupt enable
- \arg CAN_INT_BO: bus-off interrupt enable
- \arg CAN_INT_ERRN: error number interrupt enable
- \arg CAN_INT_ERR: error interrupt enable
- \arg CAN_INT_WAKEUP: wakeup interrupt enable
- \arg CAN_INT_SLPW: sleep working interrupt enable
- \param[out] none
- \retval none
-*/
-void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt)
-{
- CAN_INTEN(can_periph) |= interrupt;
-}
-
-/*!
- \brief disable CAN interrupt
- \param[in] can_periph
- \arg CANx(x=0,1)
- \param[in] interrupt
- one or more parameters can be selected which are shown as below:
- \arg CAN_INT_TME: transmit mailbox empty interrupt enable
- \arg CAN_INT_RFNE0: receive FIFO0 not empty interrupt enable
- \arg CAN_INT_RFF0: receive FIFO0 full interrupt enable
- \arg CAN_INT_RFO0: receive FIFO0 overfull interrupt enable
- \arg CAN_INT_RFNE1: receive FIFO1 not empty interrupt enable
- \arg CAN_INT_RFF1: receive FIFO1 full interrupt enable
- \arg CAN_INT_RFO1: receive FIFO1 overfull interrupt enable
- \arg CAN_INT_WERR: warning error interrupt enable
- \arg CAN_INT_PERR: passive error interrupt enable
- \arg CAN_INT_BO: bus-off interrupt enable
- \arg CAN_INT_ERRN: error number interrupt enable
- \arg CAN_INT_ERR: error interrupt enable
- \arg CAN_INT_WAKEUP: wakeup interrupt enable
- \arg CAN_INT_SLPW: sleep working interrupt enable
- \param[out] none
- \retval none
-*/
-void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
-{
- CAN_INTEN(can_periph) &= ~interrupt;
-}
-
/*!
\brief get CAN flag state
\param[in] can_periph
@@ -878,9 +822,9 @@ void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
\arg CAN_FLAG_ERRIF: error flag
\arg CAN_FLAG_SLPWS: sleep working state
\arg CAN_FLAG_IWS: initial working state
- \arg CAN_FLAG_TMLS2: transmit mailbox 2 last sending in Tx FIFO
- \arg CAN_FLAG_TMLS1: transmit mailbox 1 last sending in Tx FIFO
- \arg CAN_FLAG_TMLS0: transmit mailbox 0 last sending in Tx FIFO
+ \arg CAN_FLAG_TMLS2: transmit mailbox 2 last sending in TX FIFO
+ \arg CAN_FLAG_TMLS1: transmit mailbox 1 last sending in TX FIFO
+ \arg CAN_FLAG_TMLS0: transmit mailbox 0 last sending in TX FIFO
\arg CAN_FLAG_TME2: transmit mailbox 2 empty
\arg CAN_FLAG_TME1: transmit mailbox 1 empty
\arg CAN_FLAG_TME0: transmit mailbox 0 empty
@@ -907,11 +851,11 @@ void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
\retval FlagStatus: SET or RESET
*/
FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag)
-{
+{
/* get flag and interrupt enable state */
- if(RESET != (CAN_REG_VAL(can_periph, flag) & BIT(CAN_BIT_POS(flag)))){
+ if(RESET != (CAN_REG_VAL(can_periph, flag) & BIT(CAN_BIT_POS(flag)))) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -946,15 +890,71 @@ FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag)
*/
void can_flag_clear(uint32_t can_periph, can_flag_enum flag)
{
- if (flag == CAN_FLAG_RFO1){
+ if(flag == CAN_FLAG_RFO1) {
CAN_REG_VAL(can_periph, flag) = RFO1_CLEAR_VAL;
- } else if (flag == CAN_FLAG_RFF1){
+ } else if(flag == CAN_FLAG_RFF1) {
CAN_REG_VAL(can_periph, flag) = RFF1_CLEAR_VAL;
} else {
CAN_REG_VAL(can_periph, flag) = BIT(CAN_BIT_POS(flag));
}
}
+/*!
+ \brief enable CAN interrupt
+ \param[in] can_periph
+ \arg CANx(x=0,1)
+ \param[in] interrupt
+ one or more parameters can be selected which are shown as below:
+ \arg CAN_INT_TME: transmit mailbox empty interrupt enable
+ \arg CAN_INT_RFNE0: receive FIFO0 not empty interrupt enable
+ \arg CAN_INT_RFF0: receive FIFO0 full interrupt enable
+ \arg CAN_INT_RFO0: receive FIFO0 overfull interrupt enable
+ \arg CAN_INT_RFNE1: receive FIFO1 not empty interrupt enable
+ \arg CAN_INT_RFF1: receive FIFO1 full interrupt enable
+ \arg CAN_INT_RFO1: receive FIFO1 overfull interrupt enable
+ \arg CAN_INT_WERR: warning error interrupt enable
+ \arg CAN_INT_PERR: passive error interrupt enable
+ \arg CAN_INT_BO: bus-off interrupt enable
+ \arg CAN_INT_ERRN: error number interrupt enable
+ \arg CAN_INT_ERR: error interrupt enable
+ \arg CAN_INT_WAKEUP: wakeup interrupt enable
+ \arg CAN_INT_SLPW: sleep working interrupt enable
+ \param[out] none
+ \retval none
+*/
+void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt)
+{
+ CAN_INTEN(can_periph) |= interrupt;
+}
+
+/*!
+ \brief disable CAN interrupt
+ \param[in] can_periph
+ \arg CANx(x=0,1)
+ \param[in] interrupt
+ one or more parameters can be selected which are shown as below:
+ \arg CAN_INT_TME: transmit mailbox empty interrupt enable
+ \arg CAN_INT_RFNE0: receive FIFO0 not empty interrupt enable
+ \arg CAN_INT_RFF0: receive FIFO0 full interrupt enable
+ \arg CAN_INT_RFO0: receive FIFO0 overfull interrupt enable
+ \arg CAN_INT_RFNE1: receive FIFO1 not empty interrupt enable
+ \arg CAN_INT_RFF1: receive FIFO1 full interrupt enable
+ \arg CAN_INT_RFO1: receive FIFO1 overfull interrupt enable
+ \arg CAN_INT_WERR: warning error interrupt enable
+ \arg CAN_INT_PERR: passive error interrupt enable
+ \arg CAN_INT_BO: bus-off interrupt enable
+ \arg CAN_INT_ERRN: error number interrupt enable
+ \arg CAN_INT_ERR: error interrupt enable
+ \arg CAN_INT_WAKEUP: wakeup interrupt enable
+ \arg CAN_INT_SLPW: sleep working interrupt enable
+ \param[out] none
+ \retval none
+*/
+void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
+{
+ CAN_INTEN(can_periph) &= ~interrupt;
+}
+
/*!
\brief get CAN interrupt flag state
\param[in] can_periph
@@ -984,22 +984,22 @@ FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum f
{
uint32_t ret1 = RESET;
uint32_t ret2 = RESET;
-
- /* get the staus of interrupt flag */
- if (flag == CAN_INT_FLAG_RFL0) {
+
+ /* get the status of interrupt flag */
+ if(flag == CAN_INT_FLAG_RFL0) {
ret1 = can_receive_message_length_get(can_periph, CAN_FIFO0);
- } else if (flag == CAN_INT_FLAG_RFL1) {
+ } else if(flag == CAN_INT_FLAG_RFL1) {
ret1 = can_receive_message_length_get(can_periph, CAN_FIFO1);
- } else if (flag == CAN_INT_FLAG_ERRN) {
+ } else if(flag == CAN_INT_FLAG_ERRN) {
ret1 = can_error_get(can_periph);
} else {
ret1 = CAN_REG_VALS(can_periph, flag) & BIT(CAN_BIT_POS0(flag));
}
- /* get the staus of interrupt enale bit */
+ /* get the status of interrupt enable bit */
ret2 = CAN_INTEN(can_periph) & BIT(CAN_BIT_POS1(flag));
- if(ret1 && ret2){
+ if(ret1 && ret2) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -1025,9 +1025,9 @@ FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum f
*/
void can_interrupt_flag_clear(uint32_t can_periph, can_interrupt_flag_enum flag)
{
- if (flag == CAN_INT_FLAG_RFO1){
+ if(flag == CAN_INT_FLAG_RFO1) {
CAN_REG_VALS(can_periph, flag) = RFO1_CLEAR_VAL;
- } else if (flag == CAN_INT_FLAG_RFF1){
+ } else if(flag == CAN_INT_FLAG_RFF1) {
CAN_REG_VALS(can_periph, flag) = RFF1_CLEAR_VAL;
} else {
CAN_REG_VALS(can_periph, flag) = BIT(CAN_BIT_POS0(flag));
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau.c
index d0fd887..2b4ee8f 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau.c
@@ -2,36 +2,33 @@
\file gd32f20x_cau.c
\brief CAU driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,7 +39,7 @@ OF SUCH DAMAGE.
/*!
\brief reset the CAU peripheral
- \param[in] none
+ \param[in] none
\param[out] none
\retval none
*/
@@ -63,8 +60,8 @@ void cau_deinit(void)
void cau_enable(void)
{
/* enable the CAU processor */
- CAU_CTL |= CAU_CTL_CAUEN;
-}
+ CAU_CTL |= CAU_CTL_CAUEN;
+}
/*!
\brief disable the CAU peripheral
@@ -82,7 +79,7 @@ void cau_disable(void)
\brief enable the CAU DMA interface
\param[in] dma_req: specify the CAU DMA transfer request to be enabled
one or more parameters can be selected which are shown as below
- \arg CAU_DMA_INFIFO: DMA for incoming(Rx) data transfer
+ \arg CAU_DMA_INFIFO: DMA for incoming(Rx) data transfer
\arg CAU_DMA_OUTFIFO: DMA for outgoing(Tx) data transfer
\param[out] none
\retval none
@@ -97,7 +94,7 @@ void cau_dma_enable(uint32_t dma_req)
\brief disable the CAU DMA interface
\param[in] dma_req: specify the CAU DMA transfer request to be disabled
one or more parameters can be selected which are shown as below
- \arg CAU_DMA_INFIFO: DMA for incoming(Rx) data transfer
+ \arg CAU_DMA_INFIFO: DMA for incoming(Rx) data transfer
\arg CAU_DMA_OUTFIFO: DMA for outgoing(Tx) data transfer
\param[out] none
\retval none
@@ -123,27 +120,27 @@ void cau_dma_disable(uint32_t dma_req)
\arg CAU_MODE_AES_ECB: AES-ECB (AES Electronic codebook)
\arg CAU_MODE_AES_CBC: AES-CBC (AES Cipher block chaining)
\arg CAU_MODE_AES_CTR: AES-CTR (AES counter mode)
- \arg CAU_MODE_AES_KEY: AES decryption key preparation mode
+ \arg CAU_MODE_AES_KEY: AES decryption key preparation mode
\param[in] swapping: data swapping selection
only one parameter can be selected which is shown as below
\arg CAU_SWAPPING_32BIT: no swapping
\arg CAU_SWAPPING_16BIT: half-word swapping
\arg CAU_SWAPPING_8BIT: bytes swapping
- \arg CAU_SWAPPING_1BIT: bit swapping
+ \arg CAU_SWAPPING_1BIT: bit swapping
\param[out] none
\retval none
*/
void cau_init(uint32_t algo_dir, uint32_t algo_mode, uint32_t swapping)
-{
- /* select algorithm mode */
+{
+ /* select algorithm mode */
CAU_CTL &= ~CAU_CTL_ALGM;
CAU_CTL |= algo_mode;
-
- /* select data swapping */
+
+ /* select data swapping */
CAU_CTL &= ~CAU_CTL_DATAM;
CAU_CTL |= swapping;
- /* select algorithm direction */
+ /* select algorithm direction */
CAU_CTL &= ~CAU_CTL_CAUDIR;
CAU_CTL |= algo_dir;
}
@@ -153,16 +150,16 @@ void cau_init(uint32_t algo_dir, uint32_t algo_mode, uint32_t swapping)
\param[in] key_size: key length selection when aes mode
only one parameter can be selected which is shown as below
\arg CAU_KEYSIZE_128BIT: 128 bit key length
- \arg CAU_KEYSIZE_192BIT: 192 bit key length
- \arg CAU_KEYSIZE_256BIT: 256 bit key length
+ \arg CAU_KEYSIZE_192BIT: 192 bit key length
+ \arg CAU_KEYSIZE_256BIT: 256 bit key length
\param[out] none
\retval none
*/
void cau_aes_keysize_config(uint32_t key_size)
{
CAU_CTL &= ~CAU_CTL_KEYM;
- CAU_CTL |= key_size;
-}
+ CAU_CTL |= key_size;
+}
/*!
\brief initialize the key parameters
@@ -178,7 +175,7 @@ void cau_aes_keysize_config(uint32_t key_size)
\param[out] none
\retval none
*/
-void cau_key_init(cau_key_parameter_struct* key_initpara)
+void cau_key_init(cau_key_parameter_struct *key_initpara)
{
CAU_KEY0H = key_initpara->key_0_high;
CAU_KEY0L = key_initpara->key_0_low;
@@ -204,7 +201,7 @@ void cau_key_init(cau_key_parameter_struct* key_initpara)
\param[out] none
\retval none
*/
-void cau_key_parameter_init(cau_key_parameter_struct* key_initpara)
+void cau_key_parameter_init(cau_key_parameter_struct *key_initpara)
{
key_initpara->key_0_high = 0U;
key_initpara->key_0_low = 0U;
@@ -226,7 +223,7 @@ void cau_key_parameter_init(cau_key_parameter_struct* key_initpara)
\param[out] none
\retval none
*/
-void cau_iv_init(cau_iv_parameter_struct* iv_initpara)
+void cau_iv_init(cau_iv_parameter_struct *iv_initpara)
{
CAU_IV0H = iv_initpara->iv_0_high;
CAU_IV0L = iv_initpara->iv_0_low;
@@ -244,7 +241,7 @@ void cau_iv_init(cau_iv_parameter_struct* iv_initpara)
\param[out] none
\retval none
*/
-void cau_iv_parameter_init(cau_iv_parameter_struct* iv_initpara)
+void cau_iv_parameter_init(cau_iv_parameter_struct *iv_initpara)
{
iv_initpara->iv_0_high = 0U;
iv_initpara->iv_0_low = 0U;
@@ -273,7 +270,7 @@ void cau_fifo_flush(void)
ControlStatus cau_enable_state_get(void)
{
ControlStatus ret = DISABLE;
- if(RESET != (CAU_CTL & CAU_CTL_CAUEN)){
+ if(RESET != (CAU_CTL & CAU_CTL_CAUEN)) {
ret = ENABLE;
}
return ret;
@@ -305,13 +302,13 @@ uint32_t cau_data_read(void)
\brief get the CAU flag status
\param[in] flag: CAU flag status
only one parameter can be selected which is shown as below
- \arg CAU_FLAG_INFIFO_EMPTY: input FIFO empty
+ \arg CAU_FLAG_INFIFO_EMPTY: input FIFO empty
\arg CAU_FLAG_INFIFO_NO_FULL: input FIFO is not full
- \arg CAU_FLAG_OUTFIFO_NO_EMPTY: output FIFO not empty
+ \arg CAU_FLAG_OUTFIFO_NO_EMPTY: output FIFO not empty
\arg CAU_FLAG_OUTFIFO_FULL: output FIFO is full
- \arg CAU_FLAG_BUSY: the CAU core is busy
+ \arg CAU_FLAG_BUSY: the CAU core is busy
\arg CAU_FLAG_INFIFO: input FIFO flag status
- \arg CAU_FLAG_OUTFIFO: output FIFO flag status
+ \arg CAU_FLAG_OUTFIFO: output FIFO flag status
\param[out] none
\retval FlagStatus: SET or RESET
*/
@@ -321,18 +318,18 @@ FlagStatus cau_flag_get(uint32_t flag)
FlagStatus ret_flag = RESET;
/* check if the flag is in CAU_STAT1 register */
- if(RESET != (flag & FLAG_MASK)){
+ if(RESET != (flag & FLAG_MASK)) {
reg = CAU_STAT1;
- }else{
+ } else {
/* the flag is in CAU_STAT0 register */
reg = CAU_STAT0;
}
/* check the status of the specified CAU flag */
- if(RESET != (reg & flag)){
+ if(RESET != (reg & flag)) {
ret_flag = SET;
}
-
+
return ret_flag;
}
@@ -340,7 +337,7 @@ FlagStatus cau_flag_get(uint32_t flag)
\brief enable the CAU interrupts
\param[in] interrupt: specify the CAU interrupt source to be enabled
one or more parameters can be selected which are shown as below
- \arg CAU_INT_INFIFO: input FIFO interrupt
+ \arg CAU_INT_INFIFO: input FIFO interrupt
\arg CAU_INT_OUTFIFO: output FIFO interrupt
\param[out] none
\retval none
@@ -355,7 +352,7 @@ void cau_interrupt_enable(uint32_t interrupt)
\brief disable the CAU interrupts
\param[in] interrupt: specify the CAU interrupt source to be disabled
one or more parameters can be selected which are shown as below
- \arg CAU_INT_INFIFO: input FIFO interrupt
+ \arg CAU_INT_INFIFO: input FIFO interrupt
\arg CAU_INT_OUTFIFO: output FIFO interrupt
\param[out] none
\retval none
@@ -370,7 +367,7 @@ void cau_interrupt_disable(uint32_t interrupt)
\brief get the interrupt flag
\param[in] int_flag: CAU interrupt flag
only one parameter can be selected which is shown as below
- \arg CAU_INT_FLAG_INFIFO: input FIFO interrupt
+ \arg CAU_INT_FLAG_INFIFO: input FIFO interrupt
\arg CAU_INT_FLAG_OUTFIFO: output FIFO interrupt
\param[out] none
\retval FlagStatus: SET or RESET
@@ -378,11 +375,11 @@ void cau_interrupt_disable(uint32_t interrupt)
FlagStatus cau_interrupt_flag_get(uint32_t int_flag)
{
FlagStatus flag = RESET;
-
+
/* check the status of the specified CAU interrupt */
- if(RESET != (CAU_INTF & int_flag)){
+ if(RESET != (CAU_INTF & int_flag)) {
flag = SET;
}
-
+
return flag;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_aes.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_aes.c
index e998013..f70d7ad 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_aes.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_aes.c
@@ -2,36 +2,33 @@
\file gd32f20x_cau_aes.c
\brief CAU_AES driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -40,7 +37,7 @@ OF SUCH DAMAGE.
#define AESBSY_TIMEOUT ((uint32_t)0x00010000U)
/* AES key structure parameter config */
-static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter_struct* cau_key_initpara);
+static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter_struct *cau_key_initpara);
/* AES calculate process */
static ErrStatus cau_aes_calculate(uint8_t *input, uint32_t in_length, uint8_t *output);
@@ -52,7 +49,7 @@ static ErrStatus cau_aes_calculate(uint8_t *input, uint32_t in_length, uint8_t *
\arg CAU_DECRYPT: decrypt
\param[in] key: key used for AES algorithm
\param[in] keysize: length of the key, must be a 128, 192 or 256
- \param[in] text: pointer to the text information struct
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 16
output: pointer to the returned buffer
@@ -71,32 +68,32 @@ ErrStatus cau_aes_ecb(uint32_t algo_dir, uint8_t *key, uint16_t keysize, cau_tex
/* AES key structure parameter config */
cau_aes_key_config(key, keysize, &key_initpara);
/* key initialization */
- cau_key_init(&key_initpara);
+ cau_key_init(&key_initpara);
/* AES decryption */
- if(CAU_DECRYPT == algo_dir){
+ if(CAU_DECRYPT == algo_dir) {
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
/* initialize the CAU peripheral */
- cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT);
+ cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT);
/* enable the CAU peripheral */
cau_enable();
/* wait until the busy flag is RESET */
- do{
+ do {
busystatus = cau_flag_get(CAU_FLAG_BUSY);
counter++;
- }while((AESBSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((AESBSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
}
}
-
+
/* initialize the CAU peripheral */
cau_init(algo_dir, CAU_MODE_AES_ECB, CAU_SWAPPING_8BIT);
-
+
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
@@ -118,14 +115,14 @@ ErrStatus cau_aes_ecb(uint32_t algo_dir, uint8_t *key, uint16_t keysize, cau_tex
\arg CAU_DECRYPT: decrypt
\param[in] key: key used for AES algorithm
\param[in] keysize: length of the key, must be a 128, 192 or 256
- \param[in] iv: initialization vectors used for TDES algorithm
- \param[in] text: pointer to the text information struct
+ \param[in] iv: initialization vectors used for TDES algorithm
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 16
output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus cau_aes_cbc(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t iv[16], cau_text_struct *text)
{
ErrStatus ret = ERROR;
@@ -133,7 +130,7 @@ ErrStatus cau_aes_cbc(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t
cau_iv_parameter_struct iv_initpara;
__IO uint32_t counter = 0U;
uint32_t busystatus = 0U;
-
+
uint32_t ivaddr = (uint32_t)iv;
/* key structure initialization */
@@ -141,41 +138,41 @@ ErrStatus cau_aes_cbc(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t
/* AES key structure parameter config */
cau_aes_key_config(key, keysize, &key_initpara);
/* key initialization */
- cau_key_init(&key_initpara);
+ cau_key_init(&key_initpara);
/* AES decryption */
- if(CAU_DECRYPT == algo_dir){
+ if(CAU_DECRYPT == algo_dir) {
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
/* initialize the CAU peripheral */
- cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT);
+ cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT);
/* enable the CAU peripheral */
cau_enable();
/* wait until the busy flag is RESET */
- do{
+ do {
busystatus = cau_flag_get(CAU_FLAG_BUSY);
counter++;
- }while((AESBSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((AESBSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
}
}
-
+
/* initialize the CAU peripheral */
cau_init(algo_dir, CAU_MODE_AES_CBC, CAU_SWAPPING_8BIT);
-
+
/* vectors initialization */
- iv_initpara.iv_0_high = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_high = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_0_low = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_low = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_1_high = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_1_high = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_1_low = __REV(*(uint32_t*)(ivaddr));
- cau_iv_init(&iv_initpara);
+ iv_initpara.iv_1_low = __REV(*(uint32_t *)(ivaddr));
+ cau_iv_init(&iv_initpara);
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
@@ -198,40 +195,40 @@ ErrStatus cau_aes_cbc(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t
\arg CAU_DECRYPT: decrypt
\param[in] key: key used for AES algorithm
\param[in] keysize: length of the key, must be a 128, 192 or 256
- \param[in] iv: initialization vectors used for TDES algorithm
- \param[in] text: pointer to the text information struct
+ \param[in] iv: initialization vectors used for TDES algorithm
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 16
output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus cau_aes_ctr(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t iv[16], cau_text_struct *text)
{
ErrStatus ret = ERROR;
cau_key_parameter_struct key_initpara;
cau_iv_parameter_struct iv_initpara;
-
+
uint32_t ivaddr = (uint32_t)iv;
/* key structure initialization */
cau_key_parameter_init(&key_initpara);
/* initialize the CAU peripheral */
- cau_init(algo_dir, CAU_MODE_AES_CTR, CAU_SWAPPING_8BIT);
-
+ cau_init(algo_dir, CAU_MODE_AES_CTR, CAU_SWAPPING_8BIT);
+
/* AES key structure parameter config */
cau_aes_key_config(key, keysize, &key_initpara);
/* key initialization */
cau_key_init(&key_initpara);
-
+
/* vectors initialization */
- iv_initpara.iv_0_high = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_high = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_0_low = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_low = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_1_high = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_1_high = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_1_low = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_1_low = __REV(*(uint32_t *)(ivaddr));
cau_iv_init(&iv_initpara);
/* flush the IN and OUT FIFOs */
@@ -250,7 +247,7 @@ ErrStatus cau_aes_ctr(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t
/*!
\brief AES key structure parameter config
\param[in] key: key used for AES algorithm
- \param[in] keysize: length of the key, must be a 128, 192 or 256
+ \param[in] keysize: length of the key, must be a 128, 192 or 256
\param[out] cau_key_initpara: key init parameter struct
key_0_high: key 0 high
key_0_low: key 0 low
@@ -262,52 +259,52 @@ ErrStatus cau_aes_ctr(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t
key_3_low: key 3 low
\retval none
*/
-static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter_struct* cau_key_initpara)
+static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter_struct *cau_key_initpara)
{
uint32_t keyaddr = (uint32_t)key;
-
- switch(keysize){
- case 128:
+
+ switch(keysize) {
+ case 128:
cau_aes_keysize_config(CAU_KEYSIZE_128BIT);
- cau_key_initpara->key_2_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_2_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_2_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_2_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_3_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_3_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_3_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_3_low = __REV(*(uint32_t *)(keyaddr));
break;
case 192:
cau_aes_keysize_config(CAU_KEYSIZE_192BIT);
- cau_key_initpara->key_1_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_1_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_1_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_1_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_2_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_2_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_2_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_2_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_3_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_3_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_3_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_3_low = __REV(*(uint32_t *)(keyaddr));
break;
case 256:
cau_aes_keysize_config(CAU_KEYSIZE_256BIT);
- cau_key_initpara->key_0_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_0_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_0_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_0_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_1_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_1_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_1_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_1_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_2_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_2_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_2_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_2_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_3_high = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_3_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- cau_key_initpara->key_3_low = __REV(*(uint32_t*)(keyaddr));
+ cau_key_initpara->key_3_low = __REV(*(uint32_t *)(keyaddr));
break;
default:
break;
@@ -316,9 +313,9 @@ static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter
/*!
\brief AES calculate process
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer, must be a multiple of 16
- \param[in] output: pointer to the returned buffer
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer, must be a multiple of 16
+ \param[in] output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -328,45 +325,45 @@ static ErrStatus cau_aes_calculate(uint8_t *input, uint32_t in_length, uint8_t *
uint32_t outputaddr = (uint32_t)output;
uint32_t i = 0U;
__IO uint32_t counter = 0U;
- uint32_t busystatus = 0U;
-
- /* the clock is not enabled or there is no embeded CAU peripheral */
- if(DISABLE == cau_enable_state_get()){
+ uint32_t busystatus = 0U;
+
+ /* the clock is not enabled or there is no embeded CAU peripheral */
+ if(DISABLE == cau_enable_state_get()) {
return ERROR;
}
- for(i = 0U; i < in_length; i += 16U){
+ for(i = 0U; i < in_length; i += 16U) {
/* write data to the IN FIFO */
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
+ inputaddr += 4U;
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
- cau_data_write(*(uint32_t*)(inputaddr));
- inputaddr += 4U;
/* wait until the complete message has been processed */
counter = 0U;
- do{
+ do {
busystatus = cau_flag_get(CAU_FLAG_BUSY);
counter++;
- }while((AESBSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((AESBSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* read the output block from the output FIFO */
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
+ outputaddr += 4U;
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = cau_data_read();
- outputaddr += 4U;
}
}
-
+
return SUCCESS;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_des.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_des.c
index 3bcc398..82c646c 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_des.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_des.c
@@ -2,36 +2,33 @@
\file gd32f20x_cau_des.c
\brief CAU_DES driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -48,14 +45,14 @@ static ErrStatus cau_des_calculate(uint8_t *input, uint32_t in_length, uint8_t *
only one parameter can be selected which is shown as below
\arg CAU_ENCRYPT: encrypt
\arg CAU_DECRYPT: decrypt
- \param[in] key: key used for DES algorithm
- \param[in] text: pointer to the text information struct
+ \param[in] key: key used for DES algorithm
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 8
output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus cau_des_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text)
{
ErrStatus ret = ERROR;
@@ -66,12 +63,12 @@ ErrStatus cau_des_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text)
/* key structure initialization */
cau_key_parameter_init(&key_initpara);
/* initialize the CAU peripheral */
- cau_init(algo_dir, CAU_MODE_DES_ECB, CAU_SWAPPING_8BIT);
-
- /* key initialisation */
- key_initpara.key_1_high = __REV(*(uint32_t*)(keyaddr));
+ cau_init(algo_dir, CAU_MODE_DES_ECB, CAU_SWAPPING_8BIT);
+
+ /* key initialization */
+ key_initpara.key_1_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_1_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_1_low = __REV(*(uint32_t *)(keyaddr));
cau_key_init(& key_initpara);
/* flush the IN and OUT FIFOs */
@@ -84,7 +81,7 @@ ErrStatus cau_des_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text)
/* disable the CAU peripheral */
cau_disable();
- return ret;
+ return ret;
}
/*!
@@ -94,11 +91,11 @@ ErrStatus cau_des_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text)
\arg CAU_ENCRYPT: encrypt
\arg CAU_DECRYPT: decrypt
\param[in] key: key used for DES algorithm
- \param[in] iv: initialization vectors used for TDES algorithm
- \param[in] text: pointer to the text information struct
+ \param[in] iv: initialization vectors used for TDES algorithm
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 8
- output: pointer to the returned buffer
+ output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -115,17 +112,17 @@ ErrStatus cau_des_cbc(uint32_t algo_dir, uint8_t key[24], uint8_t iv[8], cau_tex
cau_key_parameter_init(&key_initpara);
/* initialize the CAU peripheral */
cau_init(algo_dir, CAU_MODE_DES_CBC, CAU_SWAPPING_8BIT);
-
- /* key initialisation */
- key_initpara.key_1_high = __REV(*(uint32_t*)(keyaddr));
+
+ /* key initialization */
+ key_initpara.key_1_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_1_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_1_low = __REV(*(uint32_t *)(keyaddr));
cau_key_init(&key_initpara);
/* vectors initialization */
- iv_initpara.iv_0_high = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_high = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_0_low= __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_low = __REV(*(uint32_t *)(ivaddr));
cau_iv_init(&iv_initpara);
/* flush the IN and OUT FIFOs */
@@ -138,14 +135,14 @@ ErrStatus cau_des_cbc(uint32_t algo_dir, uint8_t key[24], uint8_t iv[8], cau_tex
/* disable the CAU peripheral */
cau_disable();
- return ret;
+ return ret;
}
/*!
\brief DES calculate process
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer, must be a multiple of 8
- \param[in] output: pointer to the returned buffer
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer, must be a multiple of 8
+ \param[in] output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -155,37 +152,37 @@ static ErrStatus cau_des_calculate(uint8_t *input, uint32_t in_length, uint8_t *
uint32_t outputaddr = (uint32_t)output;
uint32_t i = 0U;
__IO uint32_t counter = 0U;
- uint32_t busystatus = 0U;
-
- /* the clock is not enabled or there is no embeded CAU peripheral */
- if(DISABLE == cau_enable_state_get()){
+ uint32_t busystatus = 0U;
+
+ /* the clock is not enabled or there is no embeded CAU peripheral */
+ if(DISABLE == cau_enable_state_get()) {
return ERROR;
}
- for(i = 0U; i < in_length; i += 8U){
+ for(i = 0U; i < in_length; i += 8U) {
/* write data to the IN FIFO */
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
/* wait until the complete message has been processed */
counter = 0U;
- do{
+ do {
busystatus = cau_flag_get(CAU_FLAG_BUSY);
counter++;
- }while((DESBUSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((DESBUSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* read the output block from the output FIFO */
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
}
}
-
+
return SUCCESS;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_tdes.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_tdes.c
index aa69822..b555c93 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_tdes.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_cau_tdes.c
@@ -2,36 +2,33 @@
\file gd32f20x_cau_tdes.c
\brief CAU_TDES driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -48,14 +45,14 @@ static ErrStatus cau_tdes_calculate(uint8_t *input, uint32_t in_length, uint8_t
only one parameter can be selected which is shown as below
\arg CAU_ENCRYPT: encrypt
\arg CAU_DECRYPT: decrypt
- \param[in] key: key used for TDES algorithm
- \param[in] text: pointer to the text information struct
+ \param[in] key: key used for TDES algorithm
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 8
output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus cau_tdes_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text)
{
ErrStatus ret = ERROR;
@@ -69,17 +66,17 @@ ErrStatus cau_tdes_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text
cau_init(algo_dir, CAU_MODE_TDES_ECB, CAU_SWAPPING_8BIT);
/* key initialization */
- key_initpara.key_1_high = __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_1_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_1_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_1_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_2_high = __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_2_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_2_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_2_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_3_high = __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_3_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_3_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_3_low = __REV(*(uint32_t *)(keyaddr));
cau_key_init(&key_initpara);
/* flush the IN and OUT FIFOs */
@@ -92,7 +89,7 @@ ErrStatus cau_tdes_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text
/* disable the CAU peripheral */
cau_disable();
- return ret;
+ return ret;
}
/*!
@@ -102,20 +99,20 @@ ErrStatus cau_tdes_ecb(uint32_t algo_dir, uint8_t key[24], cau_text_struct *text
\arg CAU_ENCRYPT: encrypt
\arg CAU_DECRYPT: decrypt
\param[in] key: key used for TDES algorithm
- \param[in] iv: initialization vectors used for TDES algorithm
- \param[in] text: pointer to the text information struct
+ \param[in] iv: initialization vectors used for TDES algorithm
+ \param[in] text: pointer to the text information struct
input: pointer to the input buffer
in_length: length of the input buffer, must be a multiple of 8
output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus cau_tdes_cbc(uint32_t algo_dir, uint8_t key[24], uint8_t iv[8], cau_text_struct *text)
{
ErrStatus ret = ERROR;
cau_key_parameter_struct key_initpara;
cau_iv_parameter_struct iv_initpara;
-
+
uint32_t keyaddr = (uint32_t)key;
uint32_t ivaddr = (uint32_t)iv;
@@ -123,25 +120,25 @@ ErrStatus cau_tdes_cbc(uint32_t algo_dir, uint8_t key[24], uint8_t iv[8], cau_te
cau_key_parameter_init(&key_initpara);
/* initialize the CAU peripheral */
cau_init(algo_dir, CAU_MODE_TDES_CBC, CAU_SWAPPING_8BIT);
-
+
/* key initialization */
- key_initpara.key_1_high = __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_1_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_1_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_1_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_2_high = __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_2_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_2_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_2_low = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_3_high = __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_3_high = __REV(*(uint32_t *)(keyaddr));
keyaddr += 4U;
- key_initpara.key_3_low= __REV(*(uint32_t*)(keyaddr));
+ key_initpara.key_3_low = __REV(*(uint32_t *)(keyaddr));
cau_key_init(&key_initpara);
/* vectors initialization */
- iv_initpara.iv_0_high = __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_high = __REV(*(uint32_t *)(ivaddr));
ivaddr += 4U;
- iv_initpara.iv_0_low= __REV(*(uint32_t*)(ivaddr));
+ iv_initpara.iv_0_low = __REV(*(uint32_t *)(ivaddr));
cau_iv_init(&iv_initpara);
/* flush the IN and OUT FIFOs */
@@ -154,14 +151,14 @@ ErrStatus cau_tdes_cbc(uint32_t algo_dir, uint8_t key[24], uint8_t iv[8], cau_te
/* disable the CAU peripheral */
cau_disable();
- return ret;
+ return ret;
}
/*!
\brief TDES calculate process
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer, must be a multiple of 8
- \param[in] output: pointer to the returned buffer
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer, must be a multiple of 8
+ \param[in] output: pointer to the returned buffer
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -171,37 +168,37 @@ static ErrStatus cau_tdes_calculate(uint8_t *input, uint32_t in_length, uint8_t
uint32_t outputaddr = (uint32_t)output;
uint32_t i = 0U;
__IO uint32_t counter = 0U;
- uint32_t busystatus = 0U;
-
- /* the clock is not enabled or there is no embeded CAU peripheral */
- if(DISABLE == cau_enable_state_get()){
+ uint32_t busystatus = 0U;
+
+ /* the clock is not enabled or there is no embedded CAU peripheral */
+ if(DISABLE == cau_enable_state_get()) {
return ERROR;
}
- for(i = 0U; i < in_length; i += 8U){
+ for(i = 0U; i < in_length; i += 8U) {
/* write data to the IN FIFO */
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
- cau_data_write(*(uint32_t*)(inputaddr));
+ cau_data_write(*(uint32_t *)(inputaddr));
inputaddr += 4U;
/* wait until the complete message has been processed */
counter = 0U;
- do{
+ do {
busystatus = cau_flag_get(CAU_FLAG_BUSY);
counter++;
- }while((TDESBSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((TDESBSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* read the output block from the output FIFO */
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = cau_data_read();
+ *(uint32_t *)(outputaddr) = cau_data_read();
outputaddr += 4U;
}
}
-
+
return SUCCESS;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_crc.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_crc.c
index 418b681..a8ca8fa 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_crc.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_crc.c
@@ -2,36 +2,33 @@
\file gd32f20x_crc.c
\brief CRC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -54,7 +51,7 @@ void crc_deinit(void)
}
/*!
- \brief reset data register to the value of initializaiton data register
+ \brief reset data register to the value of initialization data register
\param[in] none
\param[out] none
\retval none
@@ -65,7 +62,7 @@ void crc_data_register_reset(void)
}
/*!
- \brief read the value of the data register
+ \brief read the value of the data register
\param[in] none
\param[out] none
\retval 32-bit value of the data register
@@ -123,7 +120,7 @@ uint32_t crc_single_data_calculate(uint32_t sdata)
uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size)
{
uint32_t index;
- for(index = 0U; index < size; index++){
+ for(index = 0U; index < size; index++) {
CRC_DATA = array[index];
}
return (CRC_DATA);
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dac.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dac.c
index 1677143..a638fe9 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dac.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dac.c
@@ -2,36 +2,33 @@
\file gd32f20x_dac.c
\brief DAC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -63,12 +60,12 @@ void dac_deinit(void)
*/
void dac_enable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL |= DAC_CTL_DEN0;
- }else{
+ } else {
DAC_CTL |= DAC_CTL_DEN1;
}
-}
+}
/*!
\brief disable DAC
@@ -79,9 +76,9 @@ void dac_enable(uint32_t dac_periph)
*/
void dac_disable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL &= ~DAC_CTL_DEN0;
- }else{
+ } else {
DAC_CTL &= ~DAC_CTL_DEN1;
}
}
@@ -95,9 +92,9 @@ void dac_disable(uint32_t dac_periph)
*/
void dac_dma_enable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL |= DAC_CTL_DDMAEN0;
- }else{
+ } else {
DAC_CTL |= DAC_CTL_DDMAEN1;
}
}
@@ -111,9 +108,9 @@ void dac_dma_enable(uint32_t dac_periph)
*/
void dac_dma_disable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL &= ~DAC_CTL_DDMAEN0;
- }else{
+ } else {
DAC_CTL &= ~DAC_CTL_DDMAEN1;
}
}
@@ -127,9 +124,9 @@ void dac_dma_disable(uint32_t dac_periph)
*/
void dac_output_buffer_enable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL &= ~DAC_CTL_DBOFF0;
- }else{
+ } else {
DAC_CTL &= ~DAC_CTL_DBOFF1;
}
}
@@ -143,9 +140,9 @@ void dac_output_buffer_enable(uint32_t dac_periph)
*/
void dac_output_buffer_disable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL |= DAC_CTL_DBOFF0;
- }else{
+ } else {
DAC_CTL |= DAC_CTL_DBOFF1;
}
}
@@ -160,10 +157,10 @@ void dac_output_buffer_disable(uint32_t dac_periph)
uint16_t dac_output_value_get(uint32_t dac_periph)
{
uint16_t data = 0U;
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
/* store the DAC0 output value */
data = (uint16_t)DAC0_DO;
- }else{
+ } else {
/* store the DAC1 output value */
data = (uint16_t)DAC1_DO;
}
@@ -185,8 +182,8 @@ uint16_t dac_output_value_get(uint32_t dac_periph)
*/
void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
{
- if(DAC0 == dac_periph){
- switch(dac_align){
+ if(DAC0 == dac_periph) {
+ switch(dac_align) {
/* data right 12b alignment */
case DAC_ALIGN_12B_R:
DAC0_R12DH = data;
@@ -202,8 +199,8 @@ void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
default:
break;
}
- }else{
- switch(dac_align){
+ } else {
+ switch(dac_align) {
/* data right 12b alignment */
case DAC_ALIGN_12B_R:
DAC1_R12DH = data;
@@ -231,9 +228,9 @@ void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
*/
void dac_trigger_enable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL |= DAC_CTL_DTEN0;
- }else{
+ } else {
DAC_CTL |= DAC_CTL_DTEN1;
}
}
@@ -247,9 +244,9 @@ void dac_trigger_enable(uint32_t dac_periph)
*/
void dac_trigger_disable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_CTL &= ~DAC_CTL_DTEN0;
- }else{
+ } else {
DAC_CTL &= ~DAC_CTL_DTEN1;
}
}
@@ -273,11 +270,11 @@ void dac_trigger_disable(uint32_t dac_periph)
*/
void dac_trigger_source_config(uint32_t dac_periph, uint32_t triggersource)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
/* configure DAC0 trigger source */
DAC_CTL &= ~DAC_CTL_DTSEL0;
DAC_CTL |= triggersource;
- }else{
+ } else {
/* configure DAC1 trigger source */
DAC_CTL &= ~DAC_CTL_DTSEL1;
DAC_CTL |= (triggersource << DAC1_REG_OFFSET);
@@ -292,9 +289,9 @@ void dac_trigger_source_config(uint32_t dac_periph, uint32_t triggersource)
*/
void dac_software_trigger_enable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_SWT |= DAC_SWT_SWTR0;
- }else{
+ } else {
DAC_SWT |= DAC_SWT_SWTR1;
}
}
@@ -308,9 +305,9 @@ void dac_software_trigger_enable(uint32_t dac_periph)
*/
void dac_software_trigger_disable(uint32_t dac_periph)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
DAC_SWT &= ~DAC_SWT_SWTR0;
- }else{
+ } else {
DAC_SWT &= ~DAC_SWT_SWTR1;
}
}
@@ -329,11 +326,11 @@ void dac_software_trigger_disable(uint32_t dac_periph)
*/
void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
/* configure DAC0 wave mode */
DAC_CTL &= ~DAC_CTL_DWM0;
DAC_CTL |= wave_mode;
- }else{
+ } else {
/* configure DAC1 wave mode */
DAC_CTL &= ~DAC_CTL_DWM1;
DAC_CTL |= (wave_mode << DAC1_REG_OFFSET);
@@ -363,11 +360,11 @@ void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode)
*/
void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
/* configure DAC0 wave bit width */
DAC_CTL &= ~DAC_CTL_DWBW0;
DAC_CTL |= bit_width;
- }else{
+ } else {
/* configure DAC1 wave bit width */
DAC_CTL &= ~DAC_CTL_DWBW1;
DAC_CTL |= (bit_width << DAC1_REG_OFFSET);
@@ -397,11 +394,11 @@ void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width)
*/
void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
/* configure DAC0 LFSR noise mode */
DAC_CTL &= ~DAC_CTL_DWBW0;
DAC_CTL |= unmask_bits;
- }else{
+ } else {
/* configure DAC1 LFSR noise mode */
DAC_CTL &= ~DAC_CTL_DWBW1;
DAC_CTL |= (unmask_bits << DAC1_REG_OFFSET);
@@ -431,11 +428,11 @@ void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits)
*/
void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude)
{
- if(DAC0 == dac_periph){
+ if(DAC0 == dac_periph) {
/* configure DAC0 triangle noise mode */
DAC_CTL &= ~DAC_CTL_DWBW0;
DAC_CTL |= amplitude;
- }else{
+ } else {
/* configure DAC1 triangle noise mode */
DAC_CTL &= ~DAC_CTL_DWBW1;
DAC_CTL |= (amplitude << DAC1_REG_OFFSET);
@@ -478,7 +475,7 @@ void dac_concurrent_software_trigger_enable(void)
{
uint32_t swt = 0U;
swt = DAC_SWT_SWTR0 | DAC_SWT_SWTR1;
- DAC_SWT |= (swt);
+ DAC_SWT |= (swt);
}
/*!
@@ -535,7 +532,7 @@ void dac_concurrent_output_buffer_disable(void)
void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1)
{
uint32_t data = 0U;
- switch(dac_align){
+ switch(dac_align) {
/* data right 12b alignment */
case DAC_ALIGN_12B_R:
data = ((uint32_t)data1 << DH_12BIT_OFFSET) | data0;
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dbg.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dbg.c
index bbd6c9f..8bde336 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dbg.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dbg.c
@@ -2,36 +2,33 @@
\file gd32f20x_dbg.c
\brief DBG driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -67,9 +64,9 @@ void dbg_low_power_enable(uint32_t dbg_low_power)
\brief disable low power behavior when the mcu is in debug mode
\param[in] dbg_low_power:
one or more parameters can be selected which are shown as below:
- \arg DBG_LOW_POWER_SLEEP: donot keep debugger connection during sleep mode
- \arg DBG_LOW_POWER_DEEPSLEEP: donot keep debugger connection during deepsleep mode
- \arg DBG_LOW_POWER_STANDBY: donot keep debugger connection during standby mode
+ \arg DBG_LOW_POWER_SLEEP: do not keep debugger connection during sleep mode
+ \arg DBG_LOW_POWER_DEEPSLEEP: do not keep debugger connection during deepsleep mode
+ \arg DBG_LOW_POWER_STANDBY: do not keep debugger connection during standby mode
\param[out] none
\retval none
*/
@@ -82,11 +79,11 @@ void dbg_low_power_disable(uint32_t dbg_low_power)
\brief enable peripheral behavior when the mcu is in debug mode
\param[in] dbg_periph: refer to dbg_periph_enum
one or more parameters can be selected which are shown as below:
- \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
- \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
- \arg DBG_CANx_HOLD (x=0,1): hold CANx counter when core is halted
- \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
- \arg DBG_TIMERx_HOLD (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13): hold TIMERx counter when core is halted
+ \arg DBG_FWDGT_HOLD: debug FWDGT kept when core is halted
+ \arg DBG_WWDGT_HOLD: debug WWDGT kept when core is halted
+ \arg DBG_CANx_HOLD(x=0,1): hold CANx counter when core is halted
+ \arg DBG_I2Cx_HOLD(x=0,1,2): hold I2Cx smbus when core is halted
+ \arg DBG_TIMERx_HOLD(x=0,1,2,3,4,5,6,7,8,9,10,11,12,13): hold TIMERx counter when core is halted
\param[out] none
\retval none
*/
@@ -99,11 +96,11 @@ void dbg_periph_enable(dbg_periph_enum dbg_periph)
\brief disable peripheral behavior when the mcu is in debug mode
\param[in] dbg_periph: refer to dbg_periph_enum
one or more parameters can be selected which are shown as below:
- \arg DBG_FWDGT_HOLD : debug FWDGT kept when core is halted
- \arg DBG_WWDGT_HOLD : debug WWDGT kept when core is halted
- \arg DBG_CANx_HOLD (x=0,1): hold CANx counter when core is halted
- \arg DBG_I2Cx_HOLD (x=0,1): hold I2Cx smbus when core is halted
- \arg DBG_TIMERx_HOLD (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13): hold TIMERx counter when core is halted
+ \arg DBG_FWDGT_HOLD: debug FWDGT kept when core is halted
+ \arg DBG_WWDGT_HOLD: debug WWDGT kept when core is halted
+ \arg DBG_CANx_HOLD(x=0,1): hold CANx counter when core is halted
+ \arg DBG_I2Cx_HOLD(x=0,1,2): hold I2Cx smbus when core is halted
+ \arg DBG_TIMERx_HOLD(x=0,1,2,3,4,5,6,7,8,9,10,11,12,13): hold TIMERx counter when core is halted
\param[out] none
\retval none
*/
@@ -135,10 +132,10 @@ void dbg_trace_pin_disable(void)
}
/*!
- \brief trace pin mode selection
+ \brief trace pin mode selection
\param[in] trace_mode:
only one parameter can be selected which is shown as below:
- \arg TRACE_MODE_ASYNC: trace pin used for async mode
+ \arg TRACE_MODE_ASYNC: trace pin used for async mode
\arg TRACE_MODE_SYNC_DATASIZE_1: trace pin used for sync mode and data size is 1
\arg TRACE_MODE_SYNC_DATASIZE_2: trace pin used for sync mode and data size is 2
\arg TRACE_MODE_SYNC_DATASIZE_4: trace pin used for sync mode and data size is 4
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dci.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dci.c
index 33ef579..dbfa925 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dci.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dci.c
@@ -2,36 +2,33 @@
\file gd32f20x_dci.c
\brief DCI driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -63,7 +60,7 @@ void dci_deinit(void)
\param[out] none
\retval none
*/
-void dci_init(dci_parameter_struct* dci_struct)
+void dci_init(dci_parameter_struct *dci_struct)
{
uint32_t reg = 0U;
/* disable capture function and DCI */
@@ -80,18 +77,18 @@ void dci_init(dci_parameter_struct* dci_struct)
}
/*!
- \brief enable DCI function
+ \brief enable DCI function
\param[in] none
\param[out] none
\retval none
*/
void dci_enable(void)
{
- DCI_CTL |= DCI_CTL_DCIEN;
+ DCI_CTL |= DCI_CTL_DCIEN;
}
/*!
- \brief disable DCI function
+ \brief disable DCI function
\param[in] none
\param[out] none
\retval none
@@ -102,7 +99,7 @@ void dci_disable(void)
}
/*!
- \brief enable DCI capture
+ \brief enable DCI capture
\param[in] none
\param[out] none
\retval none
@@ -113,7 +110,7 @@ void dci_capture_enable(void)
}
/*!
- \brief disable DCI capture
+ \brief disable DCI capture
\param[in] none
\param[out] none
\retval none
@@ -124,7 +121,7 @@ void dci_capture_disable(void)
}
/*!
- \brief enable DCI jpeg mode
+ \brief enable DCI jpeg mode
\param[in] none
\param[out] none
\retval none
@@ -135,7 +132,7 @@ void dci_jpeg_enable(void)
}
/*!
- \brief disable DCI jpeg mode
+ \brief disable DCI jpeg mode
\param[in] none
\param[out] none
\retval none
@@ -168,7 +165,7 @@ void dci_crop_window_disable(void)
}
/*!
- \brief configure DCI cropping window
+ \brief configure DCI cropping window
\param[in] start_x: window horizontal start position
\param[in] start_y: window vertical start position
\param[in] size_width: window horizontal size
@@ -178,8 +175,8 @@ void dci_crop_window_disable(void)
*/
void dci_crop_window_config(uint16_t start_x, uint16_t start_y, uint16_t size_width, uint16_t size_height)
{
- DCI_CWSPOS = ((uint32_t)start_x | ((uint32_t)start_y<<16));
- DCI_CWSZ = ((uint32_t)size_width | ((uint32_t)size_height<<16));
+ DCI_CWSPOS = ((uint32_t)start_x | ((uint32_t)start_y << 16));
+ DCI_CWSZ = ((uint32_t)size_width | ((uint32_t)size_height << 16));
}
/*!
@@ -214,7 +211,7 @@ void dci_embedded_sync_disable(void)
*/
void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end)
{
- DCI_SC = ((uint32_t)frame_start | ((uint32_t)line_start<<8) | ((uint32_t)line_end<<16) | ((uint32_t)frame_end<<24));
+ DCI_SC = ((uint32_t)frame_start | ((uint32_t)line_start << 8) | ((uint32_t)line_end << 16) | ((uint32_t)frame_end << 24));
}
/*!
@@ -228,14 +225,14 @@ void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line
*/
void dci_sync_codes_unmask_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end)
{
- DCI_SCUMSK = ((uint32_t)frame_start | ((uint32_t)line_start<<8) | ((uint32_t)line_end<<16) | ((uint32_t)frame_end<<24));
+ DCI_SCUMSK = ((uint32_t)frame_start | ((uint32_t)line_start << 8) | ((uint32_t)line_end << 16) | ((uint32_t)frame_end << 24));
}
/*!
\brief read DCI data register
\param[in] none
\param[out] none
- \retval data
+ \retval data of DCI data register
*/
uint32_t dci_data_read(void)
{
@@ -259,18 +256,18 @@ uint32_t dci_data_read(void)
FlagStatus dci_flag_get(uint32_t flag)
{
uint32_t stat = 0U;
-
- if(flag >> 31){
+
+ if(flag >> 31) {
/* get flag status from DCI_STAT1 register */
stat = DCI_STAT1;
- }else{
+ } else {
/* get flag status from DCI_STAT0 register */
stat = DCI_STAT0;
}
-
- if(flag & stat){
+
+ if(flag & stat) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -280,7 +277,7 @@ FlagStatus dci_flag_get(uint32_t flag)
\param[in] interrupt:
\arg DCI_INT_EF: end of frame interrupt
\arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
+ \arg DCI_INT_ESE: embedded synchronous error interrupt
\arg DCI_INT_VSYNC: vsync interrupt
\arg DCI_INT_EL: end of line interrupt
\param[out] none
@@ -296,7 +293,7 @@ void dci_interrupt_enable(uint32_t interrupt)
\param[in] interrupt:
\arg DCI_INT_EF: end of frame interrupt
\arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
+ \arg DCI_INT_ESE: embedded synchronous error interrupt
\arg DCI_INT_VSYNC: vsync interrupt
\arg DCI_INT_EL: end of line interrupt
\param[out] none
@@ -312,7 +309,7 @@ void dci_interrupt_disable(uint32_t interrupt)
\param[in] int_flag:
\arg DCI_INT_FLAG_EF: end of frame interrupt flag
\arg DCI_INT_FLAG_OVR: FIFO overrun interrupt flag
- \arg DCI_INT_FLAG_ESE: embedded synchronous error interrupt flag
+ \arg DCI_INT_FLAG_ESE: embedded synchronous error interrupt flag
\arg DCI_INT_FLAG_VSYNC: vsync interrupt flag
\arg DCI_INT_FLAG_EL: end of line interrupt flag
\param[out] none
@@ -320,9 +317,9 @@ void dci_interrupt_disable(uint32_t interrupt)
*/
FlagStatus dci_interrupt_flag_get(uint32_t int_flag)
{
- if(RESET == (DCI_INTF & int_flag)){
+ if(RESET == (DCI_INTF & int_flag)) {
return RESET;
- }else{
+ } else {
return SET;
}
}
@@ -332,7 +329,7 @@ FlagStatus dci_interrupt_flag_get(uint32_t int_flag)
\param[in] int_flag:
\arg DCI_INT_EF: end of frame interrupt
\arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
+ \arg DCI_INT_ESE: embedded synchronous error interrupt
\arg DCI_INT_VSYNC: vsync interrupt
\arg DCI_INT_EL: end of line interrupt
\param[out] none
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dma.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dma.c
index 7a0650e..f41c130 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dma.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_dma.c
@@ -2,46 +2,42 @@
\file gd32f20x_dma.c
\brief DMA driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_dma.h"
-#include "gd32f20x_rcu.h"
#define DMA_WRONG_HANDLE while(1){}
/*!
- \brief deinitialize DMA a channel registers
+ \brief deinitialize a DMA channel registers
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
\param[in] channelx: specify which DMA channel is deinitialized
@@ -60,23 +56,23 @@ void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx)
DMA_CHPADDR(dma_periph, channelx) = DMA_CHPADDR_RESET_VALUE;
DMA_CHMADDR(dma_periph, channelx) = DMA_CHMADDR_RESET_VALUE;
DMA_INTC(dma_periph) |= DMA_FLAG_ADD(DMA_CHINTF_RESET_VALUE, channelx);
-
- if((DMA1 == dma_periph) && (DMA_CH5 == channelx)){
+
+ if((DMA1 == dma_periph) && (DMA_CH5 == channelx)) {
DMA_ACFG = DMA_ACFG_RESET_VALUE;
}
}
/*!
\brief initialize the parameters of DMA struct with the default values
- \param[in] init_struct: the initialization data needed to initialize DMA channel
- \param[out] none
+ \param[in] none
+ \param[out] init_struct: the initialization data needed to initialize DMA channel
\retval none
*/
-void dma_struct_para_init(dma_parameter_struct* init_struct)
+void dma_struct_para_init(dma_parameter_struct *init_struct)
{
/* set the DMA struct with the default values */
init_struct->periph_addr = 0U;
- init_struct->periph_width = 0U;
+ init_struct->periph_width = 0U;
init_struct->periph_inc = DMA_PERIPH_INCREASE_DISABLE;
init_struct->memory_addr = 0U;
init_struct->memory_width = 0U;
@@ -96,12 +92,12 @@ void dma_struct_para_init(dma_parameter_struct* init_struct)
\param[in] init_struct: the data needed to initialize DMA channel
periph_addr: peripheral base address
periph_width: DMA_PERIPHERAL_WIDTH_8BIT, DMA_PERIPHERAL_WIDTH_16BIT, DMA_PERIPHERAL_WIDTH_32BIT
- periph_inc: DMA_PERIPH_INCREASE_ENABLE, DMA_PERIPH_INCREASE_DISABLE
+ periph_inc: DMA_PERIPH_INCREASE_ENABLE, DMA_PERIPH_INCREASE_DISABLE
memory_addr: memory base address
memory_width: DMA_MEMORY_WIDTH_8BIT, DMA_MEMORY_WIDTH_16BIT, DMA_MEMORY_WIDTH_32BIT
memory_inc: DMA_MEMORY_INCREASE_ENABLE, DMA_MEMORY_INCREASE_DISABLE
direction: DMA_PERIPHERAL_TO_MEMORY, DMA_MEMORY_TO_PERIPHERAL
- number: the number of remaining data to be transferred by the DMA
+ number: the number of remaining data to be transferred by the DMA, 0 - 0xFFFF
priority: DMA_PRIORITY_LOW, DMA_PRIORITY_MEDIUM, DMA_PRIORITY_HIGH, DMA_PRIORITY_ULTRA_HIGH
\param[out] none
\retval none
@@ -112,13 +108,13 @@ void dma_init(uint32_t dma_periph, dma_channel_enum channelx, dma_parameter_stru
/* configure peripheral base address */
DMA_CHPADDR(dma_periph, channelx) = init_struct->periph_addr;
-
+
/* configure memory base address */
DMA_CHMADDR(dma_periph, channelx) = init_struct->memory_addr;
-
+
/* configure the number of remaining data to be transferred */
DMA_CHCNT(dma_periph, channelx) = (init_struct->number & DMA_CHANNEL_CNT_MASK);
-
+
/* configure peripheral transfer width,memory transfer width, */
ctl = DMA_CHCTL(dma_periph, channelx);
ctl &= ~(DMA_CHXCTL_PWIDTH | DMA_CHXCTL_MWIDTH | DMA_CHXCTL_PRIO);
@@ -126,36 +122,36 @@ void dma_init(uint32_t dma_periph, dma_channel_enum channelx, dma_parameter_stru
DMA_CHCTL(dma_periph, channelx) = ctl;
/* configure peripheral increasing mode */
- if(DMA_PERIPH_INCREASE_ENABLE == init_struct->periph_inc){
+ if(DMA_PERIPH_INCREASE_ENABLE == init_struct->periph_inc) {
DMA_CHCTL(dma_periph, channelx) |= DMA_CHXCTL_PNAGA;
- }else{
+ } else {
DMA_CHCTL(dma_periph, channelx) &= ~DMA_CHXCTL_PNAGA;
}
/* configure memory increasing mode */
- if(DMA_MEMORY_INCREASE_ENABLE == init_struct->memory_inc){
+ if(DMA_MEMORY_INCREASE_ENABLE == init_struct->memory_inc) {
DMA_CHCTL(dma_periph, channelx) |= DMA_CHXCTL_MNAGA;
- }else{
+ } else {
DMA_CHCTL(dma_periph, channelx) &= ~DMA_CHXCTL_MNAGA;
}
-
+
/* configure the direction of data transfer */
- if(DMA_PERIPHERAL_TO_MEMORY == init_struct->direction){
+ if(DMA_PERIPHERAL_TO_MEMORY == init_struct->direction) {
DMA_CHCTL(dma_periph, channelx) &= ~DMA_CHXCTL_DIR;
- }else{
+ } else {
DMA_CHCTL(dma_periph, channelx) |= DMA_CHXCTL_DIR;
- }
+ }
}
/*!
- \brief enable DMA circulation mode
+ \brief enable DMA circulation mode
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
\param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
- \retval none
+ \retval none
*/
void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx)
{
@@ -163,14 +159,14 @@ void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief disable DMA circulation mode
+ \brief disable DMA circulation mode
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
- \retval none
+ \retval none
*/
void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx)
{
@@ -181,7 +177,7 @@ void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx)
\brief enable memory to memory mode
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
@@ -208,14 +204,14 @@ void dma_memory_to_memory_disable(uint32_t dma_periph, dma_channel_enum channelx
}
/*!
- \brief enable DMA channel
+ \brief enable DMA channel
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
- \retval none
+ \retval none
*/
void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx)
{
@@ -223,14 +219,14 @@ void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief disable DMA channel
+ \brief disable DMA channel
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
- \retval none
+ \retval none
*/
void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx)
{
@@ -238,15 +234,15 @@ void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief set DMA peripheral base address
+ \brief set DMA peripheral base address
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to set peripheral base address
+ \param[in] channelx: specify which DMA channel to set peripheral base address
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] address: peripheral base address
\param[out] none
- \retval none
+ \retval none
*/
void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address)
{
@@ -254,15 +250,15 @@ void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, u
}
/*!
- \brief set DMA memory base address
+ \brief set DMA memory base address
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to set memory base address
+ \param[in] channelx: specify which DMA channel to set memory base address
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] address: memory base address
\param[out] none
- \retval none
+ \retval none
*/
void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address)
{
@@ -270,16 +266,16 @@ void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, u
}
/*!
- \brief set the number of remaining data to be transferred by the DMA
+ \brief set the number of remaining data to be transferred by the DMA
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to set number
+ \param[in] channelx: specify which DMA channel to set number
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] number: the number of remaining data to be transferred by the DMA
\arg 0x0000-0xFFFF
\param[out] none
- \retval none
+ \retval none
*/
void dma_transfer_number_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t number)
{
@@ -287,14 +283,14 @@ void dma_transfer_number_config(uint32_t dma_periph, dma_channel_enum channelx,
}
/*!
- \brief get the number of remaining data to be transferred by the DMA
+ \brief get the number of remaining data to be transferred by the DMA
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to set number
+ \param[in] channelx: specify which DMA channel to set number
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
- \retval uint32_t: the number of remaining data to be transferred by the DMA
+ \retval uint32_t: the number of remaining data to be transferred by the DMA
*/
uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx)
{
@@ -302,10 +298,10 @@ uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief configure priority level of DMA channel
+ \brief configure priority level of DMA channel
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] priority: priority Level of this channel
@@ -315,7 +311,7 @@ uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx)
\arg DMA_PRIORITY_HIGH: high priority
\arg DMA_PRIORITY_ULTRA_HIGH: ultra high priority
\param[out] none
- \retval none
+ \retval none
*/
void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t priority)
{
@@ -323,17 +319,17 @@ void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_
/* acquire DMA_CHxCTL register */
ctl = DMA_CHCTL(dma_periph, channelx);
- /* assign regiser */
+ /* assign register */
ctl &= ~DMA_CHXCTL_PRIO;
ctl |= priority;
DMA_CHCTL(dma_periph, channelx) = ctl;
}
/*!
- \brief configure transfer data size of memory
+ \brief configure transfer data size of memory
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] mwidth: transfer data width of memory
@@ -357,10 +353,10 @@ void dma_memory_width_config(uint32_t dma_periph, dma_channel_enum channelx, uin
}
/*!
- \brief configure transfer data size of peripheral
+ \brief configure transfer data size of peripheral
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] pwidth: transfer data width of peripheral
@@ -377,17 +373,17 @@ void dma_periph_width_config(uint32_t dma_periph, dma_channel_enum channelx, uin
/* acquire DMA_CHxCTL register */
ctl = DMA_CHCTL(dma_periph, channelx);
- /* assign regiser */
+ /* assign register */
ctl &= ~DMA_CHXCTL_PWIDTH;
ctl |= pwidth;
DMA_CHCTL(dma_periph, channelx) = ctl;
}
/*!
- \brief enable next address increasement algorithm of memory
+ \brief enable next address increasement algorithm of memory
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
@@ -399,10 +395,10 @@ void dma_memory_increase_enable(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief disable next address increasement algorithm of memory
+ \brief disable next address increasement algorithm of memory
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
@@ -417,7 +413,7 @@ void dma_memory_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
\brief enable next address increasement algorithm of peripheral
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
@@ -429,10 +425,10 @@ void dma_periph_increase_enable(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief disable next address increasement algorithm of peripheral
+ \brief disable next address increasement algorithm of peripheral
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[out] none
@@ -444,10 +440,10 @@ void dma_periph_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
}
/*!
- \brief configure the direction of data transfer on the channel
+ \brief configure the direction of data transfer on the channel
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] direction: specify the direction of data transfer
@@ -459,15 +455,37 @@ void dma_periph_increase_disable(uint32_t dma_periph, dma_channel_enum channelx)
*/
void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t direction)
{
- if(DMA_PERIPHERAL_TO_MEMORY == direction){
+ if(DMA_PERIPHERAL_TO_MEMORY == direction) {
DMA_CHCTL(dma_periph, channelx) &= ~DMA_CHXCTL_DIR;
- }else{
+ } else {
DMA_CHCTL(dma_periph, channelx) |= DMA_CHXCTL_DIR;
}
}
/*!
- \brief check DMA flag is set or not
+ \brief enable the DMA1 channel 5 Full_Data transfer mode
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void dma_1_channel_5_fulldata_transfer_enable(void)
+{
+ DMA_ACFG |= DMA_ACFG_FD_CH5EN;
+}
+
+/*!
+ \brief disable the DMA1 channel 5 Full_Data transfer mode
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void dma_1_channel_5_fulldata_transfer_disable(void)
+{
+ DMA_ACFG &= ~DMA_ACFG_FD_CH5EN;
+}
+
+/*!
+ \brief check DMA flag is set or not
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
\param[in] channelx: specify which DMA channel to get flag
@@ -487,12 +505,12 @@ FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t
FlagStatus reval;
/* check whether the flag is set or not */
- if(RESET != (DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx))){
+ if(RESET != (DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx))) {
reval = SET;
- }else{
+ } else {
reval = RESET;
}
-
+
return reval;
}
@@ -517,93 +535,15 @@ void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t fla
DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx);
}
-/*!
- \brief check DMA flag and interrupt enable bit is set or not
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to get flag
- only one parameter can be selected which is shown as below:
- \arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
- \param[in] flag: specify get which flag
- only one parameter can be selected which is shown as below:
- \arg DMA_INT_FLAG_G: global interrupt flag of channel
- \arg DMA_INT_FLAG_FTF: full transfer finish interrupt flag of channel
- \arg DMA_INT_FLAG_HTF: half transfer finish interrupt flag of channel
- \arg DMA_INT_FLAG_ERR: error interrupt flag of channel
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
-{
- uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
- uint32_t gif_check = 0x0FU, gif_enable = 0x0EU;
-
- switch(flag){
- case DMA_INT_FLAG_FTF:
- /* check whether the full transfer finish interrupt flag is set and enabled */
- interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
- interrupt_flag = interrupt_flag >> ((channelx) * 4U);
- interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE;
- break;
- case DMA_INT_FLAG_HTF:
- /* check whether the half transfer finish interrupt flag is set and enabled */
- interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
- interrupt_flag = interrupt_flag >> ((channelx) * 4U);
- interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_HTFIE;
- break;
- case DMA_INT_FLAG_ERR:
- /* check whether the error interrupt flag is set and enabled */
- interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
- interrupt_flag = interrupt_flag >> ((channelx) * 4U);
- interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_ERRIE;
- break;
- case DMA_INT_FLAG_G:
- interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(gif_check, channelx);
- interrupt_flag = interrupt_flag >> ((channelx) * 4U);
- interrupt_enable = DMA_CHCTL(dma_periph, channelx) & gif_enable;
- break;
- default:
- DMA_WRONG_HANDLE
- }
-
- /* when the interrupt flag is set and enabled, return SET */
- if(interrupt_flag && interrupt_enable){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear DMA a channel flag
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to clear flag
- only one parameter can be selected which is shown as below:
- \arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
- \param[in] flag: specify get which flag
- only one parameter can be selected which is shown as below:
- \arg DMA_INT_FLAG_G: global interrupt flag of channel
- \arg DMA_INT_FLAG_FTF: full transfer finish interrupt flag of channel
- \arg DMA_INT_FLAG_HTF: half transfer finish interrupt flag of channel
- \arg DMA_INT_FLAG_ERR: error interrupt flag of channel
- \param[out] none
- \retval none
-*/
-void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
-{
- DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx);
-}
-
/*!
\brief enable DMA interrupt
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
\param[in] source: specify which interrupt to enbale
- one or more parameters can be selected which are shown as below
+ one or more parameters can be selected which are shown as below:
\arg DMA_INT_FTF: channel full transfer finish interrupt
\arg DMA_INT_HTF: channel half transfer finish interrupt
\arg DMA_INT_ERR: channel error interrupt
@@ -619,11 +559,11 @@ void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32
\brief disable DMA interrupt
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
only one parameter can be selected which is shown as below:
\arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
- \param[in] source: specify which interrupt to disbale
- one or more parameters can be selected which are shown as below
+ \param[in] source: specify which interrupt to disable
+ one or more parameters can be selected which are shown as below:
\arg DMA_INT_FTF: channel full transfer finish interrupt
\arg DMA_INT_HTF: channel half transfer finish interrupt
\arg DMA_INT_ERR: channel error interrupt
@@ -636,23 +576,79 @@ void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint3
}
/*!
- \brief enable the DMA1 channel 5 Full_Data transfer mode
- \param[in] none
+ \brief check DMA flag and interrupt enable bit is set or not
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel to get flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
+ \param[in] flag: specify get which flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA_INT_FLAG_G: global interrupt flag of channel
+ \arg DMA_INT_FLAG_FTF: full transfer finish interrupt flag of channel
+ \arg DMA_INT_FLAG_HTF: half transfer finish interrupt flag of channel
+ \arg DMA_INT_FLAG_ERR: error interrupt flag of channel
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void dma_1_channel_5_fulldata_transfer_enable(void)
+FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
{
- DMA_ACFG |= DMA_ACFG_FD_CH5EN;
+ uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
+ uint32_t gif_check = 0x0FU, gif_enable = 0x0EU;
+
+ switch(flag) {
+ case DMA_INT_FLAG_FTF:
+ /* check whether the full transfer finish interrupt flag is set and enabled */
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE;
+ break;
+ case DMA_INT_FLAG_HTF:
+ /* check whether the half transfer finish interrupt flag is set and enabled */
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INT_FLAG_ERR:
+ /* check whether the error interrupt flag is set and enabled */
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_ERRIE;
+ break;
+ case DMA_INT_FLAG_G:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(gif_check, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & gif_enable;
+ break;
+ default:
+ DMA_WRONG_HANDLE
+ }
+
+ /* when the interrupt flag is set and enabled, return SET */
+ if(interrupt_flag && interrupt_enable) {
+ return SET;
+ } else {
+ return RESET;
+ }
}
/*!
- \brief disable the DMA1 channel 5 Full_Data transfer mode
- \param[in] none
+ \brief clear DMA a channel flag
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel to clear flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA0: DMA_CHx(x=0..6), DMA1: DMA_CHx(x=0..6)
+ \param[in] flag: specify get which flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA_INT_FLAG_G: global interrupt flag of channel
+ \arg DMA_INT_FLAG_FTF: full transfer finish interrupt flag of channel
+ \arg DMA_INT_FLAG_HTF: half transfer finish interrupt flag of channel
+ \arg DMA_INT_FLAG_ERR: error interrupt flag of channel
\param[out] none
\retval none
*/
-void dma_1_channel_5_fulldata_transfer_disable(void)
+void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
{
- DMA_ACFG &= ~DMA_ACFG_FD_CH5EN;
+ DMA_INTC(dma_periph) |= DMA_FLAG_ADD(flag, channelx);
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_enet.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_enet.c
index 7748d7d..ce05fc8 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_enet.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_enet.c
@@ -2,36 +2,33 @@
\file gd32f20x_enet.c
\brief ENET driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -40,13 +37,13 @@ OF SUCH DAMAGE.
#ifdef GD32F20X_CL
#if defined (__CC_ARM) /*!< ARM compiler */
-__align(4)
+__align(4)
enet_descriptors_struct rxdesc_tab[ENET_RXBUF_NUM]; /*!< ENET RxDMA descriptor */
-__align(4)
+__align(4)
enet_descriptors_struct txdesc_tab[ENET_TXBUF_NUM]; /*!< ENET TxDMA descriptor */
-__align(4)
+__align(4)
uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE]; /*!< ENET receive buffer */
-__align(4)
+__align(4)
uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE]; /*!< ENET transmit buffer */
#elif defined ( __ICCARM__ ) /*!< IAR compiler */
@@ -60,10 +57,10 @@ uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE]; /*!< ENET receive bu
uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE]; /*!< ENET transmit buffer */
#elif defined (__GNUC__) /* GNU Compiler */
-enet_descriptors_struct rxdesc_tab[ENET_RXBUF_NUM] __attribute__ ((aligned (4))); /*!< ENET RxDMA descriptor */
-enet_descriptors_struct txdesc_tab[ENET_TXBUF_NUM] __attribute__ ((aligned (4))); /*!< ENET TxDMA descriptor */
-uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE] __attribute__ ((aligned (4))); /*!< ENET receive buffer */
-uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE] __attribute__ ((aligned (4))); /*!< ENET transmit buffer */
+enet_descriptors_struct rxdesc_tab[ENET_RXBUF_NUM] __attribute__((aligned(4))); /*!< ENET RxDMA descriptor */
+enet_descriptors_struct txdesc_tab[ENET_TXBUF_NUM] __attribute__((aligned(4))); /*!< ENET TxDMA descriptor */
+uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE] __attribute__((aligned(4))); /*!< ENET receive buffer */
+uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE] __attribute__((aligned(4))); /*!< ENET transmit buffer */
#endif /* __CC_ARM */
@@ -76,21 +73,22 @@ enet_descriptors_struct *dma_current_ptp_txdesc = NULL;
enet_descriptors_struct *dma_current_ptp_rxdesc = NULL;
/* init structure parameters for ENET initialization */
-static enet_initpara_struct enet_initpara ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+static enet_initpara_struct enet_initpara = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U};
static uint32_t enet_unknow_err = 0U;
/* array of register offset for debug information get */
static const uint16_t enet_reg_tab[] = {
-0x0000, 0x0004, 0x0008, 0x000C, 0x0010, 0x0014, 0x0018, 0x1080, 0x001C, 0x0028, 0x002C,
-0x0038, 0x003C, 0x0040, 0x0044, 0x0048, 0x004C, 0x0050, 0x0054, 0x0058, 0x005C,
-
-0x0100, 0x0104, 0x0108, 0x010C, 0x0110, 0x014C, 0x0150, 0x0168, 0x0194, 0x0198, 0x01C4,
-
-0x0700, 0x0704,0x0708, 0x070C, 0x0710, 0x0714, 0x0718, 0x071C, 0x0720,
-
-0x1000, 0x1004, 0x1008, 0x100C, 0x1010, 0x1014, 0x1018, 0x101C, 0x1020, 0x1048, 0x104C,
-0x1050, 0x1054};
+ 0x0000U, 0x0004U, 0x0008U, 0x000CU, 0x0010U, 0x0014U, 0x0018U, 0x1080U, 0x001CU, 0x0028U, 0x002CU,
+
+ 0x0038U, 0x003CU, 0x0040U, 0x0044U, 0x0048U, 0x004CU, 0x0050U, 0x0054U, 0x0058U, 0x005CU, 0x0100U,
+
+ 0x0104U, 0x0108U, 0x010CU, 0x0110U, 0x014CU, 0x0150U, 0x0168U, 0x0194U, 0x0198U, 0x01C4U, 0x0700U,
+
+ 0x0704U, 0x0708U, 0x070CU, 0x0710U, 0x0714U, 0x0718U, 0x071CU, 0x0720U, 0x1000U, 0x1004U, 0x1008U,
+
+ 0x100CU, 0x1010U, 0x1014U, 0x1018U, 0x101CU, 0x1020U, 0x1048U, 0x104CU, 0x1050U, 0x1054U
+};
/*!
@@ -108,16 +106,16 @@ void enet_deinit(void)
/*!
\brief configure the parameters which are usually less cared for initialization
- note -- this function must be called before enet_init(), otherwise
+ note -- this function must be called before enet_init(), otherwise
configuration will be no effect
- \param[in] option: different function option, which is related to several parameters,
+ \param[in] option: different function option, which is related to several parameters,
only one parameter can be selected which is shown as below, refer to enet_option_enum
\arg FORWARD_OPTION: choose to configure the frame forward related parameters
\arg DMABUS_OPTION: choose to configure the DMA bus mode related parameters
\arg DMA_MAXBURST_OPTION: choose to configure the DMA max burst related parameters
\arg DMA_ARBITRATION_OPTION: choose to configure the DMA arbitration related parameters
\arg STORE_OPTION: choose to configure the store forward mode related parameters
- \arg DMA_OPTION: choose to configure the DMA descriptor related parameters
+ \arg DMA_OPTION: choose to configure the DMA descriptor related parameters
\arg VLAN_OPTION: choose to configure vlan related parameters
\arg FLOWCTL_OPTION: choose to configure flow control related parameters
\arg HASHH_OPTION: choose to configure hash high
@@ -126,7 +124,7 @@ void enet_deinit(void)
\arg HALFDUPLEX_OPTION: choose to configure halfduplex mode related parameters
\arg TIMER_OPTION: choose to configure time counter related parameters
\arg INTERFRAMEGAP_OPTION: choose to configure the inter frame gap related parameters
- \param[in] para: the related parameters according to the option
+ \param[in] para: the related parameters according to the option
all the related parameters should be configured which are shown as below
FORWARD_OPTION related parameters:
- ENET_AUTO_PADCRC_DROP_ENABLE/ ENET_AUTO_PADCRC_DROP_DISABLE ;
@@ -169,7 +167,7 @@ void enet_deinit(void)
FLOWCTL_OPTION related parameters:
- MAC_FCTL_PTM(regval) ;
- ENET_ZERO_QUANTA_PAUSE_ENABLE/ ENET_ZERO_QUANTA_PAUSE_DISABLE ;
- - ENET_PAUSETIME_MINUS4/ ENET_PAUSETIME_MINUS28/
+ - ENET_PAUSETIME_MINUS4/ ENET_PAUSETIME_MINUS28/
ENET_PAUSETIME_MINUS144/ENET_PAUSETIME_MINUS256 ;
- ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT/ ENET_UNIQUE_PAUSEDETECT ;
- ENET_RX_FLOWCONTROL_ENABLE/ ENET_RX_FLOWCONTROL_DISABLE ;
@@ -187,7 +185,15 @@ void enet_deinit(void)
- ENET_UNICAST_FILTER_EITHER/ ENET_UNICAST_FILTER_HASH/
ENET_UNICAST_FILTER_PERFECT ;
- ENET_PCFRM_PREVENT_ALL/ ENET_PCFRM_PREVENT_PAUSEFRAME/
- ENET_PCFRM_FORWARD_ALL/ ENET_PCFRM_FORWARD_FILTERED .
+ ENET_PCFRM_FORWARD_ALL/ ENET_PCFRM_FORWARD_FILTERED ;
+ - ENET_ACTIVE_THRESHOLD_256BYTES/ ENET_ACTIVE_THRESHOLD_512BYTES ;
+ - ENET_ACTIVE_THRESHOLD_768BYTES/ ENET_ACTIVE_THRESHOLD_1024BYTES ;
+ - ENET_ACTIVE_THRESHOLD_1280BYTES/ ENET_ACTIVE_THRESHOLD_1536BYTES ;
+ - ENET_ACTIVE_THRESHOLD_1792BYTES ;
+ - ENET_DEACTIVE_THRESHOLD_256BYTES/ ENET_DEACTIVE_THRESHOLD_512BYTES ;
+ - ENET_DEACTIVE_THRESHOLD_768BYTES/ ENET_DEACTIVE_THRESHOLD_1024BYTES ;
+ - ENET_DEACTIVE_THRESHOLD_1280BYTES/ ENET_DEACTIVE_THRESHOLD_1536BYTES ;
+ - ENET_DEACTIVE_THRESHOLD_1792BYTES .
HALFDUPLEX_OPTION related parameters:
- ENET_CARRIERSENSE_ENABLE/ ENET_CARRIERSENSE_DISABLE ;
- ENET_RECEIVEOWN_ENABLE/ ENET_RECEIVEOWN_DISABLE ;
@@ -203,12 +209,12 @@ void enet_deinit(void)
ENET_INTERFRAMEGAP_80BIT/ ENET_INTERFRAMEGAP_72BIT/
ENET_INTERFRAMEGAP_64BIT/ ENET_INTERFRAMEGAP_56BIT/
ENET_INTERFRAMEGAP_48BIT/ ENET_INTERFRAMEGAP_40BIT .
- \param[out] none
+ \param[out] none
\retval none
*/
void enet_initpara_config(enet_option_enum option, uint32_t para)
{
- switch(option){
+ switch(option) {
case FORWARD_OPTION:
/* choose to configure forward_frame, and save the configuration parameters */
enet_initpara.option_enable |= (uint32_t)FORWARD_OPTION;
@@ -272,7 +278,7 @@ void enet_initpara_config(enet_option_enum option, uint32_t para)
case TIMER_OPTION:
/* choose to configure timer_config, and save the configuration parameters */
enet_initpara.option_enable |= (uint32_t)TIMER_OPTION;
- enet_initpara.timer_config = para;
+ enet_initpara.timer_config = para;
break;
case INTERFRAMEGAP_OPTION:
/* choose to configure interframegap, and save the configuration parameters */
@@ -280,15 +286,15 @@ void enet_initpara_config(enet_option_enum option, uint32_t para)
enet_initpara.interframegap = para;
break;
default:
- break;
- }
-}
+ break;
+ }
+}
/*!
- \brief initialize ENET peripheral with generally concerned parameters and the less cared
+ \brief initialize ENET peripheral with generally concerned parameters and the less cared
parameters
\param[in] mediamode: PHY mode and mac loopback configurations, only one parameter can be selected
- which is shown as below, refer to enet_mediamode_enum
+ which is shown as below, refer to enet_mediamode_enum
\arg ENET_AUTO_NEGOTIATION: PHY auto negotiation
\arg ENET_100M_FULLDUPLEX: 100Mbit/s, full-duplex
\arg ENET_100M_HALFDUPLEX: 100Mbit/s, half-duplex
@@ -296,135 +302,136 @@ void enet_initpara_config(enet_option_enum option, uint32_t para)
\arg ENET_10M_HALFDUPLEX: 10Mbit/s, half-duplex
\arg ENET_LOOPBACKMODE: MAC in loopback mode at the MII
\param[in] checksum: IP frame checksum offload function, only one parameter can be selected
- which is shown as below, refer to enet_mediamode_enum
+ which is shown as below, refer to enet_mediamode_enum
\arg ENET_NO_AUTOCHECKSUM: disable IP frame checksum function
\arg ENET_AUTOCHECKSUM_DROP_FAILFRAMES: enable IP frame checksum function
\arg ENET_AUTOCHECKSUM_ACCEPT_FAILFRAMES: enable IP frame checksum function, and the received frame
with only payload error but no other errors will not be dropped
\param[in] recept: frame filter function, only one parameter can be selected
- which is shown as below, refer to enet_frmrecept_enum
+ which is shown as below, refer to enet_frmrecept_enum
\arg ENET_PROMISCUOUS_MODE: promiscuous mode enabled
\arg ENET_RECEIVEALL: all received frame are forwarded to application
\arg ENET_BROADCAST_FRAMES_PASS: the address filters pass all received broadcast frames
\arg ENET_BROADCAST_FRAMES_DROP: the address filters filter all incoming broadcast frames
- \param[out] none
+ \param[out] none
\retval ErrStatus: ERROR or SUCCESS
*/
ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum, enet_frmrecept_enum recept)
{
- uint32_t reg_value=0U, reg_temp = 0U, temp = 0U;
+ uint32_t reg_value = 0U, reg_temp = 0U, temp = 0U;
uint32_t media_temp = 0U;
uint32_t timeout = 0U;
uint16_t phy_value = 0U;
- ErrStatus phy_state= ERROR, enet_state = ERROR;
+ ErrStatus phy_state = ERROR, enet_state = ERROR;
/* PHY interface configuration, configure SMI clock and reset PHY chip */
-// if(ERROR == enet_phy_config()){
-// _ENET_DELAY_(PHY_RESETDELAY);
-// if(ERROR == enet_phy_config()){
-// return enet_state;
-// }
-// }
+/** AvV **/
+// if(ERROR == enet_phy_config()) {
+// _ENET_DELAY_(PHY_RESETDELAY);
+// if(ERROR == enet_phy_config()) {
+// return enet_state;
+// }
+// }
+/** AvV **/
/* initialize ENET peripheral with generally concerned parameters */
enet_default_init();
/* 1st, configure mediamode */
media_temp = (uint32_t)mediamode;
/* if is PHY auto negotiation */
- if((uint32_t)ENET_AUTO_NEGOTIATION == media_temp){
+ if((uint32_t)ENET_AUTO_NEGOTIATION == media_temp) {
/* wait for PHY_LINKED_STATUS bit be set */
- do{
+ do {
enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BSR, &phy_value);
- phy_value &= PHY_LINKED_STATUS;
+ phy_value &= PHY_LINKED_STATUS;
timeout++;
- }while((RESET == phy_value) && (timeout < PHY_READ_TO));
+ } while((RESET == phy_value) && (timeout < PHY_READ_TO));
/* return ERROR due to timeout */
- if(PHY_READ_TO == timeout){
+ if(PHY_READ_TO == timeout) {
return enet_state;
}
-
/* reset timeout counter */
timeout = 0U;
/* enable auto-negotiation */
phy_value = PHY_AUTONEGOTIATION;
phy_state = enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value);
- if(!phy_state){
+ if(!phy_state) {
/* return ERROR due to write timeout */
return enet_state;
}
/* wait for the PHY_AUTONEGO_COMPLETE bit be set */
- do{
+ do {
enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BSR, &phy_value);
phy_value &= PHY_AUTONEGO_COMPLETE;
timeout++;
- }while((RESET == phy_value) && (timeout < (uint32_t)PHY_READ_TO));
+ } while((RESET == phy_value) && (timeout < (uint32_t)PHY_READ_TO));
/* return ERROR due to timeout */
- if(PHY_READ_TO == timeout){
+ if(PHY_READ_TO == timeout) {
return enet_state;
}
-
/* reset timeout counter */
timeout = 0U;
/* read the result of the auto-negotiation */
- enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_SR, &phy_value);
+ enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_SR, &phy_value);
/* configure the duplex mode of MAC following the auto-negotiation result */
- if((uint16_t)RESET != (phy_value & PHY_DUPLEX_STATUS)){
+ if((uint16_t)RESET != (phy_value & PHY_DUPLEX_STATUS)) {
media_temp = ENET_MODE_FULLDUPLEX;
- }else{
+ } else {
media_temp = ENET_MODE_HALFDUPLEX;
}
-
/* configure the communication speed of MAC following the auto-negotiation result */
#if(PHY_TYPE == RTL8201F) /** AvV **/
if ((uint16_t) RESET == (phy_value & PHY_SPEED_STATUS)) {
#else
if ((uint16_t) RESET != (phy_value & PHY_SPEED_STATUS)) {
#endif
- media_temp |= ENET_SPEEDMODE_10M;
- } else {
- media_temp |= ENET_SPEEDMODE_100M;
- }
- }else{
-// phy_value = (uint16_t)((media_temp & ENET_MAC_CFG_DPM) >> 3);
-// phy_value |= (uint16_t)((media_temp & ENET_MAC_CFG_SPD) >> 1);
-// phy_state = enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value);
-// if(!phy_state){
-// /* return ERROR due to write timeout */
-// return enet_state;
-// }
-// /* PHY configuration need some time */
-// _ENET_DELAY_(PHY_CONFIGDELAY);
+ media_temp |= ENET_SPEEDMODE_10M;
+ } else {
+ media_temp |= ENET_SPEEDMODE_100M;
+ }
+ } else {
+/** AvV **/
+// phy_value = (uint16_t)((media_temp & ENET_MAC_CFG_DPM) >> 3U);
+// phy_value |= (uint16_t)((media_temp & ENET_MAC_CFG_SPD) >> 1U);
+// phy_state = enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value);
+// if(!phy_state) {
+// /* return ERROR due to write timeout */
+// return enet_state;
+// }
+// /* PHY configuration need some time */
+// _ENET_DELAY_(PHY_CONFIGDELAY);
+/** AvV **/
}
/* after configuring the PHY, use mediamode to configure registers */
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
- reg_value &= (~(ENET_MAC_CFG_SPD |ENET_MAC_CFG_DPM |ENET_MAC_CFG_LBM));
+ reg_value &= (~(ENET_MAC_CFG_SPD | ENET_MAC_CFG_DPM | ENET_MAC_CFG_LBM));
reg_value |= media_temp;
ENET_MAC_CFG = reg_value;
-
-
+
+
/* 2st, configure checksum */
- if(RESET != ((uint32_t)checksum & ENET_CHECKSUMOFFLOAD_ENABLE)){
+ if(RESET != ((uint32_t)checksum & ENET_CHECKSUMOFFLOAD_ENABLE)) {
ENET_MAC_CFG |= ENET_CHECKSUMOFFLOAD_ENABLE;
-
+
reg_value = ENET_DMA_CTL;
/* configure ENET_DMA_CTL register */
reg_value &= ~ENET_DMA_CTL_DTCERFD;
reg_value |= ((uint32_t)checksum & ENET_DMA_CTL_DTCERFD);
ENET_DMA_CTL = reg_value;
}
-
- /* 3rd, configure recept */
+
+ /* 3rd, configure receipt */
ENET_MAC_FRMF |= (uint32_t)recept;
-
+
/* 4th, configure different function options */
/* configure forward_frame related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)FORWARD_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)FORWARD_OPTION)) {
reg_temp = enet_initpara.forward_frame;
-
+
reg_value = ENET_MAC_CFG;
temp = reg_temp;
/* configure ENET_MAC_CFG register */
@@ -432,76 +439,76 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
temp &= ENET_MAC_CFG_APCD;
reg_value |= temp;
ENET_MAC_CFG = reg_value;
-
+
reg_value = ENET_DMA_CTL;
temp = reg_temp;
/* configure ENET_DMA_CTL register */
- reg_value &= (~(ENET_DMA_CTL_FERF |ENET_DMA_CTL_FUF));
- temp &= ((ENET_DMA_CTL_FERF | ENET_DMA_CTL_FUF)<<2);
+ reg_value &= (~(ENET_DMA_CTL_FERF | ENET_DMA_CTL_FUF));
+ temp &= ((ENET_DMA_CTL_FERF | ENET_DMA_CTL_FUF) << 2);
reg_value |= (temp >> 2);
ENET_DMA_CTL = reg_value;
}
/* configure dmabus_mode related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMABUS_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMABUS_OPTION)) {
temp = enet_initpara.dmabus_mode;
-
+
reg_value = ENET_DMA_BCTL;
/* configure ENET_DMA_BCTL register */
reg_value &= ~(ENET_DMA_BCTL_AA | ENET_DMA_BCTL_FB \
- |ENET_DMA_BCTL_FPBL);
+ | ENET_DMA_BCTL_FPBL);
reg_value |= temp;
ENET_DMA_BCTL = reg_value;
}
/* configure dma_maxburst related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_MAXBURST_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_MAXBURST_OPTION)) {
temp = enet_initpara.dma_maxburst;
-
+
reg_value = ENET_DMA_BCTL;
/* configure ENET_DMA_BCTL register */
- reg_value &= ~(ENET_DMA_BCTL_RXDP| ENET_DMA_BCTL_PGBL | ENET_DMA_BCTL_UIP);
+ reg_value &= ~(ENET_DMA_BCTL_RXDP | ENET_DMA_BCTL_PGBL | ENET_DMA_BCTL_UIP);
reg_value |= temp;
ENET_DMA_BCTL = reg_value;
}
/* configure dma_arbitration related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_ARBITRATION_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_ARBITRATION_OPTION)) {
temp = enet_initpara.dma_arbitration;
-
+
reg_value = ENET_DMA_BCTL;
/* configure ENET_DMA_BCTL register */
reg_value &= ~(ENET_DMA_BCTL_RTPR | ENET_DMA_BCTL_DAB);
reg_value |= temp;
ENET_DMA_BCTL = reg_value;
}
-
+
/* configure store_forward_mode related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)STORE_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)STORE_OPTION)) {
temp = enet_initpara.store_forward_mode;
-
+
reg_value = ENET_DMA_CTL;
/* configure ENET_DMA_CTL register */
- reg_value &= ~(ENET_DMA_CTL_RSFD | ENET_DMA_CTL_TSFD| ENET_DMA_CTL_RTHC| ENET_DMA_CTL_TTHC);
+ reg_value &= ~(ENET_DMA_CTL_RSFD | ENET_DMA_CTL_TSFD | ENET_DMA_CTL_RTHC | ENET_DMA_CTL_TTHC);
reg_value |= temp;
ENET_DMA_CTL = reg_value;
}
/* configure dma_function related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_OPTION)) {
reg_temp = enet_initpara.dma_function;
-
+
reg_value = ENET_DMA_CTL;
/* configure ENET_DMA_CTL register */
- reg_value &= (~(ENET_DMA_CTL_DAFRF |ENET_DMA_CTL_OSF));
+ reg_value &= (~(ENET_DMA_CTL_DAFRF | ENET_DMA_CTL_OSF));
reg_value |= reg_temp;
ENET_DMA_CTL = reg_value;
}
/* configure vlan_config related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)VLAN_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)VLAN_OPTION)) {
reg_temp = enet_initpara.vlan_config;
-
+
reg_value = ENET_MAC_VLT;
/* configure ENET_MAC_VLT register */
reg_value &= ~(ENET_MAC_VLT_VLTI | ENET_MAC_VLT_VLTC);
@@ -510,84 +517,84 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
}
/* configure flow_control related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)FLOWCTL_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)FLOWCTL_OPTION)) {
reg_temp = enet_initpara.flow_control;
-
+
reg_value = ENET_MAC_FCTL;
temp = reg_temp;
/* configure ENET_MAC_FCTL register */
- reg_value &= ~(ENET_MAC_FCTL_PTM |ENET_MAC_FCTL_DZQP |ENET_MAC_FCTL_PLTS \
- | ENET_MAC_FCTL_UPFDT |ENET_MAC_FCTL_RFCEN |ENET_MAC_FCTL_TFCEN);
- temp &= (ENET_MAC_FCTL_PTM |ENET_MAC_FCTL_DZQP |ENET_MAC_FCTL_PLTS \
- | ENET_MAC_FCTL_UPFDT |ENET_MAC_FCTL_RFCEN |ENET_MAC_FCTL_TFCEN);
+ reg_value &= ~(ENET_MAC_FCTL_PTM | ENET_MAC_FCTL_DZQP | ENET_MAC_FCTL_PLTS \
+ | ENET_MAC_FCTL_UPFDT | ENET_MAC_FCTL_RFCEN | ENET_MAC_FCTL_TFCEN);
+ temp &= (ENET_MAC_FCTL_PTM | ENET_MAC_FCTL_DZQP | ENET_MAC_FCTL_PLTS \
+ | ENET_MAC_FCTL_UPFDT | ENET_MAC_FCTL_RFCEN | ENET_MAC_FCTL_TFCEN);
reg_value |= temp;
ENET_MAC_FCTL = reg_value;
-
+
reg_value = ENET_MAC_FCTH;
temp = reg_temp;
/* configure ENET_MAC_FCTH register */
- reg_value &= ~(ENET_MAC_FCTH_RFA |ENET_MAC_FCTH_RFD);
- temp &= ((ENET_MAC_FCTH_RFA | ENET_MAC_FCTH_RFD )<<8);
- reg_value |= (temp >> 8);
+ reg_value &= ~(ENET_MAC_FCTH_RFA | ENET_MAC_FCTH_RFD);
+ temp &= ((ENET_MAC_FCTH_RFA | ENET_MAC_FCTH_RFD) << 8U);
+ reg_value |= (temp >> 8U);
ENET_MAC_FCTH = reg_value;
- }
-
+ }
+
/* configure hashtable_high related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)HASHH_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)HASHH_OPTION)) {
ENET_MAC_HLH = enet_initpara.hashtable_high;
- }
+ }
/* configure hashtable_low related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)HASHL_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)HASHL_OPTION)) {
ENET_MAC_HLL = enet_initpara.hashtable_low;
- }
+ }
/* configure framesfilter_mode related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)FILTER_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)FILTER_OPTION)) {
reg_temp = enet_initpara.framesfilter_mode;
-
+
reg_value = ENET_MAC_FRMF;
/* configure ENET_MAC_FRMF register */
reg_value &= ~(ENET_MAC_FRMF_SAFLT | ENET_MAC_FRMF_SAIFLT | ENET_MAC_FRMF_DAIFLT \
- | ENET_MAC_FRMF_HMF | ENET_MAC_FRMF_HPFLT | ENET_MAC_FRMF_MFD \
- | ENET_MAC_FRMF_HUF | ENET_MAC_FRMF_PCFRM);
+ | ENET_MAC_FRMF_HMF | ENET_MAC_FRMF_HPFLT | ENET_MAC_FRMF_MFD \
+ | ENET_MAC_FRMF_HUF | ENET_MAC_FRMF_PCFRM);
reg_value |= reg_temp;
ENET_MAC_FRMF = reg_value;
- }
+ }
/* configure halfduplex_param related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)HALFDUPLEX_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)HALFDUPLEX_OPTION)) {
reg_temp = enet_initpara.halfduplex_param;
-
+
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
reg_value &= ~(ENET_MAC_CFG_CSD | ENET_MAC_CFG_ROD | ENET_MAC_CFG_RTD \
- | ENET_MAC_CFG_BOL | ENET_MAC_CFG_DFC);
+ | ENET_MAC_CFG_BOL | ENET_MAC_CFG_DFC);
reg_value |= reg_temp;
ENET_MAC_CFG = reg_value;
- }
+ }
/* configure timer_config related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)TIMER_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)TIMER_OPTION)) {
reg_temp = enet_initpara.timer_config;
-
+
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
reg_value &= ~(ENET_MAC_CFG_WDD | ENET_MAC_CFG_JBD);
reg_value |= reg_temp;
ENET_MAC_CFG = reg_value;
- }
-
+ }
+
/* configure interframegap related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)INTERFRAMEGAP_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)INTERFRAMEGAP_OPTION)) {
reg_temp = enet_initpara.interframegap;
-
+
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
reg_value &= ~ENET_MAC_CFG_IGBS;
reg_value |= reg_temp;
ENET_MAC_CFG = reg_value;
- }
+ }
enet_state = SUCCESS;
return enet_state;
@@ -604,21 +611,21 @@ ErrStatus enet_software_reset(void)
uint32_t timeout = 0U;
ErrStatus enet_state = ERROR;
uint32_t dma_flag;
-
+
/* reset all core internal registers located in CLK_TX and CLK_RX */
ENET_DMA_BCTL |= ENET_DMA_BCTL_SWR;
-
+
/* wait for reset operation complete */
- do{
+ do {
dma_flag = (ENET_DMA_BCTL & ENET_DMA_BCTL_SWR);
timeout++;
- }while((RESET != dma_flag) && (ENET_DELAY_TO != timeout));
+ } while((RESET != dma_flag) && (ENET_DELAY_TO != timeout));
- /* reset operation complete */
- if(RESET == (ENET_DMA_BCTL & ENET_DMA_BCTL_SWR)){
+ /* reset operation complete */
+ if(RESET == (ENET_DMA_BCTL & ENET_DMA_BCTL_SWR)) {
enet_state = SUCCESS;
}
-
+
return enet_state;
}
@@ -632,19 +639,19 @@ uint32_t enet_rxframe_size_get(void)
{
uint32_t size = 0U;
uint32_t status;
-
+
/* get rdes0 information of current RxDMA descriptor */
status = dma_current_rxdesc->status;
-
- /* if the desciptor is owned by DMA */
- if((uint32_t)RESET != (status & ENET_RDES0_DAV)){
+
+ /* if the descriptor is owned by DMA */
+ if((uint32_t)RESET != (status & ENET_RDES0_DAV)) {
return 0U;
}
-
+
/* if has any error, or the frame uses two or more descriptors */
if((((uint32_t)RESET) != (status & ENET_RDES0_ERRS)) ||
- (((uint32_t)RESET) == (status & ENET_RDES0_LDES)) ||
- (((uint32_t)RESET) == (status & ENET_RDES0_FDES))){
+ (((uint32_t)RESET) == (status & ENET_RDES0_LDES)) ||
+ (((uint32_t)RESET) == (status & ENET_RDES0_FDES))) {
/* drop current receive frame */
enet_rxframe_drop();
@@ -653,30 +660,30 @@ uint32_t enet_rxframe_size_get(void)
/* if is an ethernet-type frame, and IP frame payload error occurred */
if((((uint32_t)RESET) != (status & ENET_RDES0_FRMT)) &&
- (((uint32_t)RESET) != (status & ENET_RDES0_PCERR))){
- /* drop current receive frame */
- enet_rxframe_drop();
+ (((uint32_t)RESET) != (status & ENET_RDES0_PCERR))) {
+ /* drop current receive frame */
+ enet_rxframe_drop();
return 1U;
- }
+ }
- /* if CPU owns current descriptor, no error occured, the frame uses only one descriptor */
+ /* if CPU owns current descriptor, no error occurred, the frame uses only one descriptor */
if((((uint32_t)RESET) == (status & ENET_RDES0_DAV)) &&
- (((uint32_t)RESET) == (status & ENET_RDES0_ERRS)) &&
- (((uint32_t)RESET) != (status & ENET_RDES0_LDES)) &&
- (((uint32_t)RESET) != (status & ENET_RDES0_FDES))){
+ (((uint32_t)RESET) == (status & ENET_RDES0_ERRS)) &&
+ (((uint32_t)RESET) != (status & ENET_RDES0_LDES)) &&
+ (((uint32_t)RESET) != (status & ENET_RDES0_FDES))) {
/* get the size of the received data including CRC */
size = GET_RDES0_FRML(status);
- /* substract the CRC size */
+ /* substract the CRC size */
size = size - 4U;
- }else{
+ } else {
enet_unknow_err++;
enet_rxframe_drop();
- return 1U;
+ return 1U;
}
-
- /* return packet size */
+
+ /* return packet size */
return size;
}
@@ -694,62 +701,62 @@ void enet_descriptors_chain_init(enet_dmadirection_enum direction)
uint32_t num = 0U, count = 0U, maxsize = 0U;
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc, *desc_tab;
- uint8_t *buf;
+ uint8_t *buf;
/* if want to initialize DMA Tx descriptors */
- if (ENET_DMA_TX == direction){
+ if(ENET_DMA_TX == direction) {
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
maxsize = ENET_TXBUF_SIZE;
-
+
/* select chain mode */
desc_status = ENET_TDES0_TCHM;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
- }else{
+ } else {
/* if want to initialize DMA Rx descriptors */
/* save a copy of the DMA Rx descriptors */
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
maxsize = ENET_RXBUF_SIZE;
-
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive chained mode and set buffer1 size */
desc_bufsize = ENET_RDES1_RCHM | (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
- dma_current_rxdesc = desc_tab;
+ dma_current_rxdesc = desc_tab;
}
dma_current_ptp_rxdesc = NULL;
dma_current_ptp_txdesc = NULL;
-
- /* configure each descriptor */
- for(num=0U; num < count; num++){
+
+ /* configure each descriptor */
+ for(num = 0U; num < count; num++) {
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* if is not the last descriptor */
- if(num < (count - 1U)){
+ if(num < (count - 1U)) {
/* configure the next descriptor address */
desc->buffer2_next_desc_addr = (uint32_t)(desc_tab + num + 1U);
- }else{
- /* when it is the last descriptor, the next descriptor address
- equals to first descriptor address in descriptor table */
- desc->buffer2_next_desc_addr = (uint32_t) desc_tab;
+ } else {
+ /* when it is the last descriptor, the next descriptor address
+ equals to first descriptor address in descriptor table */
+ desc->buffer2_next_desc_addr = (uint32_t) desc_tab;
}
- }
+ }
}
/*!
@@ -767,64 +774,64 @@ void enet_descriptors_ring_init(enet_dmadirection_enum direction)
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc;
enet_descriptors_struct *desc_tab;
- uint8_t *buf;
-
+ uint8_t *buf;
+
/* configure descriptor skip length */
ENET_DMA_BCTL &= ~ENET_DMA_BCTL_DPSL;
ENET_DMA_BCTL |= DMA_BCTL_DPSL(0);
-
+
/* if want to initialize DMA Tx descriptors */
- if (ENET_DMA_TX == direction){
+ if(ENET_DMA_TX == direction) {
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
- }else{
+ } else {
/* if want to initialize DMA Rx descriptors */
/* save a copy of the DMA Rx descriptors */
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* set buffer1 size */
desc_bufsize = ENET_RXBUF_SIZE;
-
- /* configure DMA Rx descriptor table address register */
+
+ /* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
- dma_current_rxdesc = desc_tab;
+ dma_current_rxdesc = desc_tab;
}
dma_current_ptp_rxdesc = NULL;
dma_current_ptp_txdesc = NULL;
-
- /* configure each descriptor */
- for(num=0U; num < count; num++){
+
+ /* configure each descriptor */
+ for(num = 0U; num < count; num++) {
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
- desc->control_buffer_size = desc_bufsize;
- desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+ desc->status = desc_status;
+ desc->control_buffer_size = desc_bufsize;
+ desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
+
/* when it is the last descriptor */
- if(num == (count - 1U)){
- if (ENET_DMA_TX == direction){
- /* configure transmit end of ring mode */
+ if(num == (count - 1U)) {
+ if(ENET_DMA_TX == direction) {
+ /* configure transmit end of ring mode */
desc->status |= ENET_TDES0_TERM;
- }else{
+ } else {
/* configure receive end of ring mode */
desc->control_buffer_size |= ENET_RDES1_RERM;
}
}
- }
+ }
}
/*!
@@ -837,64 +844,64 @@ void enet_descriptors_ring_init(enet_dmadirection_enum direction)
ErrStatus enet_frame_receive(uint8_t *buffer, uint32_t bufsize)
{
uint32_t offset = 0U, size = 0U;
-
+
/* the descriptor is busy due to own by the DMA */
- if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)){
- return ERROR;
+ if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)) {
+ return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has copied data in application */
- if(NULL != buffer){
+ if(NULL != buffer) {
/* if no error occurs, and the frame uses only one descriptor */
- if((((uint32_t)RESET) == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
- (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
- (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
+ if((((uint32_t)RESET) == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
+ (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
+ (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_FDES))) {
/* get the frame length except CRC */
size = GET_RDES0_FRML(dma_current_rxdesc->status);
size = size - 4U;
-
+
/* to avoid situation that the frame size exceeds the buffer length */
- if(size > bufsize){
+ if(size > bufsize) {
return ERROR;
}
-
+
/* copy data from Rx buffer to application buffer */
- for(offset = 0U; offsetbuffer1_addr) + offset));
+ for(offset = 0U; offset < size; offset++) {
+ (*(buffer + offset)) = (*(__IO uint8_t *)(uint32_t)((dma_current_rxdesc->buffer1_addr) + offset));
}
-
- }else{
+
+ } else {
/* return ERROR */
return ERROR;
}
}
/* enable reception, descriptor is owned by DMA */
- dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+ dma_current_rxdesc->status = ENET_RDES0_DAV;
+
/* check Rx buffer unavailable flag status */
- if ((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)){
+ if((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)) {
/* clear RBU flag */
ENET_DMA_STAT = ENET_DMA_STAT_RBU;
/* resume DMA reception by writing to the RPEN register*/
ENET_DMA_RPEN = 0U;
}
-
- /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
+
+ /* update the current RxDMA descriptor pointer to the next descriptor in RxDMA descriptor table */
/* chained mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
- dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
- }else{
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)) {
+ dma_current_rxdesc = (enet_descriptors_struct *)(dma_current_rxdesc->buffer2_next_desc_addr);
+ } else {
/* ring mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)) {
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
- }else{
+ dma_current_rxdesc = (enet_descriptors_struct *)(ENET_DMA_RDTADDR);
+ } else {
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
+ dma_current_rxdesc = (enet_descriptors_struct *)(uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
}
}
-
+
return SUCCESS;
}
@@ -910,55 +917,55 @@ ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length)
{
uint32_t offset = 0U;
uint32_t dma_tbu_flag, dma_tu_flag;
-
+
/* the descriptor is busy due to own by the DMA */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)){
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)) {
return ERROR;
}
-
+
/* only frame length no more than ENET_MAX_FRAME_SIZE is allowed */
- if(length > ENET_MAX_FRAME_SIZE){
+ if(length > ENET_MAX_FRAME_SIZE) {
return ERROR;
- }
-
+ }
+
/* if buffer pointer is null, indicates that users has handled data in application */
- if(NULL != buffer){
+ if(NULL != buffer) {
/* copy frame data from application buffer to Tx buffer */
- for(offset = 0U; offset < length; offset++){
- (*(__IO uint8_t *) (uint32_t)((dma_current_txdesc->buffer1_addr) + offset)) = (*(buffer + offset));
+ for(offset = 0U; offset < length; offset++) {
+ (*(__IO uint8_t *)(uint32_t)((dma_current_txdesc->buffer1_addr) + offset)) = (*(buffer + offset));
}
}
-
+
/* set the frame length */
dma_current_txdesc->control_buffer_size = length;
- /* set the segment of frame, frame is transmitted in one descriptor */
+ /* set the segment of frame, frame is transmitted in one descriptor */
dma_current_txdesc->status |= ENET_TDES0_LSG | ENET_TDES0_FSG;
/* enable the DMA transmission */
dma_current_txdesc->status |= ENET_TDES0_DAV;
-
+
/* check Tx buffer unavailable flag status */
- dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
+ dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
dma_tu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TU);
-
- if ((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)){
+
+ if((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)) {
/* clear TBU and TU flag */
ENET_DMA_STAT = (dma_tbu_flag | dma_tu_flag);
/* resume DMA transmission by writing to the TPEN register*/
ENET_DMA_TPEN = 0U;
}
-
- /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table*/
+
+ /* update the current TxDMA descriptor pointer to the next descriptor in TxDMA descriptor table*/
/* chained mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
- dma_current_txdesc = (enet_descriptors_struct*) (dma_current_txdesc->buffer2_next_desc_addr);
- }else{
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)) {
+ dma_current_txdesc = (enet_descriptors_struct *)(dma_current_txdesc->buffer2_next_desc_addr);
+ } else {
/* ring mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)){
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)) {
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
- }else{
+ dma_current_txdesc = (enet_descriptors_struct *)(ENET_DMA_TDTADDR);
+ } else {
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_txdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
+ dma_current_txdesc = (enet_descriptors_struct *)(uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
}
}
@@ -1008,18 +1015,18 @@ void enet_disable(void)
}
/*!
- \brief configure MAC address
- \param[in] mac_addr: select which MAC address will be set,
- only one parameter can be selected which is shown as below
+ \brief configure MAC address
+ \param[in] mac_addr: select which MAC address will be set,
+ only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS0: set MAC address 0 filter
\arg ENET_MAC_ADDRESS1: set MAC address 1 filter
\arg ENET_MAC_ADDRESS2: set MAC address 2 filter
\arg ENET_MAC_ADDRESS3: set MAC address 3 filter
\param[in] paddr: the buffer pointer which stores the MAC address
- (little-ending store, such as MAC address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
+ (little-ending store, such as MAC address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
\param[out] none
\retval none
-*/
+*/
void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[])
{
REG32(ENET_ADDRH_BASE + (uint32_t)mac_addr) = ENET_SET_MACADDRH(paddr);
@@ -1027,7 +1034,7 @@ void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[])
}
/*!
- \brief get MAC address
+ \brief get MAC address
\param[in] mac_addr: select which MAC address will be get,
only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS0: get MAC address 0 filter
@@ -1035,9 +1042,9 @@ void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[])
\arg ENET_MAC_ADDRESS2: get MAC address 2 filter
\arg ENET_MAC_ADDRESS3: get MAC address 3 filter
\param[out] paddr: the buffer pointer which is stored the MAC address
- (little-ending store, such as mac address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
+ (little-ending store, such as mac address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
\retval none
-*/
+*/
void enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[])
{
paddr[0] = ENET_GET_MACADDR(mac_addr, 0U);
@@ -1049,277 +1056,41 @@ void enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[])
}
/*!
- \brief get the ENET MAC/MSC/PTP/DMA status flag
- \param[in] enet_flag: ENET status flag, refer to enet_flag_enum,
- only one parameter can be selected which is shown as below
- \arg ENET_MAC_FLAG_MPKR: magic packet received flag
- \arg ENET_MAC_FLAG_WUFR: wakeup frame received flag
- \arg ENET_MAC_FLAG_FLOWCONTROL: flow control status flag
- \arg ENET_MAC_FLAG_WUM: WUM status flag
- \arg ENET_MAC_FLAG_MSC: MSC status flag
- \arg ENET_MAC_FLAG_MSCR: MSC receive status flag
- \arg ENET_MAC_FLAG_MSCT: MSC transmit status flag
- \arg ENET_MAC_FLAG_TMST: time stamp trigger status flag
- \arg ENET_PTP_FLAG_TSSCO: timestamp second counter overflow flag
- \arg ENET_PTP_FLAG_TTM: target time match flag
- \arg ENET_MSC_FLAG_RFCE: received frames CRC error flag
- \arg ENET_MSC_FLAG_RFAE: received frames alignment error flag
- \arg ENET_MSC_FLAG_RGUF: received good unicast frames flag
- \arg ENET_MSC_FLAG_TGFSC: transmitted good frames single collision flag
- \arg ENET_MSC_FLAG_TGFMSC: transmitted good frames more single collision flag
- \arg ENET_MSC_FLAG_TGF: transmitted good frames flag
- \arg ENET_DMA_FLAG_TS: transmit status flag
- \arg ENET_DMA_FLAG_TPS: transmit process stopped status flag
- \arg ENET_DMA_FLAG_TBU: transmit buffer unavailable status flag
- \arg ENET_DMA_FLAG_TJT: transmit jabber timeout status flag
- \arg ENET_DMA_FLAG_RO: receive overflow status flag
- \arg ENET_DMA_FLAG_TU: transmit underflow status flag
- \arg ENET_DMA_FLAG_RS: receive status flag
- \arg ENET_DMA_FLAG_RBU: receive buffer unavailable status flag
- \arg ENET_DMA_FLAG_RPS: receive process stopped status flag
- \arg ENET_DMA_FLAG_RWT: receive watchdog timeout status flag
- \arg ENET_DMA_FLAG_ET: early transmit status flag
- \arg ENET_DMA_FLAG_FBE: fatal bus error status flag
- \arg ENET_DMA_FLAG_ER: early receive status flag
- \arg ENET_DMA_FLAG_AI: abnormal interrupt summary flag
- \arg ENET_DMA_FLAG_NI: normal interrupt summary flag
- \arg ENET_DMA_FLAG_EB_DMA_ERROR: DMA error flag
- \arg ENET_DMA_FLAG_EB_TRANSFER_ERROR: transfer error flag
- \arg ENET_DMA_FLAG_EB_ACCESS_ERROR: access error flag
- \arg ENET_DMA_FLAG_MSC: MSC status flag
- \arg ENET_DMA_FLAG_WUM: WUM status flag
- \arg ENET_DMA_FLAG_TST: timestamp trigger status flag
+ \brief ENET Tx function enable (include MAC and DMA module)
+ \param[in] none
\param[out] none
- \retval FlagStatus: SET or RESET
+ \retval none
*/
-FlagStatus enet_flag_get(enet_flag_enum enet_flag)
+void enet_tx_enable(void)
{
- if(RESET != (ENET_REG_VAL(enet_flag) & BIT(ENET_BIT_POS(enet_flag)))){
- return SET;
- }else{
- return RESET;
- }
+ ENET_MAC_CFG |= ENET_MAC_CFG_TEN;
+ enet_txfifo_flush();
+ ENET_DMA_CTL |= ENET_DMA_CTL_STE;
}
/*!
- \brief clear the ENET DMA status flag
- \param[in] enet_flag: ENET DMA flag clear, refer to enet_flag_clear_enum
- only one parameter can be selected which is shown as below
- \arg ENET_DMA_FLAG_TS_CLR: transmit status flag clear
- \arg ENET_DMA_FLAG_TPS_CLR: transmit process stopped status flag clear
- \arg ENET_DMA_FLAG_TBU_CLR: transmit buffer unavailable status flag clear
- \arg ENET_DMA_FLAG_TJT_CLR: transmit jabber timeout status flag clear
- \arg ENET_DMA_FLAG_RO_CLR: receive overflow status flag clear
- \arg ENET_DMA_FLAG_TU_CLR: transmit underflow status flag clear
- \arg ENET_DMA_FLAG_RS_CLR: receive status flag clear
- \arg ENET_DMA_FLAG_RBU_CLR: receive buffer unavailable status flag clear
- \arg ENET_DMA_FLAG_RPS_CLR: receive process stopped status flag clear
- \arg ENET_DMA_FLAG_RWT_CLR: receive watchdog timeout status flag clear
- \arg ENET_DMA_FLAG_ET_CLR: early transmit status flag clear
- \arg ENET_DMA_FLAG_FBE_CLR: fatal bus error status flag clear
- \arg ENET_DMA_FLAG_ER_CLR: early receive status flag clear
- \arg ENET_DMA_FLAG_AI_CLR: abnormal interrupt summary flag clear
- \arg ENET_DMA_FLAG_NI_CLR: normal interrupt summary flag clear
+ \brief ENET Tx function disable (include MAC and DMA module)
+ \param[in] none
\param[out] none
\retval none
*/
-void enet_flag_clear(enet_flag_clear_enum enet_flag)
+void enet_tx_disable(void)
{
- /* write 1 to the corresponding bit in ENET_DMA_STAT, to clear it */
- ENET_REG_VAL(enet_flag) = BIT(ENET_BIT_POS(enet_flag));
+ ENET_DMA_CTL &= ~ENET_DMA_CTL_STE;
+ enet_txfifo_flush();
+ ENET_MAC_CFG &= ~ENET_MAC_CFG_TEN;
}
/*!
- \brief enable ENET MAC/MSC/DMA interrupt
- \param[in] enet_int: ENET interrupt,
- only one parameter can be selected which is shown as below
- \arg ENET_MAC_INT_WUMIM: WUM interrupt mask
- \arg ENET_MAC_INT_TMSTIM: timestamp trigger interrupt mask
- \arg ENET_MSC_INT_RFCEIM: received frame CRC error interrupt mask
- \arg ENET_MSC_INT_RFAEIM: received frames alignment error interrupt mask
- \arg ENET_MSC_INT_RGUFIM: received good unicast frames interrupt mask
- \arg ENET_MSC_INT_TGFSCIM: transmitted good frames single collision interrupt mask
- \arg ENET_MSC_INT_TGFMSCIM: transmitted good frames more single collision interrupt mask
- \arg ENET_MSC_INT_TGFIM: transmitted good frames interrupt mask
- \arg ENET_DMA_INT_TIE: transmit interrupt enable
- \arg ENET_DMA_INT_TPSIE: transmit process stopped interrupt enable
- \arg ENET_DMA_INT_TBUIE: transmit buffer unavailable interrupt enable
- \arg ENET_DMA_INT_TJTIE: transmit jabber timeout interrupt enable
- \arg ENET_DMA_INT_ROIE: receive overflow interrupt enable
- \arg ENET_DMA_INT_TUIE: transmit underflow interrupt enable
- \arg ENET_DMA_INT_RIE: receive interrupt enable
- \arg ENET_DMA_INT_RBUIE: receive buffer unavailable interrupt enable
- \arg ENET_DMA_INT_RPSIE: receive process stopped interrupt enable
- \arg ENET_DMA_INT_RWTIE: receive watchdog timeout interrupt enable
- \arg ENET_DMA_INT_ETIE: early transmit interrupt enable
- \arg ENET_DMA_INT_FBEIE: fatal bus error interrupt enable
- \arg ENET_DMA_INT_ERIE: early receive interrupt enable
- \arg ENET_DMA_INT_AIE: abnormal interrupt summary enable
- \arg ENET_DMA_INT_NIE: normal interrupt summary enable
+ \brief ENET Rx function enable (include MAC and DMA module)
+ \param[in] none
\param[out] none
\retval none
*/
-void enet_interrupt_enable(enet_int_enum enet_int)
+void enet_rx_enable(void)
{
- if(DMA_INTEN_REG_OFFSET == ((uint32_t)enet_int >> 6)){
- /* ENET_DMA_INTEN register interrupt */
- ENET_REG_VAL(enet_int) |= BIT(ENET_BIT_POS(enet_int));
- }else{
- /* other INTMSK register interrupt */
- ENET_REG_VAL(enet_int) &= ~BIT(ENET_BIT_POS(enet_int));
- }
-}
-
-/*!
- \brief disable ENET MAC/MSC/DMA interrupt
- \param[in] enet_int: ENET interrupt,
- only one parameter can be selected which is shown as below
- \arg ENET_MAC_INT_WUMIM: WUM interrupt mask
- \arg ENET_MAC_INT_TMSTIM: timestamp trigger interrupt mask
- \arg ENET_MSC_INT_RFCEIM: received frame CRC error interrupt mask
- \arg ENET_MSC_INT_RFAEIM: received frames alignment error interrupt mask
- \arg ENET_MSC_INT_RGUFIM: received good unicast frames interrupt mask
- \arg ENET_MSC_INT_TGFSCIM: transmitted good frames single collision interrupt mask
- \arg ENET_MSC_INT_TGFMSCIM: transmitted good frames more single collision interrupt mask
- \arg ENET_MSC_INT_TGFIM: transmitted good frames interrupt mask
- \arg ENET_DMA_INT_TIE: transmit interrupt enable
- \arg ENET_DMA_INT_TPSIE: transmit process stopped interrupt enable
- \arg ENET_DMA_INT_TBUIE: transmit buffer unavailable interrupt enable
- \arg ENET_DMA_INT_TJTIE: transmit jabber timeout interrupt enable
- \arg ENET_DMA_INT_ROIE: receive overflow interrupt enable
- \arg ENET_DMA_INT_TUIE: transmit underflow interrupt enable
- \arg ENET_DMA_INT_RIE: receive interrupt enable
- \arg ENET_DMA_INT_RBUIE: receive buffer unavailable interrupt enable
- \arg ENET_DMA_INT_RPSIE: receive process stopped interrupt enable
- \arg ENET_DMA_INT_RWTIE: receive watchdog timeout interrupt enable
- \arg ENET_DMA_INT_ETIE: early transmit interrupt enable
- \arg ENET_DMA_INT_FBEIE: fatal bus error interrupt enable
- \arg ENET_DMA_INT_ERIE: early receive interrupt enable
- \arg ENET_DMA_INT_AIE: abnormal interrupt summary enable
- \arg ENET_DMA_INT_NIE: normal interrupt summary enable
- \param[out] none
- \retval none
-*/
-void enet_interrupt_disable(enet_int_enum enet_int)
-{
- if(DMA_INTEN_REG_OFFSET == ((uint32_t)enet_int >> 6)){
- /* ENET_DMA_INTEN register interrupt */
- ENET_REG_VAL(enet_int) &= ~BIT(ENET_BIT_POS(enet_int));
- }else{
- /* other INTMSK register interrupt */
- ENET_REG_VAL(enet_int) |= BIT(ENET_BIT_POS(enet_int));
- }
-}
-
-/*!
- \brief get ENET MAC/MSC/DMA interrupt flag
- \param[in] int_flag: ENET interrupt flag,
- only one parameter can be selected which is shown as below
- \arg ENET_MAC_INT_FLAG_WUM: WUM status flag
- \arg ENET_MAC_INT_FLAG_MSC: MSC status flag
- \arg ENET_MAC_INT_FLAG_MSCR: MSC receive status flag
- \arg ENET_MAC_INT_FLAG_MSCT: MSC transmit status flag
- \arg ENET_MAC_INT_FLAG_TMST: time stamp trigger status flag
- \arg ENET_MSC_INT_FLAG_RFCE: received frames CRC error flag
- \arg ENET_MSC_INT_FLAG_RFAE: received frames alignment error flag
- \arg ENET_MSC_INT_FLAG_RGUF: received good unicast frames flag
- \arg ENET_MSC_INT_FLAG_TGFSC: transmitted good frames single collision flag
- \arg ENET_MSC_INT_FLAG_TGFMSC: transmitted good frames more single collision flag
- \arg ENET_MSC_INT_FLAG_TGF: transmitted good frames flag
- \arg ENET_DMA_INT_FLAG_TS: transmit status flag
- \arg ENET_DMA_INT_FLAG_TPS: transmit process stopped status flag
- \arg ENET_DMA_INT_FLAG_TBU: transmit buffer unavailable status flag
- \arg ENET_DMA_INT_FLAG_TJT: transmit jabber timeout status flag
- \arg ENET_DMA_INT_FLAG_RO: receive overflow status flag
- \arg ENET_DMA_INT_FLAG_TU: transmit underflow status flag
- \arg ENET_DMA_INT_FLAG_RS: receive status flag
- \arg ENET_DMA_INT_FLAG_RBU: receive buffer unavailable status flag
- \arg ENET_DMA_INT_FLAG_RPS: receive process stopped status flag
- \arg ENET_DMA_INT_FLAG_RWT: receive watchdog timeout status flag
- \arg ENET_DMA_INT_FLAG_ET: early transmit status flag
- \arg ENET_DMA_INT_FLAG_FBE: fatal bus error status flag
- \arg ENET_DMA_INT_FLAG_ER: early receive status flag
- \arg ENET_DMA_INT_FLAG_AI: abnormal interrupt summary flag
- \arg ENET_DMA_INT_FLAG_NI: normal interrupt summary flag
- \arg ENET_DMA_INT_FLAG_MSC: MSC status flag
- \arg ENET_DMA_INT_FLAG_WUM: WUM status flag
- \arg ENET_DMA_INT_FLAG_TST: timestamp trigger status flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag)
-{
- if(RESET != (ENET_REG_VAL(int_flag) & BIT(ENET_BIT_POS(int_flag)))){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear ENET DMA interrupt flag
- \param[in] int_flag_clear: clear ENET interrupt flag,
- only one parameter can be selected which is shown as below
- \arg ENET_DMA_INT_FLAG_TS_CLR: transmit status flag
- \arg ENET_DMA_INT_FLAG_TPS_CLR: transmit process stopped status flag
- \arg ENET_DMA_INT_FLAG_TBU_CLR: transmit buffer unavailable status flag
- \arg ENET_DMA_INT_FLAG_TJT_CLR: transmit jabber timeout status flag
- \arg ENET_DMA_INT_FLAG_RO_CLR: receive overflow status flag
- \arg ENET_DMA_INT_FLAG_TU_CLR: transmit underflow status flag
- \arg ENET_DMA_INT_FLAG_RS_CLR: receive status flag
- \arg ENET_DMA_INT_FLAG_RBU_CLR: receive buffer unavailable status flag
- \arg ENET_DMA_INT_FLAG_RPS_CLR: receive process stopped status flag
- \arg ENET_DMA_INT_FLAG_RWT_CLR: receive watchdog timeout status flag
- \arg ENET_DMA_INT_FLAG_ET_CLR: early transmit status flag
- \arg ENET_DMA_INT_FLAG_FBE_CLR: fatal bus error status flag
- \arg ENET_DMA_INT_FLAG_ER_CLR: early receive status flag
- \arg ENET_DMA_INT_FLAG_AI_CLR: abnormal interrupt summary flag
- \arg ENET_DMA_INT_FLAG_NI_CLR: normal interrupt summary flag
- \param[out] none
- \retval none
-*/
-void enet_interrupt_flag_clear(enet_int_flag_clear_enum int_flag_clear)
-{
- /* write 1 to the corresponding bit in ENET_DMA_STAT, to clear it */
- ENET_REG_VAL(int_flag_clear) = BIT(ENET_BIT_POS(int_flag_clear));
-}
-
-/*!
- \brief ENET Tx function enable (include MAC and DMA module)
- \param[in] none
- \param[out] none
- \retval none
-*/
-void enet_tx_enable(void)
-{
- ENET_MAC_CFG |= ENET_MAC_CFG_TEN;
- enet_txfifo_flush();
- ENET_DMA_CTL |= ENET_DMA_CTL_STE;
-}
-
-/*!
- \brief ENET Tx function disable (include MAC and DMA module)
- \param[in] none
- \param[out] none
- \retval none
-*/
-void enet_tx_disable(void)
-{
- ENET_DMA_CTL &= ~ENET_DMA_CTL_STE;
- enet_txfifo_flush();
- ENET_MAC_CFG &= ~ENET_MAC_CFG_TEN;
-}
-
-/*!
- \brief ENET Rx function enable (include MAC and DMA module)
- \param[in] none
- \param[out] none
- \retval none
-*/
-void enet_rx_enable(void)
-{
- ENET_MAC_CFG |= ENET_MAC_CFG_REN;
- ENET_DMA_CTL |= ENET_DMA_CTL_SRE;
+ ENET_MAC_CFG |= ENET_MAC_CFG_REN;
+ ENET_DMA_CTL |= ENET_DMA_CTL_SRE;
}
/*!
@@ -1335,10 +1106,10 @@ void enet_rx_disable(void)
}
/*!
- \brief put registers value into the application buffer
+ \brief put registers value into the application buffer
\param[in] type: register type which will be get, refer to enet_registers_type_enum,
only one parameter can be selected which is shown as below
- \arg ALL_MAC_REG: get the registers within the offset scope between ENET_MAC_CFG and ENET_MAC_FCTH
+ \arg ALL_MAC_REG: get the registers within the offset scope between ENET_MAC_CFG and ENET_MAC_FCTH
\arg ALL_MSC_REG: get the registers within the offset scope between ENET_MSC_CTL and ENET_MSC_RGUFCNT
\arg ALL_PTP_REG: get the registers within the offset scope between ENET_PTP_TSCTL and ENET_PTP_PPSCTL
\arg ALL_DMA_REG: get the registers within the offset scope between ENET_DMA_BCTL and ENET_DMA_CRBADDR
@@ -1349,26 +1120,26 @@ void enet_rx_disable(void)
void enet_registers_get(enet_registers_type_enum type, uint32_t *preg, uint32_t num)
{
uint32_t offset = 0U, max = 0U, limit = 0U;
-
+
offset = (uint32_t)type;
max = (uint32_t)type + num;
- limit = sizeof(enet_reg_tab)/sizeof(uint16_t);
-
+ limit = sizeof(enet_reg_tab) / sizeof(uint16_t);
+
/* prevent element in this array is out of range */
- if(max > limit){
+ if(max > limit) {
max = limit;
}
-
- for(; offset < max; offset++){
+
+ for(; offset < max; offset++) {
/* get value of the corresponding register */
- *preg = REG32((ENET) + enet_reg_tab[offset]);
+ *preg = REG32((ENET) + enet_reg_tab[offset]);
preg++;
}
-}
+}
/*!
- \brief enable the MAC address filter
- \param[in] mac_addr: select which MAC address will be enable
+ \brief enable the MAC address filter
+ \param[in] mac_addr: select which MAC address will be enable
\arg ENET_MAC_ADDRESS1: enable MAC address 1 filter
\arg ENET_MAC_ADDRESS2: enable MAC address 2 filter
\arg ENET_MAC_ADDRESS3: enable MAC address 3 filter
@@ -1381,7 +1152,7 @@ void enet_address_filter_enable(enet_macaddress_enum mac_addr)
}
/*!
- \brief disable the MAC address filter
+ \brief disable the MAC address filter
\param[in] mac_addr: select which MAC address will be disable,
only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS1: disable MAC address 1 filter
@@ -1396,7 +1167,7 @@ void enet_address_filter_disable(enet_macaddress_enum mac_addr)
}
/*!
- \brief configure the MAC address filter
+ \brief configure the MAC address filter
\param[in] mac_addr: select which MAC address will be configured,
only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS1: configure MAC address 1 filter
@@ -1405,7 +1176,7 @@ void enet_address_filter_disable(enet_macaddress_enum mac_addr)
\param[in] addr_mask: select which MAC address bytes will be mask,
one or more parameters can be selected which are shown as below
\arg ENET_ADDRESS_MASK_BYTE0: mask ENET_MAC_ADDR1L[7:0] bits
- \arg ENET_ADDRESS_MASK_BYTE1: mask ENET_MAC_ADDR1L[15:8] bits
+ \arg ENET_ADDRESS_MASK_BYTE1: mask ENET_MAC_ADDR1L[15:8] bits
\arg ENET_ADDRESS_MASK_BYTE2: mask ENET_MAC_ADDR1L[23:16] bits
\arg ENET_ADDRESS_MASK_BYTE3: mask ENET_MAC_ADDR1L [31:24] bits
\arg ENET_ADDRESS_MASK_BYTE4: mask ENET_MAC_ADDR1H [7:0] bits
@@ -1420,7 +1191,7 @@ void enet_address_filter_disable(enet_macaddress_enum mac_addr)
void enet_address_filter_config(enet_macaddress_enum mac_addr, uint32_t addr_mask, uint32_t filter_type)
{
uint32_t reg;
-
+
/* get the address filter register value which is to be configured */
reg = REG32(ENET_ADDRH_BASE + mac_addr);
@@ -1435,53 +1206,53 @@ void enet_address_filter_config(enet_macaddress_enum mac_addr, uint32_t addr_mas
\param[in] none
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus enet_phy_config(void)
{
uint32_t ahbclk;
uint32_t reg;
uint16_t phy_value;
ErrStatus enet_state = ERROR;
-
+
/* clear the previous MDC clock */
reg = ENET_MAC_PHY_CTL;
reg &= ~ENET_MAC_PHY_CTL_CLR;
/* get the HCLK frequency */
ahbclk = rcu_clock_freq_get(CK_AHB);
-
+
/* configure MDC clock according to HCLK frequency range */
- if(ENET_RANGE(ahbclk, 20000000U, 35000000U)){
+ if(ENET_RANGE(ahbclk, 20000000U, 35000000U)) {
reg |= ENET_MDC_HCLK_DIV16;
- }else if(ENET_RANGE(ahbclk, 35000000U, 60000000U)){
+ } else if(ENET_RANGE(ahbclk, 35000000U, 60000000U)) {
reg |= ENET_MDC_HCLK_DIV26;
- }else if(ENET_RANGE(ahbclk, 60000000U, 100000000U)){
+ } else if(ENET_RANGE(ahbclk, 60000000U, 100000000U)) {
reg |= ENET_MDC_HCLK_DIV42;
- }else if((ENET_RANGE(ahbclk, 100000000U, 120000000U))||(120000000U == ahbclk)){
- reg |= ENET_MDC_HCLK_DIV62;
- }else{
+ } else if((ENET_RANGE(ahbclk, 100000000U, 120000000U)) || (120000000U == ahbclk)) {
+ reg |= ENET_MDC_HCLK_DIV62;
+ } else {
return enet_state;
}
ENET_MAC_PHY_CTL = reg;
/* reset PHY */
phy_value = PHY_RESET;
- if(ERROR == (enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value))){
+ if(ERROR == (enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value))) {
return enet_state;
}
- /* PHY reset need some time */
+ /* PHY reset need some time */
_ENET_DELAY_(ENET_DELAY_TO);
-
+
/* check whether PHY reset is complete */
- if(ERROR == (enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &phy_value))){
+ if(ERROR == (enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &phy_value))) {
return enet_state;
}
/* PHY reset complete */
- if(RESET == (phy_value & PHY_RESET)){
+ if(RESET == (phy_value & PHY_RESET)) {
enet_state = SUCCESS;
}
-
+
return enet_state;
}
@@ -1492,7 +1263,7 @@ ErrStatus enet_phy_config(void)
\arg ENET_PHY_READ: read data from phy register
\param[in] phy_address: 0x0 - 0x1F
\param[in] phy_reg: 0x0 - 0x1F
- \param[in] pvalue: the value will be written to the PHY register in ENET_PHY_WRITE direction
+ \param[in] pvalue: the value will be written to the PHY register in ENET_PHY_WRITE direction
\param[out] pvalue: the value will be read from the PHY register in ENET_PHY_READ direction
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -1502,34 +1273,33 @@ ErrStatus enet_phy_write_read(enet_phydirection_enum direction, uint16_t phy_add
uint32_t timeout = 0U;
ErrStatus enet_state = ERROR;
- /* configure ENET_MAC_PHY_CTL with write/read operation */
+ /* configure ENET_MAC_PHY_CTL with write/read operation */
reg = ENET_MAC_PHY_CTL;
reg &= ~(ENET_MAC_PHY_CTL_PB | ENET_MAC_PHY_CTL_PW | ENET_MAC_PHY_CTL_PR | ENET_MAC_PHY_CTL_PA);
- reg |= (direction | MAC_PHY_CTL_PR(phy_reg) | MAC_PHY_CTL_PA(phy_address) | ENET_MAC_PHY_CTL_PB);
+ reg |= (direction | MAC_PHY_CTL_PR(phy_reg) | MAC_PHY_CTL_PA(phy_address) | ENET_MAC_PHY_CTL_PB);
/* if do the write operation, write value to the register */
- if(ENET_PHY_WRITE == direction){
- ENET_MAC_PHY_DATA = *pvalue;
+ if(ENET_PHY_WRITE == direction) {
+ ENET_MAC_PHY_DATA = *pvalue;
}
-
+
/* do PHY write/read operation, and wait the operation complete */
ENET_MAC_PHY_CTL = reg;
- do{
+ do {
phy_flag = (ENET_MAC_PHY_CTL & ENET_MAC_PHY_CTL_PB);
timeout++;
- }
- while((RESET != phy_flag) && (ENET_DELAY_TO != timeout));
+ } while((RESET != phy_flag) && (ENET_DELAY_TO != timeout));
- /* write/read operation complete */
- if(RESET == (ENET_MAC_PHY_CTL & ENET_MAC_PHY_CTL_PB)){
+ /* write/read operation complete */
+ if(RESET == (ENET_MAC_PHY_CTL & ENET_MAC_PHY_CTL_PB)) {
enet_state = SUCCESS;
}
- /* if do the read operation, get value from the register */
- if(ENET_PHY_READ == direction){
- *pvalue = (uint16_t)ENET_MAC_PHY_DATA;
+ /* if do the read operation, get value from the register */
+ if(ENET_PHY_READ == direction) {
+ *pvalue = (uint16_t)ENET_MAC_PHY_DATA;
}
-
+
return enet_state;
}
@@ -1545,7 +1315,7 @@ ErrStatus enet_phyloopback_enable(void)
ErrStatus phy_state = ERROR;
/* get the PHY configuration to update it */
- enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
+ enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
/* enable the PHY loopback mode */
temp_phy |= PHY_LOOPBACK;
@@ -1568,7 +1338,7 @@ ErrStatus enet_phyloopback_disable(void)
ErrStatus phy_state = ERROR;
/* get the PHY configuration to update it */
- enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
+ enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
/* disable the PHY loopback mode */
temp_phy &= (uint16_t)~PHY_LOOPBACK;
@@ -1592,10 +1362,10 @@ ErrStatus enet_phyloopback_disable(void)
void enet_forward_feature_enable(uint32_t feature)
{
uint32_t mask;
-
+
mask = (feature & (~(ENET_FORWARD_ERRFRAMES | ENET_FORWARD_UNDERSZ_GOODFRAMES)));
ENET_MAC_CFG |= mask;
-
+
mask = (feature & (~(ENET_AUTO_PADCRC_DROP)));
ENET_DMA_CTL |= (mask >> 2);
}
@@ -1604,24 +1374,24 @@ void enet_forward_feature_enable(uint32_t feature)
\brief disable ENET forward feature
\param[in] feature: the feature of ENET forward mode,
one or more parameters can be selected which are shown as below
- \arg ENET_AUTO_PADCRC_DROP: the automatic zero-quanta generation function
- \arg ENET_FORWARD_ERRFRAMES: decoding function for the received pause frame and process it
- \arg ENET_FORWARD_UNDERSZ_GOODFRAMES: back pressure operation in the MAC(only use in half-dulex mode)
+ \arg ENET_AUTO_PADCRC_DROP: the function of the MAC strips the Pad/FCS field on received frames
+ \arg ENET_FORWARD_ERRFRAMES: the function that all frame received with error except runt error are forwarded to memory
+ \arg ENET_FORWARD_UNDERSZ_GOODFRAMES: the function that forwarding undersized good frames
\param[out] none
\retval none
*/
void enet_forward_feature_disable(uint32_t feature)
{
uint32_t mask;
-
+
mask = (feature & (~(ENET_FORWARD_ERRFRAMES | ENET_FORWARD_UNDERSZ_GOODFRAMES)));
ENET_MAC_CFG &= ~mask;
-
+
mask = (feature & (~(ENET_AUTO_PADCRC_DROP)));
- ENET_DMA_CTL &= ~(mask >> 2);
+ ENET_DMA_CTL &= ~(mask >> 2U);
}
-
-/*!
+
+/*!
\brief enable ENET fliter feature
\param[in] feature: the feature of ENET fliter mode,
one or more parameters can be selected which are shown as below
@@ -1666,18 +1436,18 @@ void enet_fliter_feature_disable(uint32_t feature)
\param[out] none
\retval ErrStatus: ERROR or SUCCESS
*/
-ErrStatus enet_pauseframe_generate(void)
-{
- ErrStatus enet_state =ERROR;
+ErrStatus enet_pauseframe_generate(void)
+{
+ ErrStatus enet_state = ERROR;
uint32_t temp = 0U;
/* in full-duplex mode, must make sure this bit is 0 before writing register */
temp = ENET_MAC_FCTL & ENET_MAC_FCTL_FLCBBKPA;
- if(RESET == temp){
+ if(RESET == temp) {
ENET_MAC_FCTL |= ENET_MAC_FCTL_FLCBBKPA;
enet_state = SUCCESS;
}
- return enet_state;
+ return enet_state;
}
/*!
@@ -1686,7 +1456,7 @@ ErrStatus enet_pauseframe_generate(void)
only one parameter can be selected which is shown as below
\arg ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT: besides the unique multicast address, MAC can also
use the MAC0 address to detecting pause frame
- \arg ENET_UNIQUE_PAUSEDETECT: only the unique multicast address for pause frame which is specified
+ \arg ENET_UNIQUE_PAUSEDETECT: only the unique multicast address for pause frame which is specified
in IEEE802.3 can be detected
\param[out] none
\retval none
@@ -1719,7 +1489,7 @@ void enet_pauseframe_config(uint32_t pausetime, uint32_t pause_threshold)
/*!
\brief configure the threshold of the flow control(deactive and active threshold)
\param[in] deactive: the threshold of the deactive flow control, this value
- should always be less than active flow control value, only one
+ should always be less than active flow control value, only one
parameter can be selected which is shown as below
\arg ENET_DEACTIVE_THRESHOLD_256BYTES: threshold level is 256 bytes
\arg ENET_DEACTIVE_THRESHOLD_512BYTES: threshold level is 512 bytes
@@ -1742,7 +1512,7 @@ void enet_pauseframe_config(uint32_t pausetime, uint32_t pause_threshold)
*/
void enet_flowcontrol_threshold_config(uint32_t deactive, uint32_t active)
{
- ENET_MAC_FCTH = ((deactive | active) >> 8);
+ ENET_MAC_FCTH = ((deactive | active) >> 8U);
}
/*!
@@ -1758,7 +1528,7 @@ void enet_flowcontrol_threshold_config(uint32_t deactive, uint32_t active)
*/
void enet_flowcontrol_feature_enable(uint32_t feature)
{
- if(RESET != (feature & ENET_ZERO_QUANTA_PAUSE)){
+ if(RESET != (feature & ENET_ZERO_QUANTA_PAUSE)) {
ENET_MAC_FCTL &= ~ENET_ZERO_QUANTA_PAUSE;
}
feature &= ~ENET_ZERO_QUANTA_PAUSE;
@@ -1778,7 +1548,7 @@ void enet_flowcontrol_feature_enable(uint32_t feature)
*/
void enet_flowcontrol_feature_disable(uint32_t feature)
{
- if(RESET != (feature & ENET_ZERO_QUANTA_PAUSE)){
+ if(RESET != (feature & ENET_ZERO_QUANTA_PAUSE)) {
ENET_MAC_FCTL |= ENET_ZERO_QUANTA_PAUSE;
}
feature &= ~ENET_ZERO_QUANTA_PAUSE;
@@ -1787,7 +1557,7 @@ void enet_flowcontrol_feature_disable(uint32_t feature)
/*!
\brief get the dma transmit/receive process state
- \param[in] direction: choose the direction of dma process which users want to check,
+ \param[in] direction: choose the direction of dma process which users want to check,
refer to enet_dmadirection_enum, only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: dma transmit process
\arg ENET_DMA_RX: dma receive process
@@ -1806,9 +1576,9 @@ uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction)
}
/*!
- \brief poll the DMA transmission/reception enable by writing any value to the
+ \brief poll the DMA transmission/reception enable by writing any value to the
ENET_DMA_TPEN/ENET_DMA_RPEN register, this will make the DMA to resume transmission/reception
- \param[in] direction: choose the direction of DMA process which users want to resume,
+ \param[in] direction: choose the direction of DMA process which users want to resume,
refer to enet_dmadirection_enum, only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA transmit process
\arg ENET_DMA_RX: DMA receive process
@@ -1817,15 +1587,15 @@ uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction)
*/
void enet_dmaprocess_resume(enet_dmadirection_enum direction)
{
- if(ENET_DMA_TX == direction){
+ if(ENET_DMA_TX == direction) {
ENET_DMA_TPEN = 0U;
- }else{
+ } else {
ENET_DMA_RPEN = 0U;
}
}
/*!
- \brief check and recover the Rx process
+ \brief check and recover the Rx process
\param[in] none
\param[out] none
\retval none
@@ -1834,15 +1604,15 @@ void enet_rxprocess_check_recovery(void)
{
uint32_t status;
- /* get DAV information of current RxDMA descriptor */
+ /* get DAV information of current RxDMA descriptor */
status = dma_current_rxdesc->status;
status &= ENET_RDES0_DAV;
-
- /* if current descriptor is owned by DMA, but the descriptor address mismatches with
+
+ /* if current descriptor is owned by DMA, but the descriptor address mismatches with
receive descriptor address pointer updated by RxDMA controller */
if((ENET_DMA_CRDADDR != ((uint32_t)dma_current_rxdesc)) &&
- (ENET_RDES0_DAV == status)){
- dma_current_rxdesc = (enet_descriptors_struct*)ENET_DMA_CRDADDR;
+ (ENET_RDES0_DAV == status)) {
+ dma_current_rxdesc = (enet_descriptors_struct *)ENET_DMA_CRDADDR;
}
}
@@ -1857,19 +1627,19 @@ ErrStatus enet_txfifo_flush(void)
uint32_t flush_state;
uint32_t timeout = 0U;
ErrStatus enet_state = ERROR;
-
+
/* set the FTF bit for flushing transmit FIFO */
- ENET_DMA_CTL |= ENET_DMA_CTL_FTF;
+ ENET_DMA_CTL |= ENET_DMA_CTL_FTF;
/* wait until the flush operation completes */
- do{
- flush_state = ENET_DMA_CTL & ENET_DMA_CTL_FTF;
+ do {
+ flush_state = ENET_DMA_CTL & ENET_DMA_CTL_FTF;
timeout++;
- }while((RESET != flush_state) && (timeout < ENET_DELAY_TO));
+ } while((RESET != flush_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
- if(RESET == flush_state){
+ if(RESET == flush_state) {
enet_state = SUCCESS;
}
-
+
return enet_state;
}
@@ -1885,14 +1655,14 @@ ErrStatus enet_txfifo_flush(void)
\arg ENET_TX_CURRENT_DESC: the start descriptor address of the current transmit descriptor read by
the TxDMA controller
\arg ENET_TX_CURRENT_BUFFER: the current transmit buffer address being read by the TxDMA controller
- \param[out] none
+ \param[out] none
\retval address value
*/
uint32_t enet_current_desc_address_get(enet_desc_reg_enum addr_get)
{
uint32_t reval = 0U;
- reval = REG32((ENET) +(uint32_t)addr_get);
+ reval = REG32((ENET) + (uint32_t)addr_get);
return reval;
}
@@ -1914,30 +1684,30 @@ uint32_t enet_desc_information_get(enet_descriptors_struct *desc, enet_descstate
{
uint32_t reval = 0xFFFFFFFFU;
- switch(info_get){
+ switch(info_get) {
case RXDESC_BUFFER_1_SIZE:
reval = GET_RDES1_RB1S(desc->control_buffer_size);
break;
case RXDESC_BUFFER_2_SIZE:
reval = GET_RDES1_RB2S(desc->control_buffer_size);
- break;
- case RXDESC_FRAME_LENGTH:
+ break;
+ case RXDESC_FRAME_LENGTH:
reval = GET_RDES0_FRML(desc->status);
- if(reval > 4U){
+ if(reval > 4U) {
reval = reval - 4U;
- }else{
+ } else {
reval = 0U;
}
break;
- case RXDESC_BUFFER_1_ADDR:
- reval = desc->buffer1_addr;
+ case RXDESC_BUFFER_1_ADDR:
+ reval = desc->buffer1_addr;
break;
- case TXDESC_BUFFER_1_ADDR:
- reval = desc->buffer1_addr;
+ case TXDESC_BUFFER_1_ADDR:
+ reval = desc->buffer1_addr;
break;
- case TXDESC_COLLISION_COUNT:
+ case TXDESC_COLLISION_COUNT:
reval = GET_TDES0_COCNT(desc->status);
- break;
+ break;
default:
break;
}
@@ -1954,7 +1724,7 @@ uint32_t enet_desc_information_get(enet_descriptors_struct *desc, enet_descstate
void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
{
uint32_t temp_counter = 0U;
-
+
temp_counter = ENET_DMA_MFBOCNT;
*rxfifo_drop = GET_DMA_MFBOCNT_MSFA(temp_counter);
*rxdma_drop = GET_DMA_MFBOCNT_MSFC(temp_counter);
@@ -1965,7 +1735,7 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
\param[in] desc: the descriptor pointer which users want to get flag
\param[in] desc_flag: the bit flag of ENET DMA descriptor,
only one parameter can be selected which is shown as below
- \arg ENET_TDES0_DB: deferred
+ \arg ENET_TDES0_DB: deferred
\arg ENET_TDES0_UFE: underflow error
\arg ENET_TDES0_EXD: excessive deferral
\arg ENET_TDES0_VFRM: VLAN frame
@@ -1978,18 +1748,18 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
\arg ENET_TDES0_JT: jabber timeout
\arg ENET_TDES0_ES: error summary
\arg ENET_TDES0_IPHE: IP header error
- \arg ENET_TDES0_TTMSS: transmit timestamp status
+ \arg ENET_TDES0_TTMSS: transmit timestamp status
\arg ENET_TDES0_TCHM: the second address chained mode
\arg ENET_TDES0_TERM: transmit end of ring mode
\arg ENET_TDES0_TTSEN: transmit timestamp function enable
- \arg ENET_TDES0_DPAD: disable adding pad
+ \arg ENET_TDES0_DPAD: disable adding pad
\arg ENET_TDES0_DCRC: disable CRC
\arg ENET_TDES0_FSG: first segment
\arg ENET_TDES0_LSG: last segment
\arg ENET_TDES0_INTC: interrupt on completion
\arg ENET_TDES0_DAV: DAV bit
-
- \arg ENET_RDES0_PCERR: payload checksum error
+
+ \arg ENET_RDES0_PCERR: payload checksum error
\arg ENET_RDES0_CERR: CRC error
\arg ENET_RDES0_DBERR: dribble bit error
\arg ENET_RDES0_RERR: receive error
@@ -2000,11 +1770,11 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
\arg ENET_RDES0_LDES: last descriptor
\arg ENET_RDES0_FDES: first descriptor
\arg ENET_RDES0_VTAG: VLAN tag
- \arg ENET_RDES0_OERR: overflow error
+ \arg ENET_RDES0_OERR: overflow error
\arg ENET_RDES0_LERR: length error
\arg ENET_RDES0_SAFF: SA filter fail
\arg ENET_RDES0_DERR: descriptor error
- \arg ENET_RDES0_ERRS: error summary
+ \arg ENET_RDES0_ERRS: error summary
\arg ENET_RDES0_DAFF: destination address filter fail
\arg ENET_RDES0_DAV: descriptor available
\param[out] none
@@ -2013,8 +1783,8 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag)
{
FlagStatus enet_flag = RESET;
-
- if ((uint32_t)RESET != (desc->status & desc_flag)){
+
+ if((uint32_t)RESET != (desc->status & desc_flag)) {
enet_flag = SET;
}
@@ -2031,13 +1801,13 @@ FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag)
\arg ENET_TDES0_TCHM: the second address chained mode
\arg ENET_TDES0_TERM: transmit end of ring mode
\arg ENET_TDES0_TTSEN: transmit timestamp function enable
- \arg ENET_TDES0_DPAD: disable adding pad
+ \arg ENET_TDES0_DPAD: disable adding pad
\arg ENET_TDES0_DCRC: disable CRC
\arg ENET_TDES0_FSG: first segment
\arg ENET_TDES0_LSG: last segment
\arg ENET_TDES0_INTC: interrupt on completion
\arg ENET_TDES0_DAV: DAV bit
- \arg ENET_RDES0_DAV: descriptor available
+ \arg ENET_RDES0_DAV: descriptor available
\param[out] none
\retval none
*/
@@ -2056,13 +1826,13 @@ void enet_desc_flag_set(enet_descriptors_struct *desc, uint32_t desc_flag)
\arg ENET_TDES0_TCHM: the second address chained mode
\arg ENET_TDES0_TERM: transmit end of ring mode
\arg ENET_TDES0_TTSEN: transmit timestamp function enable
- \arg ENET_TDES0_DPAD: disable adding pad
+ \arg ENET_TDES0_DPAD: disable adding pad
\arg ENET_TDES0_DCRC: disable CRC
\arg ENET_TDES0_FSG: first segment
\arg ENET_TDES0_LSG: last segment
\arg ENET_TDES0_INTC: interrupt on completion
\arg ENET_TDES0_DAV: DAV bit
- \arg ENET_RDES0_DAV: descriptor available
+ \arg ENET_RDES0_DAV: descriptor available
\param[out] none
\retval none
*/
@@ -2072,7 +1842,7 @@ void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag)
}
/*!
- \brief when receiving completed, set RS bit in ENET_DMA_STAT register will set
+ \brief when receiving completed, set RS bit in ENET_DMA_STAT register will set
\param[in] desc: the descriptor pointer which users want to configure
\param[out] none
\retval none
@@ -2083,7 +1853,7 @@ void enet_desc_receive_complete_bit_enable(enet_descriptors_struct *desc)
}
/*!
- \brief when receiving completed, set RS bit in ENET_DMA_STAT register will not set
+ \brief when receiving completed, set RS bit in ENET_DMA_STAT register will not set
\param[in] desc: the descriptor pointer which users want to configure
\param[out] none
\retval none
@@ -2102,36 +1872,36 @@ void enet_desc_receive_complete_bit_disable(enet_descriptors_struct *desc)
void enet_rxframe_drop(void)
{
/* enable reception, descriptor is owned by DMA */
- dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+ dma_current_rxdesc->status = ENET_RDES0_DAV;
+
/* chained mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
- if(NULL != dma_current_ptp_rxdesc){
- dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->buffer2_next_desc_addr);
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)) {
+ if(NULL != dma_current_ptp_rxdesc) {
+ dma_current_rxdesc = (enet_descriptors_struct *)(dma_current_ptp_rxdesc->buffer2_next_desc_addr);
/* if it is the last ptp descriptor */
- if(0U != dma_current_ptp_rxdesc->status){
+ if(0U != dma_current_ptp_rxdesc->status) {
/* pointer back to the first ptp descriptor address in the desc_ptptab list address */
- dma_current_ptp_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->status);
- }else{
- /* ponter to the next ptp descriptor */
+ dma_current_ptp_rxdesc = (enet_descriptors_struct *)(dma_current_ptp_rxdesc->status);
+ } else {
+ /* pointer to the next ptp descriptor */
dma_current_ptp_rxdesc++;
}
- }else{
- dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
+ } else {
+ dma_current_rxdesc = (enet_descriptors_struct *)(dma_current_rxdesc->buffer2_next_desc_addr);
}
-
- }else{
- /* ring mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
+
+ } else {
+ /* ring mode */
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)) {
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
- if(NULL != dma_current_ptp_rxdesc){
- dma_current_ptp_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->status);
+ dma_current_rxdesc = (enet_descriptors_struct *)(ENET_DMA_RDTADDR);
+ if(NULL != dma_current_ptp_rxdesc) {
+ dma_current_ptp_rxdesc = (enet_descriptors_struct *)(dma_current_ptp_rxdesc->status);
}
- }else{
+ } else {
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
- if(NULL != dma_current_ptp_rxdesc){
+ dma_current_rxdesc = (enet_descriptors_struct *)(uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
+ if(NULL != dma_current_ptp_rxdesc) {
dma_current_ptp_rxdesc++;
}
}
@@ -2149,7 +1919,7 @@ void enet_rxframe_drop(void)
*/
void enet_dma_feature_enable(uint32_t feature)
{
- ENET_DMA_CTL |= feature;
+ ENET_DMA_CTL |= feature;
}
/*!
@@ -2182,67 +1952,67 @@ void enet_ptp_normal_descriptors_chain_init(enet_dmadirection_enum direction, en
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc, *desc_tab;
uint8_t *buf;
-
+
/* if want to initialize DMA Tx descriptors */
- if (ENET_DMA_TX == direction){
+ if(ENET_DMA_TX == direction) {
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* select chain mode, and enable transmit timestamp function */
desc_status = ENET_TDES0_TCHM | ENET_TDES0_TTSEN;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
dma_current_ptp_txdesc = desc_ptptab;
- }else{
+ } else {
/* if want to initialize DMA Rx descriptors */
/* save a copy of the DMA Rx descriptors */
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive chained mode and set buffer1 size */
desc_bufsize = ENET_RDES1_RCHM | (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
dma_current_rxdesc = desc_tab;
- dma_current_ptp_rxdesc = desc_ptptab;
+ dma_current_ptp_rxdesc = desc_ptptab;
}
-
- /* configure each descriptor */
- for(num = 0U; num < count; num++){
+
+ /* configure each descriptor */
+ for(num = 0U; num < count; num++) {
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* if is not the last descriptor */
- if(num < (count - 1U)){
+ if(num < (count - 1U)) {
/* configure the next descriptor address */
desc->buffer2_next_desc_addr = (uint32_t)(desc_tab + num + 1U);
- }else{
- /* when it is the last descriptor, the next descriptor address
- equals to first descriptor address in descriptor table */
- desc->buffer2_next_desc_addr = (uint32_t)desc_tab;
+ } else {
+ /* when it is the last descriptor, the next descriptor address
+ equals to first descriptor address in descriptor table */
+ desc->buffer2_next_desc_addr = (uint32_t)desc_tab;
}
/* set desc_ptptab equal to desc_tab */
(&desc_ptptab[num])->buffer1_addr = desc->buffer1_addr;
(&desc_ptptab[num])->buffer2_next_desc_addr = desc->buffer2_next_desc_addr;
- }
- /* when it is the last ptp descriptor, preserve the first descriptor
+ }
+ /* when it is the last ptp descriptor, preserve the first descriptor
address of desc_ptptab in ptp descriptor status */
- (&desc_ptptab[num-1U])->status = (uint32_t)desc_ptptab;
+ (&desc_ptptab[num - 1U])->status = (uint32_t)desc_ptptab;
}
/*!
@@ -2265,57 +2035,57 @@ void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, ene
/* configure descriptor skip length */
ENET_DMA_BCTL &= ~ENET_DMA_BCTL_DPSL;
ENET_DMA_BCTL |= DMA_BCTL_DPSL(0);
-
+
/* if want to initialize DMA Tx descriptors */
- if (ENET_DMA_TX == direction){
+ if(ENET_DMA_TX == direction) {
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* select ring mode, and enable transmit timestamp function */
desc_status = ENET_TDES0_TTSEN;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
dma_current_ptp_txdesc = desc_ptptab;
- }else{
+ } else {
/* if want to initialize DMA Rx descriptors */
/* save a copy of the DMA Rx descriptors */
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive ring mode and set buffer1 size */
desc_bufsize = (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
dma_current_rxdesc = desc_tab;
- dma_current_ptp_rxdesc = desc_ptptab;
+ dma_current_ptp_rxdesc = desc_ptptab;
}
-
- /* configure each descriptor */
- for(num = 0U; num < count; num++){
+
+ /* configure each descriptor */
+ for(num = 0U; num < count; num++) {
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* when it is the last descriptor */
- if(num == (count - 1U)){
- if (ENET_DMA_TX == direction){
- /* configure transmit end of ring mode */
+ if(num == (count - 1U)) {
+ if(ENET_DMA_TX == direction) {
+ /* configure transmit end of ring mode */
desc->status |= ENET_TDES0_TERM;
- }else{
+ } else {
/* configure receive end of ring mode */
desc->control_buffer_size |= ENET_RDES1_RERM;
}
@@ -2323,14 +2093,14 @@ void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, ene
/* set desc_ptptab equal to desc_tab */
(&desc_ptptab[num])->buffer1_addr = desc->buffer1_addr;
(&desc_ptptab[num])->buffer2_next_desc_addr = desc->buffer2_next_desc_addr;
- }
- /* when it is the last ptp descriptor, preserve the first descriptor
+ }
+ /* when it is the last ptp descriptor, preserve the first descriptor
address of desc_ptptab in ptp descriptor status */
- (&desc_ptptab[num-1U])->status = (uint32_t)desc_ptptab;
+ (&desc_ptptab[num - 1U])->status = (uint32_t)desc_ptptab;
}
/*!
- \brief receive a packet data with timestamp values to application buffer, when the DMA is in normal mode
+ \brief receive a packet data with timestamp values to application buffer, when the DMA is in normal mode
\param[in] bufsize: the size of buffer which is the parameter in function
\param[out] timestamp: pointer to the table which stores the timestamp high and low
\param[out] buffer: pointer to the application buffer
@@ -2340,33 +2110,33 @@ void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, ene
ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, uint32_t timestamp[])
{
uint32_t offset = 0U, size = 0U;
-
+
/* the descriptor is busy due to own by the DMA */
- if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)){
+ if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)) {
return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has copied data in application */
- if(NULL != buffer){
+ if(NULL != buffer) {
/* if no error occurs, and the frame uses only one descriptor */
if(((uint32_t)RESET == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
- ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
- ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
-
+ ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
+ ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_FDES))) {
+
/* get the frame length except CRC */
size = GET_RDES0_FRML(dma_current_rxdesc->status) - 4U;
-
+
/* to avoid situation that the frame size exceeds the buffer length */
- if(size > bufsize){
+ if(size > bufsize) {
return ERROR;
}
/* copy data from Rx buffer to application buffer */
- for(offset = 0U; offset < size; offset++){
+ for(offset = 0U; offset < size; offset++) {
(*(buffer + offset)) = (*(__IO uint8_t *)(uint32_t)((dma_current_ptp_rxdesc->buffer1_addr) + offset));
}
-
- }else{
+
+ } else {
return ERROR;
}
}
@@ -2376,42 +2146,42 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
dma_current_rxdesc->buffer1_addr = dma_current_ptp_rxdesc ->buffer1_addr ;
dma_current_rxdesc->buffer2_next_desc_addr = dma_current_ptp_rxdesc ->buffer2_next_desc_addr;
-
+
/* enable reception, descriptor is owned by DMA */
dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+
/* check Rx buffer unavailable flag status */
- if ((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)){
+ if((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)) {
/* clear RBU flag */
ENET_DMA_STAT = ENET_DMA_STAT_RBU;
/* resume DMA reception by writing to the RPEN register*/
ENET_DMA_RPEN = 0U;
}
-
- /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
+
+ /* update the current RxDMA descriptor pointer to the next descriptor in RxDMA descriptor table */
/* chained mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
- dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->buffer2_next_desc_addr);
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)) {
+ dma_current_rxdesc = (enet_descriptors_struct *)(dma_current_ptp_rxdesc->buffer2_next_desc_addr);
/* if it is the last ptp descriptor */
- if(0U != dma_current_ptp_rxdesc->status){
+ if(0U != dma_current_ptp_rxdesc->status) {
/* pointer back to the first ptp descriptor address in the desc_ptptab list address */
- dma_current_ptp_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->status);
- }else{
+ dma_current_ptp_rxdesc = (enet_descriptors_struct *)(dma_current_ptp_rxdesc->status);
+ } else {
/* ponter to the next ptp descriptor */
dma_current_ptp_rxdesc++;
}
- }else{
- /* ring mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
+ } else {
+ /* ring mode */
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)) {
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
+ dma_current_rxdesc = (enet_descriptors_struct *)(ENET_DMA_RDTADDR);
/* RDES2 and RDES3 will not be covered by buffer address, so do not need to preserve a new table,
use the same table with RxDMA descriptor */
- dma_current_ptp_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->status);
- }else{
+ dma_current_ptp_rxdesc = (enet_descriptors_struct *)(dma_current_ptp_rxdesc->status);
+ } else {
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
+ dma_current_rxdesc = (enet_descriptors_struct *)(uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
dma_current_ptp_rxdesc ++;
}
}
@@ -2420,7 +2190,7 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
}
/*!
- \brief send data with timestamp values in application buffer as a transmit packet, when the DMA is in normal mode
+ \brief send data with timestamp values in application buffer as a transmit packet, when the DMA is in normal mode
\param[in] buffer: pointer on the application buffer
note -- if the input is NULL, user should copy data in application by himself
\param[in] length: the length of frame data to be transmitted
@@ -2431,23 +2201,23 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, uint32_t timestamp[])
{
uint32_t offset = 0U, timeout = 0U;
- uint32_t dma_tbu_flag, dma_tu_flag, tdes0_ttmss_flag;
-
+ uint32_t dma_tbu_flag, dma_tu_flag, tdes0_ttmss_flag;
+
/* the descriptor is busy due to own by the DMA */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)){
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)) {
return ERROR;
}
/* only frame length no more than ENET_MAX_FRAME_SIZE is allowed */
- if(length > ENET_MAX_FRAME_SIZE){
+ if(length > ENET_MAX_FRAME_SIZE) {
return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has handled data in application */
- if(NULL != buffer){
+ if(NULL != buffer) {
/* copy frame data from application buffer to Tx buffer */
- for(offset = 0U; offset < length; offset++){
- (*(__IO uint8_t *) (uint32_t)((dma_current_ptp_txdesc->buffer1_addr) + offset)) = (*(buffer + offset));
+ for(offset = 0U; offset < length; offset++) {
+ (*(__IO uint8_t *)(uint32_t)((dma_current_ptp_txdesc->buffer1_addr) + offset)) = (*(buffer + offset));
}
}
/* set the frame length */
@@ -2456,31 +2226,31 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
dma_current_txdesc->status |= ENET_TDES0_LSG | ENET_TDES0_FSG;
/* enable the DMA transmission */
dma_current_txdesc->status |= ENET_TDES0_DAV;
-
+
/* check Tx buffer unavailable flag status */
- dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
+ dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
dma_tu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TU);
-
- if((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)){
+
+ if((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)) {
/* clear TBU and TU flag */
ENET_DMA_STAT = (dma_tbu_flag | dma_tu_flag);
/* resume DMA transmission by writing to the TPEN register*/
ENET_DMA_TPEN = 0U;
}
-
+
/* if timestamp pointer is null, indicates that users don't care timestamp in application */
- if(NULL != timestamp){
+ if(NULL != timestamp) {
/* wait for ENET_TDES0_TTMSS flag to be set, a timestamp was captured */
- do{
+ do {
tdes0_ttmss_flag = (dma_current_txdesc->status & ENET_TDES0_TTMSS);
timeout++;
- }while((RESET == tdes0_ttmss_flag) && (timeout < ENET_DELAY_TO));
-
+ } while((RESET == tdes0_ttmss_flag) && (timeout < ENET_DELAY_TO));
+
/* return ERROR due to timeout */
- if(ENET_DELAY_TO == timeout){
+ if(ENET_DELAY_TO == timeout) {
return ERROR;
- }
-
+ }
+
/* clear the ENET_TDES0_TTMSS flag */
dma_current_txdesc->status &= ~ENET_TDES0_TTMSS;
/* get the timestamp value of the transmit frame */
@@ -2490,37 +2260,37 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
dma_current_txdesc->buffer1_addr = dma_current_ptp_txdesc ->buffer1_addr ;
dma_current_txdesc->buffer2_next_desc_addr = dma_current_ptp_txdesc ->buffer2_next_desc_addr;
- /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table */
+ /* update the current TxDMA descriptor pointer to the next descriptor in TxDMA descriptor table */
/* chained mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
- dma_current_txdesc = (enet_descriptors_struct*) (dma_current_ptp_txdesc->buffer2_next_desc_addr);
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)) {
+ dma_current_txdesc = (enet_descriptors_struct *)(dma_current_ptp_txdesc->buffer2_next_desc_addr);
/* if it is the last ptp descriptor */
- if(0U != dma_current_ptp_txdesc->status){
+ if(0U != dma_current_ptp_txdesc->status) {
/* pointer back to the first ptp descriptor address in the desc_ptptab list address */
- dma_current_ptp_txdesc = (enet_descriptors_struct*) (dma_current_ptp_txdesc->status);
- }else{
- /* ponter to the next ptp descriptor */
+ dma_current_ptp_txdesc = (enet_descriptors_struct *)(dma_current_ptp_txdesc->status);
+ } else {
+ /* pointer to the next ptp descriptor */
dma_current_ptp_txdesc++;
}
- }else{
- /* ring mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)){
+ } else {
+ /* ring mode */
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)) {
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
+ dma_current_txdesc = (enet_descriptors_struct *)(ENET_DMA_TDTADDR);
/* TDES2 and TDES3 will not be covered by buffer address, so do not need to preserve a new table,
use the same table with TxDMA descriptor */
- dma_current_ptp_txdesc = (enet_descriptors_struct*) (dma_current_ptp_txdesc->status);
- }else{
+ dma_current_ptp_txdesc = (enet_descriptors_struct *)(dma_current_ptp_txdesc->status);
+ } else {
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_txdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
- dma_current_ptp_txdesc ++;
+ dma_current_txdesc = (enet_descriptors_struct *)(uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
+ dma_current_ptp_txdesc ++;
}
}
return SUCCESS;
}
/*!
- \brief wakeup frame filter register pointer reset
+ \brief wakeup frame filter register pointer reset
\param[in] none
\param[out] none
\retval none
@@ -2531,7 +2301,7 @@ void enet_wum_filter_register_pointer_reset(void)
}
/*!
- \brief set the remote wakeup frame registers
+ \brief set the remote wakeup frame registers
\param[in] pdata: pointer to buffer data which is written to remote wakeup frame registers (8 words total)
\param[out] none
\retval none
@@ -2539,15 +2309,15 @@ void enet_wum_filter_register_pointer_reset(void)
void enet_wum_filter_config(uint32_t pdata[])
{
uint32_t num = 0U;
-
+
/* configure ENET_MAC_RWFF register */
- for(num = 0U; num < ETH_WAKEUP_REGISTER_LENGTH; num++){
+ for(num = 0U; num < ETH_WAKEUP_REGISTER_LENGTH; num++) {
ENET_MAC_RWFF = pdata[num];
}
}
/*!
- \brief enable wakeup management features
+ \brief enable wakeup management features
\param[in] feature: one or more parameters can be selected which are shown as below
\arg ENET_WUM_POWER_DOWN: power down mode
\arg ENET_WUM_MAGIC_PACKET_FRAME: enable a wakeup event due to magic packet reception
@@ -2562,7 +2332,7 @@ void enet_wum_feature_enable(uint32_t feature)
}
/*!
- \brief disable wakeup management features
+ \brief disable wakeup management features
\param[in] feature: one or more parameters can be selected which are shown as below
\arg ENET_WUM_MAGIC_PACKET_FRAME: enable a wakeup event due to magic packet reception
\arg ENET_WUM_WAKE_UP_FRAME: enable a wakeup event due to wakeup frame reception
@@ -2576,8 +2346,8 @@ void enet_wum_feature_disable(uint32_t feature)
}
/*!
- \brief reset the MAC statistics counters
- \param[in] none
+ \brief reset the MAC statistics counters
+ \param[in] none
\param[out] none
\retval none
*/
@@ -2603,7 +2373,7 @@ void enet_msc_feature_enable(uint32_t feature)
/*!
\brief disable the MAC statistics counter features
- \param[in] feature: one or more parameters can be selected which are shown as below
+ \param[in] feature: one or more parameters can be selected which are shown as below
\arg ENET_MSC_COUNTER_STOP_ROLLOVER: counter stop rollover
\arg ENET_MSC_RESET_ON_READ: reset on read
\arg ENET_MSC_COUNTERS_FREEZE: MSC counter freeze
@@ -2612,11 +2382,11 @@ void enet_msc_feature_enable(uint32_t feature)
*/
void enet_msc_feature_disable(uint32_t feature)
{
- ENET_MSC_CTL &= (~feature);
+ ENET_MSC_CTL &= (~feature);
}
/*!
- \brief get MAC statistics counter
+ \brief get MAC statistics counter
\param[in] counter: MSC counters which is selected, refer to enet_msc_counter_enum,
only one parameter can be selected which is shown as below
\arg ENET_MSC_TX_SCCNT: MSC transmitted good frames after a single collision counter
@@ -2631,14 +2401,14 @@ void enet_msc_feature_disable(uint32_t feature)
uint32_t enet_msc_counters_get(enet_msc_counter_enum counter)
{
uint32_t reval;
-
+
reval = REG32((ENET + (uint32_t)counter));
-
+
return reval;
}
/*!
- \brief change subsecond to nanosecond
+ \brief change subsecond to nanosecond
\param[in] subsecond: subsecond value
\param[out] none
\retval the nanosecond value
@@ -2646,12 +2416,12 @@ uint32_t enet_msc_counters_get(enet_msc_counter_enum counter)
uint32_t enet_ptp_subsecond_2_nanosecond(uint32_t subsecond)
{
uint64_t val = subsecond * 1000000000Ull;
- val >>= 31;
+ val >>= 31U;
return (uint32_t)val;
}
/*!
- \brief change nanosecond to subsecond
+ \brief change nanosecond to subsecond
\param[in] nanosecond: nanosecond value
\param[out] none
\retval the subsecond value
@@ -2709,54 +2479,54 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
uint32_t timeout = 0U;
ErrStatus enet_state = SUCCESS;
- switch(func){
- case ENET_PTP_ADDEND_UPDATE:
+ switch(func) {
+ case ENET_PTP_ADDEND_UPDATE:
/* this bit must be read as zero before application set it */
- do{
- temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSARU;
+ do {
+ temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSARU;
timeout++;
- }while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
+ } while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
- if(ENET_DELAY_TO == timeout){
+ if(ENET_DELAY_TO == timeout) {
enet_state = ERROR;
- }else{
+ } else {
ENET_PTP_TSCTL |= ENET_PTP_TSCTL_TMSARU;
- }
+ }
break;
case ENET_PTP_SYSTIME_UPDATE:
/* both the TMSSTU and TMSSTI bits must be read as zero before application set this bit */
- do{
- temp_state = ENET_PTP_TSCTL & (ENET_PTP_TSCTL_TMSSTU | ENET_PTP_TSCTL_TMSSTI);
+ do {
+ temp_state = ENET_PTP_TSCTL & (ENET_PTP_TSCTL_TMSSTU | ENET_PTP_TSCTL_TMSSTI);
timeout++;
- }while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
+ } while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
- if(ENET_DELAY_TO == timeout){
+ if(ENET_DELAY_TO == timeout) {
enet_state = ERROR;
- }else{
+ } else {
ENET_PTP_TSCTL |= ENET_PTP_TSCTL_TMSSTU;
- }
- break;
+ }
+ break;
case ENET_PTP_SYSTIME_INIT:
/* this bit must be read as zero before application set it */
- do{
- temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSSTI;
+ do {
+ temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSSTI;
timeout++;
- }while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
+ } while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
- if(ENET_DELAY_TO == timeout){
+ if(ENET_DELAY_TO == timeout) {
enet_state = ERROR;
- }else{
+ } else {
ENET_PTP_TSCTL |= ENET_PTP_TSCTL_TMSSTI;
- }
- break;
+ }
+ break;
default:
- temp_config = (uint32_t)func & (~BIT(31));
- if(RESET != ((uint32_t)func & BIT(31))){
- ENET_PTP_TSCTL |= temp_config;
- }else{
- ENET_PTP_TSCTL &= ~temp_config;
+ temp_config = (uint32_t)func & (~BIT(31));
+ if(RESET != ((uint32_t)func & BIT(31))) {
+ ENET_PTP_TSCTL |= temp_config;
+ } else {
+ ENET_PTP_TSCTL &= ~temp_config;
}
- break;
+ break;
}
return enet_state;
@@ -2764,7 +2534,7 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
/*!
\brief configure system time subsecond increment value
- \param[in] subsecond: the value will be added to the subsecond value of system time,
+ \param[in] subsecond: the value will be added to the subsecond value of system time,
this value must be between 0 and 0xFF
\param[out] none
\retval none
@@ -2792,7 +2562,7 @@ void enet_ptp_timestamp_addend_config(uint32_t add)
\arg ENET_PTP_ADD_TO_TIME: timestamp update value is added to system time
\arg ENET_PTP_SUBSTRACT_FROM_TIME: timestamp update value is subtracted from system time
\param[in] second: initializing or adding/subtracting to second of the system time
- \param[in] subsecond: the current subsecond of the system time
+ \param[in] subsecond: the current subsecond of the system time
with 0.46 ns accuracy if required accuracy is 20 ns
\param[out] none
\retval none
@@ -2800,7 +2570,7 @@ void enet_ptp_timestamp_addend_config(uint32_t add)
void enet_ptp_timestamp_update_config(uint32_t sign, uint32_t second, uint32_t subsecond)
{
ENET_PTP_TSUH = second;
- ENET_PTP_TSUL = sign | PTP_TSUL_TMSUSS(subsecond);
+ ENET_PTP_TSUL = sign | PTP_TSUL_TMSUSS(subsecond);
}
/*!
@@ -2819,7 +2589,7 @@ void enet_ptp_expected_time_config(uint32_t second, uint32_t nanosecond)
/*!
\brief get the current system time
\param[in] none
- \param[out] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
+ \param[out] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
parameters of PTP system time
members of the structure and the member values are shown as below:
second: 0x0 - 0xFFFF FFFF
@@ -2831,11 +2601,11 @@ void enet_ptp_system_time_get(enet_ptp_systime_struct *systime_struct)
{
uint32_t temp_sec = 0U, temp_subs = 0U;
- /* get the value of sysytem time registers */
- temp_sec = (uint32_t)ENET_PTP_TSH;
+ /* get the value of system time registers */
+ temp_sec = (uint32_t)ENET_PTP_TSH;
temp_subs = (uint32_t)ENET_PTP_TSL;
-
- /* get sysytem time and construct the enet_ptp_systime_struct structure */
+
+ /* get system time and construct the enet_ptp_systime_struct structure */
systime_struct->second = temp_sec;
systime_struct->nanosecond = GET_PTP_TSL_STMSS(temp_subs);
systime_struct->nanosecond = enet_ptp_subsecond_2_nanosecond(systime_struct->nanosecond);
@@ -2865,12 +2635,12 @@ void enet_ptp_start(int32_t updatemethod, uint32_t init_sec, uint32_t init_subse
/* configure system time subsecond increment based on the PTP clock frequency */
enet_ptp_subsecond_increment_config(accuracy_cfg);
- if(ENET_PTP_FINEMODE == updatemethod){
+ if(ENET_PTP_FINEMODE == updatemethod) {
/* fine correction method: configure the timestamp addend, then update */
enet_ptp_timestamp_addend_config(carry_cfg);
enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
/* wait until update is completed */
- while(SET == enet_ptp_flag_get((uint32_t)ENET_PTP_ADDEND_UPDATE)){
+ while(SET == enet_ptp_flag_get((uint32_t)ENET_PTP_ADDEND_UPDATE)) {
}
}
@@ -2897,7 +2667,7 @@ void enet_ptp_finecorrection_adjfreq(int32_t carry_cfg)
/*!
\brief update system time in coarse method
- \param[in] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
+ \param[in] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
parameters of PTP system time
members of the structure and the member values are shown as below:
second: 0x0 - 0xFFFF FFFF
@@ -2912,7 +2682,7 @@ void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct *systime_s
uint32_t carry_cfg;
subsecond_val = enet_ptp_nanosecond_2_subsecond(systime_struct->nanosecond);
-
+
/* save the carry_cfg value */
carry_cfg = ENET_PTP_TSADDEND_TMSA;
@@ -2921,9 +2691,9 @@ void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct *systime_s
enet_ptp_timestamp_function_config(ENET_PTP_SYSTIME_UPDATE);
/* wait until the update is completed */
- while(SET == enet_ptp_flag_get((uint32_t)ENET_PTP_SYSTIME_UPDATE)){
+ while(SET == enet_ptp_flag_get((uint32_t)ENET_PTP_SYSTIME_UPDATE)) {
}
-
+
/* write back the carry_cfg value, then update */
enet_ptp_timestamp_addend_config(carry_cfg);
enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
@@ -2931,7 +2701,7 @@ void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct *systime_s
/*!
\brief set system time in fine method
- \param[in] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
+ \param[in] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
parameters of PTP system time
members of the structure and the member values are shown as below:
second: 0x0 - 0xFFFF FFFF
@@ -2940,7 +2710,7 @@ void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct *systime_s
\param[out] none
\retval none
*/
-void enet_ptp_finecorrection_settime(enet_ptp_systime_struct * systime_struct)
+void enet_ptp_finecorrection_settime(enet_ptp_systime_struct *systime_struct)
{
uint32_t subsecond_val;
@@ -2949,15 +2719,15 @@ void enet_ptp_finecorrection_settime(enet_ptp_systime_struct * systime_struct)
/* initialize the system time */
enet_ptp_timestamp_update_config(systime_struct->sign, systime_struct->second, subsecond_val);
enet_ptp_timestamp_function_config(ENET_PTP_SYSTIME_INIT);
-
+
/* wait until the system time initialzation finished */
- while(SET == enet_ptp_flag_get((uint32_t)ENET_PTP_SYSTIME_INIT)){
+ while(SET == enet_ptp_flag_get((uint32_t)ENET_PTP_SYSTIME_INIT)) {
}
}
/*!
\brief get the ptp flag status
- \param[in] flag: ptp flag status to be checked
+ \param[in] flag: ptp flag status to be checked
\arg ENET_PTP_ADDEND_UPDATE: addend register update
\arg ENET_PTP_SYSTIME_UPDATE: timestamp update
\arg ENET_PTP_SYSTIME_INIT: timestamp initialize
@@ -2968,10 +2738,10 @@ FlagStatus enet_ptp_flag_get(uint32_t flag)
{
FlagStatus bitstatus = RESET;
- if ((uint32_t)RESET != (ENET_PTP_TSCTL & flag)){
+ if((uint32_t)RESET != (ENET_PTP_TSCTL & flag)) {
bitstatus = SET;
}
-
+
return bitstatus;
}
@@ -2989,7 +2759,7 @@ void enet_initpara_reset(void)
enet_initpara.dma_maxburst = 0U;
enet_initpara.dma_arbitration = 0U;
enet_initpara.store_forward_mode = 0U;
- enet_initpara.dma_function = 0U;
+ enet_initpara.dma_function = 0U;
enet_initpara.vlan_config = 0U;
enet_initpara.flow_control = 0U;
enet_initpara.hashtable_high = 0U;
@@ -2998,10 +2768,10 @@ void enet_initpara_reset(void)
enet_initpara.halfduplex_param = 0U;
enet_initpara.timer_config = 0U;
enet_initpara.interframegap = 0U;
-}
+}
/*!
- \brief initialize ENET peripheral with generally concerned parameters, call it by enet_init()
+ \brief initialize ENET peripheral with generally concerned parameters, call it by enet_init()
\param[in] none
\param[out] none
\retval none
@@ -3015,56 +2785,53 @@ static void enet_default_init(void)
reg_value = ENET_MAC_CFG;
reg_value &= MAC_CFG_MASK;
reg_value |= ENET_WATCHDOG_ENABLE | ENET_JABBER_ENABLE | ENET_INTERFRAMEGAP_96BIT \
- | ENET_SPEEDMODE_10M |ENET_MODE_HALFDUPLEX | ENET_LOOPBACKMODE_DISABLE \
- | ENET_CARRIERSENSE_ENABLE | ENET_RECEIVEOWN_ENABLE \
- | ENET_RETRYTRANSMISSION_ENABLE | ENET_BACKOFFLIMIT_10 \
- | ENET_DEFERRALCHECK_DISABLE \
- | ENET_AUTO_PADCRC_DROP_DISABLE \
- | ENET_CHECKSUMOFFLOAD_DISABLE;
+ | ENET_SPEEDMODE_10M | ENET_MODE_HALFDUPLEX | ENET_LOOPBACKMODE_DISABLE \
+ | ENET_CARRIERSENSE_ENABLE | ENET_RECEIVEOWN_ENABLE \
+ | ENET_RETRYTRANSMISSION_ENABLE | ENET_BACKOFFLIMIT_10 \
+ | ENET_DEFERRALCHECK_DISABLE \
+ | ENET_AUTO_PADCRC_DROP_DISABLE \
+ | ENET_CHECKSUMOFFLOAD_DISABLE;
ENET_MAC_CFG = reg_value;
-
+
/* configure ENET_MAC_FRMF register */
- ENET_MAC_FRMF = ENET_SRC_FILTER_DISABLE |ENET_DEST_FILTER_INVERSE_DISABLE \
- |ENET_MULTICAST_FILTER_PERFECT |ENET_UNICAST_FILTER_PERFECT \
- |ENET_PCFRM_PREVENT_ALL |ENET_BROADCASTFRAMES_ENABLE \
- |ENET_PROMISCUOUS_DISABLE |ENET_RX_FILTER_ENABLE;
+ ENET_MAC_FRMF = ENET_SRC_FILTER_DISABLE | ENET_DEST_FILTER_INVERSE_DISABLE \
+ | ENET_MULTICAST_FILTER_PERFECT | ENET_UNICAST_FILTER_PERFECT \
+ | ENET_PCFRM_PREVENT_ALL | ENET_BROADCASTFRAMES_ENABLE \
+ | ENET_PROMISCUOUS_DISABLE | ENET_RX_FILTER_ENABLE;
/* configure ENET_MAC_HLH, ENET_MAC_HLL register */
ENET_MAC_HLH = 0x0U;
-
+
ENET_MAC_HLL = 0x0U;
/* configure ENET_MAC_FCTL, ENET_MAC_FCTH register */
reg_value = ENET_MAC_FCTL;
reg_value &= MAC_FCTL_MASK;
- reg_value |= MAC_FCTL_PTM(0) |ENET_ZERO_QUANTA_PAUSE_DISABLE \
- |ENET_PAUSETIME_MINUS4 |ENET_UNIQUE_PAUSEDETECT \
- |ENET_RX_FLOWCONTROL_DISABLE |ENET_TX_FLOWCONTROL_DISABLE;
- ENET_MAC_FCTL = reg_value;
-
- ENET_MAC_FCTH = ENET_DEACTIVE_THRESHOLD_512BYTES |ENET_ACTIVE_THRESHOLD_1536BYTES;
-
+ reg_value |= MAC_FCTL_PTM(0) | ENET_ZERO_QUANTA_PAUSE_DISABLE \
+ | ENET_PAUSETIME_MINUS4 | ENET_UNIQUE_PAUSEDETECT \
+ | ENET_RX_FLOWCONTROL_DISABLE | ENET_TX_FLOWCONTROL_DISABLE;
+ ENET_MAC_FCTL = reg_value;
+
/* configure ENET_MAC_VLT register */
- ENET_MAC_VLT = ENET_VLANTAGCOMPARISON_16BIT |MAC_VLT_VLTI(0);
-
+ ENET_MAC_VLT = ENET_VLANTAGCOMPARISON_16BIT | MAC_VLT_VLTI(0);
+
/* DMA */
/* configure ENET_DMA_CTL register */
reg_value = ENET_DMA_CTL;
reg_value &= DMA_CTL_MASK;
- reg_value |= ENET_TCPIP_CKSUMERROR_DROP |ENET_RX_MODE_STOREFORWARD \
- |ENET_FLUSH_RXFRAME_ENABLE |ENET_TX_MODE_STOREFORWARD \
- |ENET_TX_THRESHOLD_64BYTES |ENET_RX_THRESHOLD_64BYTES \
- |ENET_FORWARD_ERRFRAMES_DISABLE |ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE \
- |ENET_SECONDFRAME_OPT_DISABLE;
- ENET_DMA_CTL = reg_value;
+ reg_value |= ENET_TCPIP_CKSUMERROR_DROP | ENET_RX_MODE_STOREFORWARD \
+ | ENET_FLUSH_RXFRAME_ENABLE | ENET_TX_MODE_STOREFORWARD \
+ | ENET_TX_THRESHOLD_64BYTES | ENET_RX_THRESHOLD_64BYTES \
+ | ENET_SECONDFRAME_OPT_DISABLE;
+ ENET_DMA_CTL = reg_value;
/* configure ENET_DMA_BCTL register */
reg_value = ENET_DMA_BCTL;
reg_value &= DMA_BCTL_MASK;
- reg_value = ENET_ADDRESS_ALIGN_ENABLE |ENET_ARBITRATION_RXTX_2_1 \
- |ENET_RXDP_32BEAT |ENET_PGBL_32BEAT |ENET_RXTX_DIFFERENT_PGBL \
- |ENET_FIXED_BURST_ENABLE;
- ENET_DMA_BCTL = reg_value;
+ reg_value = ENET_ADDRESS_ALIGN_ENABLE | ENET_ARBITRATION_RXTX_2_1 \
+ | ENET_RXDP_32BEAT | ENET_PGBL_32BEAT | ENET_RXTX_DIFFERENT_PGBL \
+ | ENET_FIXED_BURST_ENABLE;
+ ENET_DMA_BCTL = reg_value;
}
#ifndef USE_DELAY
@@ -3076,11 +2843,247 @@ static void enet_default_init(void)
*/
static void enet_delay(uint32_t ncount)
{
- __IO uint32_t delay_time = 0U;
-
- for(delay_time = ncount; delay_time != 0U; delay_time--){
+ __IO uint32_t delay_time = 0U;
+
+ for(delay_time = ncount; delay_time != 0U; delay_time--) {
}
}
#endif /* USE_DELAY */
+/*!
+ \brief get the ENET MAC/MSC/PTP/DMA status flag
+ \param[in] enet_flag: ENET status flag, refer to enet_flag_enum,
+ only one parameter can be selected which is shown as below
+ \arg ENET_MAC_FLAG_MPKR: magic packet received flag
+ \arg ENET_MAC_FLAG_WUFR: wakeup frame received flag
+ \arg ENET_MAC_FLAG_FLOWCONTROL: flow control status flag
+ \arg ENET_MAC_FLAG_WUM: WUM status flag
+ \arg ENET_MAC_FLAG_MSC: MSC status flag
+ \arg ENET_MAC_FLAG_MSCR: MSC receive status flag
+ \arg ENET_MAC_FLAG_MSCT: MSC transmit status flag
+ \arg ENET_MAC_FLAG_TMST: time stamp trigger status flag
+ \arg ENET_PTP_FLAG_TSSCO: timestamp second counter overflow flag
+ \arg ENET_PTP_FLAG_TTM: target time match flag
+ \arg ENET_MSC_FLAG_RFCE: received frames CRC error flag
+ \arg ENET_MSC_FLAG_RFAE: received frames alignment error flag
+ \arg ENET_MSC_FLAG_RGUF: received good unicast frames flag
+ \arg ENET_MSC_FLAG_TGFSC: transmitted good frames single collision flag
+ \arg ENET_MSC_FLAG_TGFMSC: transmitted good frames more single collision flag
+ \arg ENET_MSC_FLAG_TGF: transmitted good frames flag
+ \arg ENET_DMA_FLAG_TS: transmit status flag
+ \arg ENET_DMA_FLAG_TPS: transmit process stopped status flag
+ \arg ENET_DMA_FLAG_TBU: transmit buffer unavailable status flag
+ \arg ENET_DMA_FLAG_TJT: transmit jabber timeout status flag
+ \arg ENET_DMA_FLAG_RO: receive overflow status flag
+ \arg ENET_DMA_FLAG_TU: transmit underflow status flag
+ \arg ENET_DMA_FLAG_RS: receive status flag
+ \arg ENET_DMA_FLAG_RBU: receive buffer unavailable status flag
+ \arg ENET_DMA_FLAG_RPS: receive process stopped status flag
+ \arg ENET_DMA_FLAG_RWT: receive watchdog timeout status flag
+ \arg ENET_DMA_FLAG_ET: early transmit status flag
+ \arg ENET_DMA_FLAG_FBE: fatal bus error status flag
+ \arg ENET_DMA_FLAG_ER: early receive status flag
+ \arg ENET_DMA_FLAG_AI: abnormal interrupt summary flag
+ \arg ENET_DMA_FLAG_NI: normal interrupt summary flag
+ \arg ENET_DMA_FLAG_EB_DMA_ERROR: DMA error flag
+ \arg ENET_DMA_FLAG_EB_TRANSFER_ERROR: transfer error flag
+ \arg ENET_DMA_FLAG_EB_ACCESS_ERROR: access error flag
+ \arg ENET_DMA_FLAG_MSC: MSC status flag
+ \arg ENET_DMA_FLAG_WUM: WUM status flag
+ \arg ENET_DMA_FLAG_TST: timestamp trigger status flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus enet_flag_get(enet_flag_enum enet_flag)
+{
+ if(RESET != (ENET_REG_VAL(enet_flag) & BIT(ENET_BIT_POS(enet_flag)))) {
+ return SET;
+ } else {
+ return RESET;
+ }
+}
+
+/*!
+ \brief clear the ENET DMA status flag
+ \param[in] enet_flag: ENET DMA flag clear, refer to enet_flag_clear_enum
+ only one parameter can be selected which is shown as below
+ \arg ENET_DMA_FLAG_TS_CLR: transmit status flag clear
+ \arg ENET_DMA_FLAG_TPS_CLR: transmit process stopped status flag clear
+ \arg ENET_DMA_FLAG_TBU_CLR: transmit buffer unavailable status flag clear
+ \arg ENET_DMA_FLAG_TJT_CLR: transmit jabber timeout status flag clear
+ \arg ENET_DMA_FLAG_RO_CLR: receive overflow status flag clear
+ \arg ENET_DMA_FLAG_TU_CLR: transmit underflow status flag clear
+ \arg ENET_DMA_FLAG_RS_CLR: receive status flag clear
+ \arg ENET_DMA_FLAG_RBU_CLR: receive buffer unavailable status flag clear
+ \arg ENET_DMA_FLAG_RPS_CLR: receive process stopped status flag clear
+ \arg ENET_DMA_FLAG_RWT_CLR: receive watchdog timeout status flag clear
+ \arg ENET_DMA_FLAG_ET_CLR: early transmit status flag clear
+ \arg ENET_DMA_FLAG_FBE_CLR: fatal bus error status flag clear
+ \arg ENET_DMA_FLAG_ER_CLR: early receive status flag clear
+ \arg ENET_DMA_FLAG_AI_CLR: abnormal interrupt summary flag clear
+ \arg ENET_DMA_FLAG_NI_CLR: normal interrupt summary flag clear
+ \param[out] none
+ \retval none
+*/
+void enet_flag_clear(enet_flag_clear_enum enet_flag)
+{
+ /* write 1 to the corresponding bit in ENET_DMA_STAT, to clear it */
+ ENET_REG_VAL(enet_flag) = BIT(ENET_BIT_POS(enet_flag));
+}
+
+/*!
+ \brief enable ENET MAC/MSC/DMA interrupt
+ \param[in] enet_int: ENET interrupt,
+ only one parameter can be selected which is shown as below
+ \arg ENET_MAC_INT_WUMIM: WUM interrupt mask
+ \arg ENET_MAC_INT_TMSTIM: timestamp trigger interrupt mask
+ \arg ENET_MSC_INT_RFCEIM: received frame CRC error interrupt mask
+ \arg ENET_MSC_INT_RFAEIM: received frames alignment error interrupt mask
+ \arg ENET_MSC_INT_RGUFIM: received good unicast frames interrupt mask
+ \arg ENET_MSC_INT_TGFSCIM: transmitted good frames single collision interrupt mask
+ \arg ENET_MSC_INT_TGFMSCIM: transmitted good frames more single collision interrupt mask
+ \arg ENET_MSC_INT_TGFIM: transmitted good frames interrupt mask
+ \arg ENET_DMA_INT_TIE: transmit interrupt enable
+ \arg ENET_DMA_INT_TPSIE: transmit process stopped interrupt enable
+ \arg ENET_DMA_INT_TBUIE: transmit buffer unavailable interrupt enable
+ \arg ENET_DMA_INT_TJTIE: transmit jabber timeout interrupt enable
+ \arg ENET_DMA_INT_ROIE: receive overflow interrupt enable
+ \arg ENET_DMA_INT_TUIE: transmit underflow interrupt enable
+ \arg ENET_DMA_INT_RIE: receive interrupt enable
+ \arg ENET_DMA_INT_RBUIE: receive buffer unavailable interrupt enable
+ \arg ENET_DMA_INT_RPSIE: receive process stopped interrupt enable
+ \arg ENET_DMA_INT_RWTIE: receive watchdog timeout interrupt enable
+ \arg ENET_DMA_INT_ETIE: early transmit interrupt enable
+ \arg ENET_DMA_INT_FBEIE: fatal bus error interrupt enable
+ \arg ENET_DMA_INT_ERIE: early receive interrupt enable
+ \arg ENET_DMA_INT_AIE: abnormal interrupt summary enable
+ \arg ENET_DMA_INT_NIE: normal interrupt summary enable
+ \param[out] none
+ \retval none
+*/
+void enet_interrupt_enable(enet_int_enum enet_int)
+{
+ if(DMA_INTEN_REG_OFFSET == ((uint32_t)enet_int >> 6U)) {
+ /* ENET_DMA_INTEN register interrupt */
+ ENET_REG_VAL(enet_int) |= BIT(ENET_BIT_POS(enet_int));
+ } else {
+ /* other INTMSK register interrupt */
+ ENET_REG_VAL(enet_int) &= ~BIT(ENET_BIT_POS(enet_int));
+ }
+}
+
+/*!
+ \brief disable ENET MAC/MSC/DMA interrupt
+ \param[in] enet_int: ENET interrupt,
+ only one parameter can be selected which is shown as below
+ \arg ENET_MAC_INT_WUMIM: WUM interrupt mask
+ \arg ENET_MAC_INT_TMSTIM: timestamp trigger interrupt mask
+ \arg ENET_MSC_INT_RFCEIM: received frame CRC error interrupt mask
+ \arg ENET_MSC_INT_RFAEIM: received frames alignment error interrupt mask
+ \arg ENET_MSC_INT_RGUFIM: received good unicast frames interrupt mask
+ \arg ENET_MSC_INT_TGFSCIM: transmitted good frames single collision interrupt mask
+ \arg ENET_MSC_INT_TGFMSCIM: transmitted good frames more single collision interrupt mask
+ \arg ENET_MSC_INT_TGFIM: transmitted good frames interrupt mask
+ \arg ENET_DMA_INT_TIE: transmit interrupt enable
+ \arg ENET_DMA_INT_TPSIE: transmit process stopped interrupt enable
+ \arg ENET_DMA_INT_TBUIE: transmit buffer unavailable interrupt enable
+ \arg ENET_DMA_INT_TJTIE: transmit jabber timeout interrupt enable
+ \arg ENET_DMA_INT_ROIE: receive overflow interrupt enable
+ \arg ENET_DMA_INT_TUIE: transmit underflow interrupt enable
+ \arg ENET_DMA_INT_RIE: receive interrupt enable
+ \arg ENET_DMA_INT_RBUIE: receive buffer unavailable interrupt enable
+ \arg ENET_DMA_INT_RPSIE: receive process stopped interrupt enable
+ \arg ENET_DMA_INT_RWTIE: receive watchdog timeout interrupt enable
+ \arg ENET_DMA_INT_ETIE: early transmit interrupt enable
+ \arg ENET_DMA_INT_FBEIE: fatal bus error interrupt enable
+ \arg ENET_DMA_INT_ERIE: early receive interrupt enable
+ \arg ENET_DMA_INT_AIE: abnormal interrupt summary enable
+ \arg ENET_DMA_INT_NIE: normal interrupt summary enable
+ \param[out] none
+ \retval none
+*/
+void enet_interrupt_disable(enet_int_enum enet_int)
+{
+ if(DMA_INTEN_REG_OFFSET == ((uint32_t)enet_int >> 6U)) {
+ /* ENET_DMA_INTEN register interrupt */
+ ENET_REG_VAL(enet_int) &= ~BIT(ENET_BIT_POS(enet_int));
+ } else {
+ /* other INTMSK register interrupt */
+ ENET_REG_VAL(enet_int) |= BIT(ENET_BIT_POS(enet_int));
+ }
+}
+
+/*!
+ \brief get ENET MAC/MSC/DMA interrupt flag
+ \param[in] int_flag: ENET interrupt flag,
+ only one parameter can be selected which is shown as below
+ \arg ENET_MAC_INT_FLAG_WUM: WUM status flag
+ \arg ENET_MAC_INT_FLAG_MSC: MSC status flag
+ \arg ENET_MAC_INT_FLAG_MSCR: MSC receive status flag
+ \arg ENET_MAC_INT_FLAG_MSCT: MSC transmit status flag
+ \arg ENET_MAC_INT_FLAG_TMST: time stamp trigger status flag
+ \arg ENET_MSC_INT_FLAG_RFCE: received frames CRC error flag
+ \arg ENET_MSC_INT_FLAG_RFAE: received frames alignment error flag
+ \arg ENET_MSC_INT_FLAG_RGUF: received good unicast frames flag
+ \arg ENET_MSC_INT_FLAG_TGFSC: transmitted good frames single collision flag
+ \arg ENET_MSC_INT_FLAG_TGFMSC: transmitted good frames more single collision flag
+ \arg ENET_MSC_INT_FLAG_TGF: transmitted good frames flag
+ \arg ENET_DMA_INT_FLAG_TS: transmit status flag
+ \arg ENET_DMA_INT_FLAG_TPS: transmit process stopped status flag
+ \arg ENET_DMA_INT_FLAG_TBU: transmit buffer unavailable status flag
+ \arg ENET_DMA_INT_FLAG_TJT: transmit jabber timeout status flag
+ \arg ENET_DMA_INT_FLAG_RO: receive overflow status flag
+ \arg ENET_DMA_INT_FLAG_TU: transmit underflow status flag
+ \arg ENET_DMA_INT_FLAG_RS: receive status flag
+ \arg ENET_DMA_INT_FLAG_RBU: receive buffer unavailable status flag
+ \arg ENET_DMA_INT_FLAG_RPS: receive process stopped status flag
+ \arg ENET_DMA_INT_FLAG_RWT: receive watchdog timeout status flag
+ \arg ENET_DMA_INT_FLAG_ET: early transmit status flag
+ \arg ENET_DMA_INT_FLAG_FBE: fatal bus error status flag
+ \arg ENET_DMA_INT_FLAG_ER: early receive status flag
+ \arg ENET_DMA_INT_FLAG_AI: abnormal interrupt summary flag
+ \arg ENET_DMA_INT_FLAG_NI: normal interrupt summary flag
+ \arg ENET_DMA_INT_FLAG_MSC: MSC status flag
+ \arg ENET_DMA_INT_FLAG_WUM: WUM status flag
+ \arg ENET_DMA_INT_FLAG_TST: timestamp trigger status flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag)
+{
+ if(RESET != (ENET_REG_VAL(int_flag) & BIT(ENET_BIT_POS(int_flag)))) {
+ return SET;
+ } else {
+ return RESET;
+ }
+}
+
+/*!
+ \brief clear ENET DMA interrupt flag
+ \param[in] int_flag_clear: clear ENET interrupt flag,
+ only one parameter can be selected which is shown as below
+ \arg ENET_DMA_INT_FLAG_TS_CLR: transmit status flag
+ \arg ENET_DMA_INT_FLAG_TPS_CLR: transmit process stopped status flag
+ \arg ENET_DMA_INT_FLAG_TBU_CLR: transmit buffer unavailable status flag
+ \arg ENET_DMA_INT_FLAG_TJT_CLR: transmit jabber timeout status flag
+ \arg ENET_DMA_INT_FLAG_RO_CLR: receive overflow status flag
+ \arg ENET_DMA_INT_FLAG_TU_CLR: transmit underflow status flag
+ \arg ENET_DMA_INT_FLAG_RS_CLR: receive status flag
+ \arg ENET_DMA_INT_FLAG_RBU_CLR: receive buffer unavailable status flag
+ \arg ENET_DMA_INT_FLAG_RPS_CLR: receive process stopped status flag
+ \arg ENET_DMA_INT_FLAG_RWT_CLR: receive watchdog timeout status flag
+ \arg ENET_DMA_INT_FLAG_ET_CLR: early transmit status flag
+ \arg ENET_DMA_INT_FLAG_FBE_CLR: fatal bus error status flag
+ \arg ENET_DMA_INT_FLAG_ER_CLR: early receive status flag
+ \arg ENET_DMA_INT_FLAG_AI_CLR: abnormal interrupt summary flag
+ \arg ENET_DMA_INT_FLAG_NI_CLR: normal interrupt summary flag
+ \param[out] none
+ \retval none
+*/
+void enet_interrupt_flag_clear(enet_int_flag_clear_enum int_flag_clear)
+{
+ /* write 1 to the corresponding bit in ENET_DMA_STAT, to clear it */
+ ENET_REG_VAL(int_flag_clear) = BIT(ENET_BIT_POS(int_flag_clear));
+}
+
#endif /* GD32F20X_CL */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exmc.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exmc.c
index ce34be5..7634a97 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exmc.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exmc.c
@@ -2,36 +2,33 @@
\file gd32f20x_exmc.c
\brief EXMC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -127,6 +124,7 @@ OF SUCH DAMAGE.
/*!
\brief deinitialize EXMC NOR/SRAM region
\param[in] exmc_norsram_region: select the region of bank0
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
\param[out] none
\retval none
@@ -140,14 +138,14 @@ void exmc_norsram_deinit(uint32_t exmc_norsram_region)
}
/*!
- \brief initialize the struct exmc_norsram_parameter_struct
+ \brief initialize exmc_norsram_parameter_struct with the default values
\param[in] none
\param[out] exmc_norsram_init_struct: the initialized struct exmc_norsram_parameter_struct pointer
\retval none
*/
-void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
+void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct *exmc_norsram_init_struct)
{
- /* configure the structure with default value */
+ /* configure the structure with default values */
exmc_norsram_init_struct->norsram_region = EXMC_BANK0_NORSRAM_REGION0;
exmc_norsram_init_struct->address_data_mux = ENABLE;
exmc_norsram_init_struct->memory_type = EXMC_MEMORY_TYPE_SRAM;
@@ -162,7 +160,7 @@ void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_i
exmc_norsram_init_struct->asyn_wait = DISABLE;
exmc_norsram_init_struct->write_mode = EXMC_ASYN_WRITE;
- /* read/write timing configure */
+ /* configure read/write timing */
exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime = 0xFU;
exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime = 0xFU;
exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime = 0xFFU;
@@ -171,7 +169,7 @@ void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_i
exmc_norsram_init_struct->read_write_timing->syn_data_latency = EXMC_DATALAT_17_CLK;
exmc_norsram_init_struct->read_write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
- /* write timing configure, when extended mode is used */
+ /* configure write timing, when extended mode is used */
exmc_norsram_init_struct->write_timing->asyn_address_setuptime = 0xFU;
exmc_norsram_init_struct->write_timing->asyn_address_holdtime = 0xFU;
exmc_norsram_init_struct->write_timing->asyn_data_setuptime = 0xFFU;
@@ -184,7 +182,7 @@ void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_i
\param[in] exmc_norsram_parameter_struct: configure the EXMC NOR/SRAM parameter
norsram_region: EXMC_BANK0_NORSRAM_REGIONx,x=0..3
write_mode: EXMC_ASYN_WRITE or EXMC_SYN_WRITE
- extended_mode: ENABLE or DISABLE
+ extended_mode: ENABLE or DISABLE
asyn_wait: ENABLE or DISABLE
nwait_signal: ENABLE or DISABLE
memory_write: ENABLE or DISABLE
@@ -198,68 +196,70 @@ void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_i
read_write_timing: struct exmc_norsram_timing_parameter_struct set the time
asyn_access_mode: EXMC_ACCESS_MODE_A, EXMC_ACCESS_MODE_B, EXMC_ACCESS_MODE_C, EXMC_ACCESS_MODE_D
syn_data_latency: EXMC_DATALAT_x_CLK, x=2..17
- syn_clk_division: EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
- bus_latency: 0x01U~0x10U
+ syn_clk_division: EXMC_SYN_CLOCK_RATIO_DISABLE, EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
+ bus_latency: 0x01U~0x10U
asyn_data_setuptime: 0x02U~0x100U
asyn_address_holdtime: 0x02U~0x10U
asyn_address_setuptime: 0x01U~0x10U
write_timing: struct exmc_norsram_timing_parameter_struct set the time
asyn_access_mode: EXMC_ACCESS_MODE_A, EXMC_ACCESS_MODE_B, EXMC_ACCESS_MODE_C, EXMC_ACCESS_MODE_D
syn_data_latency: EXMC_DATALAT_x_CLK, x=2..17
- syn_clk_division: EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
- bus_latency: 0x01U~0x10U
+ syn_clk_division: EXMC_SYN_CLOCK_RATIO_DISABLE, EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
+ bus_latency: 0x01U~0x10U
asyn_data_setuptime: 0x02U~0x100U
asyn_address_holdtime: 0x02U~0x10U
asyn_address_setuptime: 0x01U~0x10U
\param[out] none
\retval none
*/
-void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
+void exmc_norsram_init(exmc_norsram_parameter_struct *exmc_norsram_init_struct)
{
uint32_t snctl = 0x00000000U, sntcfg = 0x00000000U, snwtcfg = 0x00000000U;
-
+
/* get the register value */
snctl = EXMC_SNCTL(exmc_norsram_init_struct->norsram_region);
/* clear relative bits */
- snctl &= ((uint32_t)~(EXMC_SNCTL_NREN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_SBRSTEN |
- EXMC_SNCTL_NRWTPOL | EXMC_SNCTL_WRAPEN | EXMC_SNCTL_NRWTCFG | EXMC_SNCTL_WREN |
- EXMC_SNCTL_NRWTEN | EXMC_SNCTL_EXMODEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_SYNCWR |
- EXMC_SNCTL_NRMUX ));
+ snctl &= ((uint32_t)~(EXMC_SNCTL_NREN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_SBRSTEN |
+ EXMC_SNCTL_NRWTPOL | EXMC_SNCTL_WRAPEN | EXMC_SNCTL_NRWTCFG | EXMC_SNCTL_WREN |
+ EXMC_SNCTL_NRWTEN | EXMC_SNCTL_EXMODEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_SYNCWR |
+ EXMC_SNCTL_NRMUX));
+ /* configure control bits */
snctl |= (uint32_t)(exmc_norsram_init_struct->address_data_mux << SNCTL_NRMUX_OFFSET) |
- exmc_norsram_init_struct->memory_type |
- exmc_norsram_init_struct->databus_width |
- (exmc_norsram_init_struct->burst_mode << SNCTL_SBRSTEN_OFFSET) |
- exmc_norsram_init_struct->nwait_polarity |
- (exmc_norsram_init_struct->wrap_burst_mode << SNCTL_WRAPEN_OFFSET) |
- exmc_norsram_init_struct->nwait_config |
- (exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) |
- (exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET) |
- (exmc_norsram_init_struct->extended_mode << SNCTL_EXMODEN_OFFSET) |
- (exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET) |
- exmc_norsram_init_struct->write_mode;
-
+ exmc_norsram_init_struct->memory_type |
+ exmc_norsram_init_struct->databus_width |
+ (exmc_norsram_init_struct->burst_mode << SNCTL_SBRSTEN_OFFSET) |
+ exmc_norsram_init_struct->nwait_polarity |
+ (exmc_norsram_init_struct->wrap_burst_mode << SNCTL_WRAPEN_OFFSET) |
+ exmc_norsram_init_struct->nwait_config |
+ (exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) |
+ (exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET) |
+ (exmc_norsram_init_struct->extended_mode << SNCTL_EXMODEN_OFFSET) |
+ (exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET) |
+ exmc_norsram_init_struct->write_mode;
+
+ /* configure timing */
sntcfg = (uint32_t)((exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime - 1U) & EXMC_SNTCFG_ASET) |
- (((exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime - 1U) << SNTCFG_AHLD_OFFSET) & EXMC_SNTCFG_AHLD) |
- (((exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime - 1U) << SNTCFG_DSET_OFFSET) & EXMC_SNTCFG_DSET) |
- (((exmc_norsram_init_struct->read_write_timing->bus_latency - 1U) << SNTCFG_BUSLAT_OFFSET) & EXMC_SNTCFG_BUSLAT) |
- exmc_norsram_init_struct->read_write_timing->syn_clk_division |
- exmc_norsram_init_struct->read_write_timing->syn_data_latency |
- exmc_norsram_init_struct->read_write_timing->asyn_access_mode;
-
- /* nor flash access enable */
- if(EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type){
+ (((exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime - 1U) << SNTCFG_AHLD_OFFSET) & EXMC_SNTCFG_AHLD) |
+ (((exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime - 1U) << SNTCFG_DSET_OFFSET) & EXMC_SNTCFG_DSET) |
+ (((exmc_norsram_init_struct->read_write_timing->bus_latency - 1U) << SNTCFG_BUSLAT_OFFSET) & EXMC_SNTCFG_BUSLAT) |
+ exmc_norsram_init_struct->read_write_timing->syn_clk_division |
+ exmc_norsram_init_struct->read_write_timing->syn_data_latency |
+ exmc_norsram_init_struct->read_write_timing->asyn_access_mode;
+
+ /* enable nor flash access */
+ if(EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type) {
snctl |= (uint32_t)EXMC_SNCTL_NREN;
}
- /* extended mode configure */
- if(ENABLE == exmc_norsram_init_struct->extended_mode){
+ /* configure extended mode */
+ if(ENABLE == exmc_norsram_init_struct->extended_mode) {
snwtcfg = (uint32_t)(((exmc_norsram_init_struct->write_timing->asyn_address_setuptime - 1U) & EXMC_SNWTCFG_WASET) |
- (((exmc_norsram_init_struct->write_timing->asyn_address_holdtime - 1U) << SNTCFG_AHLD_OFFSET ) & EXMC_SNWTCFG_WAHLD)|
+ (((exmc_norsram_init_struct->write_timing->asyn_address_holdtime - 1U) << SNTCFG_AHLD_OFFSET) & EXMC_SNWTCFG_WAHLD) |
(((exmc_norsram_init_struct->write_timing->asyn_data_setuptime - 1U) << SNTCFG_DSET_OFFSET) & EXMC_SNWTCFG_WDSET) |
- exmc_norsram_init_struct->write_timing->asyn_access_mode);
- }else{
+ exmc_norsram_init_struct->write_timing->asyn_access_mode);
+ } else {
snwtcfg = BANK0_SNWTCFG_RESET;
}
@@ -271,7 +271,8 @@ void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
/*!
\brief enable EXMC NOR/PSRAM bank region
- \param[in] exmc_norsram_region: specifie the region of NOR/PSRAM bank
+ \param[in] exmc_norsram_region: specify the region of NOR/PSRAM bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
\param[out] none
\retval none
@@ -283,7 +284,8 @@ void exmc_norsram_enable(uint32_t exmc_norsram_region)
/*!
\brief disable EXMC NOR/PSRAM bank region
- \param[in] exmc_norsram_region: specifie the region of NOR/PSRAM Bank
+ \param[in] exmc_norsram_region: specify the region of NOR/PSRAM Bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
\param[out] none
\retval none
@@ -296,7 +298,8 @@ void exmc_norsram_disable(uint32_t exmc_norsram_region)
/*!
\brief deinitialize EXMC NAND bank
\param[in] exmc_nand_bank: select the bank of NAND
- \arg EXMC_BANKx_NAND(x=1..2)
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_BANKx_NAND(x=1, 2)
\param[out] none
\retval none
*/
@@ -310,14 +313,14 @@ void exmc_nand_deinit(uint32_t exmc_nand_bank)
}
/*!
- \brief initialize the struct exmc_nand_init_struct
+ \brief initialize exmc_nand_parameter_struct with the default values
\param[in] none
- \param[out] the initialized struct exmc_nand_init_struct pointer
+ \param[out] the initialized struct exmc_nand_parameter_struct pointer
\retval none
*/
-void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
+void exmc_nand_struct_para_init(exmc_nand_parameter_struct *exmc_nand_init_struct)
{
- /* configure the structure with default value */
+ /* configure the structure with default values */
exmc_nand_init_struct->nand_bank = EXMC_BANK1_NAND;
exmc_nand_init_struct->wait_feature = DISABLE;
exmc_nand_init_struct->databus_width = EXMC_NAND_DATABUS_WIDTH_8B;
@@ -358,29 +361,29 @@ void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struc
\param[out] none
\retval none
*/
-void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
+void exmc_nand_init(exmc_nand_parameter_struct *exmc_nand_init_struct)
{
uint32_t npctl = 0x00000000U, npctcfg = 0x00000000U, npatcfg = 0x00000000U;
-
- npctl = (uint32_t)(exmc_nand_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET)|
- EXMC_NPCTL_NDTP |
- exmc_nand_init_struct->databus_width |
- (exmc_nand_init_struct->ecc_logic << NPCTL_ECCEN_OFFSET)|
- exmc_nand_init_struct->ecc_size |
- exmc_nand_init_struct->ctr_latency |
- exmc_nand_init_struct->atr_latency;
-
- npctcfg = (uint32_t)((exmc_nand_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET ) |
- (((exmc_nand_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT ) |
- ((exmc_nand_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD ) |
- (((exmc_nand_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ );
-
- npatcfg = (uint32_t)((exmc_nand_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET ) |
- (((exmc_nand_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT ) |
- ((exmc_nand_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD ) |
- (((exmc_nand_init_struct->attribute_space_timing->databus_hiztime - 1U) << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ );
-
- /* EXMC_BANK1_NAND or EXMC_BANK2_NAND initialize */
+
+ npctl = (uint32_t)(exmc_nand_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET) |
+ EXMC_NPCTL_NDTP |
+ exmc_nand_init_struct->databus_width |
+ (exmc_nand_init_struct->ecc_logic << NPCTL_ECCEN_OFFSET) |
+ exmc_nand_init_struct->ecc_size |
+ exmc_nand_init_struct->ctr_latency |
+ exmc_nand_init_struct->atr_latency;
+
+ npctcfg = (uint32_t)((exmc_nand_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET) |
+ (((exmc_nand_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT) |
+ ((exmc_nand_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD) |
+ (((exmc_nand_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ);
+
+ npatcfg = (uint32_t)((exmc_nand_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET) |
+ (((exmc_nand_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT) |
+ ((exmc_nand_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD) |
+ (((exmc_nand_init_struct->attribute_space_timing->databus_hiztime - 1U) << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ);
+
+ /* initialize EXMC_BANK1_NAND or EXMC_BANK2_NAND */
EXMC_NPCTL(exmc_nand_init_struct->nand_bank) = npctl;
EXMC_NPCTCFG(exmc_nand_init_struct->nand_bank) = npctcfg;
EXMC_NPATCFG(exmc_nand_init_struct->nand_bank) = npatcfg;
@@ -388,7 +391,8 @@ void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
/*!
\brief enable NAND bank
- \param[in] exmc_nand_bank: specifie the NAND bank
+ \param[in] exmc_nand_bank: specify the NAND bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1,2)
\param[out] none
\retval none
@@ -400,7 +404,8 @@ void exmc_nand_enable(uint32_t exmc_nand_bank)
/*!
\brief disable NAND bank
- \param[in] exmc_nand_bank: specifie the NAND bank
+ \param[in] exmc_nand_bank: specify the NAND bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1,2)
\param[out] none
\retval none
@@ -412,7 +417,8 @@ void exmc_nand_disable(uint32_t exmc_nand_bank)
/*!
\brief enable or disable the EXMC NAND ECC function
- \param[in] exmc_nand_bank: specifie the NAND bank
+ \param[in] exmc_nand_bank: specify the NAND bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1,2)
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
@@ -420,10 +426,10 @@ void exmc_nand_disable(uint32_t exmc_nand_bank)
*/
void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue)
{
- if (ENABLE == newvalue){
+ if(ENABLE == newvalue) {
/* enable the selected NAND bank ECC function */
EXMC_NPCTL(exmc_nand_bank) |= EXMC_NPCTL_ECCEN;
- }else{
+ } else {
/* disable the selected NAND bank ECC function */
EXMC_NPCTL(exmc_nand_bank) &= ~EXMC_NPCTL_ECCEN;
}
@@ -431,7 +437,8 @@ void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue)
/*!
\brief get the EXMC ECC value
- \param[in] exmc_nand_bank: specifie the NAND bank
+ \param[in] exmc_nand_bank: specify the NAND bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1,2)
\param[out] none
\retval the error correction code(ECC) value
@@ -457,6 +464,32 @@ void exmc_pccard_deinit(void)
EXMC_PIOTCFG3 = BANK3_PIOTCFG3_RESET;
}
+/*!
+ \brief initialize exmc_pccard_parameter_struct with the default values
+ \param[in] none
+ \param[out] the initialized struct exmc_pccard_parameter_struct pointer
+ \retval none
+*/
+void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct *exmc_pccard_init_struct)
+{
+ /* configure the structure with default value */
+ exmc_pccard_init_struct->wait_feature = DISABLE;
+ exmc_pccard_init_struct->ctr_latency = 0x0U;
+ exmc_pccard_init_struct->atr_latency = 0x0U;
+ exmc_pccard_init_struct->common_space_timing->setuptime = 0xFCU;
+ exmc_pccard_init_struct->common_space_timing->waittime = 0xFCU;
+ exmc_pccard_init_struct->common_space_timing->holdtime = 0xFCU;
+ exmc_pccard_init_struct->common_space_timing->databus_hiztime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->setuptime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->waittime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->holdtime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->setuptime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->waittime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->holdtime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->databus_hiztime = 0xFCU;
+}
+
/*!
\brief initialize EXMC PC card bank
\param[in] exmc_pccard_parameter_struct: configure the EXMC NAND parameter
@@ -481,61 +514,35 @@ void exmc_pccard_deinit(void)
\param[out] none
\retval none
*/
-void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
+void exmc_pccard_init(exmc_pccard_parameter_struct *exmc_pccard_init_struct)
{
/* configure the EXMC bank3 PC card control register */
EXMC_NPCTL3 = (uint32_t)(exmc_pccard_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET) |
- EXMC_NAND_DATABUS_WIDTH_16B |
- exmc_pccard_init_struct->ctr_latency |
- exmc_pccard_init_struct->atr_latency ;
-
+ EXMC_NAND_DATABUS_WIDTH_16B |
+ exmc_pccard_init_struct->ctr_latency |
+ exmc_pccard_init_struct->atr_latency ;
+
/* configure the EXMC bank3 PC card common space timing configuration register */
- EXMC_NPCTCFG3 = (uint32_t)((exmc_pccard_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET ) |
- (((exmc_pccard_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT ) |
- ((exmc_pccard_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD ) |
- (((exmc_pccard_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ );
+ EXMC_NPCTCFG3 = (uint32_t)((exmc_pccard_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET) |
+ (((exmc_pccard_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT) |
+ ((exmc_pccard_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD) |
+ (((exmc_pccard_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ);
/* configure the EXMC bank3 PC card attribute space timing configuration register */
- EXMC_NPATCFG3 = (uint32_t)((exmc_pccard_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET ) |
- (((exmc_pccard_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT ) |
- ((exmc_pccard_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD ) |
- (((exmc_pccard_init_struct->attribute_space_timing->databus_hiztime - 1U) << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ);
+ EXMC_NPATCFG3 = (uint32_t)((exmc_pccard_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET) |
+ (((exmc_pccard_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT) |
+ ((exmc_pccard_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD) |
+ (((exmc_pccard_init_struct->attribute_space_timing->databus_hiztime - 1U) << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ);
/* configure the EXMC bank3 PC card io space timing configuration register */
- EXMC_PIOTCFG3 = (uint32_t)((exmc_pccard_init_struct->io_space_timing->setuptime - 1U) & EXMC_PIOTCFG3_IOSET ) |
- (((exmc_pccard_init_struct->io_space_timing->waittime - 1U) << PIOTCFG_IOWAIT_OFFSET) & EXMC_PIOTCFG3_IOWAIT ) |
- ((exmc_pccard_init_struct->io_space_timing->holdtime << PIOTCFG_IOHLD_OFFSET) & EXMC_PIOTCFG3_IOHLD ) |
- ((exmc_pccard_init_struct->io_space_timing->databus_hiztime << PIOTCFG_IOHIZ_OFFSET) & EXMC_PIOTCFG3_IOHIZ );
+ EXMC_PIOTCFG3 = (uint32_t)((exmc_pccard_init_struct->io_space_timing->setuptime - 1U) & EXMC_PIOTCFG3_IOSET) |
+ (((exmc_pccard_init_struct->io_space_timing->waittime - 1U) << PIOTCFG_IOWAIT_OFFSET) & EXMC_PIOTCFG3_IOWAIT) |
+ ((exmc_pccard_init_struct->io_space_timing->holdtime << PIOTCFG_IOHLD_OFFSET) & EXMC_PIOTCFG3_IOHLD) |
+ ((exmc_pccard_init_struct->io_space_timing->databus_hiztime << PIOTCFG_IOHIZ_OFFSET) & EXMC_PIOTCFG3_IOHIZ);
}
/*!
- \brief initialize the struct exmc_pccard_parameter_struct
- \param[in] none
- \param[out] the initialized struct exmc_pccard_parameter_struct pointer
- \retval none
-*/
-void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
-{
- /* configure the structure with default value */
- exmc_pccard_init_struct->wait_feature = DISABLE;
- exmc_pccard_init_struct->ctr_latency = 0x0U;
- exmc_pccard_init_struct->atr_latency = 0x0U;
- exmc_pccard_init_struct->common_space_timing->setuptime = 0xFCU;
- exmc_pccard_init_struct->common_space_timing->waittime = 0xFCU;
- exmc_pccard_init_struct->common_space_timing->holdtime = 0xFCU;
- exmc_pccard_init_struct->common_space_timing->databus_hiztime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->setuptime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->waittime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->holdtime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->setuptime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->waittime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->holdtime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->databus_hiztime = 0xFCU;
-}
-
-/*!
- \brief enable PC Card Bank
+ \brief enable PC card bank
\param[in] none
\param[out] none
\retval none
@@ -546,19 +553,21 @@ void exmc_pccard_enable(void)
}
/*!
- \brief disable PC Card Bank
+ \brief disable PC card bank
\param[in] none
\param[out] none
\retval none
*/
void exmc_pccard_disable(void)
{
- EXMC_NPCTL3 &= ~EXMC_NPCTL_NDBKEN;
+ EXMC_NPCTL3 &= ~EXMC_NPCTL_NDBKEN;
}
/*!
\brief deinitialize EXMC SDRAM device
- \param[in] exmc_sdram_device:
+ \param[in] exmc_sdram_device: select the SDRAM device
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_SDRAM_DEVICEx(x=0, 1)
\param[out] none
\retval none
*/
@@ -572,6 +581,35 @@ void exmc_sdram_deinit(uint32_t exmc_sdram_device)
EXMC_SDRSCTL = SDRAM_DEVICE_SDRSCTL_RESET;
}
+/*!
+ \brief initialize exmc_sdram_init_struct with the default values
+ \param[in] none
+ \param[out] the initialized struct exmc_sdram_parameter_struct pointer
+ \retval none
+*/
+void exmc_sdram_struct_para_init(exmc_sdram_parameter_struct *exmc_sdram_init_struct)
+{
+ /* configure the structure with default value */
+ exmc_sdram_init_struct->sdram_device = EXMC_SDRAM_DEVICE0;
+ exmc_sdram_init_struct->column_address_width = EXMC_SDRAM_COW_ADDRESS_8;
+ exmc_sdram_init_struct->row_address_width = EXMC_SDRAM_ROW_ADDRESS_11;
+ exmc_sdram_init_struct->data_width = EXMC_SDRAM_DATABUS_WIDTH_16B;
+ exmc_sdram_init_struct->internal_bank_number = EXMC_SDRAM_4_INTER_BANK;
+ exmc_sdram_init_struct->cas_latency = EXMC_CAS_LATENCY_1_SDCLK;
+ exmc_sdram_init_struct->write_protection = ENABLE;
+ exmc_sdram_init_struct->sdclock_config = EXMC_SDCLK_DISABLE;
+ exmc_sdram_init_struct->burst_read_switch = DISABLE;
+ exmc_sdram_init_struct->pipeline_read_delay = EXMC_PIPELINE_DELAY_0_HCLK;
+
+ exmc_sdram_init_struct->timing->load_mode_register_delay = 16U;
+ exmc_sdram_init_struct->timing->exit_selfrefresh_delay = 16U;
+ exmc_sdram_init_struct->timing->row_address_select_delay = 16U;
+ exmc_sdram_init_struct->timing->auto_refresh_delay = 16U;
+ exmc_sdram_init_struct->timing->write_recovery_delay = 16U;
+ exmc_sdram_init_struct->timing->row_precharge_delay = 16U;
+ exmc_sdram_init_struct->timing->row_to_column_delay = 16U;
+}
+
/*!
\brief initialize EXMC SDRAM device
\param[in] exmc_sdram_parameter_struct: configure the EXMC SDRAM parameter
@@ -596,62 +634,62 @@ void exmc_sdram_deinit(uint32_t exmc_sdram_device)
\param[out] none
\retval none
*/
-void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
+void exmc_sdram_init(exmc_sdram_parameter_struct *exmc_sdram_init_struct)
{
uint32_t sdctl0, sdctl1, sdtcfg0, sdtcfg1;
- /* configuration EXMC_SDCTL0 or EXMC_SDCTL1 */
- if(EXMC_SDRAM_DEVICE0 == exmc_sdram_init_struct->sdram_device){
- /* configuration EXMC_SDCTL0 */
- EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = (uint32_t)exmc_sdram_init_struct->column_address_width |
- exmc_sdram_init_struct->row_address_width |
- exmc_sdram_init_struct->data_width |
- exmc_sdram_init_struct->internal_bank_number |
- exmc_sdram_init_struct->cas_latency |
- (exmc_sdram_init_struct->write_protection << SDCTL_WPEN_OFFSET)|
- exmc_sdram_init_struct->sdclock_config |
- (exmc_sdram_init_struct->brust_read_switch << SDCTL_BRSTRD_OFFSET)|
- exmc_sdram_init_struct->pipeline_read_delay;
+ /* configure EXMC_SDCTL0 or EXMC_SDCTL1 */
+ if(EXMC_SDRAM_DEVICE0 == exmc_sdram_init_struct->sdram_device) {
+ /* configure EXMC_SDCTL0 */
+ EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = (uint32_t)(exmc_sdram_init_struct->column_address_width |
+ exmc_sdram_init_struct->row_address_width |
+ exmc_sdram_init_struct->data_width |
+ exmc_sdram_init_struct->internal_bank_number |
+ exmc_sdram_init_struct->cas_latency |
+ (exmc_sdram_init_struct->write_protection << SDCTL_WPEN_OFFSET) |
+ exmc_sdram_init_struct->sdclock_config |
+ (exmc_sdram_init_struct->burst_read_switch << SDCTL_BRSTRD_OFFSET) |
+ exmc_sdram_init_struct->pipeline_read_delay);
- /* configuration EXMC_SDTCFG0 */
- EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay)-1U) |
- (((exmc_sdram_init_struct->timing->exit_selfrefresh_delay)-1U) << SDTCFG_XSRD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_address_select_delay)-1U) << SDTCFG_RASD_OFFSET) |
- (((exmc_sdram_init_struct->timing->auto_refresh_delay)-1U) << SDTCFG_ARFD_OFFSET) |
- (((exmc_sdram_init_struct->timing->write_recovery_delay)-1U) << SDTCFG_WRD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_precharge_delay)-1U) << SDTCFG_RPD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_to_column_delay)-1U) << SDTCFG_RCD_OFFSET);
- }else{
- /* configuration EXMC_SDCTL0 and EXMC_SDCTL1 */
+ /* configure EXMC_SDTCFG0 */
+ EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay) - 1U) |
+ (((exmc_sdram_init_struct->timing->exit_selfrefresh_delay) - 1U) << SDTCFG_XSRD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->row_address_select_delay) - 1U) << SDTCFG_RASD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->auto_refresh_delay) - 1U) << SDTCFG_ARFD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->write_recovery_delay) - 1U) << SDTCFG_WRD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->row_precharge_delay) - 1U) << SDTCFG_RPD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->row_to_column_delay) - 1U) << SDTCFG_RCD_OFFSET);
+ } else {
+ /* configure EXMC_SDCTL0 and EXMC_SDCTL1 */
/* some bits in the EXMC_SDCTL1 register are reserved */
- sdctl0 = EXMC_SDCTL(EXMC_SDRAM_DEVICE0) & (~( EXMC_SDCTL_PIPED | EXMC_SDCTL_BRSTRD | EXMC_SDCTL_SDCLK ));
-
- sdctl0 |= (uint32_t)exmc_sdram_init_struct->sdclock_config |
- exmc_sdram_init_struct->brust_read_switch |
- exmc_sdram_init_struct->pipeline_read_delay;
+ sdctl0 = EXMC_SDCTL(EXMC_SDRAM_DEVICE0) & (~(EXMC_SDCTL_PIPED | EXMC_SDCTL_BRSTRD | EXMC_SDCTL_SDCLK));
+
+ sdctl0 |= (uint32_t)(exmc_sdram_init_struct->sdclock_config |
+ (exmc_sdram_init_struct->burst_read_switch << SDCTL_BRSTRD_OFFSET) |
+ exmc_sdram_init_struct->pipeline_read_delay);
- sdctl1 = (uint32_t)exmc_sdram_init_struct->column_address_width |
- exmc_sdram_init_struct->row_address_width |
- exmc_sdram_init_struct->data_width |
- exmc_sdram_init_struct->internal_bank_number |
- exmc_sdram_init_struct->cas_latency |
- exmc_sdram_init_struct->write_protection ;
+ sdctl1 = (uint32_t)(exmc_sdram_init_struct->column_address_width |
+ exmc_sdram_init_struct->row_address_width |
+ exmc_sdram_init_struct->data_width |
+ exmc_sdram_init_struct->internal_bank_number |
+ exmc_sdram_init_struct->cas_latency |
+ (exmc_sdram_init_struct->write_protection << SDCTL_WPEN_OFFSET));
EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = sdctl0;
EXMC_SDCTL(EXMC_SDRAM_DEVICE1) = sdctl1;
-
+
/* configuration EXMC_SDTCFG0 and EXMC_SDTCFG1 */
/* some bits in the EXMC_SDTCFG1 register are reserved */
sdtcfg0 = EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) & (~(EXMC_SDTCFG_RPD | EXMC_SDTCFG_WRD | EXMC_SDTCFG_ARFD));
- sdtcfg0 |= (uint32_t)(((exmc_sdram_init_struct->timing->auto_refresh_delay)-1U) << SDTCFG_ARFD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_precharge_delay)-1U) << SDTCFG_RPD_OFFSET) |
- (((exmc_sdram_init_struct->timing->write_recovery_delay)-1U) << SDTCFG_WRD_OFFSET);
+ sdtcfg0 |= (uint32_t)(((exmc_sdram_init_struct->timing->auto_refresh_delay) - 1U) << SDTCFG_ARFD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->row_precharge_delay) - 1U) << SDTCFG_RPD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->write_recovery_delay) - 1U) << SDTCFG_WRD_OFFSET);
- sdtcfg1 = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay)-1U) |
- (((exmc_sdram_init_struct->timing->exit_selfrefresh_delay)-1U) << SDTCFG_XSRD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_address_select_delay)-1U) << SDTCFG_RASD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_to_column_delay)-1U) << SDTCFG_RCD_OFFSET);
+ sdtcfg1 = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay) - 1U) |
+ (((exmc_sdram_init_struct->timing->exit_selfrefresh_delay) - 1U) << SDTCFG_XSRD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->row_address_select_delay) - 1U) << SDTCFG_RASD_OFFSET) |
+ (((exmc_sdram_init_struct->timing->row_to_column_delay) - 1U) << SDTCFG_RCD_OFFSET);
EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = sdtcfg0;
EXMC_SDTCFG(EXMC_SDRAM_DEVICE1) = sdtcfg1;
@@ -659,88 +697,74 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
}
/*!
- \brief initialize the struct exmc_sdram_parameter_struct
+ \brief initialize exmc_sdram_struct_command_para_init with the default values
\param[in] none
- \param[out] the initialized struct exmc_sdram_parameter_struct pointer
+ \param[out] the initialized struct exmc_sdram_struct_command_para_init pointer
\retval none
*/
-void exmc_sdram_parameter_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
+void exmc_sdram_struct_command_para_init(exmc_sdram_command_parameter_struct *exmc_sdram_command_init_struct)
{
/* configure the structure with default value */
- exmc_sdram_init_struct->sdram_device = EXMC_SDRAM_DEVICE0;
- exmc_sdram_init_struct->column_address_width = EXMC_SDRAM_COW_ADDRESS_8;
- exmc_sdram_init_struct->row_address_width = EXMC_SDRAM_ROW_ADDRESS_11;
- exmc_sdram_init_struct->data_width = EXMC_SDRAM_DATABUS_WIDTH_16B;
- exmc_sdram_init_struct->internal_bank_number = EXMC_SDRAM_4_INTER_BANK;
- exmc_sdram_init_struct->cas_latency = EXMC_CAS_LATENCY_1_SDCLK;
- exmc_sdram_init_struct->write_protection = ENABLE;
- exmc_sdram_init_struct->sdclock_config = EXMC_SDCLK_DISABLE;
- exmc_sdram_init_struct->brust_read_switch = DISABLE;
- exmc_sdram_init_struct->pipeline_read_delay = EXMC_PIPELINE_DELAY_0_HCLK;
-
- exmc_sdram_init_struct->timing->load_mode_register_delay = 16U;
- exmc_sdram_init_struct->timing->exit_selfrefresh_delay = 16U;
- exmc_sdram_init_struct->timing->row_address_select_delay = 16U;
- exmc_sdram_init_struct->timing->auto_refresh_delay = 16U;
- exmc_sdram_init_struct->timing->write_recovery_delay = 16U;
- exmc_sdram_init_struct->timing->row_precharge_delay = 16U;
- exmc_sdram_init_struct->timing->row_to_column_delay = 16U;
+ exmc_sdram_command_init_struct->mode_register_content = 0U;
+ exmc_sdram_command_init_struct->auto_refresh_number = EXMC_SDRAM_AUTO_REFLESH_1_SDCLK;
+ exmc_sdram_command_init_struct->bank_select = EXMC_SDRAM_DEVICE0_SELECT;
+ exmc_sdram_command_init_struct->command = EXMC_SDRAM_NORMAL_OPERATION;
}
/*!
\brief configure the SDRAM memory command
- \param[in] exmc_sdram_command_init_struct: initialize EXMC SDRAM command
+ \param[in] exmc_sdram_command_init_struct: initialize EXMC SDRAM command
mode_register_content:
auto_refresh_number: EXMC_SDRAM_AUTO_REFLESH_x_SDCLK, x=1..15
- bank_select: EXMC_SDRAM_DEVICE0_SELECT, EXMC_SDRAM_DEVICE1_SELECT, EXMC_SDRAM_DEVICE0_1_SELECT
- command: EXMC_SDRAM_NORMAL_OPERATION, EXMC_SDRAM_CLOCK_ENABLE, EXMC_SDRAM_PRECHARGE_ALL,
- EXMC_SDRAM_AUTO_REFRESH, EXMC_SDRAM_LOAD_MODE_REGISTER, EXMC_SDRAM_SELF_REFRESH,
- EXMC_SDRAM_POWERDOWN_ENTRY
+ bank_select: EXMC_SDRAM_DEVICE0_SELECT, EXMC_SDRAM_DEVICE1_SELECT, EXMC_SDRAM_DEVICE0_1_SELECT
+ command: EXMC_SDRAM_NORMAL_OPERATION, EXMC_SDRAM_CLOCK_ENABLE, EXMC_SDRAM_PRECHARGE_ALL,
+ EXMC_SDRAM_AUTO_REFRESH, EXMC_SDRAM_LOAD_MODE_REGISTER, EXMC_SDRAM_SELF_REFRESH,
+ EXMC_SDRAM_POWERDOWN_ENTRY
\param[out] none
\retval none
*/
-void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct)
+void exmc_sdram_command_config(exmc_sdram_command_parameter_struct *exmc_sdram_command_init_struct)
{
/* configure command register */
EXMC_SDCMD = (uint32_t)((exmc_sdram_command_init_struct->command) |
- (exmc_sdram_command_init_struct->bank_select) |
- ((exmc_sdram_command_init_struct->auto_refresh_number)) |
- ((exmc_sdram_command_init_struct->mode_register_content)<bank_select) |
+ ((exmc_sdram_command_init_struct->auto_refresh_number)) |
+ ((exmc_sdram_command_init_struct->mode_register_content) << SDCMD_MRC_OFFSET));
}
/*!
\brief set auto-refresh interval
- \param[in] exmc_count: the number SDRAM clock cycles unit between two successive auto-refresh commands
- \arg (SDRAM refresh period / number of rows) - 20
+ \param[in] exmc_count: the number SDRAM clock cycles unit between two successive auto-refresh commands, 0x0000~0x1FFF
\param[out] none
\retval none
*/
void exmc_sdram_refresh_count_set(uint32_t exmc_count)
{
uint32_t sdari;
-
+
sdari = EXMC_SDARI & (~EXMC_SDARI_ARINTV);
EXMC_SDARI = sdari | (uint32_t)((exmc_count << SDARI_ARINTV_OFFSET) & EXMC_SDARI_ARINTV);
}
/*!
\brief set the number of successive auto-refresh command
- \param[in] exmc_number: how many successive Auto-refresh cycles will be send when CMD = Auto-refresh command
- \arg EXMC_SDRAM_AUTO_REFLESH_x_SDCLK, x=1..15
+ \param[in] exmc_number: the number of successive auto-refresh cycles will be send, 1~15
+ \arg EXMC_SDRAM_AUTO_REFLESH_x_SDCLK(x=1..15)
\param[out] none
\retval none
*/
void exmc_sdram_autorefresh_number_set(uint32_t exmc_number)
{
uint32_t sdcmd;
-
+
sdcmd = EXMC_SDCMD & (~EXMC_SDCMD_NARF);
EXMC_SDCMD = sdcmd | (uint32_t)((exmc_number << SDCMD_NARF_OFFSET) & EXMC_SDCMD_NARF) ;
}
/*!
- \brief config the write protection function
- \param[in] exmc_sdram_device: specifie the SDRAM device
+ \brief configure the write protection function
+ \param[in] exmc_sdram_device: specify the SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_SDRAM_DEVICEx(x=0,1)
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
@@ -748,9 +772,9 @@ void exmc_sdram_autorefresh_number_set(uint32_t exmc_number)
*/
void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue)
{
- if (ENABLE == newvalue){
+ if(ENABLE == newvalue) {
EXMC_SDCTL(exmc_sdram_device) |= (uint32_t)EXMC_SDCTL_WPEN;
- }else{
+ } else {
EXMC_SDCTL(exmc_sdram_device) &= ~((uint32_t)EXMC_SDCTL_WPEN);
}
@@ -758,7 +782,8 @@ void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatu
/*!
\brief get the status of SDRAM device0 or device1
- \param[in] exmc_sdram_device: specifie the SDRAM device
+ \param[in] exmc_sdram_device: specify the SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_SDRAM_DEVICEx(x=0,1)
\param[out] none
\retval the status of SDRAM device
@@ -770,9 +795,9 @@ uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
{
uint32_t sdstat = 0U;
- if(EXMC_SDRAM_DEVICE0 == exmc_sdram_device){
+ if(EXMC_SDRAM_DEVICE0 == exmc_sdram_device) {
sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA0) >> SDSTAT_STA0_OFFSET);
- }else{
+ } else {
sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA1) >> SDSTAT_STA1_OFFSET);
}
@@ -782,8 +807,10 @@ uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
/*!
\brief configure the delayed sample clock of read data
\param[in] delay_cell: SDRAM the delayed sample clock of read data
+ only one parameter can be selected which is shown as below:
\arg EXMC_SDRAM_x_DELAY_CELL(x=0..15)
\param[in] extra_hclk: sample cycle of read data
+ only one parameter can be selected which is shown as below:
\arg EXMC_SDRAM_READSAMPLE_x_EXTRAHCLK(x=0,1)
\param[out] none
\retval none
@@ -791,10 +818,10 @@ uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
void exmc_sdram_readsample_config(uint32_t delay_cell, uint32_t extra_hclk)
{
uint32_t sdrsctl = 0U;
-
+
sdrsctl = EXMC_SDRSCTL & (~(EXMC_SDRSCTL_SDSC | EXMC_SDRSCTL_SSCR));
sdrsctl |= (uint32_t)(delay_cell & EXMC_SDRSCTL_SDSC) |
- ((extra_hclk << SDRSCTL_SSCR_OFFSET) & EXMC_SDRSCTL_SSCR);
+ ((extra_hclk << SDRSCTL_SSCR_OFFSET) & EXMC_SDRSCTL_SSCR);
EXMC_SDRSCTL = sdrsctl;
}
@@ -822,7 +849,7 @@ void exmc_sdram_readsample_disable(void)
/*!
- \brief deinitialize exmc SQPIPSRAM
+ \brief deinitialize EXMC SQPIPSRAM
\param[in] none
\param[out] none
\retval none
@@ -837,6 +864,21 @@ void exmc_sqpipsram_deinit(void)
EXMC_SIDH = BANK0_SQPI_SIDH_RESET;
}
+/*!
+ \brief initialize exmc_sqpipsram_init_struct with the default values
+ \param[in] the structure exmc_sqpipsram_parameter_struct pointer
+ \param[out] none
+ \retval none
+*/
+void exmc_sqpipsram_struct_para_init(exmc_sqpipsram_parameter_struct *exmc_sqpipsram_init_struct)
+{
+ /* configure the structure with default value */
+ exmc_sqpipsram_init_struct->sample_polarity = EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE;
+ exmc_sqpipsram_init_struct->id_length = EXMC_SQPIPSRAM_ID_LENGTH_64B;
+ exmc_sqpipsram_init_struct->address_bits = EXMC_SQPIPSRAM_ADDR_LENGTH_24B;
+ exmc_sqpipsram_init_struct->command_bits = EXMC_SQPIPSRAM_COMMAND_LENGTH_8B;
+}
+
/*!
\brief initialize EXMC SQPIPSRAM
\param[in] exmc_sqpipsram_parameter_struct: configure the EXMC SQPIPSRAM parameter
@@ -847,33 +889,19 @@ void exmc_sqpipsram_deinit(void)
\param[out] none
\retval none
*/
-void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
+void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct *exmc_sqpipsram_init_struct)
{
/* initialize SQPI controller */
EXMC_SINIT = (uint32_t)exmc_sqpipsram_init_struct->sample_polarity |
- exmc_sqpipsram_init_struct->id_length |
- exmc_sqpipsram_init_struct->address_bits |
- exmc_sqpipsram_init_struct->command_bits;
-}
-
-/*!
- \brief initialize the struct exmc_sqpipsram_parameter_struct
- \param[in] the struct exmc_sqpipsram_parameter_struct pointer
- \param[out] none
- \retval none
-*/
-void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
-{
- /* configure the structure with default value */
- exmc_sqpipsram_init_struct->sample_polarity = EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE;
- exmc_sqpipsram_init_struct->id_length = EXMC_SQPIPSRAM_ID_LENGTH_64B;
- exmc_sqpipsram_init_struct->address_bits = EXMC_SQPIPSRAM_ADDR_LENGTH_24B;
- exmc_sqpipsram_init_struct->command_bits = EXMC_SQPIPSRAM_COMMAND_LENGTH_8B;
+ exmc_sqpipsram_init_struct->id_length |
+ exmc_sqpipsram_init_struct->address_bits |
+ exmc_sqpipsram_init_struct->command_bits;
}
/*!
\brief set the read command
\param[in] read_command_mode: configure SPI PSRAM read command mode
+ only one parameter can be selected which is shown as below:
\arg EXMC_SQPIPSRAM_READ_MODE_DISABLE: not SPI mode
\arg EXMC_SQPIPSRAM_READ_MODE_SPI: SPI mode
\arg EXMC_SQPIPSRAM_READ_MODE_SQPI: SQPI mode
@@ -886,16 +914,17 @@ void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsr
void exmc_sqpipsram_read_command_set(uint32_t read_command_mode, uint32_t read_wait_cycle, uint32_t read_command_code)
{
uint32_t srcmd;
-
+
srcmd = (uint32_t) read_command_mode |
- ((read_wait_cycle << SRCMD_RWAITCYCLE_OFFSET) & EXMC_SRCMD_RWAITCYCLE) |
- ((read_command_code & EXMC_SRCMD_RCMD));
+ ((read_wait_cycle << SRCMD_RWAITCYCLE_OFFSET) & EXMC_SRCMD_RWAITCYCLE) |
+ ((read_command_code & EXMC_SRCMD_RCMD));
EXMC_SRCMD = srcmd;
}
/*!
\brief set the write command
\param[in] write_command_mode: configure SPI PSRAM write command mode
+ only one parameter can be selected which is shown as below:
\arg EXMC_SQPIPSRAM_WRITE_MODE_DISABLE: not SPI mode
\arg EXMC_SQPIPSRAM_WRITE_MODE_SPI: SPI mode
\arg EXMC_SQPIPSRAM_WRITE_MODE_SQPI: SQPI mode
@@ -908,10 +937,10 @@ void exmc_sqpipsram_read_command_set(uint32_t read_command_mode, uint32_t read_w
void exmc_sqpipsram_write_command_set(uint32_t write_command_mode, uint32_t write_wait_cycle, uint32_t write_command_code)
{
uint32_t swcmd;
-
+
swcmd = (uint32_t) write_command_mode |
- ((write_wait_cycle << SWCMD_WWAITCYCLE_OFFSET) & EXMC_SWCMD_WWAITCYCLE) |
- ((write_command_code & EXMC_SWCMD_WCMD));
+ ((write_wait_cycle << SWCMD_WWAITCYCLE_OFFSET) & EXMC_SWCMD_WWAITCYCLE) |
+ ((write_command_code & EXMC_SWCMD_WCMD));
EXMC_SWCMD = swcmd;
}
@@ -962,6 +991,7 @@ uint32_t exmc_sqpipsram_high_id_get(void)
/*!
\brief get the bit value of EXMC send write command bit or read ID command
\param[in] send_command_flag: the send command flag
+ only one parameter can be selected which is shown as below:
\arg EXMC_SEND_COMMAND_FLAG_RDID: EXMC_SRCMD_RDID flag bit
\arg EXMC_SEND_COMMAND_FLAG_SC: EXMC_SWCMD_SC flag bit
\param[out] none
@@ -970,32 +1000,34 @@ uint32_t exmc_sqpipsram_high_id_get(void)
FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag)
{
uint32_t flag = 0x00000000U;
-
- if(EXMC_SEND_COMMAND_FLAG_RDID == send_command_flag){
+
+ if(EXMC_SEND_COMMAND_FLAG_RDID == send_command_flag) {
flag = EXMC_SRCMD;
- }else if(EXMC_SEND_COMMAND_FLAG_SC == send_command_flag){
+ } else if(EXMC_SEND_COMMAND_FLAG_SC == send_command_flag) {
flag = EXMC_SWCMD;
- }else{
+ } else {
}
-
- if (flag & send_command_flag){
+
+ if(flag & send_command_flag) {
/* flag is set */
return SET;
- }else{
+ } else {
/* flag is reset */
return RESET;
}
}
/*!
- \brief check EXMC flag is set or not
- \param[in] bank: specifies the NAND bank , PC card bank or SDRAM device
+ \brief get EXMC flag status
+ \param[in] exmc_bank: specify the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC Card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] flag: specify get which flag
+ \param[in] flag: EXMC status and flag
+ only one parameter can be selected which is shown as below:
\arg EXMC_NAND_PCCARD_FLAG_RISE: interrupt rising edge status
\arg EXMC_NAND_PCCARD_FLAG_LEVEL: interrupt high-level status
\arg EXMC_NAND_PCCARD_FLAG_FALL: interrupt falling edge status
@@ -1009,32 +1041,34 @@ FlagStatus exmc_flag_get(uint32_t bank, uint32_t flag)
{
uint32_t status = 0x00000000U;
- if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)){
+ if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)) {
/* NAND bank1,bank2 or PC card bank3 */
status = EXMC_NPINTEN(bank);
- }else{
- /* SDRAM device0 or device1 */
+ } else {
+ /* SDRAM device0 or device1 */
status = EXMC_SDSTAT;
}
-
- if((status & flag) != (uint32_t)flag){
+
+ if((status & flag) != (uint32_t)flag) {
/* flag is reset */
return RESET;
- }else{
+ } else {
/* flag is set */
return SET;
}
}
/*!
- \brief clear EXMC flag
- \param[in] bank: specifie the NAND bank , PCCARD bank or SDRAM device
+ \brief clear EXMC flag status
+ \param[in] exmc_bank: specify the NAND bank , PCCARD bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] flag: specify get which flag
+ \param[in] flag: EXMC status and flag
+ only one parameter can be selected which is shown as below:
\arg EXMC_NAND_PCCARD_FLAG_RISE: interrupt rising edge status
\arg EXMC_NAND_PCCARD_FLAG_LEVEL: interrupt high-level status
\arg EXMC_NAND_PCCARD_FLAG_FALL: interrupt falling edge status
@@ -1046,133 +1080,140 @@ FlagStatus exmc_flag_get(uint32_t bank, uint32_t flag)
*/
void exmc_flag_clear(uint32_t bank, uint32_t flag)
{
- if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)){
+ if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)) {
/* NAND bank1,bank2 or PC card bank3 */
EXMC_NPINTEN(bank) &= ~flag;
- }else{
+ } else {
/* SDRAM device0 or device1 */
EXMC_SDSTAT &= ~flag;
- }
+ }
}
/*!
- \brief check EXMC interrupt flag is set or not
- \param[in] bank: specifies the NAND bank , PC card bank or SDRAM device
+ \brief enable EXMC interrupt
+ \param[in] bank: specify the NAND bank,PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_FLAG_REFRESH: interrupt source of refresh error
+ \param[in] interrupt: specify get which interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
+ \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
+ \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
+ \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
\param[out] none
- \retval FlagStatus: SET or RESET
+ \retval none
*/
-FlagStatus exmc_interrupt_flag_get(uint32_t bank, uint32_t interrupt_source)
+void exmc_interrupt_enable(uint32_t bank, uint32_t interrupt)
{
- uint32_t status = 0x00000000U, interrupt_enable = 0x00000000U, interrupt_state = 0x00000000U;
-
- if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)){
+ if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)) {
/* NAND bank1,bank2 or PC card bank3 */
- status = EXMC_NPINTEN(bank);
- interrupt_state = (status & (interrupt_source >> INTEN_INTS_OFFSET));
- }else{
- /* SDRAM device0 or device1 */
- status = EXMC_SDARI;
- interrupt_state = (EXMC_SDSTAT & EXMC_SDSDAT_REIF);
- }
-
- interrupt_enable = (status & interrupt_source);
-
- if ((interrupt_enable) && (interrupt_state)){
- /* interrupt flag is set */
- return SET;
- }else{
- /* interrupt flag is reset */
- return RESET;
+ EXMC_NPINTEN(bank) |= interrupt;
+ } else {
+ /* SDRAM device0 or device1 */
+ EXMC_SDARI |= EXMC_SDARI_REIE;
}
}
/*!
- \brief clear EXMC interrupt flag
- \param[in] bank: specifies the NAND bank , PC card bank or SDRAM device
+ \brief disable EXMC interrupt
+ \param[in] bank: specify the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_FLAG_REFRESH: interrupt source of refresh error
+ \param[in] interrupt: specify get which interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
+ \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
+ \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
+ \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
\param[out] none
\retval none
*/
-void exmc_interrupt_flag_clear(uint32_t bank, uint32_t interrupt_source)
+void exmc_interrupt_disable(uint32_t bank, uint32_t interrupt)
{
- if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)){
+ if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)) {
/* NAND bank1,bank2 or PC card bank3 */
- EXMC_NPINTEN(bank) &= ~(interrupt_source >> INTEN_INTS_OFFSET);
- }else{
+ EXMC_NPINTEN(bank) &= ~interrupt;
+ } else {
/* SDRAM device0 or device1 */
- EXMC_SDARI |= EXMC_SDARI_REC;
+ EXMC_SDARI &= ~EXMC_SDARI_REIE;
}
}
/*!
- \brief enable EXMC interrupt
- \param[in] bank: specifies the NAND bank,PC card bank or SDRAM device
+ \brief get EXMC interrupt flag
+ \param[in] bank: specify the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
+ \param[in] interrupt: EXMC interrupt flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: interrupt source of rising edge
+ \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: interrupt source of high-level
+ \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: interrupt source of falling edge
+ \arg EXMC_SDRAM_INT_FLAG_REFRESH: interrupt source of refresh error
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void exmc_interrupt_enable(uint32_t bank, uint32_t interrupt_source)
+FlagStatus exmc_interrupt_flag_get(uint32_t bank, uint32_t interrupt)
{
- if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)){
+ uint32_t status = 0x00000000U, interrupt_enable = 0x00000000U, interrupt_state = 0x00000000U;
+
+ if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)) {
/* NAND bank1,bank2 or PC card bank3 */
- EXMC_NPINTEN(bank) |= interrupt_source;
- }else{
+ status = EXMC_NPINTEN(bank);
+ interrupt_state = (status & (interrupt >> INTEN_INTS_OFFSET));
+ } else {
/* SDRAM device0 or device1 */
- EXMC_SDARI |= EXMC_SDARI_REIE;
+ status = EXMC_SDARI;
+ interrupt_state = (EXMC_SDSTAT & EXMC_SDSDAT_REIF);
+ }
+
+ interrupt_enable = (status & interrupt);
+
+ if((interrupt_enable) && (interrupt_state)) {
+ /* interrupt flag is set */
+ return SET;
+ } else {
+ /* interrupt flag is reset */
+ return RESET;
}
}
/*!
- \brief disable EXMC interrupt
- \param[in] bank: specifies the NAND bank , PC card bank or SDRAM device
+ \brief clear EXMC interrupt flag
+ \param[in] bank: specify the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
+ \param[in] interrupt: specify get which interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: interrupt source of rising edge
+ \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: interrupt source of high-level
+ \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: interrupt source of falling edge
+ \arg EXMC_SDRAM_INT_FLAG_REFRESH: interrupt source of refresh error
\param[out] none
\retval none
*/
-void exmc_interrupt_disable(uint32_t bank, uint32_t interrupt_source)
+void exmc_interrupt_flag_clear(uint32_t bank, uint32_t interrupt)
{
- if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)){
+ if((EXMC_BANK1_NAND == bank) || (EXMC_BANK2_NAND == bank) || (EXMC_BANK3_PCCARD == bank)) {
/* NAND bank1,bank2 or PC card bank3 */
- EXMC_NPINTEN(bank) &= ~interrupt_source;
- }else{
+ EXMC_NPINTEN(bank) &= ~(interrupt >> INTEN_INTS_OFFSET);
+ } else {
/* SDRAM device0 or device1 */
- EXMC_SDARI &= ~EXMC_SDARI_REIE;
+ EXMC_SDARI |= EXMC_SDARI_REC;
}
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exti.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exti.c
index ffa56cc..70246c2 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exti.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_exti.c
@@ -2,36 +2,33 @@
\file gd32f20x_exti.c
\brief EXTI driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -56,7 +53,7 @@ void exti_deinit(void)
}
/*!
- \brief initialize the EXTI
+ \brief initialize the EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
@@ -67,8 +64,9 @@ void exti_deinit(void)
\param[in] trig_type: interrupt trigger type, refer to exti_trig_type_enum
only one parameter can be selected which is shown as below:
\arg EXTI_TRIG_RISING: rising edge trigger
- \arg EXTI_TRIG_FALLING: falling edge trigger
- \arg EXTI_TRIG_BOTH: rising edge and falling edge trigger
+ \arg EXTI_TRIG_FALLING: falling trigger
+ \arg EXTI_TRIG_BOTH: rising and falling trigger
+ \arg EXTI_TRIG_NONE: without rising edge or falling edge trigger
\param[out] none
\retval none
*/
@@ -79,9 +77,9 @@ void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum tr
EXTI_EVEN &= ~(uint32_t)linex;
EXTI_RTEN &= ~(uint32_t)linex;
EXTI_FTEN &= ~(uint32_t)linex;
-
+
/* set the EXTI mode and enable the interrupts or events from EXTI line x */
- switch(mode){
+ switch(mode) {
case EXTI_INTERRUPT:
EXTI_INTEN |= (uint32_t)linex;
break;
@@ -91,9 +89,9 @@ void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum tr
default:
break;
}
-
+
/* set the EXTI trigger type */
- switch(trig_type){
+ switch(trig_type) {
case EXTI_TRIG_RISING:
EXTI_RTEN |= (uint32_t)linex;
EXTI_FTEN &= ~(uint32_t)linex;
@@ -106,6 +104,7 @@ void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum tr
EXTI_RTEN |= (uint32_t)linex;
EXTI_FTEN |= (uint32_t)linex;
break;
+ case EXTI_TRIG_NONE:
default:
break;
}
@@ -125,29 +124,29 @@ void exti_interrupt_enable(exti_line_enum linex)
}
/*!
- \brief enable the events from EXTI line x
+ \brief disable the interrupts from EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
\retval none
*/
-void exti_event_enable(exti_line_enum linex)
+void exti_interrupt_disable(exti_line_enum linex)
{
- EXTI_EVEN |= (uint32_t)linex;
+ EXTI_INTEN &= ~(uint32_t)linex;
}
/*!
- \brief disable the interrupt from EXTI line x
+ \brief enable the events from EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
\retval none
*/
-void exti_interrupt_disable(exti_line_enum linex)
+void exti_event_enable(exti_line_enum linex)
{
- EXTI_INTEN &= ~(uint32_t)linex;
+ EXTI_EVEN |= (uint32_t)linex;
}
/*!
@@ -164,92 +163,87 @@ void exti_event_disable(exti_line_enum linex)
}
/*!
- \brief get EXTI lines flag
+ \brief enable the software interrupt event from EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
- \retval FlagStatus: status of flag (RESET or SET)
+ \retval none
*/
-FlagStatus exti_flag_get(exti_line_enum linex)
+void exti_software_interrupt_enable(exti_line_enum linex)
{
- if(RESET != (EXTI_PD & (uint32_t)linex)){
- return SET;
- }else{
- return RESET;
- }
+ EXTI_SWIEV |= (uint32_t)linex;
}
/*!
- \brief clear EXTI lines pending flag
+ \brief disable the software interrupt event from EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
\retval none
*/
-void exti_flag_clear(exti_line_enum linex)
+void exti_software_interrupt_disable(exti_line_enum linex)
{
- EXTI_PD = (uint32_t)linex;
+ EXTI_SWIEV &= ~(uint32_t)linex;
}
/*!
- \brief get EXTI lines flag when the interrupt flag is set
+ \brief get EXTI line x interrupt pending flag
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
\retval FlagStatus: status of flag (RESET or SET)
*/
-FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
+FlagStatus exti_flag_get(exti_line_enum linex)
{
- uint32_t flag_left, flag_right;
-
- flag_left = EXTI_PD & (uint32_t)linex;
- flag_right = EXTI_INTEN & (uint32_t)linex;
-
- if((RESET != flag_left) && (RESET != flag_right)){
+ if(RESET != (EXTI_PD & (uint32_t)linex)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear EXTI lines pending flag
+ \brief clear EXTI line x interrupt pending flag
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
\retval none
*/
-void exti_interrupt_flag_clear(exti_line_enum linex)
+void exti_flag_clear(exti_line_enum linex)
{
EXTI_PD = (uint32_t)linex;
}
/*!
- \brief enable EXTI software interrupt event
+ \brief get EXTI line x interrupt pending flag
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
- \retval none
+ \retval FlagStatus: status of flag (RESET or SET)
*/
-void exti_software_interrupt_enable(exti_line_enum linex)
+FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
{
- EXTI_SWIEV |= (uint32_t)linex;
+ if(RESET != (EXTI_PD & (uint32_t)linex)) {
+ return SET;
+ } else {
+ return RESET;
+ }
}
/*!
- \brief disable EXTI software interrupt event
+ \brief clear EXTI line x interrupt pending flag
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..19): EXTI line x
\param[out] none
\retval none
*/
-void exti_software_interrupt_disable(exti_line_enum linex)
+void exti_interrupt_flag_clear(exti_line_enum linex)
{
- EXTI_SWIEV &= ~(uint32_t)linex;
+ EXTI_PD = (uint32_t)linex;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fmc.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fmc.c
index f10bf34..aee94fa 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fmc.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fmc.c
@@ -2,44 +2,51 @@
\file gd32f20x_fmc.c
\brief FMC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_fmc.h"
+/* return the FMC bank0 state */
+fmc_state_enum fmc_bank0_state_get(void); /** AvV **/
+/* return the FMC bank1 state */
+fmc_state_enum fmc_bank1_state_get(void); /** AvV **/
+/* check FMC bank0 ready or not */
+static fmc_state_enum fmc_bank0_ready_wait(uint32_t timeout);
+/* check FMC bank1 ready or not */
+static fmc_state_enum fmc_bank1_ready_wait(uint32_t timeout);
+
/*!
\brief set the wait state counter value
- \param[in] wscnt£ºwait state counter value
+ \param[in] wscnt��wait state counter value
+ only one parameter can be selected which is shown as below:
\arg WS_WSCNT_0: FMC 0 wait state
\arg WS_WSCNT_1: FMC 1 wait state
\arg WS_WSCNT_2: FMC 2 wait state
@@ -49,7 +56,7 @@ OF SUCH DAMAGE.
void fmc_wscnt_set(uint32_t wscnt)
{
uint32_t reg;
-
+
reg = FMC_WS;
/* set the wait state counter value */
reg &= ~FMC_WS_WSCNT;
@@ -64,14 +71,14 @@ void fmc_wscnt_set(uint32_t wscnt)
*/
void fmc_unlock(void)
{
- if((RESET != (FMC_CTL0 & FMC_CTL0_LK))){
+ if((RESET != (FMC_CTL0 & FMC_CTL0_LK))) {
/* write the FMC unlock key */
FMC_KEY0 = UNLOCK_KEY0;
FMC_KEY0 = UNLOCK_KEY1;
}
- if(FMC_BANK0_SIZE < FMC_SIZE){
+ if(FMC_BANK0_SIZE < FMC_SIZE) {
/* write the FMC unlock key */
- if(RESET != (FMC_CTL1 & FMC_CTL1_LK)){
+ if(RESET != (FMC_CTL1 & FMC_CTL1_LK)) {
FMC_KEY1 = UNLOCK_KEY0;
FMC_KEY1 = UNLOCK_KEY1;
}
@@ -79,7 +86,7 @@ void fmc_unlock(void)
}
/*!
- \brief unlock the FMC bank0 operation
+ \brief unlock the FMC bank0 operation
this function can be used for all GD32F20x devices.
for GD32F20x with flash more than 512KB, this function unlocks bank0.
for GD32F20x with flash no more than 512KB and it is equivalent to fmc_unlock function.
@@ -89,7 +96,7 @@ void fmc_unlock(void)
*/
void fmc_bank0_unlock(void)
{
- if((RESET != (FMC_CTL0 & FMC_CTL0_LK))){
+ if((RESET != (FMC_CTL0 & FMC_CTL0_LK))) {
/* write the FMC unlock key */
FMC_KEY0 = UNLOCK_KEY0;
FMC_KEY0 = UNLOCK_KEY1;
@@ -97,7 +104,7 @@ void fmc_bank0_unlock(void)
}
/*!
- \brief unlock the FMC bank1 operation
+ \brief unlock the FMC bank1 operation
this function can be used for GD32F20x with flash more than 512KB.
\param[in] none
\param[out] none
@@ -105,7 +112,7 @@ void fmc_bank0_unlock(void)
*/
void fmc_bank1_unlock(void)
{
- if((RESET != (FMC_CTL1 & FMC_CTL1_LK))){
+ if((RESET != (FMC_CTL1 & FMC_CTL1_LK))) {
/* write the FMC unlock key */
FMC_KEY1 = UNLOCK_KEY0;
FMC_KEY1 = UNLOCK_KEY1;
@@ -122,8 +129,8 @@ void fmc_lock(void)
{
/* set the LK bit */
FMC_CTL0 |= FMC_CTL0_LK;
-
- if(FMC_BANK0_SIZE < FMC_SIZE){
+
+ if(FMC_BANK0_SIZE < FMC_SIZE) {
/* set the LK bit */
FMC_CTL1 |= FMC_CTL1_LK;
}
@@ -167,11 +174,11 @@ fmc_state_enum fmc_page_erase(uint32_t page_address)
{
fmc_state_enum fmc_state;
/* flash size is greater than 512k */
- if(FMC_BANK0_SIZE < FMC_SIZE){
- if(FMC_BANK0_END_ADDRESS > page_address){
+ if(FMC_BANK0_SIZE < FMC_SIZE) {
+ if(FMC_BANK0_END_ADDRESS > page_address) {
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
/* if the last operation is completed, start page erase */
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
FMC_CTL0 |= FMC_CTL0_PER;
FMC_ADDR0 = page_address;
FMC_CTL0 |= FMC_CTL0_START;
@@ -180,14 +187,14 @@ fmc_state_enum fmc_page_erase(uint32_t page_address)
/* reset the PER bit */
FMC_CTL0 &= ~FMC_CTL0_PER;
}
- }else{
+ } else {
/* wait for the FMC ready */
fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
/* if the last operation is completed, start page erase */
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
FMC_CTL1 |= FMC_CTL1_PER;
FMC_ADDR1 = page_address;
- if(FMC_OBSTAT & FMC_OBSTAT_SPC){
+ if(FMC_OBSTAT & FMC_OBSTAT_SPC) {
FMC_ADDR0 = page_address;
}
FMC_CTL1 |= FMC_CTL1_START;
@@ -197,10 +204,10 @@ fmc_state_enum fmc_page_erase(uint32_t page_address)
FMC_CTL1 &= ~FMC_CTL1_PER;
}
}
- }else{
+ } else {
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
/* if the last operation is completed, start page erase */
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
FMC_CTL0 |= FMC_CTL0_PER;
FMC_ADDR0 = page_address;
FMC_CTL0 |= FMC_CTL0_START;
@@ -224,10 +231,10 @@ fmc_state_enum fmc_mass_erase(void)
{
fmc_state_enum fmc_state;
/* flash size is greater than 512k */
- if(FMC_BANK0_SIZE < FMC_SIZE){
+ if(FMC_BANK0_SIZE < FMC_SIZE) {
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
/* start whole chip erase */
FMC_CTL0 |= FMC_CTL0_MER;
FMC_CTL0 |= FMC_CTL0_START;
@@ -237,7 +244,7 @@ fmc_state_enum fmc_mass_erase(void)
FMC_CTL0 &= ~FMC_CTL0_MER;
}
fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
/* start whole chip erase */
FMC_CTL1 |= FMC_CTL1_MER;
FMC_CTL1 |= FMC_CTL1_START;
@@ -246,20 +253,20 @@ fmc_state_enum fmc_mass_erase(void)
/* reset the MER bit */
FMC_CTL1 &= ~FMC_CTL1_MER;
}
- }else{
+ } else {
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* start whole chip erase */
FMC_CTL0 |= FMC_CTL0_MER;
- FMC_CTL0 |= FMC_CTL0_START;
+ FMC_CTL0 |= FMC_CTL0_START;
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
/* reset the MER bit */
FMC_CTL0 &= ~FMC_CTL0_MER;
}
}
- /* return the FMC state */
+ /* return the FMC state */
return fmc_state;
}
@@ -275,7 +282,7 @@ fmc_state_enum fmc_bank0_erase(void)
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
/* start FMC bank0 erase */
FMC_CTL0 |= FMC_CTL0_MER;
FMC_CTL0 |= FMC_CTL0_START;
@@ -284,7 +291,7 @@ fmc_state_enum fmc_bank0_erase(void)
/* reset the MER bit */
FMC_CTL0 &= ~FMC_CTL0_MER;
}
- /* return the fmc state */
+ /* return the FMC state */
return fmc_state;
}
@@ -299,8 +306,8 @@ fmc_state_enum fmc_bank1_erase(void)
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* start FMC bank1 erase */
FMC_CTL1 |= FMC_CTL1_MER;
FMC_CTL1 |= FMC_CTL1_START;
@@ -309,7 +316,7 @@ fmc_state_enum fmc_bank1_erase(void)
/* reset the MER bit */
FMC_CTL1 &= ~FMC_CTL1_MER;
}
- /* return the fmc state */
+ /* return the FMC state */
return fmc_state;
}
@@ -324,11 +331,11 @@ fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
{
fmc_state_enum fmc_state = FMC_READY;
/* flash size is greater than 512k */
- if(FMC_BANK0_SIZE < FMC_SIZE){
- if(FMC_BANK0_END_ADDRESS > address){
- fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+ if(FMC_BANK0_SIZE < FMC_SIZE) {
+ if(FMC_BANK0_END_ADDRESS > address) {
+ fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
+
+ if(FMC_READY == fmc_state) {
/* set the PG bit to start program */
FMC_CTL0 |= FMC_CTL0_PG;
REG32(address) = data;
@@ -337,10 +344,10 @@ fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
/* reset the PG bit */
FMC_CTL0 &= ~FMC_CTL0_PG;
}
- }else{
- fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+ } else {
+ fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
+
+ if(FMC_READY == fmc_state) {
/* set the PG bit to start program */
FMC_CTL1 |= FMC_CTL1_PG;
REG32(address) = data;
@@ -350,10 +357,10 @@ fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
FMC_CTL1 &= ~FMC_CTL1_PG;
}
}
- }else{
+ } else {
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* set the PG bit to start program */
FMC_CTL0 |= FMC_CTL0_PG;
REG32(address) = data;
@@ -361,7 +368,7 @@ fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
/* reset the PG bit */
FMC_CTL0 &= ~FMC_CTL0_PG;
- }
+ }
}
/* return the FMC state */
return fmc_state;
@@ -378,11 +385,11 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
{
fmc_state_enum fmc_state = FMC_READY;
/* flash size is greater than 512k */
- if(FMC_BANK0_SIZE < FMC_SIZE){
- if(FMC_BANK0_END_ADDRESS > address){
- fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+ if(FMC_BANK0_SIZE < FMC_SIZE) {
+ if(FMC_BANK0_END_ADDRESS > address) {
+ fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
+
+ if(FMC_READY == fmc_state) {
/* set the PG bit to start program */
FMC_CTL0 |= FMC_CTL0_PG;
REG16(address) = data;
@@ -391,10 +398,10 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
/* reset the PG bit */
FMC_CTL0 &= ~FMC_CTL0_PG;
}
- }else{
- fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+ } else {
+ fmc_state = fmc_bank1_ready_wait(FMC_TIMEOUT_COUNT);
+
+ if(FMC_READY == fmc_state) {
/* set the PG bit to start program */
FMC_CTL1 |= FMC_CTL1_PG;
REG16(address) = data;
@@ -404,10 +411,10 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
FMC_CTL1 &= ~FMC_CTL1_PG;
}
}
- }else{
+ } else {
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* set the PG bit to start program */
FMC_CTL0 |= FMC_CTL0_PG;
REG16(address) = data;
@@ -415,7 +422,7 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
/* reset the PG bit */
FMC_CTL0 &= ~FMC_CTL0_PG;
- }
+ }
}
/* return the FMC state */
return fmc_state;
@@ -429,14 +436,14 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
*/
void ob_unlock(void)
{
- if(RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)){
+ if(RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)) {
/* write the FMC key */
FMC_OBKEY = UNLOCK_KEY0;
FMC_OBKEY = UNLOCK_KEY1;
}
/* wait until OBWEN bit is set by hardware */
- while(RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)){
+ while(RESET == (FMC_CTL0 & FMC_CTL0_OBWEN)) {
}
}
@@ -466,11 +473,11 @@ fmc_state_enum ob_erase(void)
fmc_state_enum fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
/* check the option byte security protection value */
- if(RESET != ob_spc_get()){
- temp_spc = FMC_USPC;
+ if(RESET != ob_spc_get()) {
+ temp_spc = FMC_USPC;
}
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
/* start erase the option byte */
FMC_CTL0 |= FMC_CTL0_OBER;
@@ -478,22 +485,22 @@ fmc_state_enum ob_erase(void)
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* reset the OBER bit */
FMC_CTL0 &= ~FMC_CTL0_OBER;
/* set the OBPG bit */
FMC_CTL0 |= FMC_CTL0_OBPG;
/* no security protection */
- OB_SPC = (uint16_t)temp_spc;
+ OB_SPC = (uint16_t)temp_spc;
/* wait for the FMC ready */
- fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_TOERR != fmc_state){
+ fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
+ if(FMC_TOERR != fmc_state) {
/* reset the OBPG bit */
FMC_CTL0 &= ~FMC_CTL0_OBPG;
}
- }else{
- if(FMC_TOERR != fmc_state){
+ } else {
+ if(FMC_TOERR != fmc_state) {
/* reset the OBPG bit */
FMC_CTL0 &= ~FMC_CTL0_OBPG;
}
@@ -505,10 +512,11 @@ fmc_state_enum ob_erase(void)
/*!
\brief enable write protection
- \param[in] ob_wp: specify sector to be write protected, set the bit to 1 if
- you want to protect the corresponding pages. meanwhile, sector
- macro could used to set specific sector write protected.
+ \param[in] ob_wp: specify sector to be write protected, set the bit to 1 if
+ you want to protect the corresponding pages. meanwhile, sector
+ macro could used to set specific sector write protected.
one or more parameters can be selected which are shown as below:
+ OB_WP_NONE: disable all erase/program protection
\arg OB_WPx(x = 0..31): write protect specify sector
\arg OB_WP_ALL: write protect all sector
\param[out] none
@@ -526,40 +534,40 @@ fmc_state_enum ob_write_protection_enable(uint32_t ob_wp)
temp_wp2 = (uint16_t)((ob_wp & OB_WP2_WP2) >> 16U);
temp_wp3 = (uint16_t)((ob_wp & OB_WP3_WP3) >> 24U);
- if(FMC_READY == fmc_state){
-
+ if(FMC_READY == fmc_state) {
+
/* set the OBPG bit*/
FMC_CTL0 |= FMC_CTL0_OBPG;
- if(0xFFU != temp_wp0){
+ if(0xFFU != temp_wp0) {
OB_WP0 = temp_wp0;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
}
- if((FMC_READY == fmc_state) && (0xFFU != temp_wp1)){
+ if((FMC_READY == fmc_state) && (0xFFU != temp_wp1)) {
OB_WP1 = temp_wp1;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
}
- if((FMC_READY == fmc_state) && (0xFFU != temp_wp2)){
+ if((FMC_READY == fmc_state) && (0xFFU != temp_wp2)) {
OB_WP2 = temp_wp2;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
}
- if((FMC_READY == fmc_state) && (0xFFU != temp_wp3)){
+ if((FMC_READY == fmc_state) && (0xFFU != temp_wp3)) {
OB_WP3 = temp_wp3;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
}
- if(FMC_TOERR != fmc_state){
+ if(FMC_TOERR != fmc_state) {
/* reset the OBPG bit */
FMC_CTL0 &= ~FMC_CTL0_OBPG;
}
- }
+ }
/* return the FMC state */
return fmc_state;
}
@@ -577,31 +585,31 @@ fmc_state_enum ob_security_protection_config(uint8_t ob_spc)
{
fmc_state_enum fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
FMC_CTL0 |= FMC_CTL0_OBER;
FMC_CTL0 |= FMC_CTL0_START;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* reset the OBER bit */
FMC_CTL0 &= ~FMC_CTL0_OBER;
-
+
/* start the option byte program */
FMC_CTL0 |= FMC_CTL0_OBPG;
-
+
OB_SPC = (uint16_t)ob_spc;
/* wait for the FMC ready */
- fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_TOERR != fmc_state){
+ fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
+
+ if(FMC_TOERR != fmc_state) {
/* reset the OBPG bit */
FMC_CTL0 &= ~FMC_CTL0_OBPG;
}
- }else{
- if(FMC_TOERR != fmc_state){
+ } else {
+ if(FMC_TOERR != fmc_state) {
/* reset the OBER bit */
FMC_CTL0 &= ~FMC_CTL0_OBER;
}
@@ -612,17 +620,21 @@ fmc_state_enum ob_security_protection_config(uint8_t ob_spc)
}
/*!
- \brief program the FMC user option byte
+ \brief program option bytes user
\param[in] ob_fwdgt: option byte watchdog value
+ only one parameter can be selected which is shown as below:
\arg OB_FWDGT_SW: software free watchdog
\arg OB_FWDGT_HW: hardware free watchdog
\param[in] ob_deepsleep: option byte deepsleep reset value
+ only one parameter can be selected which is shown as below:
\arg OB_DEEPSLEEP_NRST: no reset when entering deepsleep mode
- \arg OB_DEEPSLEEP_RST: generate a reset instead of entering deepsleep mode
+ \arg OB_DEEPSLEEP_RST: generate a reset instead of entering deepsleep mode
\param[in] ob_stdby:option byte standby reset value
+ only one parameter can be selected which is shown as below:
\arg OB_STDBY_NRST: no reset when entering standby mode
\arg OB_STDBY_RST: generate a reset instead of entering standby mode
\param[in] ob_boot: specifies the option byte boot bank value
+ only one parameter can be selected which is shown as below:
\arg OB_BOOT_B0: boot from bank0
\arg OB_BOOT_B1: boot from bank1 or bank0 if bank1 is void
\param[out] none
@@ -635,18 +647,18 @@ fmc_state_enum ob_user_write(uint8_t ob_fwdgt, uint8_t ob_deepsleep, uint8_t ob_
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+
+ if(FMC_READY == fmc_state) {
/* set the OBPG bit*/
- FMC_CTL0 |= FMC_CTL0_OBPG;
+ FMC_CTL0 |= FMC_CTL0_OBPG;
temp = ((uint8_t)((uint8_t)((uint8_t)(ob_boot | ob_fwdgt) | ob_deepsleep) | ob_stdby) | OB_USER_MASK);
OB_USER = (uint16_t)temp;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_TOERR != fmc_state){
+ if(FMC_TOERR != fmc_state) {
/* reset the OBPG bit */
FMC_CTL0 &= ~FMC_CTL0_OBPG;
}
@@ -666,15 +678,15 @@ fmc_state_enum ob_data_program(uint32_t address, uint8_t data)
{
fmc_state_enum fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
- if(FMC_READY == fmc_state){
+ if(FMC_READY == fmc_state) {
/* set the OBPG bit */
- FMC_CTL0 |= FMC_CTL0_OBPG;
+ FMC_CTL0 |= FMC_CTL0_OBPG;
REG16(address) = data;
-
+
/* wait for the FMC ready */
fmc_state = fmc_bank0_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_TOERR != fmc_state){
+
+ if(FMC_TOERR != fmc_state) {
/* reset the OBPG bit */
FMC_CTL0 &= ~FMC_CTL0_OBPG;
}
@@ -684,7 +696,7 @@ fmc_state_enum ob_data_program(uint32_t address, uint8_t data)
}
/*!
- \brief get the FMC user option byte
+ \brief get the FMC option bytes user
\param[in] none
\param[out] none
\retval the FMC user option byte values
@@ -696,7 +708,7 @@ uint8_t ob_user_get(void)
}
/*!
- \brief get OB_DATA in register FMC_OBSTAT
+ \brief get the FMC option bytes data
\param[in] none
\param[out] none
\retval ob_data
@@ -728,46 +740,14 @@ FlagStatus ob_spc_get(void)
{
FlagStatus spc_state = RESET;
- if(RESET != (FMC_OBSTAT & FMC_OBSTAT_SPC)){
+ if(RESET != (FMC_OBSTAT & FMC_OBSTAT_SPC)) {
spc_state = SET;
- }else{
+ } else {
spc_state = RESET;
}
return spc_state;
}
-/*!
- \brief enable FMC interrupt
- \param[in] interrupt: the FMC interrupt source
- only one parameter can be selected which is shown as below:
- \arg FMC_INT_BANK0_END: enable FMC end of program interrupt
- \arg FMC_INT_BANK0_ERR: enable FMC error interrupt
- \arg FMC_INT_BANK1_END: enable FMC bank1 end of program interrupt
- \arg FMC_INT_BANK1_ERR: enable FMC bank1 error interrupt
- \param[out] none
- \retval none
-*/
-void fmc_interrupt_enable(uint32_t interrupt)
-{
- FMC_REG_VAL(interrupt) |= BIT(FMC_BIT_POS(interrupt));
-}
-
-/*!
- \brief disable FMC interrupt
- \param[in] interrupt: the FMC interrupt source
- only one parameter can be selected which is shown as below:
- \arg FMC_INT_BANK0_END: enable FMC end of program interrupt
- \arg FMC_INT_BANK0_ERR: enable FMC error interrupt
- \arg FMC_INT_BANK1_END: enable FMC bank1 end of program interrupt
- \arg FMC_INT_BANK1_ERR: enable FMC bank1 error interrupt
- \param[out] none
- \retval none
-*/
-void fmc_interrupt_disable(uint32_t interrupt)
-{
- FMC_REG_VAL(interrupt) &= ~BIT(FMC_BIT_POS(interrupt));
-}
-
/*!
\brief check flag is set or not
\param[in] flag: check FMC flag
@@ -786,9 +766,9 @@ void fmc_interrupt_disable(uint32_t interrupt)
*/
FlagStatus fmc_flag_get(uint32_t flag)
{
- if(RESET != (FMC_REG_VAL(flag) & BIT(FMC_BIT_POS(flag)))){
+ if(RESET != (FMC_REG_VAL(flag) & BIT(FMC_BIT_POS(flag)))) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -811,9 +791,41 @@ void fmc_flag_clear(uint32_t flag)
FMC_REG_VAL(flag) |= BIT(FMC_BIT_POS(flag));
}
+/*!
+ \brief enable FMC interrupt
+ \param[in] interrupt: the FMC interrupt source
+ only one parameter can be selected which is shown as below:
+ \arg FMC_INT_BANK0_END: FMC bank0 end of program interrupt
+ \arg FMC_INT_BANK0_ERR: FMC bank0 error interrupt
+ \arg FMC_INT_BANK1_END: FMC bank1 end of program interrupt
+ \arg FMC_INT_BANK1_ERR: FMC bank1 error interrupt
+ \param[out] none
+ \retval none
+*/
+void fmc_interrupt_enable(fmc_interrupt_enum interrupt)
+{
+ FMC_REG_VAL(interrupt) |= BIT(FMC_BIT_POS(interrupt));
+}
+
+/*!
+ \brief disable FMC interrupt
+ \param[in] interrupt: the FMC interrupt source
+ only one parameter can be selected which is shown as below:
+ \arg FMC_INT_BANK0_END: FMC bank0 end of program interrupt
+ \arg FMC_INT_BANK0_ERR: FMC bank0 error interrupt
+ \arg FMC_INT_BANK1_END: FMC bank1 end of program interrupt
+ \arg FMC_INT_BANK1_ERR: FMC bank1 error interrupt
+ \param[out] none
+ \retval none
+*/
+void fmc_interrupt_disable(fmc_interrupt_enum interrupt)
+{
+ FMC_REG_VAL(interrupt) &= ~BIT(FMC_BIT_POS(interrupt));
+}
+
/*!
\brief get FMC interrupt flag state
- \param[in] flag: FMC interrupt flags, refer to fmc_interrupt_flag_enum
+ \param[in] int_flag: FMC interrupt flags, refer to fmc_interrupt_flag_enum
only one parameter can be selected which is shown as below:
\arg FMC_INT_FLAG_BANK0_PGERR: FMC bank0 operation error interrupt flag bit
\arg FMC_INT_FLAG_BANK0_WPERR: FMC bank0 erase/program protection error interrupt flag bit
@@ -824,33 +836,33 @@ void fmc_flag_clear(uint32_t flag)
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag)
-{
- FlagStatus ret1 = RESET;
- FlagStatus ret2 = RESET;
-
- if(FMC_STAT0_REG_OFFSET == FMC_REG_OFFSET_GET(flag)){
- /* get the staus of interrupt flag */
- ret1 = (FlagStatus)(FMC_REG_VALS(flag) & BIT(FMC_BIT_POS0(flag)));
- /* get the staus of interrupt enale bit */
- ret2 = (FlagStatus)(FMC_CTL0 & BIT(FMC_BIT_POS1(flag)));
- }else{
- /* get the staus of interrupt flag */
- ret1 = (FlagStatus)(FMC_REG_VALS(flag) & BIT(FMC_BIT_POS0(flag)));
- /* get the staus of interrupt enale bit */
- ret2 = (FlagStatus)(FMC_CTL1 & BIT(FMC_BIT_POS1(flag)));
+FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum int_flag)
+{
+ uint32_t ret1 = RESET;
+ uint32_t ret2 = RESET;
+
+ if(FMC_STAT0_REG_OFFSET == FMC_REG_OFFSET_GET(int_flag)) {
+ /* get the status of interrupt flag */
+ ret1 = (uint32_t)(FMC_REG_VALS(int_flag) & BIT(FMC_BIT_POS0(int_flag)));
+ /* get the status of interrupt enable bit */
+ ret2 = (uint32_t)(FMC_CTL0 & BIT(FMC_BIT_POS1(int_flag)));
+ } else {
+ /* get the status of interrupt flag */
+ ret1 = (uint32_t)(FMC_REG_VALS(int_flag) & BIT(FMC_BIT_POS0(int_flag)));
+ /* get the status of interrupt enable bit */
+ ret2 = (uint32_t)(FMC_CTL1 & BIT(FMC_BIT_POS1(int_flag)));
}
- if(ret1 && ret2){
+ if(ret1 && ret2) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
\brief clear FMC interrupt flag state
- \param[in] flag: FMC interrupt flags, refer to can_interrupt_flag_enum
+ \param[in] int_flag: FMC interrupt flags, refer to can_interrupt_flag_enum
only one parameter can be selected which is shown as below:
\arg FMC_INT_FLAG_BANK0_PGERR: FMC bank0 operation error interrupt flag bit
\arg FMC_INT_FLAG_BANK0_WPERR: FMC bank0 erase/program protection error interrupt flag bit
@@ -861,9 +873,9 @@ FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag)
\param[out] none
\retval none
*/
-void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag)
+void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum int_flag)
{
- FMC_REG_VALS(flag) |= BIT(FMC_BIT_POS0(flag));
+ FMC_REG_VALS(int_flag) |= BIT(FMC_BIT_POS0(int_flag));
}
/*!
@@ -872,18 +884,18 @@ void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag)
\param[out] none
\retval state of FMC, refer to fmc_state_enum
*/
-fmc_state_enum fmc_bank0_state_get(void)
+fmc_state_enum fmc_bank0_state_get(void) /** AvV **/
{
fmc_state_enum fmc_state = FMC_READY;
-
- if((uint32_t)0x00U != (FMC_STAT0 & FMC_STAT0_BUSY)){
+
+ if((uint32_t)0x00U != (FMC_STAT0 & FMC_STAT0_BUSY)) {
fmc_state = FMC_BUSY;
- }else{
- if((uint32_t)0x00U != (FMC_STAT0 & FMC_STAT0_WPERR)){
+ } else {
+ if((uint32_t)0x00U != (FMC_STAT0 & FMC_STAT0_WPERR)) {
fmc_state = FMC_WPERR;
- }else{
- if((uint32_t)0x00U != (FMC_STAT0 & (FMC_STAT0_PGERR))){
- fmc_state = FMC_PGERR;
+ } else {
+ if((uint32_t)0x00U != (FMC_STAT0 & (FMC_STAT0_PGERR))) {
+ fmc_state = FMC_PGERR;
}
}
}
@@ -897,18 +909,18 @@ fmc_state_enum fmc_bank0_state_get(void)
\param[out] none
\retval state of FMC, refer to fmc_state_enum
*/
-fmc_state_enum fmc_bank1_state_get(void)
+fmc_state_enum fmc_bank1_state_get(void) /** AvV **/
{
fmc_state_enum fmc_state = FMC_READY;
- if((uint32_t)0x00U != (FMC_STAT1 & FMC_STAT1_BUSY)){
+ if((uint32_t)0x00U != (FMC_STAT1 & FMC_STAT1_BUSY)) {
fmc_state = FMC_BUSY;
- }else{
- if((uint32_t)0x00U != (FMC_STAT1 & FMC_STAT1_WPERR)){
+ } else {
+ if((uint32_t)0x00U != (FMC_STAT1 & FMC_STAT1_WPERR)) {
fmc_state = FMC_WPERR;
- }else{
- if((uint32_t)0x00U != (FMC_STAT1 & FMC_STAT1_PGERR)){
- fmc_state = FMC_PGERR;
+ } else {
+ if((uint32_t)0x00U != (FMC_STAT1 & FMC_STAT1_PGERR)) {
+ fmc_state = FMC_PGERR;
}
}
}
@@ -923,18 +935,18 @@ fmc_state_enum fmc_bank1_state_get(void)
\param[out] none
\retval state of FMC, refer to fmc_state_enum
*/
-fmc_state_enum fmc_bank0_ready_wait(uint32_t timeout)
+static fmc_state_enum fmc_bank0_ready_wait(uint32_t timeout)
{
fmc_state_enum fmc_state = FMC_BUSY;
-
+
/* wait for FMC ready */
- do{
+ do {
/* get FMC state */
fmc_state = fmc_bank0_state_get();
timeout--;
- }while((FMC_BUSY == fmc_state) && (0x00U != timeout));
-
- if(FMC_BUSY == fmc_state){
+ } while((FMC_BUSY == fmc_state) && (0x00U != timeout));
+
+ if(FMC_BUSY == fmc_state) {
fmc_state = FMC_TOERR;
}
/* return the FMC state */
@@ -947,18 +959,18 @@ fmc_state_enum fmc_bank0_ready_wait(uint32_t timeout)
\param[out] none
\retval state of FMC, refer to fmc_state_enum
*/
-fmc_state_enum fmc_bank1_ready_wait(uint32_t timeout)
+static fmc_state_enum fmc_bank1_ready_wait(uint32_t timeout)
{
fmc_state_enum fmc_state = FMC_BUSY;
-
+
/* wait for FMC ready */
- do{
+ do {
/* get FMC state */
fmc_state = fmc_bank1_state_get();
timeout--;
- }while((FMC_BUSY == fmc_state) && (0x00U != timeout));
-
- if(FMC_BUSY == fmc_state){
+ } while((FMC_BUSY == fmc_state) && (0x00U != timeout));
+
+ if(FMC_BUSY == fmc_state) {
fmc_state = FMC_TOERR;
}
/* return the FMC state */
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fwdgt.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fwdgt.c
index 0afbec2..1c7fdd3 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fwdgt.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_fwdgt.c
@@ -2,46 +2,38 @@
\file gd32f20x_fwdgt.c
\brief FWDGT driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_fwdgt.h"
-/* write value to FWDGT_CTL_CMD bit field */
-#define CTL_CMD(regval) (BITS(0,15) & ((uint32_t)(regval) << 0))
-/* write value to FWDGT_RLD_RLD bit field */
-#define RLD_RLD(regval) (BITS(0,11) & ((uint32_t)(regval) << 0))
-
/*!
\brief enable write access to FWDGT_PSC and FWDGT_RLD
\param[in] none
@@ -75,6 +67,71 @@ void fwdgt_enable(void)
FWDGT_CTL = FWDGT_KEY_ENABLE;
}
+/*!
+ \brief configure the free watchdog timer counter prescaler value
+ \param[in] prescaler_value: specify prescaler value
+ only one parameter can be selected which is shown as below:
+ \arg FWDGT_PSC_DIV4: FWDGT prescaler set to 4
+ \arg FWDGT_PSC_DIV8: FWDGT prescaler set to 8
+ \arg FWDGT_PSC_DIV16: FWDGT prescaler set to 16
+ \arg FWDGT_PSC_DIV32: FWDGT prescaler set to 32
+ \arg FWDGT_PSC_DIV64: FWDGT prescaler set to 64
+ \arg FWDGT_PSC_DIV128: FWDGT prescaler set to 128
+ \arg FWDGT_PSC_DIV256: FWDGT prescaler set to 256
+ \param[out] none
+ \retval ErrStatus: ERROR or SUCCESS
+*/
+ErrStatus fwdgt_prescaler_value_config(uint16_t prescaler_value)
+{
+ uint32_t timeout = FWDGT_PSC_TIMEOUT;
+ uint32_t flag_status = RESET;
+
+ /* enable write access to FWDGT_PSC */
+ FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
+
+ /* wait until the PUD flag to be reset */
+ do{
+ flag_status = FWDGT_STAT & FWDGT_STAT_PUD;
+ }while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
+
+ if ((uint32_t)RESET != flag_status){
+ return ERROR;
+ }
+
+ /* configure FWDGT */
+ FWDGT_PSC = (uint32_t)prescaler_value;
+
+ return SUCCESS;
+}
+
+/*!
+ \brief configure the free watchdog timer counter reload value
+ \param[in] reload_value: specify reload value(0x0000 - 0x0FFF)
+ \param[out] none
+ \retval ErrStatus: ERROR or SUCCESS
+*/
+ErrStatus fwdgt_reload_value_config(uint16_t reload_value)
+{
+ uint32_t timeout = FWDGT_RLD_TIMEOUT;
+ uint32_t flag_status = RESET;
+
+ /* enable write access to FWDGT_RLD */
+ FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
+
+ /* wait until the RUD flag to be reset */
+ do{
+ flag_status = FWDGT_STAT & FWDGT_STAT_RUD;
+ }while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
+
+ if ((uint32_t)RESET != flag_status){
+ return ERROR;
+ }
+
+ FWDGT_RLD = RLD_RLD(reload_value);
+
+ return SUCCESS;
+}
+
/*!
\brief reload the counter of FWDGT
\param[in] none
@@ -105,16 +162,16 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
{
uint32_t timeout = FWDGT_PSC_TIMEOUT;
uint32_t flag_status = RESET;
-
+
/* enable write access to FWDGT_PSC,and FWDGT_RLD */
FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
-
+
/* wait until the PUD flag to be reset */
- do{
- flag_status = FWDGT_STAT & FWDGT_STAT_PUD;
- }while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
-
- if ((uint32_t)RESET != flag_status){
+ do {
+ flag_status = FWDGT_STAT & FWDGT_STAT_PUD;
+ } while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
+
+ if((uint32_t)RESET != flag_status) {
return ERROR;
}
@@ -123,16 +180,16 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
timeout = FWDGT_RLD_TIMEOUT;
/* wait until the RUD flag to be reset */
- do{
- flag_status = FWDGT_STAT & FWDGT_STAT_RUD;
- }while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
-
- if ((uint32_t)RESET != flag_status){
+ do {
+ flag_status = FWDGT_STAT & FWDGT_STAT_RUD;
+ } while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
+
+ if((uint32_t)RESET != flag_status) {
return ERROR;
}
-
+
FWDGT_RLD = RLD_RLD(reload_value);
-
+
/* reload the counter */
FWDGT_CTL = FWDGT_KEY_RELOAD;
@@ -141,7 +198,7 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
/*!
\brief get flag state of FWDGT
- \param[in] flag: flag to get
+ \param[in] flag: flag to get
only one parameter can be selected which is shown as below:
\arg FWDGT_FLAG_PUD: a write operation to FWDGT_PSC register is on going
\arg FWDGT_FLAG_RUD: a write operation to FWDGT_RLD register is on going
@@ -150,9 +207,9 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
*/
FlagStatus fwdgt_flag_get(uint16_t flag)
{
- if(FWDGT_STAT & flag){
+ if(FWDGT_STAT & flag) {
return SET;
}
-
+
return RESET;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_gpio.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_gpio.c
index 0acf109..4fd2c55 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_gpio.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_gpio.c
@@ -2,46 +2,43 @@
\file gd32f20x_gpio.c
\brief GPIO driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_gpio.h"
-#define AFIO_EXTI_SOURCE_MASK ((uint8_t)0x03U) /*!< AFIO exti source selection mask*/
+#define AFIO_EXTI_SOURCE_MASK ((uint8_t)0x03U) /*!< AFIO exti source selection mask*/
#define AFIO_EXTI_SOURCE_FIELDS ((uint8_t)0x04U) /*!< select AFIO exti source registers */
#define LSB_16BIT_MASK ((uint16_t)0xFFFFU) /*!< LSB 16-bit mask */
#define PCF_POSITION_MASK ((uint32_t)0x000F0000U) /*!< AFIO_PCF register position mask */
-#define PCF_SWJCFG_MASK ((uint32_t)0xF0FFFFFFU) /*!< AFIO_PCF register SWJCFG mask */
+#define PCF_SWJCFG_MASK ((uint32_t)0xF8FFFFFFU) /*!< AFIO_PCF register SWJCFG mask */
#define PCF_LOCATION1_MASK ((uint32_t)0x00200000U) /*!< AFIO_PCF register location1 mask */
#define PCF_LOCATION2_MASK ((uint32_t)0x00100000U) /*!< AFIO_PCF register location2 mask */
#define AFIO_PCF1_FIELDS ((uint32_t)0x80000000U) /*!< select AFIO_PCF1 register */
@@ -55,7 +52,7 @@ OF SUCH DAMAGE.
*/
void gpio_deinit(uint32_t gpio_periph)
{
- switch(gpio_periph){
+ switch(gpio_periph) {
case GPIOA:
/* reset GPIOA */
rcu_periph_reset_enable(RCU_GPIOARST);
@@ -120,7 +117,7 @@ void gpio_afio_deinit(void)
/*!
\brief GPIO parameter initialization
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[in] mode: gpio pin mode
only one parameter can be selected which is shown as below:
\arg GPIO_MODE_AIN: analog input mode
@@ -139,7 +136,6 @@ void gpio_afio_deinit(void)
\param[in] pin: GPIO pin
one or more parameters can be selected which are shown as below:
\arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
-
\param[out] none
\retval none
*/
@@ -151,30 +147,29 @@ void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed, uint32_t pin
/* GPIO mode configuration */
temp_mode = (uint32_t)(mode & ((uint32_t)0x0FU));
-
+
/* GPIO speed configuration */
- if(((uint32_t)0x00U) != ((uint32_t)mode & ((uint32_t)0x10U))){
- /* output mode max speed:10MHz,2MHz,50MHz */
+ if(((uint32_t)0x00U) != ((uint32_t)mode & ((uint32_t)0x10U))) {
+ /* output mode max speed: 10MHz, 2MHz, 50MHz */
temp_mode |= (uint32_t)speed;
}
/* configure the eight low port pins with GPIO_CTL0 */
- for(i = 0U;i < 8U;i++){
- if((1U << i) & pin){
+ for(i = 0U; i < 8U; i++) {
+ if((1U << i) & pin) {
reg = GPIO_CTL0(gpio_periph);
-
/* clear the specified pin mode bits */
reg &= ~GPIO_MODE_MASK(i);
/* set the specified pin mode bits */
reg |= GPIO_MODE_SET(i, temp_mode);
-
+
/* set IPD or IPU */
- if(GPIO_MODE_IPD == mode){
+ if(GPIO_MODE_IPD == mode) {
/* reset the corresponding OCTL bit */
GPIO_BC(gpio_periph) = (uint32_t)((1U << i) & pin);
- }else{
+ } else {
/* set the corresponding OCTL bit */
- if(GPIO_MODE_IPU == mode){
+ if(GPIO_MODE_IPU == mode) {
GPIO_BOP(gpio_periph) = (uint32_t)((1U << i) & pin);
}
}
@@ -183,22 +178,21 @@ void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed, uint32_t pin
}
}
/* configure the eight high port pins with GPIO_CTL1 */
- for(i = 8U;i < 16U;i++){
- if((1U << i) & pin){
+ for(i = 8U; i < 16U; i++) {
+ if((1U << i) & pin) {
reg = GPIO_CTL1(gpio_periph);
-
/* clear the specified pin mode bits */
reg &= ~GPIO_MODE_MASK(i - 8U);
/* set the specified pin mode bits */
reg |= GPIO_MODE_SET(i - 8U, temp_mode);
-
+
/* set IPD or IPU */
- if(GPIO_MODE_IPD == mode){
+ if(GPIO_MODE_IPD == mode) {
/* reset the corresponding OCTL bit */
GPIO_BC(gpio_periph) = (uint32_t)((1U << i) & pin);
- }else{
+ } else {
/* set the corresponding OCTL bit */
- if(GPIO_MODE_IPU == mode){
+ if(GPIO_MODE_IPU == mode) {
GPIO_BOP(gpio_periph) = (uint32_t)((1U << i) & pin);
}
}
@@ -210,35 +204,35 @@ void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed, uint32_t pin
/*!
\brief set GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[in] pin: GPIO pin
one or more parameters can be selected which are shown as below:
\arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_bit_set(uint32_t gpio_periph,uint32_t pin)
+void gpio_bit_set(uint32_t gpio_periph, uint32_t pin)
{
GPIO_BOP(gpio_periph) = (uint32_t)pin;
}
/*!
\brief reset GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[in] pin: GPIO pin
one or more parameters can be selected which are shown as below:
\arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_bit_reset(uint32_t gpio_periph,uint32_t pin)
+void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin)
{
GPIO_BC(gpio_periph) = (uint32_t)pin;
}
/*!
\brief write data to the specified GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[in] pin: GPIO pin
one or more parameters can be selected which are shown as below:
\arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
@@ -248,23 +242,23 @@ void gpio_bit_reset(uint32_t gpio_periph,uint32_t pin)
\param[out] none
\retval none
*/
-void gpio_bit_write(uint32_t gpio_periph,uint32_t pin,bit_status bit_value)
+void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value)
{
- if(RESET != bit_value){
+ if(RESET != bit_value) {
GPIO_BOP(gpio_periph) = (uint32_t)pin;
- }else{
+ } else {
GPIO_BC(gpio_periph) = (uint32_t)pin;
}
}
/*!
\brief write data to the specified GPIO port
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[in] data: specify the value to be written to the port output data register
\param[out] none
\retval none
*/
-void gpio_port_write(uint32_t gpio_periph,uint16_t data)
+void gpio_port_write(uint32_t gpio_periph, uint16_t data)
{
GPIO_OCTL(gpio_periph) = (uint32_t)data;
}
@@ -278,11 +272,11 @@ void gpio_port_write(uint32_t gpio_periph,uint16_t data)
\param[out] none
\retval input status of gpio pin: SET or RESET
*/
-FlagStatus gpio_input_bit_get(uint32_t gpio_periph,uint32_t pin)
+FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin)
{
- if((uint32_t)RESET != (GPIO_ISTAT(gpio_periph)&(pin))){
- return SET;
- }else{
+ if((uint32_t)RESET != (GPIO_ISTAT(gpio_periph) & (pin))) {
+ return SET;
+ } else {
return RESET;
}
}
@@ -307,11 +301,11 @@ uint16_t gpio_input_port_get(uint32_t gpio_periph)
\param[out] none
\retval output status of gpio pin: SET or RESET
*/
-FlagStatus gpio_output_bit_get(uint32_t gpio_periph,uint32_t pin)
+FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin)
{
- if((uint32_t)RESET !=(GPIO_OCTL(gpio_periph)&(pin))){
+ if((uint32_t)RESET != (GPIO_OCTL(gpio_periph) & (pin))) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -329,14 +323,15 @@ uint16_t gpio_output_port_get(uint32_t gpio_periph)
/*!
\brief configure GPIO pin remap
- \param[in] gpio_remap: select the pin to remap
+ \param[in] remap: select the pin to remap
+ only one parameter can be selected which are shown as below:
\arg GPIO_SPI0_REMAP: SPI0 remapping
\arg GPIO_I2C0_REMAP: I2C0 remapping
\arg GPIO_USART0_REMAP: USART0 remapping
\arg GPIO_USART1_REMAP: USART1 remapping
\arg GPIO_USART2_PARTIAL_REMAP: USART2 partial remapping
\arg GPIO_USART2_FULL_REMAP: USART2 full remapping
- \arg GPIO_TIMER0_PARTIAL_REMAP: TIMER0 partial remapping
+ \arg GPIO_TIMER0_PARTIAL_REMAP: TIMER0 partial remapping
\arg GPIO_TIMER0_FULL_REMAP: TIMER0 full remapping
\arg GPIO_TIMER1_PARTIAL_REMAP0: TIMER1 partial remapping
\arg GPIO_TIMER1_PARTIAL_REMAP1: TIMER1 partial remapping
@@ -354,12 +349,12 @@ uint16_t gpio_output_port_get(uint32_t gpio_periph)
\arg GPIO_ADC1_ETRGREG_REMAP: ADC1 external trigger regular conversion remapping
\arg GPIO_ENET_REMAP: ENET remapping
\arg GPIO_CAN1_REMAP: CAN1 remapping
- \arg GPIO_SWJ_NONJTRST_REMAP: full SWJ(JTAG-DP + SW-DP),but without NJTRST
+ \arg GPIO_SWJ_NONJTRST_REMAP: full SWJ(JTAG-DP + SW-DP), but without NJTRST
\arg GPIO_SWJ_SWDPENABLE_REMAP: JTAG-DP disabled and SW-DP enabled
\arg GPIO_SWJ_DISABLE_REMAP: JTAG-DP disabled and SW-DP disabled
\arg GPIO_SPI2_REMAP: SPI2 remapping
\arg GPIO_TIMER1ITI1_REMAP: TIMER1 internal trigger 1 remapping
- \arg GPIO_PTP_PPS_REMAP: ethernet PTP PPS remapping
+ \arg GPIO_PTP_PPS_REMAP: ethernet PTP PPS remapping
\arg GPIO_TIMER8_REMAP: TIMER8 remapping
\arg GPIO_TIMER9_REMAP: TIMER9 remapping
\arg GPIO_TIMER10_REMAP: TIMER10 remapping
@@ -370,51 +365,51 @@ uint16_t gpio_output_port_get(uint32_t gpio_periph)
\param[out] none
\retval none
*/
-void gpio_pin_remap_config(uint32_t gpio_remap, ControlStatus newvalue)
+void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue)
{
uint32_t remap1 = 0U, remap2 = 0U, temp_reg = 0U, temp_mask = 0U;
- if(AFIO_PCF1_FIELDS == (gpio_remap & AFIO_PCF1_FIELDS)){
+ if(AFIO_PCF1_FIELDS == (remap & AFIO_PCF1_FIELDS)) {
/* get AFIO_PCF1 regiter value */
temp_reg = AFIO_PCF1;
- }else{
+ } else {
/* get AFIO_PCF0 regiter value */
temp_reg = AFIO_PCF0;
}
- temp_mask = (gpio_remap & PCF_POSITION_MASK) >> 0x10U;
- remap1 = gpio_remap & LSB_16BIT_MASK;
+ temp_mask = (remap & PCF_POSITION_MASK) >> 0x10U;
+ remap1 = remap & LSB_16BIT_MASK;
/* judge pin remap type */
- if((PCF_LOCATION1_MASK | PCF_LOCATION2_MASK) == (gpio_remap & (PCF_LOCATION1_MASK | PCF_LOCATION2_MASK))){
+ if((PCF_LOCATION1_MASK | PCF_LOCATION2_MASK) == (remap & (PCF_LOCATION1_MASK | PCF_LOCATION2_MASK))) {
temp_reg &= PCF_SWJCFG_MASK;
AFIO_PCF0 &= PCF_SWJCFG_MASK;
- }else if(PCF_LOCATION2_MASK == (gpio_remap & PCF_LOCATION2_MASK)){
+ } else if(PCF_LOCATION2_MASK == (remap & PCF_LOCATION2_MASK)) {
remap2 = ((uint32_t)0x03U) << temp_mask;
temp_reg &= ~remap2;
temp_reg |= ~PCF_SWJCFG_MASK;
- }else{
- temp_reg &= ~(remap1 << ((gpio_remap >> 0x15U)*0x10U));
+ } else {
+ temp_reg &= ~(remap1 << ((remap >> 0x15U) * 0x10U));
temp_reg |= ~PCF_SWJCFG_MASK;
}
-
+
/* set pin remap value */
- if(DISABLE != newvalue){
- temp_reg |= (remap1 << ((gpio_remap >> 0x15U)*0x10U));
+ if(DISABLE != newvalue) {
+ temp_reg |= (remap1 << ((remap >> 0x15U) * 0x10U));
}
-
- if(AFIO_PCF1_FIELDS == (gpio_remap & AFIO_PCF1_FIELDS)){
- /* set AFIO_PCF1 regiter value */
+
+ if(AFIO_PCF1_FIELDS == (remap & AFIO_PCF1_FIELDS)) {
+ /* set AFIO_PCF1 register value */
AFIO_PCF1 = temp_reg;
- }else{
- /* set AFIO_PCF0 regiter value */
+ } else {
+ /* set AFIO_PCF0 register value */
AFIO_PCF0 = temp_reg;
}
}
/*!
\brief configure GPIO pin remap1
- \param[in] remap_reg:
+ \param[in] remap_reg:
\arg GPIO_PCF2: AFIO port configuration register 2
\arg GPIO_PCF3: AFIO port configuration register 3
\arg GPIO_PCF4: AFIO port configuration register 4
@@ -437,109 +432,109 @@ void gpio_pin_remap_config(uint32_t gpio_remap, ControlStatus newvalue)
\arg GPIO_PCF2_DCI_D5_PD3_REMAP: DCI D5 remapped to PD3
\arg GPIO_PCF2_DCI_D5_PI4_REMAP: DCI D5 remapped to PI4
\arg GPIO_PCF2_DCI_D6_PE5_REMAP: DCI D6 remapped to PE5
- \arg GPIO_PCF2_DCI_D6_PI6_REMAP: DCI D6 remapped to PI6
- \arg GPIO_PCF2_DCI_D7_PE6_REMAP: DCI D7 remapped to PE6
- \arg GPIO_PCF2_DCI_D7_PI7_REMAP: DCI D7 remapped to PI7
- \arg GPIO_PCF2_DCI_D8_PH6_REMAP: DCI D8 remapped to PH6
- \arg GPIO_PCF2_DCI_D8_PI1_REMAP: DCI D8 remapped to PI1
- \arg GPIO_PCF2_DCI_D9_PH7_REMAP: DCI D9 remapped to PH7
- \arg GPIO_PCF2_DCI_D9_PI2_REMAP: DCI D9 remapped to PI2
- \arg GPIO_PCF2_DCI_D10_PD6_REMAP: DCI D10 remapped to PD6
- \arg GPIO_PCF2_DCI_D10_PI3_REMAP: DCI D10 remapped to PI3
- \arg GPIO_PCF2_DCI_D11_PF10_REMAP: DCI D11 remapped to PF10
- \arg GPIO_PCF2_DCI_D11_PH15_REMAP: DCI D11 remapped to PH15
- \arg GPIO_PCF2_DCI_D12_PG6_REMAP: DCI D12 remapped to PG6
- \arg GPIO_PCF2_DCI_D13_PG15_REMAP: DCI D12 remapped to PG15
- \arg GPIO_PCF2_DCI_D13_PI0_REMAP: DCI D13 remapped to PI0
- \arg GPIO_PCF2_DCI_HSYNC_PH8_REMAP: DCI HSYNC to PH8
- \arg GPIO_PCF2_PH01_REMAP: PH0/PH1 remapping
- \arg GPIO_PCF3_TLI_B5_PA3_REMAP: TLI B5 remapped to PA3
- \arg GPIO_PCF3_TLI_VSYNC_PA4_REMAP: TLI VSYNC remapped to PA4
- \arg GPIO_PCF3_TLI_G2_PA6_REMAP: TLI G2 remapped to PA6
- \arg GPIO_PCF3_TLI_R6_PA8_REMAP: TLI R6 remapped to PA8
- \arg GPIO_PCF3_TLI_R4_PA11_REMAP: TLI R4 remapped to PA11
- \arg GPIO_PCF3_TLI_R5_PA12_REMAP: TLI R5 remapped to PA12
- \arg GPIO_PCF3_TLI_R3_PB0_REMAP: TLI R3 remapped to PB0
- \arg GPIO_PCF3_TLI_R6_PB1_REMAP: TLI R6 remapped to PB1
- \arg GPIO_PCF3_TLI_B6_PB8_REMAP: TLI B6 remapped to PB8
- \arg GPIO_PCF3_TLI_B7_PB9_REMAP: TLI B7 remapped to PB9
- \arg GPIO_PCF3_TLI_G4_PB10_REMAP: TLI G4 remapped to PB10
- \arg GPIO_PCF3_TLI_G5_PB11_REMAP: TLI G5 remapped to PB11
- \arg GPIO_PCF3_TLI_HSYNC_PC6_REMAP: TLI HSYNC remapped to PC6
- \arg GPIO_PCF3_TLI_G6_PC7_REMAP: TLI G6 remapped to PC7
- \arg GPIO_PCF3_TLI_R2_PC10_REMAP: TLI R2 remapped to PC10
- \arg GPIO_PCF3_TLI_G7_PD3_REMAP: TLI G7 remapped to PD3
- \arg GPIO_PCF3_TLI_B2_PD6_REMAP: TLI B2 remapped to PD6
- \arg GPIO_PCF3_TLI_B3_PD10_REMAP: TLI B3 remapped to PD10
- \arg GPIO_PCF3_TLI_B0_PE4_REMAP: TLI B0 remapped to PE4
- \arg GPIO_PCF3_TLI_G0_PE5_REMAP: TLI G0 remapped to PE5
- \arg GPIO_PCF3_TLI_G1_PE6_REMAP: TLI G1 remapped to PE6
- \arg GPIO_PCF3_TLI_G3_PE11_REMAP: TLI G3 remapped to PE11
- \arg GPIO_PCF3_TLI_B4_PE12_REMAP: TLI B4 remapped to PE12
- \arg GPIO_PCF3_TLI_DE_PE13_REMAP: TLI DE remapped to PE13
- \arg GPIO_PCF3_TLI_CLK_PE14_REMAP: TLI CLK remapped to PE14
- \arg GPIO_PCF3_TLI_R7_PE15_REMAP: TLI R7 remapped to PE15
- \arg GPIO_PCF3_TLI_DE_PF10_REMAP: TLI DE remapped to PF10
- \arg GPIO_PCF3_TLI_R7_PG6_REMAP: TLI R7 remapped to PG6
- \arg GPIO_PCF3_TLI_CLK_PG7_REMAP: TLI CLK remapped to PG7
- \arg GPIO_PCF3_TLI_G3_PG10_REMAP: TLI G3 remapped to PG10
- \arg GPIO_PCF3_TLI_B2_PG10_REMAP: TLI B2 remapped to PG10
- \arg GPIO_PCF3_TLI_B3_PG11_REMAP: TLI B3 remapped to PG11
- \arg GPIO_PCF4_TLI_B4_PG12_REMAP: B4 remapped to PG12
- \arg GPIO_PCF4_TLI_B1_PG12_REMAP: B1 remapped to PG12
- \arg GPIO_PCF4_TLI_R0_PH2_REMAP2: R0 remapped to PH2
- \arg GPIO_PCF4_TLI_R1_PH3_REMAP: TLI R1 remapped to PH3
- \arg GPIO_PCF4_TLI_R2_PH8_REMAP: TLI R2 remapped to PH8
- \arg GPIO_PCF4_TLI_R3_PH9_REMAP: TLI R3 remapped to PH9
- \arg GPIO_PCF4_TLI_R4_PH10_REMAP: TLI R4 remapped to PH10
- \arg GPIO_PCF4_TLI_R5_PH11_REMAP: TLI R5 remapped to PH11
- \arg GPIO_PCF4_TLI_R6_PH12_REMAP: TLI R6 remapped to PH12
- \arg GPIO_PCF4_TLI_G2_PH13_REMAP: TLI G2 remapped to PH13
- \arg GPIO_PCF4_TLI_G3_PH14_REMAP: TLI G3 remapped to PH14
- \arg GPIO_PCF4_TLI_G4_PH15_REMAP: TLI G4 remapped to PH15
- \arg GPIO_PCF4_TLI_G5_PI0_REMAP: TLI G5 remapped to PI0
- \arg GPIO_PCF4_TLI_G6_PI1_REMAP: TLI G6 remapped to PI1
- \arg GPIO_PCF4_TLI_G7_PI2_REMAP: TLI G7 remapped to PI2
- \arg GPIO_PCF4_TLI_B4_PI4_REMAP: TLI B4 remapped to PI4
- \arg GPIO_PCF4_TLI_B5_PI5_REMAP: TLI B5 remapped to PI5
- \arg GPIO_PCF4_TLI_B6_PI6_REMAP: TLI B6 remapped to PI6
- \arg GPIO_PCF4_TLI_B7_PI7_REMAP: TLI B7 remapped to PI7
- \arg GPIO_PCF4_TLI_VSYNC_PI9_REMAP: TLI VSYNC remapped to PI9
- \arg GPIO_PCF4_TLI_HSYNC_PI10_REMAP: TLI HSYNC remapped to PI10
- \arg GPIO_PCF4_TLI_R0_PH4_REMAP: TLI R0 remapped to PH4
- \arg GPIO_PCF4_TLI_R1_PI3_REMAP: TLI R1 remapped to PI3
- \arg GPIO_PCF4_SPI1_SCK_PD3_REMAP: SPI1 SCK remapped to PD3
- \arg GPIO_PCF4_SPI2_MOSI_PD6_REMAP: SPI2 MOSI remapped to PD6
- \arg GPIO_PCF5_I2C2_REMAP0: I2C2 remapping 0
- \arg GPIO_PCF5_I2C2_REMAP1: I2C2 remapping 1
- \arg GPIO_PCF5_TIMER1_CH0_REMAP: TIMER1 CH0 remapped to PA5
- \arg GPIO_PCF5_TIMER4_REMAP: TIMER4 CH0 remapping
- \arg GPIO_PCF5_TIMER7_CHON_REMAP0: TIMER7 CHON remapping 0
- \arg GPIO_PCF5_TIMER7_CHON_REMAP1: TIMER7 CHON remapping 1
- \arg GPIO_PCF5_TIMER7_CH_REMAP: TIMER7 CH remapping
- \arg GPIO_PCF5_I2C1_REMAP0: I2C1 remapping 0
- \arg GPIO_PCF5_I2C1_REMAP1: I2C1 remapping 1
- \arg GPIO_PCF5_SPI1_NSCK_REMAP0: SPI1 NSS/SCK remapping 0
- \arg GPIO_PCF5_SPI1_NSCK_REMAP1: SPI1 NSS/SCK remapping 1
- \arg GPIO_PCF5_SPI1_IO_REMAP0: SPI1 MISO/MOSI remapping 0
- \arg GPIO_PCF5_SPI1_IO_REMAP1: SPI1 MISO/MOSI remapping 1
- \arg GPIO_PCF5_UART3_REMAP: UART3 remapping
- \arg GPIO_PCF5_TIMER11_REMAP: TIMER11 remapping
- \arg GPIO_PCF5_CAN0_ADD_REMAP: CAN0 addition remapping
- \arg GPIO_PCF5_ENET_TXD3_REMAP: ETH_TXD3 remapped to PE2
- \arg GPIO_PCF5_PPS_HI_REMAP: ETH_PPS_OUT remapped to PG8
- \arg GPIO_PCF5_ENET_TXD01_REMAP: ETH_TX_EN/ETH_TXD0/ETH_TXD1 remapping
- \arg GPIO_PCF5_ENET_CRSCOL_REMAP: ETH_MII_CRS/ETH_MII_COL remapping
- \arg GPIO_PCF5_ENET_RX_HI_REMAP: ETH_RXD2/ETH_RXD3/ETH_RX_ER remapping
- \arg GPIO_PCF5_UART6_REMAP: UART6 remapping
- \arg GPIO_PCF5_USART5_CK_PG7_REMAP: USART5 CK remapped to PG7
- \arg GPIO_PCF5_USART5_RTS_PG12_REMAP: USART5 RTS remapped to PG12
- \arg GPIO_PCF5_USART5_CTS_PG13_REMAP: USART5 CTS remapped to PG13
- \arg GPIO_PCF5_USART5_TX_PG14_REMAP: USART5 TX remapped to PG14
- \arg GPIO_PCF5_USART5_RX_PG9_REMAP: USART5 RX remapped to PG9
- \arg GPIO_PCF5_EXMC_SDNWE_PC0_REMAP: EXMC SDNWE remapped to PC0
- \arg GPIO_PCF5_EXMC_SDCKE0_PC3_REMAP: EXMC SDCKE0 remapped to PC3
- \arg GPIO_PCF5_EXMC_SDCKE1_PB5_REMAP: EXMC SDCKE1 remapped to PB5
+ \arg GPIO_PCF2_DCI_D6_PI6_REMAP: DCI D6 remapped to PI6
+ \arg GPIO_PCF2_DCI_D7_PE6_REMAP: DCI D7 remapped to PE6
+ \arg GPIO_PCF2_DCI_D7_PI7_REMAP: DCI D7 remapped to PI7
+ \arg GPIO_PCF2_DCI_D8_PH6_REMAP: DCI D8 remapped to PH6
+ \arg GPIO_PCF2_DCI_D8_PI1_REMAP: DCI D8 remapped to PI1
+ \arg GPIO_PCF2_DCI_D9_PH7_REMAP: DCI D9 remapped to PH7
+ \arg GPIO_PCF2_DCI_D9_PI2_REMAP: DCI D9 remapped to PI2
+ \arg GPIO_PCF2_DCI_D10_PD6_REMAP: DCI D10 remapped to PD6
+ \arg GPIO_PCF2_DCI_D10_PI3_REMAP: DCI D10 remapped to PI3
+ \arg GPIO_PCF2_DCI_D11_PF10_REMAP: DCI D11 remapped to PF10
+ \arg GPIO_PCF2_DCI_D11_PH15_REMAP: DCI D11 remapped to PH15
+ \arg GPIO_PCF2_DCI_D12_PG6_REMAP: DCI D12 remapped to PG6
+ \arg GPIO_PCF2_DCI_D13_PG15_REMAP: DCI D12 remapped to PG15
+ \arg GPIO_PCF2_DCI_D13_PI0_REMAP: DCI D13 remapped to PI0
+ \arg GPIO_PCF2_DCI_HSYNC_PH8_REMAP: DCI HSYNC to PH8
+ \arg GPIO_PCF2_PH01_REMAP: PH0/PH1 remapping
+ \arg GPIO_PCF3_TLI_B5_PA3_REMAP: TLI B5 remapped to PA3
+ \arg GPIO_PCF3_TLI_VSYNC_PA4_REMAP: TLI VSYNC remapped to PA4
+ \arg GPIO_PCF3_TLI_G2_PA6_REMAP: TLI G2 remapped to PA6
+ \arg GPIO_PCF3_TLI_R6_PA8_REMAP: TLI R6 remapped to PA8
+ \arg GPIO_PCF3_TLI_R4_PA11_REMAP: TLI R4 remapped to PA11
+ \arg GPIO_PCF3_TLI_R5_PA12_REMAP: TLI R5 remapped to PA12
+ \arg GPIO_PCF3_TLI_R3_PB0_REMAP: TLI R3 remapped to PB0
+ \arg GPIO_PCF3_TLI_R6_PB1_REMAP: TLI R6 remapped to PB1
+ \arg GPIO_PCF3_TLI_B6_PB8_REMAP: TLI B6 remapped to PB8
+ \arg GPIO_PCF3_TLI_B7_PB9_REMAP: TLI B7 remapped to PB9
+ \arg GPIO_PCF3_TLI_G4_PB10_REMAP: TLI G4 remapped to PB10
+ \arg GPIO_PCF3_TLI_G5_PB11_REMAP: TLI G5 remapped to PB11
+ \arg GPIO_PCF3_TLI_HSYNC_PC6_REMAP: TLI HSYNC remapped to PC6
+ \arg GPIO_PCF3_TLI_G6_PC7_REMAP: TLI G6 remapped to PC7
+ \arg GPIO_PCF3_TLI_R2_PC10_REMAP: TLI R2 remapped to PC10
+ \arg GPIO_PCF3_TLI_G7_PD3_REMAP: TLI G7 remapped to PD3
+ \arg GPIO_PCF3_TLI_B2_PD6_REMAP: TLI B2 remapped to PD6
+ \arg GPIO_PCF3_TLI_B3_PD10_REMAP: TLI B3 remapped to PD10
+ \arg GPIO_PCF3_TLI_B0_PE4_REMAP: TLI B0 remapped to PE4
+ \arg GPIO_PCF3_TLI_G0_PE5_REMAP: TLI G0 remapped to PE5
+ \arg GPIO_PCF3_TLI_G1_PE6_REMAP: TLI G1 remapped to PE6
+ \arg GPIO_PCF3_TLI_G3_PE11_REMAP: TLI G3 remapped to PE11
+ \arg GPIO_PCF3_TLI_B4_PE12_REMAP: TLI B4 remapped to PE12
+ \arg GPIO_PCF3_TLI_DE_PE13_REMAP: TLI DE remapped to PE13
+ \arg GPIO_PCF3_TLI_CLK_PE14_REMAP: TLI CLK remapped to PE14
+ \arg GPIO_PCF3_TLI_R7_PE15_REMAP: TLI R7 remapped to PE15
+ \arg GPIO_PCF3_TLI_DE_PF10_REMAP: TLI DE remapped to PF10
+ \arg GPIO_PCF3_TLI_R7_PG6_REMAP: TLI R7 remapped to PG6
+ \arg GPIO_PCF3_TLI_CLK_PG7_REMAP: TLI CLK remapped to PG7
+ \arg GPIO_PCF3_TLI_G3_PG10_REMAP: TLI G3 remapped to PG10
+ \arg GPIO_PCF3_TLI_B2_PG10_REMAP: TLI B2 remapped to PG10
+ \arg GPIO_PCF3_TLI_B3_PG11_REMAP: TLI B3 remapped to PG11
+ \arg GPIO_PCF4_TLI_B4_PG12_REMAP: B4 remapped to PG12
+ \arg GPIO_PCF4_TLI_B1_PG12_REMAP: B1 remapped to PG12
+ \arg GPIO_PCF4_TLI_R0_PH2_REMAP2: R0 remapped to PH2
+ \arg GPIO_PCF4_TLI_R1_PH3_REMAP: TLI R1 remapped to PH3
+ \arg GPIO_PCF4_TLI_R2_PH8_REMAP: TLI R2 remapped to PH8
+ \arg GPIO_PCF4_TLI_R3_PH9_REMAP: TLI R3 remapped to PH9
+ \arg GPIO_PCF4_TLI_R4_PH10_REMAP: TLI R4 remapped to PH10
+ \arg GPIO_PCF4_TLI_R5_PH11_REMAP: TLI R5 remapped to PH11
+ \arg GPIO_PCF4_TLI_R6_PH12_REMAP: TLI R6 remapped to PH12
+ \arg GPIO_PCF4_TLI_G2_PH13_REMAP: TLI G2 remapped to PH13
+ \arg GPIO_PCF4_TLI_G3_PH14_REMAP: TLI G3 remapped to PH14
+ \arg GPIO_PCF4_TLI_G4_PH15_REMAP: TLI G4 remapped to PH15
+ \arg GPIO_PCF4_TLI_G5_PI0_REMAP: TLI G5 remapped to PI0
+ \arg GPIO_PCF4_TLI_G6_PI1_REMAP: TLI G6 remapped to PI1
+ \arg GPIO_PCF4_TLI_G7_PI2_REMAP: TLI G7 remapped to PI2
+ \arg GPIO_PCF4_TLI_B4_PI4_REMAP: TLI B4 remapped to PI4
+ \arg GPIO_PCF4_TLI_B5_PI5_REMAP: TLI B5 remapped to PI5
+ \arg GPIO_PCF4_TLI_B6_PI6_REMAP: TLI B6 remapped to PI6
+ \arg GPIO_PCF4_TLI_B7_PI7_REMAP: TLI B7 remapped to PI7
+ \arg GPIO_PCF4_TLI_VSYNC_PI9_REMAP: TLI VSYNC remapped to PI9
+ \arg GPIO_PCF4_TLI_HSYNC_PI10_REMAP: TLI HSYNC remapped to PI10
+ \arg GPIO_PCF4_TLI_R0_PH4_REMAP: TLI R0 remapped to PH4
+ \arg GPIO_PCF4_TLI_R1_PI3_REMAP: TLI R1 remapped to PI3
+ \arg GPIO_PCF4_SPI1_SCK_PD3_REMAP: SPI1 SCK remapped to PD3
+ \arg GPIO_PCF4_SPI2_MOSI_PD6_REMAP: SPI2 MOSI remapped to PD6
+ \arg GPIO_PCF5_I2C2_REMAP0: I2C2 remapping 0
+ \arg GPIO_PCF5_I2C2_REMAP1: I2C2 remapping 1
+ \arg GPIO_PCF5_TIMER1_CH0_REMAP: TIMER1 CH0 remapped to PA5
+ \arg GPIO_PCF5_TIMER4_REMAP: TIMER4 CH0 remapping
+ \arg GPIO_PCF5_TIMER7_CHON_REMAP0: TIMER7 CHON remapping 0
+ \arg GPIO_PCF5_TIMER7_CHON_REMAP1: TIMER7 CHON remapping 1
+ \arg GPIO_PCF5_TIMER7_CH_REMAP: TIMER7 CH remapping
+ \arg GPIO_PCF5_I2C1_REMAP0: I2C1 remapping 0
+ \arg GPIO_PCF5_I2C1_REMAP1: I2C1 remapping 1
+ \arg GPIO_PCF5_SPI1_NSCK_REMAP0: SPI1 NSS/SCK remapping 0
+ \arg GPIO_PCF5_SPI1_NSCK_REMAP1: SPI1 NSS/SCK remapping 1
+ \arg GPIO_PCF5_SPI1_IO_REMAP0: SPI1 MISO/MOSI remapping 0
+ \arg GPIO_PCF5_SPI1_IO_REMAP1: SPI1 MISO/MOSI remapping 1
+ \arg GPIO_PCF5_UART3_REMAP: UART3 remapping
+ \arg GPIO_PCF5_TIMER11_REMAP: TIMER11 remapping
+ \arg GPIO_PCF5_CAN0_ADD_REMAP: CAN0 addition remapping
+ \arg GPIO_PCF5_ENET_TXD3_REMAP: ETH_TXD3 remapped to PE2
+ \arg GPIO_PCF5_PPS_HI_REMAP: ETH_PPS_OUT remapped to PG8
+ \arg GPIO_PCF5_ENET_TXD01_REMAP: ETH_TX_EN/ETH_TXD0/ETH_TXD1 remapping
+ \arg GPIO_PCF5_ENET_CRSCOL_REMAP: ETH_MII_CRS/ETH_MII_COL remapping
+ \arg GPIO_PCF5_ENET_RX_HI_REMAP: ETH_RXD2/ETH_RXD3/ETH_RX_ER remapping
+ \arg GPIO_PCF5_UART6_REMAP: UART6 remapping
+ \arg GPIO_PCF5_USART5_CK_PG7_REMAP: USART5 CK remapped to PG7
+ \arg GPIO_PCF5_USART5_RTS_PG12_REMAP: USART5 RTS remapped to PG12
+ \arg GPIO_PCF5_USART5_CTS_PG13_REMAP: USART5 CTS remapped to PG13
+ \arg GPIO_PCF5_USART5_TX_PG14_REMAP: USART5 TX remapped to PG14
+ \arg GPIO_PCF5_USART5_RX_PG9_REMAP: USART5 RX remapped to PG9
+ \arg GPIO_PCF5_EXMC_SDNWE_PC0_REMAP: EXMC SDNWE remapped to PC0
+ \arg GPIO_PCF5_EXMC_SDCKE0_PC3_REMAP: EXMC SDCKE0 remapped to PC3
+ \arg GPIO_PCF5_EXMC_SDCKE1_PB5_REMAP: EXMC SDCKE1 remapped to PB5
\arg GPIO_PCF5_EXMC_SDNE0_PC2_REMAP: EXMC SDNE0 remapped to PC2
\arg GPIO_PCF5_EXMC_SDNE1_PB6_REMAP: EXMC SDNE1 remapped to PB6
\param[in] newvalue: ENABLE or DISABLE
@@ -550,63 +545,83 @@ void gpio_pin_remap1_config(uint8_t remap_reg, uint32_t remap, ControlStatus new
{
uint32_t reg = 0U;
- if(DISABLE != newvalue){
+ if(DISABLE != newvalue) {
/* AFIO port configuration register selection */
- if(GPIO_PCF2 == remap_reg){
+ if(GPIO_PCF2 == remap_reg) {
reg = AFIO_PCF2;
reg |= remap;
AFIO_PCF2 = reg;
- }else if(GPIO_PCF3 == remap_reg){
+ } else if(GPIO_PCF3 == remap_reg) {
reg = AFIO_PCF3;
reg |= remap;
AFIO_PCF3 = reg;
- }else if(GPIO_PCF4 == remap_reg){
+ } else if(GPIO_PCF4 == remap_reg) {
reg = AFIO_PCF4;
reg |= remap;
AFIO_PCF4 = reg;
- }else if(GPIO_PCF5 == remap_reg){
+ } else if(GPIO_PCF5 == remap_reg) {
reg = AFIO_PCF5;
reg |= remap;
AFIO_PCF5 = reg;
- }else{
+ } else {
/* illegal parameters */
}
- }else{
- if(GPIO_PCF2 == remap_reg){
+ } else {
+ if(GPIO_PCF2 == remap_reg) {
reg = AFIO_PCF2;
reg &= ~remap;
AFIO_PCF2 = reg;
- }else if(GPIO_PCF3 == remap_reg){
+ } else if(GPIO_PCF3 == remap_reg) {
reg = AFIO_PCF3;
reg &= ~remap;
AFIO_PCF3 = reg;
- }else if(GPIO_PCF4 == remap_reg){
+ } else if(GPIO_PCF4 == remap_reg) {
reg = AFIO_PCF4;
reg &= ~remap;
AFIO_PCF4 = reg;
- }else if(GPIO_PCF5 == remap_reg){
+ } else if(GPIO_PCF5 == remap_reg) {
reg = AFIO_PCF5;
reg &= ~remap;
AFIO_PCF5 = reg;
- }else{
+ } else {
/* illegal parameters */
}
}
}
+/*!
+ \brief select ethernet MII or RMII PHY
+ \param[in] enet_sel: ethernet MII or RMII PHY selection
+ \arg GPIO_ENET_PHY_MII: configure ethernet MAC for connection with an MII PHY
+ \arg GPIO_ENET_PHY_RMII: configure ethernet MAC for connection with an RMII PHY
+ \param[out] none
+ \retval none
+*/
+void gpio_ethernet_phy_select(uint32_t enet_sel)
+{
+ /* clear AFIO_PCF0_ENET_PHY_SEL bit */
+ AFIO_PCF0 &= (uint32_t)(~AFIO_PCF0_ENET_PHY_SEL);
+
+ /* select MII or RMII PHY */
+ AFIO_PCF0 |= (uint32_t)enet_sel;
+}
+
/*!
\brief select GPIO pin exti sources
\param[in] output_port: gpio event output port
+ only one parameter can be selected which are shown as below:
\arg GPIO_PORT_SOURCE_GPIOA: output port source A
\arg GPIO_PORT_SOURCE_GPIOB: output port source B
\arg GPIO_PORT_SOURCE_GPIOC: output port source C
\arg GPIO_PORT_SOURCE_GPIOD: output port source D
- \arg GPIO_PORT_SOURCE_GPIOE: output port source E
+ \arg GPIO_PORT_SOURCE_GPIOE: output port source E
\arg GPIO_PORT_SOURCE_GPIOF: output port source F
\arg GPIO_PORT_SOURCE_GPIOG: output port source G
\arg GPIO_PORT_SOURCE_GPIOH: output port source H
\arg GPIO_PORT_SOURCE_GPIOI: output port source I
- \param[in] output_pin: GPIO_PIN_SOURCE_x(x=0..15)
+ \param[in] output_pin: GPIO output pin source
+ only one parameter can be selected which are shown as below:
+ \arg GPIO_PIN_SOURCE_x(x=0..15)
\param[out] none
\retval none
*/
@@ -616,19 +631,19 @@ void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin)
source = ((uint32_t)0x0FU) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK));
/* select EXTI sources */
- if(GPIO_PIN_SOURCE_4 > output_pin){
+ if(GPIO_PIN_SOURCE_4 > output_pin) {
/* select EXTI0/EXTI1/EXTI2/EXTI3 */
AFIO_EXTISS0 &= ~source;
AFIO_EXTISS0 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
- }else if(GPIO_PIN_SOURCE_8 > output_pin){
+ } else if(GPIO_PIN_SOURCE_8 > output_pin) {
/* select EXTI4/EXTI5/EXTI6/EXTI7 */
AFIO_EXTISS1 &= ~source;
AFIO_EXTISS1 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
- }else if(GPIO_PIN_SOURCE_12 > output_pin){
+ } else if(GPIO_PIN_SOURCE_12 > output_pin) {
/* select EXTI8/EXTI9/EXTI10/EXTI11 */
AFIO_EXTISS2 &= ~source;
AFIO_EXTISS2 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
- }else{
+ } else {
/* select EXTI12/EXTI13/EXTI14/EXTI15 */
AFIO_EXTISS3 &= ~source;
AFIO_EXTISS3 |= (((uint32_t)output_port) << (AFIO_EXTI_SOURCE_FIELDS * (output_pin & AFIO_EXTI_SOURCE_MASK)));
@@ -644,7 +659,7 @@ void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin)
\arg GPIO_EVENT_PORT_GPIOC: event output port C
\arg GPIO_EVENT_PORT_GPIOD: event output port D
\arg GPIO_EVENT_PORT_GPIOE: event output port E
- \param[in] output_pin:
+ \param[in] output_pin: GPIO event output pin
only one parameter can be selected which are shown as below:
\arg GPIO_EVENT_PIN_x(x=0..15)
\param[out] none
@@ -654,13 +669,13 @@ void gpio_event_output_config(uint8_t output_port, uint8_t output_pin)
{
uint32_t reg = 0U;
reg = AFIO_EC;
-
+
/* clear AFIO_EC_PORT and AFIO_EC_PIN bits */
- reg &= (uint32_t)(~(AFIO_EC_PORT|AFIO_EC_PIN));
-
+ reg &= (uint32_t)(~(AFIO_EC_PORT | AFIO_EC_PIN));
+
reg |= (uint32_t)((uint32_t)output_port << GPIO_OUTPUT_PORT_OFFSET);
reg |= (uint32_t)output_pin;
-
+
AFIO_EC = reg;
}
@@ -695,7 +710,7 @@ void gpio_event_output_disable(void)
\param[out] none
\retval none
*/
-void gpio_pin_lock(uint32_t gpio_periph,uint32_t pin)
+void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin)
{
uint32_t lock = 0x00010000U;
lock |= pin;
@@ -707,20 +722,3 @@ void gpio_pin_lock(uint32_t gpio_periph,uint32_t pin)
lock = GPIO_LOCK(gpio_periph);
lock = GPIO_LOCK(gpio_periph);
}
-
-/*!
- \brief select ethernet MII or RMII PHY
- \param[in] enet_sel: ethernet MII or RMII PHY selection
- \arg GPIO_ENET_PHY_MII: configure ethernet MAC for connection with an MII PHY
- \arg GPIO_ENET_PHY_RMII: configure ethernet MAC for connection with an RMII PHY
- \param[out] none
- \retval none
-*/
-void gpio_ethernet_phy_select(uint32_t enet_sel)
-{
- /* clear AFIO_PCF0_ENET_PHY_SEL bit */
- AFIO_PCF0 &= (uint32_t)(~AFIO_PCF0_ENET_PHY_SEL);
-
- /* select MII or RMII PHY */
- AFIO_PCF0 |= (uint32_t)enet_sel;
-}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau.c
index 6b2482f..5cc79f0 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau.c
@@ -1,37 +1,34 @@
/*!
- \file gd32f20x_cau.c
- \brief CAU driver
+ \file gd32f20x_hau.c
+ \brief HAU driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -40,7 +37,7 @@ OF SUCH DAMAGE.
/*!
\brief reset the HAU peripheral
- \param[in] none
+ \param[in] none
\param[out] none
\retval none
*/
@@ -63,20 +60,20 @@ void hau_deinit(void)
\param[out] none
\retval none
*/
-void hau_init(hau_init_parameter_struct* initpara)
+void hau_init(hau_init_parameter_struct *initpara)
{
/* configure the algorithm, mode and the data type */
HAU_CTL &= ~(HAU_CTL_ALGM_0 | HAU_CTL_ALGM_1 | HAU_CTL_DATAM | HAU_CTL_HMS);
HAU_CTL |= (initpara->algo | initpara->datatype | initpara->mode);
-
- /* when mode is HMAC, set the key */
- if(HAU_MODE_HMAC == initpara->mode){
+
+ /* when mode is HMAC, set the key */
+ if(HAU_MODE_HMAC == initpara->mode) {
HAU_CTL &= ~HAU_CTL_KLM;
HAU_CTL |= initpara->keytype;
}
/* start the digest of a new message */
- HAU_CTL |= HAU_CTL_START;
+ HAU_CTL |= HAU_CTL_START;
}
/*!
@@ -90,7 +87,7 @@ void hau_init(hau_init_parameter_struct* initpara)
\param[out] none
\retval none
*/
-void hau_init_parameter_init(hau_init_parameter_struct* initpara)
+void hau_init_struct_para_init(hau_init_parameter_struct *initpara)
{
initpara->algo = HAU_ALGO_SHA1;
initpara->mode = HAU_MODE_HASH;
@@ -100,7 +97,7 @@ void hau_init_parameter_init(hau_init_parameter_struct* initpara)
/*!
\brief reset the HAU processor core
- \param[in] none
+ \param[in] none
\param[out] none
\retval none
*/
@@ -123,7 +120,7 @@ void hau_reset(void)
\retval none
*/
void hau_last_word_validbits_num_config(uint32_t valid_num)
-{
+{
HAU_CFG &= ~(HAU_CFG_VBL);
HAU_CFG |= CFG_VBL(valid_num);
}
@@ -146,8 +143,8 @@ void hau_data_write(uint32_t data)
\retval number of words in the input FIFO
*/
uint32_t hau_infifo_words_num_get(void)
-{
- uint32_t ret = 0U;
+{
+ uint32_t ret = 0U;
ret = GET_CTL_NWIF(HAU_CTL);
return ret;
}
@@ -159,7 +156,7 @@ uint32_t hau_infifo_words_num_get(void)
out[7:0]: message digest result 0-7
\retval none
*/
-void hau_digest_read(hau_digest_parameter_struct* digestpara)
+void hau_digest_read(hau_digest_parameter_struct *digestpara)
{
digestpara->out[0] = HAU_DO0;
digestpara->out[1] = HAU_DO1;
@@ -172,7 +169,7 @@ void hau_digest_read(hau_digest_parameter_struct* digestpara)
}
/*!
- \brief enable digest calculation
+ \brief enable digest calculation
\param[in] none
\param[out] none
\retval none
@@ -183,7 +180,7 @@ void hau_digest_calculation_enable(void)
}
/*!
- \brief configure single or multiple DMA is used, and digest calculation at the end of a DMA transfer or not
+ \brief configure single or multiple DMA is used, and digest calculation at the end of a DMA transfer or not
\param[in] multi_single
only one parameter can be selected which is shown as below
\arg SINGLE_DMA_AUTO_DIGEST: message padding and message digest calculation at the end of a DMA transfer
@@ -196,9 +193,9 @@ void hau_multiple_single_dma_config(uint32_t multi_single)
HAU_CTL &= ~HAU_CTL_MDS;
HAU_CTL |= multi_single;
}
-
+
/*!
- \brief enable the HAU DMA interface
+ \brief enable the HAU DMA interface
\param[in] none
\param[out] none
\retval none
@@ -209,7 +206,7 @@ void hau_dma_enable(void)
}
/*!
- \brief disable the HAU DMA interface
+ \brief disable the HAU DMA interface
\param[in] none
\param[out] none
\retval none
@@ -223,7 +220,7 @@ void hau_dma_disable(void)
\brief get the HAU flag status
\param[in] flag: HAU flag status
only one parameter can be selected which is shown as below
- \arg HAU_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
+ \arg HAU_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
\arg HAU_FLAG_CALCULATION_COMPLETE: digest calculation is completed
\arg HAU_FLAG_DMA: DMA is enabled (DMAE =1) or a transfer is processing
\arg HAU_FLAG_BUSY: data block is in process
@@ -237,13 +234,13 @@ FlagStatus hau_flag_get(uint32_t flag)
FlagStatus ret_flag = RESET;
/* check if the flag is in HAU_CTL register */
- if(RESET != (flag & HAU_FLAG_INFIFO_NO_EMPTY)){
+ if(RESET != (flag & HAU_FLAG_INFIFO_NO_EMPTY)) {
ret = HAU_CTL;
- }else{
+ } else {
ret = HAU_STAT;
}
- if (RESET != (ret & flag)){
+ if(RESET != (ret & flag)) {
ret_flag = SET;
}
@@ -254,7 +251,7 @@ FlagStatus hau_flag_get(uint32_t flag)
\brief clear the HAU flag status
\param[in] flag: HAU flag status
one or more parameters can be selected which are shown as below
- \arg HAU_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
+ \arg HAU_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
\arg HAU_FLAG_CALCULATION_COMPLETE: digest calculation is completed
\param[out] none
\retval none
@@ -268,7 +265,7 @@ void hau_flag_clear(uint32_t flag)
\brief enable the HAU interrupts
\param[in] interrupt: specify the HAU interrupt source to be enabled
one or more parameters can be selected which are shown as below
- \arg HAU_INT_DATA_INPUT: a new block can be entered into the IN buffer
+ \arg HAU_INT_DATA_INPUT: a new block can be entered into the IN buffer
\arg HAU_INT_CALCULATION_COMPLETE: calculation complete
\param[out] none
\retval none
@@ -282,7 +279,7 @@ void hau_interrupt_enable(uint32_t interrupt)
\brief disable the HAU interrupts
\param[in] interrupt: specify the HAU interrupt source to be disabled
one or more parameters can be selected which are shown as below
- \arg HAU_INT_DATA_INPUT: a new block can be entered into the IN buffer
+ \arg HAU_INT_DATA_INPUT: a new block can be entered into the IN buffer
\arg HAU_INT_CALCULATION_COMPLETE: calculation complete
\param[out] none
\retval none
@@ -296,7 +293,7 @@ void hau_interrupt_disable(uint32_t interrupt)
\brief get the HAU interrupt flag status
\param[in] int_flag: HAU interrupt flag status
only one parameter can be selected which is shown as below
- \arg HAU_INT_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
+ \arg HAU_INT_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
\arg HAU_INT_FLAG_CALCULATION_COMPLETE: digest calculation is completed
\param[out] none
\retval FlagStatus: SET or RESET
@@ -309,10 +306,10 @@ FlagStatus hau_interrupt_flag_get(uint32_t int_flag)
/* return the status of the interrupt */
ret = HAU_STAT;
- if(RESET != ((HAU_INTEN & ret) & int_flag)){
+ if(RESET != ((HAU_INTEN & ret) & int_flag)) {
flag = SET;
}
-
+
return flag;
}
@@ -320,7 +317,7 @@ FlagStatus hau_interrupt_flag_get(uint32_t int_flag)
\brief clear the HAU interrupt flag status
\param[in] int_flag: HAU interrupt flag status
one or more parameters can be selected which are shown as below
- \arg HAU_INT_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
+ \arg HAU_INT_FLAG_DATA_INPUT: there is enough space (16 bytes) in the input FIFO
\arg HAU_INT_FLAG_CALCULATION_COMPLETE: digest calculation is completed
\param[out] none
\retval none
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau_sha_md5.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau_sha_md5.c
index a486f9b..4b456d6 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau_sha_md5.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_hau_sha_md5.c
@@ -2,36 +2,33 @@
\file gd32f20x_hau_sha_md5.c
\brief HAU_SHA_MD5 driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -42,15 +39,15 @@ OF SUCH DAMAGE.
/* HAU SHA/MD5 digest read in HASH mode */
static void hau_sha_md5_digest_read(uint32_t algo, uint8_t *output);
/* HAU digest calculate process in HASH mode */
-static ErrStatus hau_hash_calculate(uint32_t algo, uint8_t *input, uint32_t in_length, uint8_t *output);
+static ErrStatus hau_hash_calculate(uint32_t algo, uint8_t *input, uint32_t in_length, uint8_t *output);
/* HAU digest calculate process in HMAC mode */
static ErrStatus hau_hmac_calculate(uint32_t algo, uint8_t *key, uint32_t keysize, uint8_t *input, uint32_t in_length, uint8_t *output);
/*!
- \brief calculate digest using SHA1 in HASH mode
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \brief calculate digest using SHA1 in HASH mode
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -64,10 +61,10 @@ ErrStatus hau_hash_sha_1(uint8_t *input, uint32_t in_length, uint8_t output[20])
/*!
\brief calculate digest using SHA1 in HMAC mode
\param[in] key: pointer to the key used for HMAC
- \param[in] keysize: length of the key used for HMAC
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] keysize: length of the key used for HMAC
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -80,9 +77,9 @@ ErrStatus hau_hmac_sha_1(uint8_t *key, uint32_t keysize, uint8_t *input, uint32_
/*!
\brief calculate digest using SHA224 in HASH mode
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -96,10 +93,10 @@ ErrStatus hau_hash_sha_224(uint8_t *input, uint32_t in_length, uint8_t output[28
/*!
\brief calculate digest using SHA224 in HMAC mode
\param[in] key: pointer to the key used for HMAC
- \param[in] keysize: length of the key used for HMAC
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] keysize: length of the key used for HMAC
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -112,9 +109,9 @@ ErrStatus hau_hmac_sha_224(uint8_t *key, uint32_t keysize, uint8_t *input, uint3
/*!
\brief calculate digest using SHA256 in HASH mode
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -128,10 +125,10 @@ ErrStatus hau_hash_sha_256(uint8_t *input, uint32_t in_length, uint8_t output[32
/*!
\brief calculate digest using SHA256 in HMAC mode
\param[in] key: pointer to the key used for HMAC
- \param[in] keysize: length of the key used for HMAC
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] keysize: length of the key used for HMAC
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -139,14 +136,14 @@ ErrStatus hau_hmac_sha_256(uint8_t *key, uint32_t keysize, uint8_t *input, uint3
{
ErrStatus ret = ERROR;
ret = hau_hmac_calculate(HAU_ALGO_SHA256, key, keysize, input, in_length, output);
- return ret;
+ return ret;
}
/*!
- \brief calculate digest using MD5 in HASH mode
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \brief calculate digest using MD5 in HASH mode
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -160,10 +157,10 @@ ErrStatus hau_hash_md5(uint8_t *input, uint32_t in_length, uint8_t output[16])
/*!
\brief calculate digest using MD5 in HMAC mode
\param[in] key: pointer to the key used for HMAC
- \param[in] keysize: length of the key used for HMAC
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] keysize: length of the key used for HMAC
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -176,72 +173,72 @@ ErrStatus hau_hmac_md5(uint8_t *key, uint32_t keysize, uint8_t *input, uint32_t
/*!
\brief HAU SHA/MD5 digest read
- \param[in] algo: algorithm selection
+ \param[in] algo: algorithm selection
\param[out] output: the result digest
\retval none
*/
static void hau_sha_md5_digest_read(uint32_t algo, uint8_t *output)
{
hau_digest_parameter_struct digest_para;
- uint32_t outputaddr = (uint32_t)output;
-
- switch(algo){
- case HAU_ALGO_SHA1:
+ uint32_t outputaddr = (uint32_t)output;
+
+ switch(algo) {
+ case HAU_ALGO_SHA1:
hau_digest_read(&digest_para);
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[0]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[0]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[1]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[1]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[2]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[2]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[3]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[3]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[4]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[4]);
break;
case HAU_ALGO_SHA224:
hau_digest_read(&digest_para);
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[0]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[0]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[1]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[1]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[2]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[2]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[3]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[3]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[4]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[4]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[5]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[5]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[6]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[6]);
break;
case HAU_ALGO_SHA256:
hau_digest_read(&digest_para);
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[0]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[0]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[1]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[1]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[2]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[2]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[3]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[3]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[4]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[4]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[5]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[5]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[6]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[6]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[7]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[7]);
break;
case HAU_ALGO_MD5:
hau_digest_read(&digest_para);
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[0]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[0]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[1]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[1]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[2]);
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[2]);
outputaddr += 4U;
- *(uint32_t*)(outputaddr) = __REV(digest_para.out[3]);
- break;
+ *(uint32_t *)(outputaddr) = __REV(digest_para.out[3]);
+ break;
default:
break;
}
@@ -250,16 +247,16 @@ static void hau_sha_md5_digest_read(uint32_t algo, uint8_t *output)
/*!
\brief HAU digest calculate process in HASH mode
\param[in] algo: algorithm selection
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
static ErrStatus hau_hash_calculate(uint32_t algo, uint8_t *input, uint32_t in_length, uint8_t *output)
{
hau_init_parameter_struct init_para;
-
+
__IO uint32_t num_last_valid = 0U;
uint32_t i = 0U;
__IO uint32_t counter = 0U;
@@ -282,8 +279,8 @@ static ErrStatus hau_hash_calculate(uint32_t algo, uint8_t *input, uint32_t in_l
hau_last_word_validbits_num_config(num_last_valid);
/* write data to the IN FIFO */
- for(i = 0U; i < in_length; i += 4U){
- hau_data_write(*(uint32_t*)inputaddr);
+ for(i = 0U; i < in_length; i += 4U) {
+ hau_data_write(*(uint32_t *)inputaddr);
inputaddr += 4U;
}
@@ -291,14 +288,14 @@ static ErrStatus hau_hash_calculate(uint32_t algo, uint8_t *input, uint32_t in_l
hau_digest_calculation_enable();
/* wait until the busy flag is reset */
- do{
+ do {
busystatus = hau_flag_get(HAU_FLAG_BUSY);
counter++;
- }while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* read the message digest */
hau_sha_md5_digest_read(algo, output);
}
@@ -309,10 +306,10 @@ static ErrStatus hau_hash_calculate(uint32_t algo, uint8_t *input, uint32_t in_l
\brief HAU digest calculate process in HMAC mode
\param[in] algo: algorithm selection
\param[in] key: pointer to the key used for HMAC
- \param[in] keysize: length of the key used for HMAC
- \param[in] input: pointer to the input buffer
- \param[in] in_length: length of the input buffer
- \param[in] output: the result digest
+ \param[in] keysize: length of the key used for HMAC
+ \param[in] input: pointer to the input buffer
+ \param[in] in_length: length of the input buffer
+ \param[in] output: the result digest
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -340,9 +337,9 @@ static ErrStatus hau_hmac_calculate(uint32_t algo, uint8_t *key, uint32_t keysiz
init_para.algo = algo;
init_para.mode = HAU_MODE_HMAC;
init_para.datatype = HAU_SWAPPING_8BIT;
- if(keysize > 64U){
+ if(keysize > 64U) {
init_para.keytype = HAU_KEY_LONGGER_64;
- }else{
+ } else {
init_para.keytype = HAU_KEY_SHORTER_64;
}
hau_init(&init_para);
@@ -351,8 +348,8 @@ static ErrStatus hau_hmac_calculate(uint32_t algo, uint8_t *key, uint32_t keysiz
hau_last_word_validbits_num_config((uint32_t)num_key_valid);
/* write the key */
- for(i = 0U; i < keysize; i += 4U){
- hau_data_write(*(uint32_t*)keyaddr);
+ for(i = 0U; i < keysize; i += 4U) {
+ hau_data_write(*(uint32_t *)keyaddr);
keyaddr += 4U;
}
@@ -360,20 +357,20 @@ static ErrStatus hau_hmac_calculate(uint32_t algo, uint8_t *key, uint32_t keysiz
hau_digest_calculation_enable();
/* wait until the busy flag is reset */
- do{
+ do {
busystatus = hau_flag_get(HAU_FLAG_BUSY);
counter++;
- }while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* configure the number of valid bits in last word of the message */
hau_last_word_validbits_num_config((uint32_t)num_last_valid);
/* write data to the IN FIFO */
- for(i = 0U; i < in_length; i += 4U){
- hau_data_write(*(uint32_t*)inputaddr);
+ for(i = 0U; i < in_length; i += 4U) {
+ hau_data_write(*(uint32_t *)inputaddr);
inputaddr += 4U;
}
@@ -382,21 +379,21 @@ static ErrStatus hau_hmac_calculate(uint32_t algo, uint8_t *key, uint32_t keysiz
/* wait until the busy flag is reset */
counter = 0U;
- do{
+ do {
busystatus = hau_flag_get(HAU_FLAG_BUSY);
counter++;
- }while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* configure the number of valid bits in last word of the key */
hau_last_word_validbits_num_config((uint32_t)num_key_valid);
/* write the key */
keyaddr = (uint32_t)key;
- for(i = 0U; i < keysize; i += 4U){
- hau_data_write(*(uint32_t*)keyaddr);
+ for(i = 0U; i < keysize; i += 4U) {
+ hau_data_write(*(uint32_t *)keyaddr);
keyaddr += 4U;
}
@@ -404,19 +401,19 @@ static ErrStatus hau_hmac_calculate(uint32_t algo, uint8_t *key, uint32_t keysiz
hau_digest_calculation_enable();
/* wait until the busy flag is reset */
- counter =0U;
- do{
+ counter = 0U;
+ do {
busystatus = hau_flag_get(HAU_FLAG_BUSY);
counter++;
- }while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
+ } while((SHAMD5_BSY_TIMEOUT != counter) && (RESET != busystatus));
- if(RESET != busystatus){
+ if(RESET != busystatus) {
return ERROR;
- }else{
+ } else {
/* read the message digest */
hau_sha_md5_digest_read(algo, output);
}
- }
+ }
}
- return SUCCESS;
+ return SUCCESS;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_i2c.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_i2c.c
index 1911cd7..9947df6 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_i2c.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_i2c.c
@@ -2,51 +2,47 @@
\file gd32f20x_i2c.c
\brief I2C driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
- \version 2019-04-16, V2.1.1, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_i2c.h"
/* I2C register bit mask */
-#define I2CCLK_MAX ((uint32_t)0x0000003FU) /*!< i2cclk maximum value */
+#define I2CCLK_MAX ((uint32_t)0x0000003CU) /*!< i2cclk maximum value */
#define I2CCLK_MIN ((uint32_t)0x00000002U) /*!< i2cclk minimum value */
#define I2C_FLAG_MASK ((uint32_t)0x0000FFFFU) /*!< i2c flag mask */
#define I2C_ADDRESS_MASK ((uint32_t)0x000003FFU) /*!< i2c address mask */
#define I2C_ADDRESS2_MASK ((uint32_t)0x000000FEU) /*!< the second i2c address mask */
/* I2C register bit offset */
-#define STAT1_PECV_OFFSET ((uint32_t)8U) /* bit offset of PECV in I2C_STAT1 */
+#define STAT1_PECV_OFFSET ((uint32_t)0x00000008U) /* bit offset of PECV in I2C_STAT1 */
/*!
\brief reset I2C
@@ -56,7 +52,7 @@ OF SUCH DAMAGE.
*/
void i2c_deinit(uint32_t i2c_periph)
{
- switch(i2c_periph){
+ switch(i2c_periph) {
case I2C0:
/* reset I2C0 */
rcu_periph_reset_enable(RCU_I2C0RST);
@@ -74,7 +70,6 @@ void i2c_deinit(uint32_t i2c_periph)
break;
default:
break;
-
}
}
@@ -82,92 +77,92 @@ void i2c_deinit(uint32_t i2c_periph)
\brief configure I2C clock
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] clkspeed: I2C clock speed, supports standard mode (up to 100 kHz), fast mode (up to 400 kHz)
- and fast mode plus (up to 1MHz)
- \param[in] dutycyc: duty cycle in fast mode or fast mode plus
+ \param[in] dutycyc: duty cycle in fast mode
only one parameter can be selected which is shown as below:
- \arg I2C_DTCY_2: T_low/T_high=2
- \arg I2C_DTCY_16_9: T_low/T_high=16/9
+ \arg I2C_DTCY_2: T_low/T_high = 2 in fast mode
+ \arg I2C_DTCY_16_9: T_low/T_high = 16/9 in fast mode
\param[out] none
\retval none
*/
-void i2c_clock_config(uint32_t i2c_periph,uint32_t clkspeed,uint32_t dutycyc)
+void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc)
{
- uint32_t pclk1,clkc,freq,risetime;
+ uint32_t pclk1, clkc, freq, risetime;
uint32_t temp;
-
+
pclk1 = rcu_clock_freq_get(CK_APB1);
/* I2C peripheral clock frequency */
- freq = (uint32_t)(pclk1/1000000U);
- if(freq >= I2CCLK_MAX){
+ freq = (uint32_t)(pclk1 / 1000000U);
+ if(freq >= I2CCLK_MAX) {
freq = I2CCLK_MAX;
}
temp = I2C_CTL1(i2c_periph);
temp &= ~I2C_CTL1_I2CCLK;
temp |= freq;
-
+
I2C_CTL1(i2c_periph) = temp;
-
- if(100000U >= clkspeed){
+
+ if(100000U >= clkspeed) {
/* the maximum SCL rise time is 1000ns in standard mode */
- risetime = (uint32_t)((pclk1/1000000U)+1U);
- if(risetime >= I2CCLK_MAX){
+ risetime = (uint32_t)((pclk1 / 1000000U) + 1U);
+ if(risetime >= I2CCLK_MAX) {
I2C_RT(i2c_periph) = I2CCLK_MAX;
- }else if(risetime <= I2CCLK_MIN){
+ } else if(risetime <= I2CCLK_MIN) {
I2C_RT(i2c_periph) = I2CCLK_MIN;
- }else{
+ } else {
I2C_RT(i2c_periph) = risetime;
}
- clkc = (uint32_t)(pclk1/(clkspeed*2U));
- if(clkc < 0x04U){
- /* the CLKC in standard mode minmum value is 4 */
+ clkc = (uint32_t)(pclk1 / (clkspeed * 2U));
+ if(clkc < 0x04U) {
+ /* the CLKC in standard mode minimum value is 4 */
clkc = 0x04U;
}
+
I2C_CKCFG(i2c_periph) |= (I2C_CKCFG_CLKC & clkc);
- }else if(400000U >= clkspeed){
+ } else if(400000U >= clkspeed) {
/* the maximum SCL rise time is 300ns in fast mode */
- I2C_RT(i2c_periph) = (uint32_t)(((freq*(uint32_t)300U)/(uint32_t)1000U)+(uint32_t)1U);
- if(I2C_DTCY_2 == dutycyc){
+ I2C_RT(i2c_periph) = (uint32_t)(((freq * (uint32_t)300U) / (uint32_t)1000U) + (uint32_t)1U);
+ if(I2C_DTCY_2 == dutycyc) {
/* I2C duty cycle is 2 */
- clkc = (uint32_t)(pclk1/(clkspeed*3U));
+ clkc = (uint32_t)(pclk1 / (clkspeed * 3U));
I2C_CKCFG(i2c_periph) &= ~I2C_CKCFG_DTCY;
- }else{
+ } else {
/* I2C duty cycle is 16/9 */
- clkc = (uint32_t)(pclk1/(clkspeed*25U));
+ clkc = (uint32_t)(pclk1 / (clkspeed * 25U));
I2C_CKCFG(i2c_periph) |= I2C_CKCFG_DTCY;
}
- if(0U == (clkc & I2C_CKCFG_CLKC)){
- /* the CLKC in fast mode minmum value is 1 */
- clkc |= 0x0001U;
+ if(0U == (clkc & I2C_CKCFG_CLKC)) {
+ /* the CLKC in fast mode minimum value is 1 */
+ clkc |= 0x0001U;
}
I2C_CKCFG(i2c_periph) |= I2C_CKCFG_FAST;
I2C_CKCFG(i2c_periph) |= clkc;
- }else{
+ } else {
}
}
/*!
- \brief configure I2C address
+ \brief configure I2C address
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] mod:
+ \param[in] mode:
only one parameter can be selected which is shown as below:
- \arg I2C_I2CMODE_ENABLE: I2C mode
+ \arg I2C_I2CMODE_ENABLE: I2C mode
\arg I2C_SMBUSMODE_ENABLE: SMBus mode
\param[in] addformat: 7bits or 10bits
only one parameter can be selected which is shown as below:
- \arg I2C_ADDFORMAT_7BITS: 7bits
- \arg I2C_ADDFORMAT_10BITS: 10bits
+ \arg I2C_ADDFORMAT_7BITS: address format is 7 bits
+ \arg I2C_ADDFORMAT_10BITS: address format is 10 bits
\param[in] addr: I2C address
\param[out] none
\retval none
*/
-void i2c_mode_addr_config(uint32_t i2c_periph,uint32_t mode,uint32_t addformat,uint32_t addr)
+void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode, uint32_t addformat, uint32_t addr)
{
/* SMBus/I2C mode selected */
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_SMBEN);
+ ctl &= ~(I2C_CTL0_SMBEN);
ctl |= mode;
I2C_CTL0(i2c_periph) = ctl;
/* configure address */
@@ -176,20 +171,20 @@ void i2c_mode_addr_config(uint32_t i2c_periph,uint32_t mode,uint32_t addformat,u
}
/*!
- \brief SMBus type selection
+ \brief select SMBus type
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] type:
only one parameter can be selected which is shown as below:
- \arg I2C_SMBUS_DEVICE: device
- \arg I2C_SMBUS_HOST: host
+ \arg I2C_SMBUS_DEVICE: SMBus mode device type
+ \arg I2C_SMBUS_HOST: SMBus mode host type
\param[out] none
\retval none
*/
void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type)
{
- if(I2C_SMBUS_HOST == type){
+ if(I2C_SMBUS_HOST == type) {
I2C_CTL0(i2c_periph) |= I2C_CTL0_SMBSEL;
- }else{
+ } else {
I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_SMBSEL);
}
}
@@ -206,11 +201,12 @@ void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type)
*/
void i2c_ack_config(uint32_t i2c_periph, uint32_t ack)
{
- if(I2C_ACK_ENABLE == ack){
- I2C_CTL0(i2c_periph) |= I2C_CTL0_ACKEN;
- }else{
- I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_ACKEN);
- }
+ uint32_t ctl = 0U;
+
+ ctl = I2C_CTL0(i2c_periph);
+ ctl &= ~(I2C_CTL0_ACKEN);
+ ctl |= ack;
+ I2C_CTL0(i2c_periph) = ctl;
}
/*!
@@ -218,38 +214,38 @@ void i2c_ack_config(uint32_t i2c_periph, uint32_t ack)
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] pos:
only one parameter can be selected which is shown as below:
- \arg I2C_ACKPOS_CURRENT: whether to send ACK or not for the current
- \arg I2C_ACKPOS_NEXT: whether to send ACK or not for the next byte
+ \arg I2C_ACKPOS_CURRENT: ACKEN bit decides whether or not to send ACK or not for the current byte
+ \arg I2C_ACKPOS_NEXT: ACKEN bit decides whether or not to send ACK for the next byte
\param[out] none
\retval none
*/
void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos)
{
+ uint32_t ctl = 0U;
/* configure I2C POAP position */
- if(I2C_ACKPOS_NEXT == pos){
- I2C_CTL0(i2c_periph) |= I2C_CTL0_POAP;
- }else{
- I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_POAP);
- }
+ ctl = I2C_CTL0(i2c_periph);
+ ctl &= ~(I2C_CTL0_POAP);
+ ctl |= pos;
+ I2C_CTL0(i2c_periph) = ctl;
}
/*!
\brief master sends slave address
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] addr: slave address
+ \param[in] addr: slave address
\param[in] trandirection: transmitter or receiver
only one parameter can be selected which is shown as below:
- \arg I2C_TRANSMITTER: transmitter
- \arg I2C_RECEIVER: receiver
+ \arg I2C_TRANSMITTER: transmitter
+ \arg I2C_RECEIVER: receiver
\param[out] none
\retval none
*/
void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr, uint32_t trandirection)
{
/* master is a transmitter or a receiver */
- if(I2C_TRANSMITTER == trandirection){
+ if(I2C_TRANSMITTER == trandirection) {
addr = addr & I2C_TRANSMITTER;
- }else{
+ } else {
addr = addr | I2C_RECEIVER;
}
/* send slave address */
@@ -272,7 +268,7 @@ void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr)
/*!
\brief disable dual-address mode
- \param[in] i2c_periph: I2Cx(x=0,1,2)
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval none
*/
@@ -283,7 +279,7 @@ void i2c_dualaddr_disable(uint32_t i2c_periph)
/*!
\brief enable I2C
- \param[in] i2c_periph: I2Cx(x=0,1)
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval none
*/
@@ -294,7 +290,7 @@ void i2c_enable(uint32_t i2c_periph)
/*!
\brief disable I2C
- \param[in] i2c_periph: I2Cx(x=0,1)
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval none
*/
@@ -328,7 +324,7 @@ void i2c_stop_on_bus(uint32_t i2c_periph)
/*!
\brief I2C transmit data function
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] data: data of transmission
+ \param[in] data: data of transmission
\param[out] none
\retval none
*/
@@ -349,20 +345,20 @@ uint8_t i2c_data_receive(uint32_t i2c_periph)
}
/*!
- \brief enable I2C DMA mode
+ \brief configure I2C DMA mode
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] dmastate:
only one parameter can be selected which is shown as below:
- \arg I2C_DMA_ON: DMA mode enable
- \arg I2C_DMA_OFF: DMA mode disable
+ \arg I2C_DMA_ON: enable DMA mode
+ \arg I2C_DMA_OFF: disable DMA mode
\param[out] none
\retval none
*/
-void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate)
+void i2c_dma_config(uint32_t i2c_periph, uint32_t dmastate)
{
/* configure I2C DMA function */
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL1(i2c_periph);
ctl &= ~(I2C_CTL1_DMAON);
ctl |= dmastate;
@@ -372,7 +368,7 @@ void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate)
/*!
\brief configure whether next DMA EOT is DMA last transfer or not
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] dmalast:
+ \param[in] dmalast:
only one parameter can be selected which is shown as below:
\arg I2C_DMALST_ON: next DMA EOT is the last transfer
\arg I2C_DMALST_OFF: next DMA EOT is not the last transfer
@@ -383,7 +379,7 @@ void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast)
{
/* configure DMA last transfer */
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL1(i2c_periph);
ctl &= ~(I2C_CTL1_DMALST);
ctl |= dmalast;
@@ -391,28 +387,28 @@ void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast)
}
/*!
- \brief whether to stretch SCL low when data is not ready in slave mode
+ \brief whether to stretch SCL low when data is not ready in slave mode
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] stretchpara:
only one parameter can be selected which is shown as below:
- \arg I2C_SCLSTRETCH_ENABLE: SCL stretching is enabled
- \arg I2C_SCLSTRETCH_DISABLE: SCL stretching is disabled
+ \arg I2C_SCLSTRETCH_ENABLE: enable SCL stretching
+ \arg I2C_SCLSTRETCH_DISABLE: disable SCL stretching
\param[out] none
\retval none
*/
void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara)
{
- /* configure I2C SCL strerching enable or disable */
+ /* configure I2C SCL strerching */
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_DISSTRC);
+ ctl &= ~(I2C_CTL0_SS);
ctl |= stretchpara;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief whether or not to response to a general call
+ \brief whether or not to response to a general call
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] gcallpara:
only one parameter can be selected which is shown as below:
@@ -425,15 +421,15 @@ void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara)
{
/* configure slave response to a general call enable or disable */
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_GCEN);
+ ctl &= ~(I2C_CTL0_GCEN);
ctl |= gcallpara;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief software reset I2C
+ \brief configure software reset of I2C
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] sreset:
only one parameter can be selected which is shown as below:
@@ -454,16 +450,16 @@ void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset)
}
/*!
- \brief I2C PEC calculation on or off
+ \brief configure I2C PEC calculation
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] pecpara:
+ \param[in] pecstate:
only one parameter can be selected which is shown as below:
- \arg I2C_PEC_ENABLE: PEC calculation on
- \arg I2C_PEC_DISABLE: PEC calculation off
+ \arg I2C_PEC_ENABLE: PEC calculation on
+ \arg I2C_PEC_DISABLE: PEC calculation off
\param[out] none
\retval none
*/
-void i2c_pec_enable(uint32_t i2c_periph,uint32_t pecstate)
+void i2c_pec_config(uint32_t i2c_periph, uint32_t pecstate)
{
/* on/off PEC calculation */
uint32_t ctl = 0U;
@@ -475,19 +471,20 @@ void i2c_pec_enable(uint32_t i2c_periph,uint32_t pecstate)
}
/*!
- \brief I2C whether to transfer PEC value
+ \brief configure whether to transfer PEC value
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] pecpara:
only one parameter can be selected which is shown as below:
- \arg I2C_PECTRANS_ENABLE: transfer PEC
- \arg I2C_PECTRANS_DISABLE: not transfer PEC
+ \arg I2C_PECTRANS_ENABLE: transfer PEC value
+ \arg I2C_PECTRANS_DISABLE: not transfer PEC value
\param[out] none
\retval none
*/
-void i2c_pec_transfer_enable(uint32_t i2c_periph,uint32_t pecpara)
+void i2c_pec_transfer_config(uint32_t i2c_periph, uint32_t pecpara)
{
/* whether to transfer PEC */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
ctl &= ~(I2C_CTL0_PECTRANS);
ctl |= pecpara;
@@ -495,31 +492,31 @@ void i2c_pec_transfer_enable(uint32_t i2c_periph,uint32_t pecpara)
}
/*!
- \brief get packet error checking value
+ \brief get packet error checking value
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval PEC value
*/
uint8_t i2c_pec_value_get(uint32_t i2c_periph)
{
- return (uint8_t)((I2C_STAT1(i2c_periph) &I2C_STAT1_ECV) >> STAT1_PECV_OFFSET);
+ return (uint8_t)((I2C_STAT1(i2c_periph) & I2C_STAT1_PECV) >> STAT1_PECV_OFFSET);
}
/*!
- \brief I2C issue alert through SMBA pin
+ \brief configure I2C alert through SMBA pin
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] smbuspara:
only one parameter can be selected which is shown as below:
- \arg I2C_SALTSEND_ENABLE: issue alert through SMBA pin
- \arg I2C_SALTSEND_DISABLE: not issue alert through SMBA pin
+ \arg I2C_SALTSEND_ENABLE: issue alert through SMBA pin
+ \arg I2C_SALTSEND_DISABLE: not issue alert through SMBA pin
\param[out] none
\retval none
*/
-void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara)
+void i2c_smbus_alert_config(uint32_t i2c_periph, uint32_t smbuspara)
{
- /* issue alert through SMBA pin configure*/
+ /* configure smbus alert through SMBA pin */
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL0(i2c_periph);
ctl &= ~(I2C_CTL0_SALT);
ctl |= smbuspara;
@@ -527,7 +524,7 @@ void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara)
}
/*!
- \brief enable or disable I2C ARP protocol in SMBus switch
+ \brief configure I2C ARP protocol in SMBus
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] arpstate:
only one parameter can be selected which is shown as below:
@@ -536,11 +533,11 @@ void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara)
\param[out] none
\retval none
*/
-void i2c_smbus_arp_enable(uint32_t i2c_periph,uint32_t arpstate)
+void i2c_smbus_arp_config(uint32_t i2c_periph, uint32_t arpstate)
{
/* enable or disable I2C ARP protocol*/
uint32_t ctl = 0U;
-
+
ctl = I2C_CTL0(i2c_periph);
ctl &= ~(I2C_CTL0_ARPEN);
ctl |= arpstate;
@@ -552,23 +549,23 @@ void i2c_smbus_arp_enable(uint32_t i2c_periph,uint32_t arpstate)
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] flag: I2C flags, refer to i2c_flag_enum
only one parameter can be selected which is shown as below:
- \arg I2C_FLAG_SBSEND: start condition send out
+ \arg I2C_FLAG_SBSEND: start condition sent out in master mode
\arg I2C_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode
\arg I2C_FLAG_BTC: byte transmission finishes
\arg I2C_FLAG_ADD10SEND: header of 10-bit address is sent in master mode
\arg I2C_FLAG_STPDET: stop condition detected in slave mode
- \arg I2C_FLAG_RBNE: I2C_DATA is not Empty during receiving
+ \arg I2C_FLAG_RBNE: I2C_DATA is not empty during receiving
\arg I2C_FLAG_TBE: I2C_DATA is empty during transmitting
\arg I2C_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus
\arg I2C_FLAG_LOSTARB: arbitration lost in master mode
\arg I2C_FLAG_AERR: acknowledge error
- \arg I2C_FLAG_OUERR: overrun or underrun situation occurs in slave mode
+ \arg I2C_FLAG_OUERR: over-run or under-run situation occurs in slave mode
\arg I2C_FLAG_PECERR: PEC error when receiving data
\arg I2C_FLAG_SMBTO: timeout signal in SMBus mode
\arg I2C_FLAG_SMBALT: SMBus alert status
\arg I2C_FLAG_MASTER: a flag indicating whether I2C block is in master or slave mode
\arg I2C_FLAG_I2CBSY: busy flag
- \arg I2C_FLAG_TRS: whether the I2C is a transmitter or a receiver
+ \arg I2C_FLAG_TR: whether the I2C is a transmitter or a receiver
\arg I2C_FLAG_RXGC: general call address (00h) received
\arg I2C_FLAG_DEFSMB: default address of SMBus device
\arg I2C_FLAG_HSTSMB: SMBus host header detected in slave mode
@@ -578,36 +575,36 @@ void i2c_smbus_arp_enable(uint32_t i2c_periph,uint32_t arpstate)
*/
FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag)
{
- if(RESET != (I2C_REG_VAL(i2c_periph, flag) & BIT(I2C_BIT_POS(flag)))){
+ if(RESET != (I2C_REG_VAL(i2c_periph, flag) & BIT(I2C_BIT_POS(flag)))) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear I2C flag
+ \brief clear I2C flag status
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] flag: I2C flags, refer to i2c_flag_enum
only one parameter can be selected which is shown as below:
- \arg I2C_FLAG_SMBALT: SMBus Alert status
+ \arg I2C_FLAG_SMBALT: SMBus alert status
\arg I2C_FLAG_SMBTO: timeout signal in SMBus mode
\arg I2C_FLAG_PECERR: PEC error when receiving data
- \arg I2C_FLAG_OUERR: over-run or under-run situation occurs in slave mode
+ \arg I2C_FLAG_OUERR: over-run or under-run situation occurs in slave mode
\arg I2C_FLAG_AERR: acknowledge error
- \arg I2C_FLAG_LOSTARB: arbitration lost in master mode
- \arg I2C_FLAG_BERR: a bus error
- \arg I2C_FLAG_ADDSEND: cleared by reading I2C_STAT0 and reading I2C_STAT1
+ \arg I2C_FLAG_LOSTARB: arbitration lost in master mode
+ \arg I2C_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus
+ \arg I2C_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode
\param[out] none
\retval none
*/
void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag)
{
- if(I2C_FLAG_ADDSEND == flag){
+ if(I2C_FLAG_ADDSEND == flag) {
/* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
I2C_STAT0(i2c_periph);
I2C_STAT1(i2c_periph);
- }else{
+ } else {
I2C_REG_VAL(i2c_periph, flag) &= ~BIT(I2C_BIT_POS(flag));
}
}
@@ -617,9 +614,9 @@ void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag)
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] interrupt: I2C interrupts, refer to i2c_interrupt_enum
only one parameter can be selected which is shown as below:
- \arg I2C_INT_ERR: error interrupt enable
- \arg I2C_INT_EV: event interrupt enable
- \arg I2C_INT_BUF: buffer interrupt enable
+ \arg I2C_INT_ERR: error interrupt
+ \arg I2C_INT_EV: event interrupt
+ \arg I2C_INT_BUF: buffer interrupt
\param[out] none
\retval none
*/
@@ -631,11 +628,11 @@ void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
/*!
\brief disable I2C interrupt
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] interrupt: I2C interrupts, refer to i2c_flag_enum
+ \param[in] interrupt: I2C interrupts, refer to i2c_interrupt_enum
only one parameter can be selected which is shown as below:
- \arg I2C_INT_ERR: error interrupt enable
- \arg I2C_INT_EV: event interrupt enable
- \arg I2C_INT_BUF: buffer interrupt enable
+ \arg I2C_INT_ERR: error interrupt
+ \arg I2C_INT_EV: event interrupt
+ \arg I2C_INT_BUF: buffer interrupt
\param[out] none
\retval none
*/
@@ -645,15 +642,15 @@ void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
}
/*!
- \brief check I2C interrupt flag
+ \brief get I2C interrupt flag status
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] int_flag: I2C interrupt flags, refer to i2c_interrupt_flag_enum
only one parameter can be selected which is shown as below:
\arg I2C_INT_FLAG_SBSEND: start condition sent out in master mode interrupt flag
\arg I2C_INT_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode interrupt flag
- \arg I2C_INT_FLAG_BTC: byte transmission finishes
+ \arg I2C_INT_FLAG_BTC: byte transmission finishes interrupt flag
\arg I2C_INT_FLAG_ADD10SEND: header of 10-bit address is sent in master mode interrupt flag
- \arg I2C_INT_FLAG_STPDET: etop condition detected in slave mode interrupt flag
+ \arg I2C_INT_FLAG_STPDET: stop condition detected in slave mode interrupt flag
\arg I2C_INT_FLAG_RBNE: I2C_DATA is not Empty during receiving interrupt flag
\arg I2C_INT_FLAG_TBE: I2C_DATA is empty during transmitting interrupt flag
\arg I2C_INT_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus interrupt flag
@@ -662,40 +659,40 @@ void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
\arg I2C_INT_FLAG_OUERR: over-run or under-run situation occurs in slave mode interrupt flag
\arg I2C_INT_FLAG_PECERR: PEC error when receiving data interrupt flag
\arg I2C_INT_FLAG_SMBTO: timeout signal in SMBus mode interrupt flag
- \arg I2C_INT_FLAG_SMBALT: SMBus Alert status interrupt flag
+ \arg I2C_INT_FLAG_SMBALT: SMBus alert status interrupt flag
\param[out] none
- \retval FlagStatus SET or RESET
+ \retval FlagStatus: SET or RESET
*/
FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag)
{
uint32_t intenable = 0U, flagstatus = 0U, bufie;
-
+
/* check BUFIE */
bufie = I2C_CTL1(i2c_periph)&I2C_CTL1_BUFIE;
-
+
/* get the interrupt enable bit status */
intenable = (I2C_REG_VAL(i2c_periph, int_flag) & BIT(I2C_BIT_POS(int_flag)));
/* get the corresponding flag bit status */
flagstatus = (I2C_REG_VAL2(i2c_periph, int_flag) & BIT(I2C_BIT_POS2(int_flag)));
- if((I2C_INT_FLAG_RBNE == int_flag) || (I2C_INT_FLAG_TBE == int_flag)){
- if(intenable && bufie){
+ if((I2C_INT_FLAG_RBNE == int_flag) || (I2C_INT_FLAG_TBE == int_flag)) {
+ if(intenable && bufie) {
intenable = 1U;
- }else{
+ } else {
intenable = 0U;
}
}
- if((0U != flagstatus) && (0U != intenable)){
+ if((0U != flagstatus) && (0U != intenable)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear I2C interrupt flag
+ \brief clear I2C interrupt flag status
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] intflag: I2C interrupt flags, refer to i2c_interrupt_flag_enum
+ \param[in] int_flag: I2C interrupt flags, refer to i2c_interrupt_flag_enum
only one parameter can be selected which is shown as below:
\arg I2C_INT_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode interrupt flag
\arg I2C_INT_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus interrupt flag
@@ -704,17 +701,17 @@ FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph, i2c_interrupt_flag_enum i
\arg I2C_INT_FLAG_OUERR: over-run or under-run situation occurs in slave mode interrupt flag
\arg I2C_INT_FLAG_PECERR: PEC error when receiving data interrupt flag
\arg I2C_INT_FLAG_SMBTO: timeout signal in SMBus mode interrupt flag
- \arg I2C_INT_FLAG_SMBALT: SMBus Alert status interrupt flag
+ \arg I2C_INT_FLAG_SMBALT: SMBus alert status interrupt flag
\param[out] none
\retval none
*/
void i2c_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag)
{
- if(I2C_INT_FLAG_ADDSEND == int_flag){
+ if(I2C_INT_FLAG_ADDSEND == int_flag) {
/* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
I2C_STAT0(i2c_periph);
I2C_STAT1(i2c_periph);
- }else{
+ } else {
I2C_REG_VAL2(i2c_periph, int_flag) &= ~BIT(I2C_BIT_POS2(int_flag));
}
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_misc.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_misc.c
index 4a45def..2f0fe09 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_misc.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_misc.c
@@ -2,36 +2,33 @@
\file gd32f20x_misc.c
\brief MISC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -40,11 +37,11 @@ OF SUCH DAMAGE.
/*!
\brief set the priority group
\param[in] nvic_prigroup: the NVIC priority group
- \arg NVIC_PRIGROUP_PRE0_SUB4:0 bits for pre-emption priority 4 bits for subpriority
- \arg NVIC_PRIGROUP_PRE1_SUB3:1 bits for pre-emption priority 3 bits for subpriority
- \arg NVIC_PRIGROUP_PRE2_SUB2:2 bits for pre-emption priority 2 bits for subpriority
- \arg NVIC_PRIGROUP_PRE3_SUB1:3 bits for pre-emption priority 1 bits for subpriority
- \arg NVIC_PRIGROUP_PRE4_SUB0:4 bits for pre-emption priority 0 bits for subpriority
+ \arg NVIC_PRIGROUP_PRE0_SUB4: 0 bits for pre-emption priority, 4 bits for subpriority
+ \arg NVIC_PRIGROUP_PRE1_SUB3: 1 bits for pre-emption priority, 3 bits for subpriority
+ \arg NVIC_PRIGROUP_PRE2_SUB2: 2 bits for pre-emption priority, 2 bits for subpriority
+ \arg NVIC_PRIGROUP_PRE3_SUB1: 3 bits for pre-emption priority, 1 bits for subpriority
+ \arg NVIC_PRIGROUP_PRE4_SUB0: 4 bits for pre-emption priority, 0 bits for subpriority
\param[out] none
\retval none
*/
@@ -55,21 +52,21 @@ void nvic_priority_group_set(uint32_t nvic_prigroup)
}
/*!
- \brief enable NVIC request
+ \brief enable NVIC interrupt request
\param[in] nvic_irq: the NVIC interrupt request, detailed in IRQn_Type
\param[in] nvic_irq_pre_priority: the pre-emption priority needed to set
\param[in] nvic_irq_sub_priority: the subpriority needed to set
\param[out] none
\retval none
*/
-void nvic_irq_enable(uint8_t nvic_irq,
- uint8_t nvic_irq_pre_priority,
+void nvic_irq_enable(uint8_t nvic_irq,
+ uint8_t nvic_irq_pre_priority,
uint8_t nvic_irq_sub_priority)
{
uint32_t temp_priority = 0x00U, temp_pre = 0x00U, temp_sub = 0x00U;
/* use the priority group value to get the temp_pre and the temp_sub */
- switch ((SCB->AIRCR) & (uint32_t)0x700U) {
+ switch((SCB->AIRCR) & (uint32_t)0x700U) {
case NVIC_PRIGROUP_PRE0_SUB4:
temp_pre = 0U;
temp_sub = 0x4U;
@@ -99,7 +96,7 @@ void nvic_irq_enable(uint8_t nvic_irq,
/* get the temp_priority to fill the NVIC->IP register */
temp_priority = (uint32_t)nvic_irq_pre_priority << (0x4U - temp_pre);
- temp_priority |= nvic_irq_sub_priority &(0x0FU >> (0x4U - temp_sub));
+ temp_priority |= nvic_irq_sub_priority & (0x0FU >> (0x4U - temp_sub));
temp_priority = temp_priority << 0x04U;
NVIC->IP[nvic_irq] = (uint8_t)temp_priority;
@@ -108,7 +105,7 @@ void nvic_irq_enable(uint8_t nvic_irq,
}
/*!
- \brief disable NVIC request
+ \brief disable NVIC interrupt request
\param[in] nvic_irq: the NVIC interrupt request, detailed in IRQn_Type
\param[out] none
\retval none
@@ -124,22 +121,24 @@ void nvic_irq_disable(uint8_t nvic_irq)
\param[in] nvic_vict_tab: the RAM or FLASH base address
\arg NVIC_VECTTAB_RAM: RAM base address
\are NVIC_VECTTAB_FLASH: Flash base address
- \param[in] offset: Vector Table offset
+ \param[in] offset: vector table offset
\param[out] none
\retval none
*/
void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset)
{
SCB->VTOR = nvic_vict_tab | (offset & NVIC_VECTTAB_OFFSET_MASK);
+
+ __DSB();
}
/*!
\brief set the state of the low power mode
\param[in] lowpower_mode: the low power mode state
- \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system always enter low power
+ \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system always enter low power
mode by exiting from ISR
\arg SCB_LPM_DEEPSLEEP: if chose this para, the system will enter the DEEPSLEEP mode
- \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the lowpower mode can be woke up
+ \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the low power mode can be woke up
by all the enable and disable interrupts
\param[out] none
\retval none
@@ -152,10 +151,10 @@ void system_lowpower_set(uint8_t lowpower_mode)
/*!
\brief reset the state of the low power mode
\param[in] lowpower_mode: the low power mode state
- \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system will exit low power
+ \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system will exit low power
mode by exiting from ISR
\arg SCB_LPM_DEEPSLEEP: if chose this para, the system will enter the SLEEP mode
- \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the lowpower mode only can be
+ \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the low power mode only can be
woke up by the enable interrupts
\param[out] none
\retval none
@@ -176,10 +175,10 @@ void system_lowpower_reset(uint8_t lowpower_mode)
void systick_clksource_set(uint32_t systick_clksource)
{
- if(SYSTICK_CLKSOURCE_HCLK == systick_clksource ){
+ if(SYSTICK_CLKSOURCE_HCLK == systick_clksource) {
/* set the systick clock source from HCLK */
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
- }else{
+ } else {
/* set the systick clock source from HCLK/8 */
SysTick->CTRL &= SYSTICK_CLKSOURCE_HCLK_DIV8;
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_pmu.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_pmu.c
index f66e5fc..e284d06 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_pmu.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_pmu.c
@@ -2,36 +2,33 @@
\file gd32f20x_pmu.c
\brief PMU driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -90,7 +87,7 @@ void pmu_lvd_disable(void)
}
/*!
- \brief PMU work at sleep mode
+ \brief PMU work in sleep mode
\param[in] sleepmodecmd:
only one parameter can be selected which is shown as below:
\arg WFI_CMD: use WFI command
@@ -102,98 +99,96 @@ void pmu_to_sleepmode(uint8_t sleepmodecmd)
{
/* clear sleepdeep bit of Cortex-M3 system control register */
SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
-
+
/* select WFI or WFE command to enter sleep mode */
- if(WFI_CMD == sleepmodecmd){
+ if(WFI_CMD == sleepmodecmd) {
__WFI();
- }else{
+ } else {
__WFE();
}
}
/*!
- \brief PMU work at deepsleep mode
+ \brief PMU work in deepsleep mode
\param[in] ldo:
only one parameter can be selected which is shown as below:
\arg PMU_LDO_NORMAL: LDO work at normal power mode when pmu enter deepsleep mode
\arg PMU_LDO_LOWPOWER: LDO work at low power mode when pmu enter deepsleep mode
\param[in] deepsleepmodecmd:
- only one parameter can be selected which is shown as below:
+ only one parameter can be selected which is shown as below:
\arg WFI_CMD: use WFI command
\arg WFE_CMD: use WFE command
\param[out] none
\retval none
*/
-void pmu_to_deepsleepmode(uint32_t ldo,uint8_t deepsleepmodecmd)
+void pmu_to_deepsleepmode(uint32_t ldo, uint8_t deepsleepmodecmd)
{
- static uint32_t reg_snap[ 4 ];
+ static uint32_t reg_snap[4];
/* clear stbmod and ldolp bits */
PMU_CTL &= ~((uint32_t)(PMU_CTL_STBMOD | PMU_CTL_LDOLP));
-
+
/* set ldolp bit according to pmu_ldo */
PMU_CTL |= ldo;
-
+
/* set sleepdeep bit of Cortex-M3 system control register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
- reg_snap[ 0 ] = REG32( 0xE000E010U );
- reg_snap[ 1 ] = REG32( 0xE000E100U );
- reg_snap[ 2 ] = REG32( 0xE000E104U );
- reg_snap[ 3 ] = REG32( 0xE000E108U );
-
- REG32( 0xE000E010U ) &= 0x00010004U;
- REG32( 0xE000E180U ) = 0XFF7FF83DU;
- REG32( 0xE000E184U ) = 0XBFFFF8FFU;
- REG32( 0xE000E188U ) = 0xFFFFFFFFU;
-
+ reg_snap[0] = REG32(0xE000E010U);
+ reg_snap[1] = REG32(0xE000E100U);
+ reg_snap[2] = REG32(0xE000E104U);
+ reg_snap[3] = REG32(0xE000E108U);
+
+ REG32(0xE000E010U) &= 0x00010004U;
+ REG32(0xE000E180U) = 0XFF7FF83DU;
+ REG32(0xE000E184U) = 0XBFFFF8FFU;
+ REG32(0xE000E188U) = 0xFFFFFFFFU;
+
/* select WFI or WFE command to enter deepsleep mode */
- if(WFI_CMD == deepsleepmodecmd){
+ if(WFI_CMD == deepsleepmodecmd) {
__WFI();
- }else{
+ } else {
__SEV();
__WFE();
__WFE();
}
-
- REG32( 0xE000E010U ) = reg_snap[ 0 ] ;
- REG32( 0xE000E100U ) = reg_snap[ 1 ] ;
- REG32( 0xE000E104U ) = reg_snap[ 2 ] ;
- REG32( 0xE000E108U ) = reg_snap[ 3 ] ;
-
+
+ REG32(0xE000E010U) = reg_snap[0] ;
+ REG32(0xE000E100U) = reg_snap[1] ;
+ REG32(0xE000E104U) = reg_snap[2] ;
+ REG32(0xE000E108U) = reg_snap[3] ;
+
/* reset sleepdeep bit of Cortex-M3 system control register */
SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
}
/*!
- \brief pmu work at standby mode
- \param[in] standbymodecmd:
- only one parameter can be selected which is shown as below:
- \arg WFI_CMD: use WFI command
- \arg WFE_CMD: use WFE command
+ \brief pmu work in standby mode
+ \param[in] none
\param[out] none
\retval none
*/
-void pmu_to_standbymode(uint8_t standbymodecmd)
+void pmu_to_standbymode(void)
{
- /* set sleepdeep bit of Cortex-M3 system control register */
- SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
-
/* set stbmod bit */
PMU_CTL |= PMU_CTL_STBMOD;
-
+
/* reset wakeup flag */
PMU_CTL |= PMU_CTL_WURST;
-
+
+ /* set sleepdeep bit of Cortex-M3 system control register */
+ SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+
+ REG32(0xE000E010U) &= 0x00010004U;
+ REG32(0xE000E180U) = 0XFFFFFFF7U;
+ REG32(0xE000E184U) = 0XFFFFFDFFU;
+ REG32(0xE000E188U) = 0xFFFFFFFFU;
+
/* select WFI or WFE command to enter standby mode */
- if(WFI_CMD == standbymodecmd){
- __WFI();
- }else{
- __WFE();
- }
+ __WFI();
}
/*!
- \brief enable wakeup pin
+ \brief enable PMU wakeup pin
\param[in] none
\param[out] none
\retval none
@@ -204,7 +199,7 @@ void pmu_wakeup_pin_enable(void)
}
/*!
- \brief disable wakeup pin
+ \brief disable PMU wakeup pin
\param[in] none
\param[out] none
\retval none
@@ -248,25 +243,25 @@ void pmu_backup_write_disable(void)
*/
FlagStatus pmu_flag_get(uint32_t flag)
{
- if(PMU_CS & flag){
+ if(PMU_CS & flag) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
\brief clear flag bit
- \param[in] flag_reset:
+ \param[in] flag:
only one parameter can be selected which is shown as below:
\arg PMU_FLAG_RESET_WAKEUP: reset wakeup flag
\arg PMU_FLAG_RESET_STANDBY: reset standby flag
\param[out] none
\retval none
*/
-void pmu_flag_clear(uint32_t flag_reset)
+void pmu_flag_clear(uint32_t flag)
{
- switch(flag_reset){
+ switch(flag) {
case PMU_FLAG_RESET_WAKEUP:
/* reset wakeup flag */
PMU_CTL |= PMU_CTL_WURST;
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rcu.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rcu.c
index 69e3341..3f7bc64 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rcu.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rcu.c
@@ -2,36 +2,33 @@
\file gd32f20x_rcu.c
\brief RCU driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -58,16 +55,20 @@ void rcu_deinit(void)
RCU_CTL |= RCU_CTL_IRC8MEN;
rcu_osci_stab_wait(RCU_IRC8M);
+ RCU_CFG0 &= ~RCU_CFG0_SCS;
+ /* reset HXTALEN, CKMEN, PLLEN bits */
+ RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
+
/* reset SCS, AHBPSC, APB1PSC, APB2PSC, ADCPSC, CKOUT0SEL bits */
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC | RCU_CFG0_APB2PSC |
RCU_CFG0_ADCPSC | RCU_CFG0_ADCPSC_2 | RCU_CFG0_CKOUT0SEL);
/* reset HXTALEN, CKMEN, PLLEN bits */
- RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN );
+ RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN);
/* Reset HXTALBPS bit */
RCU_CTL &= ~(RCU_CTL_HXTALBPS);
-
+
/* reset PLLSEL, PREDV0_LSB, PLLMF, USBFSPSC bits */
RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PREDV0_LSB | RCU_CFG0_PLLMF |
RCU_CFG0_USBFSPSC | RCU_CFG0_PLLMF_4);
@@ -77,16 +78,16 @@ void rcu_deinit(void)
/* reset CFG1 register */
RCU_CFG1 = 0x00000000U;
-
+
/* reset INT register */
RCU_INT = 0x00FF0000U;
-
+
/* reset CFG2 register */
RCU_CFG2 = 0x00000000U;
-
+
/* reset PLLTCTL register */
- RCU_PLLTCTL &= (~RCU_PLLTCTL_PLLTEN);
-
+ RCU_PLLTCTL &= (~RCU_PLLTCTL_PLLTEN);
+
/* reset PLLTINT register */
RCU_PLLTINT = 0x00400000U;
@@ -217,7 +218,7 @@ void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph)
\arg RCU_CANxRST (x=0,1): reset CAN
\arg RCU_PMURST: reset PMU
\arg RCU_DACRST: reset DAC
- \arg RCU_ADCRST (x=0,1,2): reset ADC
+ \arg RCU_ADCxRST (x=0,1,2): reset ADC
\arg RCU_BKPIRST: reset BKPI
\arg RCU_TLIRST: reset TLI
\arg RCU_DCIRST: reset DCI
@@ -249,7 +250,7 @@ void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset)
\arg RCU_CANxRST (x=0,1): reset CAN
\arg RCU_PMURST: reset PMU
\arg RCU_DACRST: reset DAC
- \arg RCU_ADCRST (x=0,1,2): reset ADC
+ \arg RCU_ADCxRST (x=0,1,2): reset ADC
\arg RCU_BKPIRST: reset BKPI
\arg RCU_TLIRST: reset TLI
\arg RCU_DCIRST: reset DCI
@@ -299,7 +300,7 @@ void rcu_bkp_reset_disable(void)
void rcu_system_clock_source_config(uint32_t ck_sys)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the SCS bits and set according to ck_sys */
reg &= ~RCU_CFG0_SCS;
@@ -324,14 +325,14 @@ uint32_t rcu_system_clock_source_get(void)
\brief configure the AHB clock prescaler selection
\param[in] ck_ahb: AHB clock prescaler selection
only one parameter can be selected which is shown as below:
- \arg RCU_AHB_CKSYS_DIVx, x=1, 2, 4, 8, 16, 64, 128, 256, 512
+\arg RCU_AHB_CKSYS_DIVx (x=1, 2, 4, 8, 16, 64, 128, 256, 512): select CK_SYS / x as CK_AHB
\param[out] none
\retval none
*/
void rcu_ahb_clock_config(uint32_t ck_ahb)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the AHBPSC bits and set according to ck_ahb */
@@ -354,7 +355,7 @@ void rcu_ahb_clock_config(uint32_t ck_ahb)
void rcu_apb1_clock_config(uint32_t ck_apb1)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the APB1PSC and set according to ck_apb1 */
@@ -377,7 +378,7 @@ void rcu_apb1_clock_config(uint32_t ck_apb1)
void rcu_apb2_clock_config(uint32_t ck_apb2)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the APB2PSC and set according to ck_apb2 */
@@ -398,7 +399,7 @@ void rcu_apb2_clock_config(uint32_t ck_apb2)
\arg RCU_CKOUT0SRC_CKPLL2_DIV2: CK_PLL2/2 selected
\arg RCU_CKOUT0SRC_EXT1: EXT1 selected
\arg RCU_CKOUT0SRC_CKPLL2: PLL selected
- \param[in] ckout0_div: CK_OUT0 divider
+ \param[in] ckout0_div: CK_OUT0 divider
\arg RCU_CKOUT0_DIVx(x=1..64): CK_OUT0 is divided by x
\param[out] none
\retval none
@@ -406,15 +407,15 @@ void rcu_apb2_clock_config(uint32_t ck_apb2)
void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
-
+
/* set the CKOUT0SEL according to ckout0_src */
reg &= ~RCU_CFG0_CKOUT0SEL;
RCU_CFG0 = (reg | ckout0_src);
-
+
reg = RCU_CFG2;
-
+
/* set the CKOUT0DIV according to ckout0_div */
reg &= ~RCU_CFG2_CKOUT0DIV;
RCU_CFG2 = (reg | ckout0_div);
@@ -433,7 +434,7 @@ void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div)
\arg RCU_CKOUT1SRC_CKPLL2_DIV2: CK_PLL2/2 selected
\arg RCU_CKOUT1SRC_EXT1: EXT1 selected
\arg RCU_CKOUT1SRC_CKPLL2: PLL selected
- \param[in] ckout1_div: CK_OUT1 divider
+ \param[in] ckout1_div: CK_OUT1 divider
\arg RCU_CKOUT1_DIVx(x=1..64): CK_OUT1 is divided by x
\param[out] none
\retval none
@@ -441,7 +442,7 @@ void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div)
void rcu_ckout1_config(uint32_t ckout1_src, uint32_t ckout1_div)
{
uint32_t reg;
-
+
reg = RCU_CFG2;
/* set the CKOUT1SEL and CKOUT1DIV according to ckout1_src and ckout1_div */
reg &= ~(RCU_CFG2_CKOUT1SEL | RCU_CFG2_CKOUT1DIV);
@@ -450,12 +451,12 @@ void rcu_ckout1_config(uint32_t ckout1_src, uint32_t ckout1_div)
}
/*!
- \brief configure the main PLL clock
+ \brief configure the main PLL clock
\param[in] pll_src: PLL clock source selection
\arg RCU_PLLSRC_IRC8M_DIV2: IRC8M/2 clock selected as source clock of PLL
\arg RCU_PLLSRC_HXTAL: HXTAL selected as source clock of PLL
\param[in] pll_mul: PLL clock multiplication factor
- \arg RCU_PLL_MULx (x = 2..14,16..32,6.5)
+ \arg RCU_PLL_MULx (x = 2..14,16..32,6.5): PLL clock * x
\param[out] none
\retval none
*/
@@ -480,14 +481,14 @@ void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul)
\arg RCU_PREDV0SRC_CKPLL1: CK_PLL1 selected as PREDV0 input source clock
\param[in] predv0_div: PREDV0 division factor
only one parameter can be selected which is shown as below:
- \arg RCU_PREDV0_DIVx, x = 1..16
+ \arg RCU_PREDV0_DIVx (x= 1..16): PREDV0 input source clock is divided x
\param[out] none
\retval none
*/
void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div)
{
uint32_t reg = 0U;
-
+
reg = RCU_CFG1;
/* reset PREDV0SEL and PREDV0 bits */
reg &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV0);
@@ -501,14 +502,14 @@ void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div)
\brief configure the PREDV1 division factor
\param[in] predv1_div: PREDV1 division factor
only one parameter can be selected which is shown as below:
- \arg RCU_PREDV1_DIVx, x = 1..16
+ \arg RCU_PREDV1_DIVx (x = 1..16): PREDV1 input source clock is divided x
\param[out] none
\retval none
*/
void rcu_predv1_config(uint32_t predv1_div)
{
uint32_t reg = 0U;
-
+
reg = RCU_CFG1;
/* reset the PREDV1 bits */
reg &= ~RCU_CFG1_PREDV1;
@@ -519,10 +520,10 @@ void rcu_predv1_config(uint32_t predv1_div)
}
/*!
- \brief configure the PLL1 clock
+ \brief configure the PLL1 clock
\param[in] pll_mul: PLL clock multiplication factor
only one parameter can be selected which is shown as below:
- \arg RCU_PLL1_MULx (x = 8..16, 20)
+ \arg RCU_PLL1_MULx (x = 8..16, 20): PLL1 clock * x
\param[out] none
\retval none
*/
@@ -533,17 +534,17 @@ void rcu_pll1_config(uint32_t pll_mul)
}
/*!
- \brief configure the PLL2 clock
+ \brief configure the PLL2 clock
\param[in] pll_mul: PLL clock multiplication factor
only one parameter can be selected which is shown as below:
- \arg RCU_PLL2_MULx (x = 8..16, 20)
+ \arg RCU_PLL2_MULx (x = 8..16, 20): PLL2 clock * x
\param[out] none
\retval none
*/
void rcu_pll2_config(uint32_t pll_mul)
{
RCU_CFG1 &= ~RCU_CFG1_PLL2MF;
- RCU_CFG1 |= pll_mul;
+ RCU_CFG1 |= pll_mul;
}
/*!
@@ -568,22 +569,22 @@ void rcu_adc_clock_config(uint32_t adc_psc)
reg0 &= ~(RCU_CFG0_ADCPSC_2 | RCU_CFG0_ADCPSC);
/* set the ADC prescaler factor */
- switch(adc_psc){
- case RCU_CKADC_CKAPB2_DIV2:
- case RCU_CKADC_CKAPB2_DIV4:
- case RCU_CKADC_CKAPB2_DIV6:
- case RCU_CKADC_CKAPB2_DIV8:
- reg0 |= (adc_psc << 14);
- break;
-
- case RCU_CKADC_CKAPB2_DIV12:
- case RCU_CKADC_CKAPB2_DIV16:
- adc_psc &= ~BIT(2);
- reg0 |= (adc_psc << 14 | RCU_CFG0_ADCPSC_2);
- break;
-
- default:
- break;
+ switch(adc_psc) {
+ case RCU_CKADC_CKAPB2_DIV2:
+ case RCU_CKADC_CKAPB2_DIV4:
+ case RCU_CKADC_CKAPB2_DIV6:
+ case RCU_CKADC_CKAPB2_DIV8:
+ reg0 |= (adc_psc << 14);
+ break;
+
+ case RCU_CKADC_CKAPB2_DIV12:
+ case RCU_CKADC_CKAPB2_DIV16:
+ adc_psc &= ~BIT(2);
+ reg0 |= (adc_psc << 14 | RCU_CFG0_ADCPSC_2);
+ break;
+
+ default:
+ break;
}
/* set the register */
@@ -603,7 +604,7 @@ void rcu_adc_clock_config(uint32_t adc_psc)
void rcu_usbfs_trng_clock_config(uint32_t usbfs_trng_psc)
{
uint32_t reg = 0U;
-
+
reg = RCU_CFG0;
/* configure the USBFS/TRNG prescaler factor */
@@ -611,7 +612,6 @@ void rcu_usbfs_trng_clock_config(uint32_t usbfs_trng_psc)
RCU_CFG0 = (reg | usbfs_trng_psc);
}
-
/*!
\brief configure the RTC clock source selection
\param[in] rtc_clock_source: RTC clock source selection
@@ -626,8 +626,8 @@ void rcu_usbfs_trng_clock_config(uint32_t usbfs_trng_psc)
void rcu_rtc_clock_config(uint32_t rtc_clock_source)
{
uint32_t reg;
-
- reg = RCU_BDCTL;
+
+ reg = RCU_BDCTL;
/* reset the RTCSRC bits and set according to rtc_clock_source */
reg &= ~RCU_BDCTL_RTCSRC;
RCU_BDCTL = (reg | rtc_clock_source);
@@ -645,8 +645,8 @@ void rcu_rtc_clock_config(uint32_t rtc_clock_source)
void rcu_i2s1_clock_config(uint32_t i2s_clock_source)
{
uint32_t reg;
-
- reg = RCU_CFG1;
+
+ reg = RCU_CFG1;
/* reset the I2S1SEL bit and set according to i2s_clock_source */
reg &= ~RCU_CFG1_I2S1SEL;
RCU_CFG1 = (reg | i2s_clock_source);
@@ -664,140 +664,98 @@ void rcu_i2s1_clock_config(uint32_t i2s_clock_source)
void rcu_i2s2_clock_config(uint32_t i2s_clock_source)
{
uint32_t reg;
-
- reg = RCU_CFG1;
+
+ reg = RCU_CFG1;
/* reset the I2S2SEL bit and set according to i2s_clock_source */
reg &= ~RCU_CFG1_I2S2SEL;
RCU_CFG1 = (reg | i2s_clock_source);
}
/*!
- \brief get the clock stabilization and periphral reset flags
- \param[in] flag: the clock stabilization and periphral reset flags, refer to rcu_flag_enum
- only one parameter can be selected which is shown as below:
- \arg RCU_FLAG_IRC8MSTB: IRC8M stabilization flag
- \arg RCU_FLAG_HXTALSTB: HXTAL stabilization flag
- \arg RCU_FLAG_PLLSTB: PLL stabilization flag
- \arg RCU_FLAG_PLL1STB: PLL1 stabilization flag
- \arg RCU_FLAG_PLL2STB: PLL2 stabilization flag
- \arg RCU_FLAG_PLLTSTB: PLLT stabilization flag
- \arg RCU_FLAG_LXTALSTB: LXTAL stabilization flag
- \arg RCU_FLAG_IRC40KSTB: IRC40K stabilization flag
- \arg RCU_FLAG_EPRST: external PIN reset flag
- \arg RCU_FLAG_PORRST: power reset flag
- \arg RCU_FLAG_SWRST: software reset flag
- \arg RCU_FLAG_FWDGTRST: free watchdog timer reset flag
- \arg RCU_FLAG_WWDGTRST: window watchdog timer reset flag
- \arg RCU_FLAG_LPRST: low-power reset flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus rcu_flag_get(rcu_flag_enum flag)
-{
- /* get the rcu flag */
- if(RESET != (RCU_REG_VAL(flag) & BIT(RCU_BIT_POS(flag)))){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear all the reset flag
- \param[in] none
+ \brief configure the PLLT clock selection
+ \param[in] pllt_src: PLLT clock source selection
+ \arg RCU_PLLTSRC_IRC8M: IRC8M selected as source clock of PLLT
+ \arg RCU_PLLTSRC_HXTAL: HXTAL selected as source clock of PLLT
\param[out] none
\retval none
*/
-void rcu_all_reset_flag_clear(void)
+void rcu_pllt_config(uint32_t pllt_src)
{
- RCU_RSTSCK |= RCU_RSTSCK_RSTFC;
+ uint32_t reg = 0U;
+
+ reg = RCU_PLLTCFG;
+
+ /* reset the PLLT clock source bit PLLTSEL */
+ reg &= ~RCU_PLLTCFG_PLLTSEL;
+
+ RCU_PLLTCFG = (reg | pllt_src);
}
/*!
- \brief get the clock stabilization and ckm interrupt flags
- \param[in] int_flag: interrupt and ckm flags, refer to rcu_int_flag_enum
- only one parameter can be selected which is shown as below:
- \arg RCU_INT_FLAG_IRC40KSTB: IRC40K stabilization interrupt flag
- \arg RCU_INT_FLAG_LXTALSTB: LXTAL stabilization interrupt flag
- \arg RCU_INT_FLAG_IRC8MSTB: IRC8M stabilization interrupt flag
- \arg RCU_INT_FLAG_HXTALSTB: HXTAL stabilization interrupt flag
- \arg RCU_INT_FLAG_PLLSTB: PLL stabilization interrupt flag
- \arg RCU_INT_FLAG_PLL1STB: PLL1 stabilization interrupt flag
- \arg RCU_INT_FLAG_PLL2STB: PLL2 stabilization interrupt flag
- \arg RCU_INT_FLAG_CKM: HXTAL clock stuck interrupt flag
- \arg RCU_INT_FLAG_PLLTSTB: PLLT stabilization interrupt flag
+ \brief configure the PLLT clock multiplication and division factors
+ \param[in] pllt_psc: the PLLT VCO input clock division factor
+ \arg this parameter should be selected between 2 and 63. And this parameter should
+ be selected correctly to ensure that the VCO input frequency ranges from 1 to 2 MHz
+ \param[in] pllt_mul: he PLLT VCO output clock multiplication factor
+ \arg this parameter should be selected between 49 and 432
+ \param[in] ppltr_psc: the PLLTR division factor
+ \arg this parameter should be selected between 2 and 7
\param[out] none
- \retval FlagStatus: SET or RESET
+ \retval ErrStatus: SUCCESS or ERROR
*/
-FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag)
+ErrStatus rcu_pllt_vco_config(uint32_t pllt_psc, uint32_t pllt_mul, uint32_t ppltr_psc)
{
- /* get the rcu interrupt flag */
- if(RESET != (RCU_REG_VAL(int_flag) & BIT(RCU_BIT_POS(int_flag)))){
- return SET;
- }else{
- return RESET;
+ uint32_t reg = 0U;
+
+ /* check the function parameter */
+ if((pllt_psc < 2U) || (pllt_psc > 63U)) {
+ return ERROR;
+ } else {
}
-}
-/*!
- \brief clear the interrupt flags
- \param[in] int_flag_clear: clock stabilization and stuck interrupt flags clear, refer to rcu_int_flag_clear_enum
- only one parameter can be selected which is shown as below:
- \arg RCU_INT_FLAG_IRC40KSTB_CLR: IRC40K stabilization interrupt flag clear
- \arg RCU_INT_FLAG_LXTALSTB_CLR: LXTAL stabilization interrupt flag clear
- \arg RCU_INT_FLAG_IRC8MSTB_CLR: IRC8M stabilization interrupt flag clear
- \arg RCU_INT_FLAG_HXTALSTB_CLR: HXTAL stabilization interrupt flag clear
- \arg RCU_INT_FLAG_PLLSTB_CLR: PLL stabilization interrupt flag clear
- \arg RCU_INT_FLAG_PLL1STB_CLR: PLL1 stabilization interrupt flag clear
- \arg RCU_INT_FLAG_PLL2STB_CLR: PLL2 stabilization interrupt flag clear
- \arg RCU_INT_FLAG_CKM_CLR: clock stuck interrupt flag clear
- \arg RCU_INT_FLAG_PLLTSTB_CLR: PLLT stabilization interrupt flag clear
- \param[out] none
- \retval none
-*/
-void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear)
-{
- RCU_REG_VAL(int_flag_clear) |= BIT(RCU_BIT_POS(int_flag_clear));
-}
+ if((pllt_mul < 49U) || (pllt_mul > 432U)) {
+ return ERROR;
+ } else {
+ }
-/*!
- \brief enable the stabilization interrupt
- \param[in] stab_int: clock stabilization interrupt, refer to rcu_int_enum
- Only one parameter can be selected which is shown as below:
- \arg RCU_INT_IRC40KSTB: IRC40K stabilization interrupt enable
- \arg RCU_INT_LXTALSTB: LXTAL stabilization interrupt enable
- \arg RCU_INT_IRC8MSTB: IRC8M stabilization interrupt enable
- \arg RCU_INT_HXTALSTB: HXTAL stabilization interrupt enable
- \arg RCU_INT_PLLSTB: PLL stabilization interrupt enable
- \arg RCU_INT_PLL1STB: PLL1 stabilization interrupt enable
- \arg RCU_INT_PLL2STB: PLL2 stabilization interrupt enable
- \arg RCU_INT_PLLTSTB: PLLT stabilization interrupt enable
- \param[out] none
- \retval none
-*/
-void rcu_interrupt_enable(rcu_int_enum stab_int)
-{
- RCU_REG_VAL(stab_int) |= BIT(RCU_BIT_POS(stab_int));
+ if((ppltr_psc < 2U) || (ppltr_psc > 7U)) {
+ return ERROR;
+ } else {
+ }
+
+ reg = RCU_PLLTCFG;
+
+ /* reset the PLLTRPSC bits, PLLTMF bits and PLLTPSC bits */
+ reg &= ~(RCU_PLLTCFG_PLLTRPSC | RCU_PLLTCFG_PLLTMF | RCU_PLLTCFG_PLLTPSC);
+
+ reg |= (PLLTCFG_PLLTPSC(pllt_psc) | PLLTCFG_PLLTMF(pllt_mul) | PLLTCFG_PLLTRPSC(ppltr_psc));
+
+ RCU_PLLTCFG = reg;
+
+ return SUCCESS;
}
/*!
- \brief disable the stabilization interrupt
- \param[in] stab_int: clock stabilization interrupt, refer to rcu_int_enum
+ \brief configure the TLI prescaler factor from PLLTR clock
+ \param[in] tli_psc: TLI prescaler factor
only one parameter can be selected which is shown as below:
- \arg RCU_INT_IRC40KSTB: IRC40K stabilization interrupt enable
- \arg RCU_INT_LXTALSTB: LXTAL stabilization interrupt enable
- \arg RCU_INT_IRC8MSTB: IRC8M stabilization interrupt enable
- \arg RCU_INT_HXTALSTB: HXTAL stabilization interrupt enable
- \arg RCU_INT_PLLSTB: PLL stabilization interrupt enable
- \arg RCU_INT_PLL1STB: PLL1 stabilization interrupt enable
- \arg RCU_INT_PLL2STB: PLL2 stabilization interrupt enable
- \arg RCU_INT_PLLTSTB: PLLT stabilization interrupt enable
+ \arg RCU_CKTLI_CKPLLTR_DIV2: TLI prescaler select CK_PLLTR/2
+ \arg RCU_CKTLI_CKPLLTR_DIV4: TLI prescaler select CK_PLLTR/4
+ \arg RCU_CKTLI_CKPLLTR_DIV8: TLI prescaler select CK_PLLTR/8
+ \arg RCU_CKTLI_CKPLLTR_DIV16: TLI prescaler select CK_PLLTR/16
\param[out] none
\retval none
*/
-void rcu_interrupt_disable(rcu_int_enum stab_int)
+void rcu_tli_clock_config(uint32_t tli_psc)
{
- RCU_REG_VAL(stab_int) &= ~BIT(RCU_BIT_POS(stab_int));
+ uint32_t reg = 0U;
+
+ reg = RCU_PLLTCFG;
+
+ /* reset the TLIPSC bits */
+ reg &= ~RCU_PLLTCFG_TLIPSC;
+
+ RCU_PLLTCFG = (reg | tli_psc);
}
/*!
@@ -814,9 +772,9 @@ void rcu_interrupt_disable(rcu_int_enum stab_int)
void rcu_lxtal_drive_capability_config(uint32_t lxtal_dricap)
{
uint32_t reg;
-
+
reg = RCU_BDCTL;
-
+
/* reset the LXTALDRI bits and set according to lxtal_dricap */
reg &= ~RCU_BDCTL_LXTALDRI;
RCU_BDCTL = (reg | lxtal_dricap);
@@ -842,112 +800,112 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
uint32_t stb_cnt = 0U;
ErrStatus reval = ERROR;
FlagStatus osci_stat = RESET;
-
- switch(osci){
+
+ switch(osci) {
/* wait HXTAL stable */
case RCU_HXTAL:
- while((RESET == osci_stat) && (HXTAL_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (HXTAL_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_HXTALSTB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_HXTALSTB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_HXTALSTB)) {
reval = SUCCESS;
}
break;
/* wait LXTAL stable */
case RCU_LXTAL:
- while((RESET == osci_stat) && (LXTAL_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (LXTAL_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_LXTALSTB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_LXTALSTB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_LXTALSTB)) {
reval = SUCCESS;
}
break;
/* wait IRC8M stable */
case RCU_IRC8M:
- while((RESET == osci_stat) && (IRC8M_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (IRC8M_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_IRC8MSTB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_IRC8MSTB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_IRC8MSTB)) {
reval = SUCCESS;
}
break;
/* wait IRC40K stable */
case RCU_IRC40K:
- while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_IRC40KSTB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_IRC40KSTB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_IRC40KSTB)) {
reval = SUCCESS;
}
break;
/* wait PLL stable */
case RCU_PLL_CK:
- while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_PLLSTB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_PLLSTB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_PLLSTB)) {
reval = SUCCESS;
}
break;
/* wait PLL1 stable */
case RCU_PLL1_CK:
- while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_PLL1STB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_PLL1STB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_PLL1STB)) {
reval = SUCCESS;
}
break;
-
+
/* wait PLL2 stable */
case RCU_PLL2_CK:
- while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_PLL2STB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_PLL2STB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_PLL2STB)) {
reval = SUCCESS;
}
break;
/* wait PLLT stable */
case RCU_PLLT_CK:
- while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
+ while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)) {
osci_stat = rcu_flag_get(RCU_FLAG_PLLTSTB);
stb_cnt++;
}
/* check whether flag is set or not */
- if(RESET != rcu_flag_get(RCU_FLAG_PLLTSTB)){
+ if(RESET != rcu_flag_get(RCU_FLAG_PLLTSTB)) {
reval = SUCCESS;
}
break;
-
+
default:
break;
}
@@ -1009,7 +967,7 @@ void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
{
uint32_t reg;
- switch(osci){
+ switch(osci) {
/* enable HXTAL to bypass mode */
case RCU_HXTAL:
reg = RCU_CTL;
@@ -1046,8 +1004,8 @@ void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci)
{
uint32_t reg;
-
- switch(osci){
+
+ switch(osci) {
/* disable HXTAL to bypass mode */
case RCU_HXTAL:
reg = RCU_CTL;
@@ -1078,7 +1036,6 @@ void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci)
\param[out] none
\retval none
*/
-
void rcu_hxtal_clock_monitor_enable(void)
{
RCU_CTL |= RCU_CTL_CKMEN;
@@ -1104,7 +1061,7 @@ void rcu_hxtal_clock_monitor_disable(void)
void rcu_irc8m_adjust_value_set(uint8_t irc8m_adjval)
{
uint32_t reg;
-
+
reg = RCU_CTL;
/* reset the IRC8MADJ bits and set according to irc8m_adjval */
reg &= ~RCU_CTL_IRC8MADJ;
@@ -1123,7 +1080,7 @@ void rcu_irc8m_adjust_value_set(uint8_t irc8m_adjval)
\retval none
*/
void rcu_deepsleep_voltage_set(uint32_t dsvol)
-{
+{
dsvol &= RCU_DSV_DSLPVS;
RCU_DSV = dsvol;
}
@@ -1143,7 +1100,7 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
{
uint32_t sws, ck_freq = 0U;
uint32_t cksys_freq, ahb_freq, apb1_freq, apb2_freq;
- uint32_t pllsel, predv0sel, pllmf,ck_src, idx, clk_exp;
+ uint32_t pllsel, predv0sel, pllmf, ck_src, idx, clk_exp;
uint32_t predv0, predv1, pll1mf;
/* exponent of AHB, APB1 and APB2 clock divider */
@@ -1152,7 +1109,7 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
uint8_t apb2_exp[8] = {0, 0, 0, 0, 1, 2, 3, 4};
sws = GET_BITS(RCU_CFG0, 2, 3);
- switch(sws){
+ switch(sws) {
/* IRC8M is selected as CK_SYS */
case SEL_IRC8M:
cksys_freq = IRC8M_VALUE;
@@ -1169,41 +1126,41 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
if(RCU_PLLSRC_HXTAL == pllsel) {
/* PLL clock source is HXTAL */
ck_src = HXTAL_VALUE;
-
+
predv0sel = (RCU_CFG1 & RCU_CFG1_PREDV0SEL);
/* source clock use PLL1 */
- if(RCU_PREDV0SRC_CKPLL1 == predv0sel){
+ if(RCU_PREDV0SRC_CKPLL1 == predv0sel) {
predv1 = (uint32_t)((RCU_CFG1 & RCU_CFG1_PREDV1) >> 4) + 1U;
pll1mf = (uint32_t)((RCU_CFG1 & RCU_CFG1_PLL1MF) >> 8) + 2U;
- if(17U == pll1mf){
+ if(17U == pll1mf) {
pll1mf = 20U;
}
- ck_src = (ck_src/predv1)*pll1mf;
+ ck_src = (ck_src / predv1) * pll1mf;
}
predv0 = (RCU_CFG1 & RCU_CFG1_PREDV0) + 1U;
ck_src /= predv0;
- }else{
+ } else {
/* PLL clock source is IRC8M/2 */
- ck_src = IRC8M_VALUE/2U;
+ ck_src = IRC8M_VALUE / 2U;
}
/* PLL multiplication factor */
pllmf = GET_BITS(RCU_CFG0, 18, 21);
- if((RCU_CFG0 & RCU_CFG0_PLLMF_4)){
+ if((RCU_CFG0 & RCU_CFG0_PLLMF_4)) {
pllmf |= 0x10U;
}
- if(13U == pllmf){
+ if(13U == pllmf) {
/* PLL source clock multiply by 6.5 */
- cksys_freq = ck_src*6U + ck_src/2U;
- }else{
- if(pllmf < 15U){
+ cksys_freq = ck_src * 6U + ck_src / 2U;
+ } else {
+ if(pllmf < 15U) {
pllmf += 2U;
- }else{
+ } else {
pllmf += 1U;
}
- cksys_freq = ck_src*pllmf;
+ cksys_freq = ck_src * pllmf;
}
break;
/* IRC8M is selected as CK_SYS */
@@ -1216,19 +1173,19 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
idx = GET_BITS(RCU_CFG0, 4, 7);
clk_exp = ahb_exp[idx];
ahb_freq = cksys_freq >> clk_exp;
-
+
/* calculate APB1 clock frequency */
idx = GET_BITS(RCU_CFG0, 8, 10);
clk_exp = apb1_exp[idx];
apb1_freq = ahb_freq >> clk_exp;
-
+
/* calculate APB2 clock frequency */
idx = GET_BITS(RCU_CFG0, 11, 13);
clk_exp = apb2_exp[idx];
apb2_freq = ahb_freq >> clk_exp;
-
+
/* return the clocks frequency */
- switch(clock){
+ switch(clock) {
case CK_SYS:
ck_freq = cksys_freq;
break;
@@ -1248,89 +1205,130 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
}
/*!
- \brief configure the PLLT clock selection
- \param[in] pllt_src: PLLT clock source selection
- \arg RCU_PLLTSRC_IRC8M: IRC8M selected as source clock of PLLT
- \arg RCU_PLLTSRC_HXTAL: HXTAL selected as source clock of PLLT
+ \brief get the clock stabilization and periphral reset flags
+ \param[in] flag: the clock stabilization and periphral reset flags, refer to rcu_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg RCU_FLAG_IRC8MSTB: IRC8M stabilization flag
+ \arg RCU_FLAG_HXTALSTB: HXTAL stabilization flag
+ \arg RCU_FLAG_PLLSTB: PLL stabilization flag
+ \arg RCU_FLAG_PLL1STB: PLL1 stabilization flag
+ \arg RCU_FLAG_PLL2STB: PLL2 stabilization flag
+ \arg RCU_FLAG_PLLTSTB: PLLT stabilization flag
+ \arg RCU_FLAG_LXTALSTB: LXTAL stabilization flag
+ \arg RCU_FLAG_IRC40KSTB: IRC40K stabilization flag
+ \arg RCU_FLAG_EPRST: external PIN reset flag
+ \arg RCU_FLAG_PORRST: power reset flag
+ \arg RCU_FLAG_SWRST: software reset flag
+ \arg RCU_FLAG_FWDGTRST: free watchdog timer reset flag
+ \arg RCU_FLAG_WWDGTRST: window watchdog timer reset flag
+ \arg RCU_FLAG_LPRST: low-power reset flag
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void rcu_pllt_config(uint32_t pllt_src)
+FlagStatus rcu_flag_get(rcu_flag_enum flag)
{
- uint32_t reg = 0U;
+ /* get the rcu flag */
+ if(RESET != (RCU_REG_VAL(flag) & BIT(RCU_BIT_POS(flag)))) {
+ return SET;
+ } else {
+ return RESET;
+ }
+}
- reg = RCU_PLLTCFG;
+/*!
+ \brief clear all the reset flag
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void rcu_all_reset_flag_clear(void)
+{
+ RCU_RSTSCK |= RCU_RSTSCK_RSTFC;
+}
- /* reset the PLLT clock source bit PLLTSEL */
- reg &= ~RCU_PLLTCFG_PLLTSEL;
+/*!
+ \brief enable the stabilization interrupt
+ \param[in] stab_int: clock stabilization interrupt, refer to rcu_int_enum
+ Only one parameter can be selected which is shown as below:
+ \arg RCU_INT_IRC40KSTB: IRC40K stabilization interrupt enable
+ \arg RCU_INT_LXTALSTB: LXTAL stabilization interrupt enable
+ \arg RCU_INT_IRC8MSTB: IRC8M stabilization interrupt enable
+ \arg RCU_INT_HXTALSTB: HXTAL stabilization interrupt enable
+ \arg RCU_INT_PLLSTB: PLL stabilization interrupt enable
+ \arg RCU_INT_PLL1STB: PLL1 stabilization interrupt enable
+ \arg RCU_INT_PLL2STB: PLL2 stabilization interrupt enable
+ \arg RCU_INT_PLLTSTB: PLLT stabilization interrupt enable
+ \param[out] none
+ \retval none
+*/
+void rcu_interrupt_enable(rcu_int_enum stab_int)
+{
+ RCU_REG_VAL(stab_int) |= BIT(RCU_BIT_POS(stab_int));
+}
- RCU_PLLTCFG = (reg | pllt_src);
+/*!
+ \brief disable the stabilization interrupt
+ \param[in] stab_int: clock stabilization interrupt, refer to rcu_int_enum
+ only one parameter can be selected which is shown as below:
+ \arg RCU_INT_IRC40KSTB: IRC40K stabilization interrupt enable
+ \arg RCU_INT_LXTALSTB: LXTAL stabilization interrupt enable
+ \arg RCU_INT_IRC8MSTB: IRC8M stabilization interrupt enable
+ \arg RCU_INT_HXTALSTB: HXTAL stabilization interrupt enable
+ \arg RCU_INT_PLLSTB: PLL stabilization interrupt enable
+ \arg RCU_INT_PLL1STB: PLL1 stabilization interrupt enable
+ \arg RCU_INT_PLL2STB: PLL2 stabilization interrupt enable
+ \arg RCU_INT_PLLTSTB: PLLT stabilization interrupt enable
+ \param[out] none
+ \retval none
+*/
+void rcu_interrupt_disable(rcu_int_enum stab_int)
+{
+ RCU_REG_VAL(stab_int) &= ~BIT(RCU_BIT_POS(stab_int));
}
/*!
- \brief configure the PLLT clock multiplication and division factors
- \param[in] pllt_psc: the PLLT VCO input clock division factor
- \arg this parameter should be selected between 2 and 63. And this parameter should
- be selected correctly to ensure that the VCO input frequency ranges from 1 to 2 MHz
- \param[in] pllt_mul: he PLLT VCO output clock multiplication factor
- \arg this parameter should be selected between 49 and 432
- \param[in] ppltr_psc: the PLLTR division factor
- \arg this parameter should be selected between 2 and 7
+ \brief get the clock stabilization and ckm interrupt flags
+ \param[in] int_flag: interrupt and ckm flags, refer to rcu_int_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg RCU_INT_FLAG_IRC40KSTB: IRC40K stabilization interrupt flag
+ \arg RCU_INT_FLAG_LXTALSTB: LXTAL stabilization interrupt flag
+ \arg RCU_INT_FLAG_IRC8MSTB: IRC8M stabilization interrupt flag
+ \arg RCU_INT_FLAG_HXTALSTB: HXTAL stabilization interrupt flag
+ \arg RCU_INT_FLAG_PLLSTB: PLL stabilization interrupt flag
+ \arg RCU_INT_FLAG_PLL1STB: PLL1 stabilization interrupt flag
+ \arg RCU_INT_FLAG_PLL2STB: PLL2 stabilization interrupt flag
+ \arg RCU_INT_FLAG_CKM: HXTAL clock stuck interrupt flag
+ \arg RCU_INT_FLAG_PLLTSTB: PLLT stabilization interrupt flag
\param[out] none
- \retval ErrStatus: SUCCESS or ERROR
+ \retval FlagStatus: SET or RESET
*/
-ErrStatus rcu_pllt_vco_config(uint32_t pllt_psc, uint32_t pllt_mul, uint32_t ppltr_psc)
+FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag)
{
- uint32_t reg = 0U;
-
- /* check the function parameter */
- if((pllt_psc < 2U) || (pllt_psc > 63U)){
- return ERROR;
- }else{
- }
-
- if((pllt_mul < 49U) || (pllt_mul > 432U)){
- return ERROR;
- }else{
- }
-
- if((ppltr_psc < 2U) || (ppltr_psc > 7U)){
- return ERROR;
- }else{
+ /* get the rcu interrupt flag */
+ if(RESET != (RCU_REG_VAL(int_flag) & BIT(RCU_BIT_POS(int_flag)))) {
+ return SET;
+ } else {
+ return RESET;
}
-
- reg = RCU_PLLTCFG;
-
- /* reset the PLLTRPSC bits, PLLTMF bits and PLLTPSC bits */
- reg &= ~(RCU_PLLTCFG_PLLTRPSC | RCU_PLLTCFG_PLLTMF | RCU_PLLTCFG_PLLTPSC);
-
- reg |= (PLLTCFG_PLLTPSC(pllt_psc) | PLLTCFG_PLLTMF(pllt_mul) | PLLTCFG_PLLTRPSC(ppltr_psc));
-
- RCU_PLLTCFG = reg;
-
- return SUCCESS;
}
/*!
- \brief configure the TLI prescaler factor from PLLTR clock
- \param[in] tli_psc: TLI prescaler factor
+ \brief clear the interrupt flags
+ \param[in] int_flag_clear: clock stabilization and stuck interrupt flags clear, refer to rcu_int_flag_clear_enum
only one parameter can be selected which is shown as below:
- \arg RCU_CKTLI_CKPLLTR_DIV2: TLI prescaler select CK_PLLTR/2
- \arg RCU_CKTLI_CKPLLTR_DIV4: TLI prescaler select CK_PLLTR/4
- \arg RCU_CKTLI_CKPLLTR_DIV8: TLI prescaler select CK_PLLTR/8
- \arg RCU_CKTLI_CKPLLTR_DIV16: TLI prescaler select CK_PLLTR/16
+ \arg RCU_INT_FLAG_IRC40KSTB_CLR: IRC40K stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_LXTALSTB_CLR: LXTAL stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_IRC8MSTB_CLR: IRC8M stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_HXTALSTB_CLR: HXTAL stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_PLLSTB_CLR: PLL stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_PLL1STB_CLR: PLL1 stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_PLL2STB_CLR: PLL2 stabilization interrupt flag clear
+ \arg RCU_INT_FLAG_CKM_CLR: clock stuck interrupt flag clear
+ \arg RCU_INT_FLAG_PLLTSTB_CLR: PLLT stabilization interrupt flag clear
\param[out] none
\retval none
*/
-void rcu_tli_clock_config(uint32_t tli_psc)
+void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear)
{
- uint32_t reg = 0U;
-
- reg = RCU_PLLTCFG;
-
- /* reset the TLIPSC bits */
- reg &= ~RCU_PLLTCFG_TLIPSC;
-
- RCU_PLLTCFG = (reg | tli_psc);
+ RCU_REG_VAL(int_flag_clear) |= BIT(RCU_BIT_POS(int_flag_clear));
}
-
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rtc.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rtc.c
index 2f2b100..b6c5b92 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rtc.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_rtc.c
@@ -2,36 +2,33 @@
\file gd32f20x_rtc.c
\brief RTC driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -56,7 +53,7 @@ void rtc_configuration_mode_enter(void)
}
/*!
- \brief exit RTC configuration mode
+ \brief exit RTC configuration mode
\param[in] none
\param[out] none
\retval none
@@ -66,6 +63,49 @@ void rtc_configuration_mode_exit(void)
RTC_CTL &= ~RTC_CTL_CMF;
}
+/*!
+ \brief wait RTC last write operation finished flag set
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void rtc_lwoff_wait(void)
+{
+ /* loop until LWOFF flag is set */
+ while(RESET == (RTC_CTL & RTC_CTL_LWOFF)) {
+ }
+}
+
+/*!
+ \brief wait RTC registers synchronized flag set
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void rtc_register_sync_wait(void)
+{
+ /* clear RSYNF flag */
+ RTC_CTL &= ~RTC_CTL_RSYNF;
+ /* loop until RSYNF flag is set */
+ while(RESET == (RTC_CTL & RTC_CTL_RSYNF)) {
+ }
+}
+
+/*!
+ \brief get RTC counter value
+ \param[in] none
+ \param[out] none
+ \retval RTC counter value
+*/
+uint32_t rtc_counter_get(void)
+{
+ uint32_t temp = 0x0U;
+
+ temp = RTC_CNTL;
+ temp |= (RTC_CNTH << RTC_HIGH_BITS_OFFSET);
+ return temp;
+}
+
/*!
\brief set RTC counter value
\param[in] cnt: RTC counter value
@@ -98,33 +138,6 @@ void rtc_prescaler_set(uint32_t psc)
rtc_configuration_mode_exit();
}
-/*!
- \brief wait RTC last write operation finished flag set
- \param[in] none
- \param[out] none
- \retval none
-*/
-void rtc_lwoff_wait(void)
-{
- /* loop until LWOFF flag is set */
- while(RESET == (RTC_CTL & RTC_CTL_LWOFF)){
- }
-}
-
-/*!
- \brief wait RTC registers synchronized flag set
- \param[in] none
- \param[out] none
- \retval none
-*/
-void rtc_register_sync_wait(void)
-{
- /* clear RSYNF flag */
- RTC_CTL &= ~RTC_CTL_RSYNF;
- /* loop until RSYNF flag is set */
- while(RESET == (RTC_CTL & RTC_CTL_RSYNF)){
- }
-}
/*!
\brief set RTC alarm value
@@ -142,20 +155,6 @@ void rtc_alarm_config(uint32_t alarm)
rtc_configuration_mode_exit();
}
-/*!
- \brief get RTC counter value
- \param[in] none
- \param[out] none
- \retval RTC counter value
-*/
-uint32_t rtc_counter_get(void)
-{
- uint32_t temp = 0x0U;
-
- temp = RTC_CNTL;
- temp |= (RTC_CNTH << RTC_HIGH_BITS_OFFSET);
- return temp;
-}
/*!
\brief get RTC divider value
@@ -166,111 +165,76 @@ uint32_t rtc_counter_get(void)
uint32_t rtc_divider_get(void)
{
uint32_t temp = 0x00U;
-
+
temp = ((RTC_DIVH & RTC_DIVH_DIV) << RTC_HIGH_BITS_OFFSET);
temp |= RTC_DIVL;
return temp;
}
/*!
- \brief get RTC flag status
- \param[in] flag: specify which flag status to get
- only one parameter can be selected which is shown as below:
- \arg RTC_FLAG_SECOND: second interrupt flag
- \arg RTC_FLAG_ALARM: alarm interrupt flag
- \arg RTC_FLAG_OVERFLOW: overflow interrupt flag
- \arg RTC_FLAG_RSYN: registers synchronized flag
- \arg RTC_FLAG_LWOF: last write operation finished flag
+ \brief enable RTC interrupt
+ \param[in] interrupt: specify which interrupt to enbale
+ one or more parameters can be selected which are shown as below:
+ \arg RTC_INT_SECOND: second interrupt
+ \arg RTC_INT_ALARM: alarm interrupt
+ \arg RTC_INT_OVERFLOW: overflow interrupt
\param[out] none
- \retval SET or RESET
+ \retval none
*/
-FlagStatus rtc_flag_get(uint32_t flag)
+void rtc_interrupt_enable(uint32_t interrupt)
{
- if(RESET != (RTC_CTL & flag)){
- return SET;
- }else{
- return RESET;
- }
+ RTC_INTEN |= interrupt;
}
/*!
- \brief clear RTC flag status
- \param[in] flag: specify which flag status to clear
+ \brief disable RTC interrupt
+ \param[in] interrupt: specify which interrupt to disable
one or more parameters can be selected which are shown as below:
- \arg RTC_FLAG_SECOND: second interrupt flag
- \arg RTC_FLAG_ALARM: alarm interrupt flag
- \arg RTC_FLAG_OVERFLOW: overflow interrupt flag
- \arg RTC_FLAG_RSYN: registers synchronized flag
+ \arg RTC_INT_SECOND: second interrupt
+ \arg RTC_INT_ALARM: alarm interrupt
+ \arg RTC_INT_OVERFLOW: overflow interrupt
\param[out] none
\retval none
*/
-void rtc_flag_clear(uint32_t flag)
+void rtc_interrupt_disable(uint32_t interrupt)
{
- /* clear RTC flag */
- RTC_CTL &= ~flag;
+ RTC_INTEN &= ~interrupt;
}
/*!
- \brief get RTC interrupt flag status
+ \brief get RTC flag status
\param[in] flag: specify which flag status to get
only one parameter can be selected which is shown as below:
- \arg RTC_INT_FLAG_SECOND: second interrupt flag
- \arg RTC_INT_FLAG_ALARM: alarm interrupt flag
- \arg RTC_INT_FLAG_OVERFLOW: overflow interrupt flag
+ \arg RTC_FLAG_SECOND: second interrupt flag
+ \arg RTC_FLAG_ALARM: alarm interrupt flag
+ \arg RTC_FLAG_OVERFLOW: overflow interrupt flag
+ \arg RTC_FLAG_RSYN: registers synchronized flag
+ \arg RTC_FLAG_LWOF: last write operation finished flag
\param[out] none
\retval SET or RESET
*/
-FlagStatus rtc_interrupt_flag_get(uint32_t flag)
+FlagStatus rtc_flag_get(uint32_t flag)
{
- if(RESET != (RTC_CTL & flag)){
+ if(RESET != (RTC_CTL & flag)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear RTC interrupt flag status
+ \brief clear RTC flag status
\param[in] flag: specify which flag status to clear
one or more parameters can be selected which are shown as below:
- \arg RTC_INT_FLAG_SECOND: second interrupt flag
- \arg RTC_INT_FLAG_ALARM: alarm interrupt flag
- \arg RTC_INT_FLAG_OVERFLOW: overflow interrupt flag
+ \arg RTC_FLAG_SECOND: second interrupt flag
+ \arg RTC_FLAG_ALARM: alarm interrupt flag
+ \arg RTC_FLAG_OVERFLOW: overflow interrupt flag
+ \arg RTC_FLAG_RSYN: registers synchronized flag
\param[out] none
\retval none
*/
-void rtc_interrupt_flag_clear(uint32_t flag)
+void rtc_flag_clear(uint32_t flag)
{
- /* clear RTC interrupt flag */
+ /* clear RTC flag */
RTC_CTL &= ~flag;
}
-
-/*!
- \brief enable RTC interrupt
- \param[in] interrupt: specify which interrupt to enbale
- one or more parameters can be selected which are shown as below:
- \arg RTC_INT_SECOND: second interrupt
- \arg RTC_INT_ALARM: alarm interrupt
- \arg RTC_INT_OVERFLOW: overflow interrupt
- \param[out] none
- \retval none
-*/
-void rtc_interrupt_enable(uint32_t interrupt)
-{
- RTC_INTEN |= interrupt;
-}
-
-/*!
- \brief disable RTC interrupt
- \param[in] interrupt: specify which interrupt to disbale
- one or more parameters can be selected which are shown as below:
- \arg RTC_INT_SECOND: second interrupt
- \arg RTC_INT_ALARM: alarm interrupt
- \arg RTC_INT_OVERFLOW: overflow interrupt
- \param[out] none
- \retval none
-*/
-void rtc_interrupt_disable(uint32_t interrupt)
-{
- RTC_INTEN &= ~interrupt;
-}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_sdio.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_sdio.c
index 84b0d73..ba7505b 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_sdio.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_sdio.c
@@ -2,36 +2,33 @@
\file gd32f20x_sdio.c
\brief SDIO driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -83,7 +80,7 @@ void sdio_clock_config(uint32_t clock_edge, uint32_t clock_bypass, uint32_t cloc
/* reset the CLKEDGE, CLKBYP, CLKPWRSAV, DIV */
clock_config &= ~(SDIO_CLKCTL_CLKEDGE | SDIO_CLKCTL_CLKBYP | SDIO_CLKCTL_CLKPWRSAV | SDIO_CLKCTL_DIV8 | SDIO_CLKCTL_DIV);
/* if the clock division is greater or equal to 256, set the DIV[8] */
- if(clock_division >= 256U){
+ if(clock_division >= 256U) {
clock_config |= SDIO_CLKCTL_DIV8;
clock_division -= 256U;
}
@@ -271,7 +268,7 @@ uint8_t sdio_command_index_get(void)
uint32_t sdio_response_get(uint32_t responsex)
{
uint32_t resp_content = 0U;
- switch(responsex){
+ switch(responsex) {
case SDIO_RESPONSE0:
resp_content = SDIO_RESP0;
break;
@@ -492,9 +489,9 @@ void sdio_stop_readwait_disable(void)
*/
void sdio_readwait_type_set(uint32_t readwait_type)
{
- if(SDIO_READWAITTYPE_CLK == readwait_type){
+ if(SDIO_READWAITTYPE_CLK == readwait_type) {
SDIO_DATACTL |= SDIO_DATACTL_RWTYPE;
- }else{
+ } else {
SDIO_DATACTL &= ~SDIO_DATACTL_RWTYPE;
}
}
@@ -643,7 +640,7 @@ void sdio_ceata_command_completion_disable(void)
FlagStatus sdio_flag_get(uint32_t flag)
{
FlagStatus temp_flag = RESET;
- if(RESET != (SDIO_STAT & flag)){
+ if(RESET != (SDIO_STAT & flag)) {
temp_flag = SET;
}
return temp_flag;
@@ -781,10 +778,10 @@ FlagStatus sdio_interrupt_flag_get(uint32_t int_flag)
{
uint32_t state = 0U;
state = SDIO_STAT;
- if(state & int_flag){
+ if(state & int_flag) {
state = SDIO_INTEN;
/* check whether the corresponding bit in SDIO_INTEN is set or not */
- if(state & int_flag){
+ if(state & int_flag) {
return SET;
}
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_spi.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_spi.c
index d491db2..ef61dad 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_spi.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_spi.c
@@ -2,36 +2,33 @@
\file gd32f20x_spi.c
\brief SPI driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
@@ -53,14 +50,14 @@ OF SUCH DAMAGE.
#define RCU_CFG1_PLL2MF_OFFSET 12U /* PLL2MF offset in RCU_CFG1 */
/*!
- \brief reset SPI and I2S
+ \brief reset SPI and I2S
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval none
*/
void spi_i2s_deinit(uint32_t spi_periph)
{
- switch(spi_periph){
+ switch(spi_periph) {
case SPI0:
/* reset SPI0 */
rcu_periph_reset_enable(RCU_SPI0RST);
@@ -76,32 +73,33 @@ void spi_i2s_deinit(uint32_t spi_periph)
rcu_periph_reset_enable(RCU_SPI2RST);
rcu_periph_reset_disable(RCU_SPI2RST);
break;
- default :
+ default:
break;
}
}
/*!
- \brief initialize the parameters of SPI struct with the default values
- \param[in] spi_struct: SPI parameter stuct
- \param[out] none
+ \brief initialize the parameters of SPI structure with the default values
+ \param[in] none
+ \param[out] spi_struct: the initialized structure spi_parameter_struct pointer
\retval none
*/
-void spi_struct_para_init(spi_parameter_struct* spi_struct)
+void spi_struct_para_init(spi_parameter_struct *spi_struct)
{
- /* set the SPI struct with the default values */
- spi_struct->device_mode = SPI_SLAVE;
- spi_struct->trans_mode = SPI_TRANSMODE_FULLDUPLEX;
- spi_struct->frame_size = SPI_FRAMESIZE_8BIT;
- spi_struct->nss = SPI_NSS_HARD;
+ /* configure the SPI structure with the default values */
+ spi_struct->device_mode = SPI_SLAVE;
+ spi_struct->trans_mode = SPI_TRANSMODE_FULLDUPLEX;
+ spi_struct->frame_size = SPI_FRAMESIZE_8BIT;
+ spi_struct->nss = SPI_NSS_HARD;
+ spi_struct->endian = SPI_ENDIAN_MSB;
spi_struct->clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE;
- spi_struct->prescale = SPI_PSC_2;
+ spi_struct->prescale = SPI_PSC_2;
}
/*!
\brief initialize SPI parameter
\param[in] spi_periph: SPIx(x=0,1,2)
- \param[in] spi_struct: SPI parameter initialization stuct members of the structure
+ \param[in] spi_struct: SPI parameter initialization struct members of the structure
and the member values are shown as below:
device_mode: SPI_MASTER, SPI_SLAVE
trans_mode: SPI_TRANSMODE_FULLDUPLEX, SPI_TRANSMODE_RECEIVEONLY,
@@ -115,8 +113,8 @@ void spi_struct_para_init(spi_parameter_struct* spi_struct)
\param[out] none
\retval none
*/
-void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct)
-{
+void spi_init(uint32_t spi_periph, spi_parameter_struct *spi_struct)
+{
uint32_t reg = 0U;
reg = SPI_CTL0(spi_periph);
reg &= SPI_INIT_MASK;
@@ -133,7 +131,7 @@ void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct)
reg |= spi_struct->endian;
/* select SPI polarity and phase */
reg |= spi_struct->clock_polarity_phase;
- /* select SPI prescale to adjust transmit speed */
+ /* select SPI prescaler to adjust transmit speed */
reg |= spi_struct->prescale;
/* write to SPI_CTL0 register */
@@ -154,7 +152,7 @@ void spi_enable(uint32_t spi_periph)
}
/*!
- \brief disable SPI
+ \brief disable SPI
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval none
@@ -165,7 +163,7 @@ void spi_disable(uint32_t spi_periph)
}
/*!
- \brief initialize I2S parameter
+ \brief initialize I2S parameters
\param[in] spi_periph: SPIx(x=1,2)
\param[in] mode: I2S operation mode
only one parameter can be selected which is shown as below:
@@ -194,7 +192,7 @@ void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ck
reg &= I2S_INIT_MASK;
/* enable I2S mode */
- reg |= (uint32_t)SPI_I2SCTL_I2SSEL;
+ reg |= (uint32_t)SPI_I2SCTL_I2SSEL;
/* select I2S mode */
reg |= (uint32_t)mode;
/* select I2S standard */
@@ -207,7 +205,7 @@ void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ck
}
/*!
- \brief configure I2S prescaler
+ \brief configure I2S prescaler
\param[in] spi_periph: SPIx(x=1,2)
\param[in] audiosample: I2S audio sample rate
only one parameter can be selected which is shown as below:
@@ -228,8 +226,8 @@ void i2s_init(uint32_t spi_periph, uint32_t mode, uint32_t standard, uint32_t ck
\arg I2S_FRAMEFORMAT_DT32B_CH32B: I2S data length is 32 bit and channel length is 32 bit
\param[in] mckout: I2S master clock output
only one parameter can be selected which is shown as below:
- \arg I2S_MCKOUT_ENABLE: I2S master clock output enable
- \arg I2S_MCKOUT_DISABLE: I2S master clock output disable
+ \arg I2S_MCKOUT_ENABLE: enable I2S master clock output
+ \arg I2S_MCKOUT_DISABLE: disable I2S master clock output
\param[out] none
\retval none
*/
@@ -239,52 +237,52 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t audiosample, uint32_t framefor
uint32_t clks = 0U;
uint32_t i2sclock = 0U;
- /* deinit SPI_I2SPSC register */
+ /* deinitialize SPI_I2SPSC register */
SPI_I2SPSC(spi_periph) = SPI_I2SPSC_DEFAULT_VALUE;
/* get the I2S clock source */
- if(SPI1 == ((uint32_t)spi_periph)){
+ if(SPI1 == ((uint32_t)spi_periph)) {
/* I2S1 clock source selection */
clks = I2S1_CLOCK_SEL;
- }else{
+ } else {
/* I2S2 clock source selection */
clks = I2S2_CLOCK_SEL;
}
-
- if(0U != (RCU_CFG1 & clks)){
+
+ if(0U != (RCU_CFG1 & clks)) {
/* get RCU PLL2 clock multiplication factor */
clks = (uint32_t)((RCU_CFG1 & I2S_CLOCK_MUL_MASK) >> RCU_CFG1_PLL2MF_OFFSET);
-
- if((clks > 5U) && (clks < 15U)){
+
+ if((clks > 5U) && (clks < 15U)) {
/* multiplier is between 8 and 14 */
clks += 2U;
- }else{
- if(15U == clks){
+ } else {
+ if(15U == clks) {
/* multiplier is 20 */
clks = 20U;
}
}
-
+
/* get the PREDV1 value */
- i2sclock = (uint32_t)(((RCU_CFG1 & I2S_CLOCK_DIV_MASK) >> RCU_CFG1_PREDV1_OFFSET) + 1U);
+ i2sclock = (uint32_t)(((RCU_CFG1 & I2S_CLOCK_DIV_MASK) >> RCU_CFG1_PREDV1_OFFSET) + 1U);
/* calculate I2S clock based on PLL2 and PREDV1 */
- i2sclock = (uint32_t)((HXTAL_VALUE / i2sclock) * clks * 2U);
- }else{
+ i2sclock = (uint32_t)((HXTAL_VALUE / i2sclock) * clks * 2U);
+ } else {
/* get system clock */
i2sclock = rcu_clock_freq_get(CK_SYS);
}
-
- /* config the prescaler depending on the mclk output state, the frame format and audio sample rate */
- if(I2S_MCKOUT_ENABLE == mckout){
+
+ /* configure the prescaler depending on the mclk output state, the frame format and audio sample rate */
+ if(I2S_MCKOUT_ENABLE == mckout) {
clks = (uint32_t)(((i2sclock / 256U) * 10U) / audiosample);
- }else{
- if(I2S_FRAMEFORMAT_DT16B_CH16B == frameformat){
- clks = (uint32_t)(((i2sclock / 32U) *10U ) / audiosample);
- }else{
- clks = (uint32_t)(((i2sclock / 64U) *10U ) / audiosample);
+ } else {
+ if(I2S_FRAMEFORMAT_DT16B_CH16B == frameformat) {
+ clks = (uint32_t)(((i2sclock / 32U) * 10U) / audiosample);
+ } else {
+ clks = (uint32_t)(((i2sclock / 64U) * 10U) / audiosample);
}
}
-
+
/* remove the floating point */
clks = (clks + 5U) / 10U;
i2sof = (clks & 0x00000001U);
@@ -292,7 +290,7 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t audiosample, uint32_t framefor
i2sof = (i2sof << 8U);
/* set the default values */
- if((i2sdiv < 2U) || (i2sdiv > 255U)){
+ if((i2sdiv < 2U) || (i2sdiv > 255U)) {
i2sdiv = 2U;
i2sof = 0U;
}
@@ -302,12 +300,13 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t audiosample, uint32_t framefor
/* clear SPI_I2SCTL_DTLEN and SPI_I2SCTL_CHLEN bits */
SPI_I2SCTL(spi_periph) &= (uint32_t)(~(SPI_I2SCTL_DTLEN | SPI_I2SCTL_CHLEN));
+
/* configure data frame format */
SPI_I2SCTL(spi_periph) |= (uint32_t)frameformat;
}
/*!
- \brief enable I2S
+ \brief enable I2S
\param[in] spi_periph: SPIx(x=1,2)
\param[out] none
\retval none
@@ -318,7 +317,7 @@ void i2s_enable(uint32_t spi_periph)
}
/*!
- \brief disable I2S
+ \brief disable I2S
\param[in] spi_periph: SPIx(x=1,2)
\param[out] none
\retval none
@@ -329,7 +328,7 @@ void i2s_disable(uint32_t spi_periph)
}
/*!
- \brief enable SPI NSS output
+ \brief enable SPI NSS output
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval none
@@ -340,7 +339,7 @@ void spi_nss_output_enable(uint32_t spi_periph)
}
/*!
- \brief disable SPI NSS output
+ \brief disable SPI NSS output
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval none
@@ -373,7 +372,7 @@ void spi_nss_internal_low(uint32_t spi_periph)
}
/*!
- \brief enable SPI DMA send or receive
+ \brief enable SPI DMA send or receive
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] dma: SPI DMA mode
only one parameter can be selected which is shown as below:
@@ -384,15 +383,15 @@ void spi_nss_internal_low(uint32_t spi_periph)
*/
void spi_dma_enable(uint32_t spi_periph, uint8_t dma)
{
- if(SPI_DMA_TRANSMIT == dma){
+ if(SPI_DMA_TRANSMIT == dma) {
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_DMATEN;
- }else{
+ } else {
SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_DMAREN;
}
}
/*!
- \brief disable SPI DMA send or receive
+ \brief disable SPI DMA send or receive
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] dma: SPI DMA mode
only one parameter can be selected which is shown as below:
@@ -403,15 +402,15 @@ void spi_dma_enable(uint32_t spi_periph, uint8_t dma)
*/
void spi_dma_disable(uint32_t spi_periph, uint8_t dma)
{
- if(SPI_DMA_TRANSMIT == dma){
+ if(SPI_DMA_TRANSMIT == dma) {
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_DMATEN);
- }else{
+ } else {
SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_DMAREN);
}
}
/*!
- \brief configure SPI/I2S data frame format
+ \brief configure SPI data frame format
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] frame_format: SPI frame size
only one parameter can be selected which is shown as below:
@@ -428,6 +427,27 @@ void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format
SPI_CTL0(spi_periph) |= (uint32_t)frame_format;
}
+/*!
+ \brief configure SPI bidirectional transfer direction
+ \param[in] spi_periph: SPIx(x=0,1,2)
+ \param[in] transfer_direction: SPI transfer direction
+ only one parameter can be selected which is shown as below:
+ \arg SPI_BIDIRECTIONAL_TRANSMIT: SPI work in transmit-only mode
+ \arg SPI_BIDIRECTIONAL_RECEIVE: SPI work in receive-only mode
+ \param[out] none
+ \retval none
+*/
+void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction)
+{
+ if(SPI_BIDIRECTIONAL_TRANSMIT == transfer_direction) {
+ /* set the transmit only mode */
+ SPI_CTL0(spi_periph) |= (uint32_t)SPI_BIDIRECTIONAL_TRANSMIT;
+ } else {
+ /* set the receive only mode */
+ SPI_CTL0(spi_periph) &= SPI_BIDIRECTIONAL_RECEIVE;
+ }
+}
+
/*!
\brief SPI transmit data
\param[in] spi_periph: SPIx(x=0,1,2)
@@ -452,28 +472,7 @@ uint16_t spi_i2s_data_receive(uint32_t spi_periph)
}
/*!
- \brief configure SPI bidirectional transfer direction
- \param[in] spi_periph: SPIx(x=0,1,2)
- \param[in] transfer_direction: SPI transfer direction
- only one parameter can be selected which is shown as below:
- \arg SPI_BIDIRECTIONAL_TRANSMIT: SPI work in transmit-only mode
- \arg SPI_BIDIRECTIONAL_RECEIVE: SPI work in receive-only mode
- \param[out] none
- \retval none
-*/
-void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction)
-{
- if(SPI_BIDIRECTIONAL_TRANSMIT == transfer_direction){
- /* set the transmit only mode */
- SPI_CTL0(spi_periph) |= (uint32_t)SPI_BIDIRECTIONAL_TRANSMIT;
- }else{
- /* set the receive only mode */
- SPI_CTL0(spi_periph) &= SPI_BIDIRECTIONAL_RECEIVE;
- }
-}
-
-/*!
- \brief set CRC polynomial
+ \brief set CRC polynomial
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] crc_poly: CRC polynomial value
\param[out] none
@@ -481,14 +480,12 @@ void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_di
*/
void spi_crc_polynomial_set(uint32_t spi_periph, uint16_t crc_poly)
{
- /* enable SPI CRC */
- SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN;
/* set SPI CRC polynomial */
SPI_CRCPOLY(spi_periph) = (uint32_t)crc_poly;
}
/*!
- \brief get SPI CRC polynomial
+ \brief get SPI CRC polynomial
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval 16-bit CRC polynomial
@@ -499,7 +496,7 @@ uint16_t spi_crc_polynomial_get(uint32_t spi_periph)
}
/*!
- \brief turn on CRC function
+ \brief turn on CRC function
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval none
@@ -510,7 +507,7 @@ void spi_crc_on(uint32_t spi_periph)
}
/*!
- \brief turn off CRC function
+ \brief turn off CRC function
\param[in] spi_periph: SPIx(x=0,1,2)
\param[out] none
\retval none
@@ -543,75 +540,151 @@ void spi_crc_next(uint32_t spi_periph)
*/
uint16_t spi_crc_get(uint32_t spi_periph, uint8_t crc)
{
- if(SPI_CRC_TX == crc){
+ if(SPI_CRC_TX == crc) {
return ((uint16_t)(SPI_TCRC(spi_periph)));
- }else{
+ } else {
return ((uint16_t)(SPI_RCRC(spi_periph)));
}
}
/*!
- \brief enable SPI and I2S interrupt
+ \brief clear SPI CRC error flag status
+ \param[in] spi_periph: SPIx(x=0,1,2)
+ \param[out] none
+ \retval none
+*/
+void spi_crc_error_clear(uint32_t spi_periph)
+{
+ SPI_STAT(spi_periph) = (uint32_t)(~SPI_FLAG_CRCERR);
+}
+
+/*!
+ \brief enable quad wire SPI
+ \param[in] spi_periph: SPIx(only x=0)
+ \param[out] none
+ \retval none
+*/
+void spi_quad_enable(uint32_t spi_periph)
+{
+ SPI_QCTL(spi_periph) |= (uint32_t)SPI_QCTL_QMOD;
+}
+
+/*!
+ \brief disable quad wire SPI
+ \param[in] spi_periph: SPIx(only x=0)
+ \param[out] none
+ \retval none
+*/
+void spi_quad_disable(uint32_t spi_periph)
+{
+ SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_QMOD);
+}
+
+/*!
+ \brief enable quad wire SPI write
+ \param[in] spi_periph: SPIx(only x=0)
+ \param[out] none
+ \retval none
+*/
+void spi_quad_write_enable(uint32_t spi_periph)
+{
+ SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_QRD);
+}
+
+/*!
+ \brief enable quad wire SPI read
+ \param[in] spi_periph: SPIx(only x=0)
+ \param[out] none
+ \retval none
+*/
+void spi_quad_read_enable(uint32_t spi_periph)
+{
+ SPI_QCTL(spi_periph) |= (uint32_t)SPI_QCTL_QRD;
+}
+
+/*!
+ \brief enable SPI_IO2 and SPI_IO3 pin output
+ \param[in] spi_periph: SPIx(only x=0)
+ \param[out] none
+ \retval none
+*/
+void spi_quad_io23_output_enable(uint32_t spi_periph)
+{
+ SPI_QCTL(spi_periph) |= (uint32_t)SPI_QCTL_IO23_DRV;
+}
+
+/*!
+ \brief disable SPI_IO2 and SPI_IO3 pin output
+ \param[in] spi_periph: SPIx(only x=0)
+ \param[out] none
+ \retval none
+*/
+void spi_quad_io23_output_disable(uint32_t spi_periph)
+{
+ SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_IO23_DRV);
+}
+
+/*!
+ \brief get SPI and I2S flag status
+ \param[in] spi_periph: SPIx(x=0,1,2)
+ \param[in] flag: SPI/I2S flag status
+ only one parameter can be selected which is shown as below:
+ \arg SPI_FLAG_TBE: transmit buffer empty flag
+ \arg SPI_FLAG_RBNE: receive buffer not empty flag
+ \arg SPI_FLAG_TRANS: transmit on-going flag
+ \arg SPI_FLAG_RXORERR: receive overrun error flag
+ \arg SPI_FLAG_CONFERR: mode config error flag
+ \arg SPI_FLAG_CRCERR: CRC error flag
+ \arg I2S_FLAG_TBE: transmit buffer empty flag
+ \arg I2S_FLAG_RBNE: receive buffer not empty flag
+ \arg I2S_FLAG_TRANS: transmit on-going flag
+ \arg I2S_FLAG_RXORERR: overrun error flag
+ \arg I2S_FLAG_TXURERR: underrun error flag
+ \arg I2S_FLAG_CH: channel side flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag)
+{
+ if(RESET != (SPI_STAT(spi_periph) & flag)) {
+ return SET;
+ } else {
+ return RESET;
+ }
+}
+
+/*!
+ \brief enable SPI and I2S interrupt
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] interrupt: SPI/I2S interrupt
only one parameter can be selected which is shown as below:
\arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
\arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
- \arg SPI_I2S_INT_ERR: CRC error,configuration error,reception overrun error,
+ \arg SPI_I2S_INT_ERR: CRC error, configuration error, reception overrun error,
transmission underrun error and format error interrupt
\param[out] none
\retval none
*/
void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt)
{
- switch(interrupt){
- /* SPI/I2S transmit buffer empty interrupt */
- case SPI_I2S_INT_TBE:
- SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_TBEIE;
- break;
- /* SPI/I2S receive buffer not empty interrupt */
- case SPI_I2S_INT_RBNE:
- SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_RBNEIE;
- break;
- /* SPI/I2S error */
- case SPI_I2S_INT_ERR:
- SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_ERRIE;
- break;
- default:
- break;
- }
+ SPI_CTL1(spi_periph) |= (uint32_t)interrupt;
}
/*!
- \brief disable SPI and I2S interrupt
+ \brief disable SPI and I2S interrupt
\param[in] spi_periph: SPIx(x=0,1,2)
\param[in] interrupt: SPI/I2S interrupt
only one parameter can be selected which is shown as below:
\arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
\arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
- \arg SPI_I2S_INT_ERR: CRC error,configuration error,reception overrun error,
+ \arg SPI_I2S_INT_ERR: CRC error, configuration error, reception overrun error,
transmission underrun error and format error interrupt
\param[out] none
\retval none
*/
void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt)
{
- switch(interrupt){
- /* SPI/I2S transmit buffer empty interrupt */
- case SPI_I2S_INT_TBE:
- SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_TBEIE);
- break;
- /* SPI/I2S receive buffer not empty interrupt */
- case SPI_I2S_INT_RBNE:
- SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_RBNEIE);
- break;
- /* SPI/I2S error */
- case SPI_I2S_INT_ERR:
- SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_ERRIE);
- break;
- default :
- break;
- }
+ SPI_CTL1(spi_periph) &= ~(uint32_t)interrupt;
}
/*!
@@ -633,7 +706,7 @@ FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt)
uint32_t reg1 = SPI_STAT(spi_periph);
uint32_t reg2 = SPI_CTL1(spi_periph);
- switch(interrupt){
+ switch(interrupt) {
/* SPI/I2S transmit buffer empty interrupt */
case SPI_I2S_INT_FLAG_TBE:
reg1 = reg1 & SPI_STAT_TBE;
@@ -664,119 +737,13 @@ FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt)
reg1 = reg1 & SPI_STAT_TXURERR;
reg2 = reg2 & SPI_CTL1_ERRIE;
break;
- default :
+ default:
break;
}
/*get SPI/I2S interrupt flag status */
- if((0U != reg1) && (0U != reg2)){
+ if((0U != reg1) && (0U != reg2)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
-
-/*!
- \brief get SPI and I2S flag status
- \param[in] spi_periph: SPIx(x=0,1,2)
- \param[in] flag: SPI/I2S flag status
- only one parameter can be selected which is shown as below:
- \arg SPI_FLAG_TBE: transmit buffer empty flag
- \arg SPI_FLAG_RBNE: receive buffer not empty flag
- \arg SPI_FLAG_TRANS: transmit on-going flag
- \arg SPI_FLAG_RXORERR: receive overrun error flag
- \arg SPI_FLAG_CONFERR: mode config error flag
- \arg SPI_FLAG_CRCERR: CRC error flag
- \arg I2S_FLAG_TBE: transmit buffer empty flag
- \arg I2S_FLAG_RBNE: receive buffer not empty flag
- \arg I2S_FLAG_TRANS: transmit on-going flag
- \arg I2S_FLAG_RXORERR: overrun error flag
- \arg I2S_FLAG_TXURERR: underrun error flag
- \arg I2S_FLAG_CH: channel side flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag)
-{
- if(RESET != (SPI_STAT(spi_periph) & flag)){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear SPI CRC error flag status
- \param[in] spi_periph: SPIx(x=0,1,2)
- \param[out] none
- \retval none
-*/
-void spi_crc_error_clear(uint32_t spi_periph)
-{
- SPI_STAT(spi_periph) &= (uint32_t)(~SPI_FLAG_CRCERR);
-}
-
-/*!
- \brief enable quad wire SPI
- \param[in] spi_periph: SPIx(only x=0)
- \param[out] none
- \retval none
-*/
-void qspi_enable(uint32_t spi_periph)
-{
- SPI_QCTL(spi_periph) |= (uint32_t)SPI_QCTL_QMOD;
-}
-
-/*!
- \brief disable quad wire SPI
- \param[in] spi_periph: SPIx(only x=0)
- \param[out] none
- \retval none
-*/
-void qspi_disable(uint32_t spi_periph)
-{
- SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_QMOD);
-}
-
-/*!
- \brief enable quad wire SPI write
- \param[in] spi_periph: SPIx(only x=0)
- \param[out] none
- \retval none
-*/
-void qspi_write_enable(uint32_t spi_periph)
-{
- SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_QRD);
-}
-
-/*!
- \brief enable quad wire SPI read
- \param[in] spi_periph: SPIx(only x=0)
- \param[out] none
- \retval none
-*/
-void qspi_read_enable(uint32_t spi_periph)
-{
- SPI_QCTL(spi_periph) |= (uint32_t)SPI_QCTL_QRD;
-}
-
-/*!
- \brief enable SPI_IO2 and SPI_IO3 pin output
- \param[in] spi_periph: SPIx(only x=0)
- \param[out] none
- \retval none
-*/
-void qspi_io23_output_enable(uint32_t spi_periph)
-{
- SPI_QCTL(spi_periph) |= (uint32_t)SPI_QCTL_IO23_DRV;
-}
-
- /*!
- \brief disable SPI_IO2 and SPI_IO3 pin output
- \param[in] spi_periph: SPIx(only x=0)
- \param[out] none
- \retval none
-*/
-void qspi_io23_output_disable(uint32_t spi_periph)
-{
- SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_IO23_DRV);
-}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_timer.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_timer.c
index 2b89391..8318da6 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_timer.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_timer.c
@@ -2,40 +2,38 @@
\file gd32f20x_timer.c
\brief TIMER driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_timer.h"
+
/* TIMER init parameter mask */
#define ALIGNEDMODE_MASK ((uint32_t)0x00000060U) /*!< TIMER init parameter aligne dmode mask */
#define COUNTERDIRECTION_MASK ((uint32_t)0x00000010U) /*!< TIMER init parameter counter direction mask */
@@ -49,7 +47,7 @@ OF SUCH DAMAGE.
*/
void timer_deinit(uint32_t timer_periph)
{
- switch(timer_periph){
+ switch(timer_periph) {
case TIMER0:
/* reset TIMER0 */
rcu_periph_reset_enable(RCU_TIMER0RST);
@@ -127,11 +125,11 @@ void timer_deinit(uint32_t timer_periph)
/*!
\brief initialize TIMER init parameter struct with a default value
- \param[in] initpara: init parameter struct
- \param[out] none
+ \param[in] none
+ \param[out] initpara: init parameter struct
\retval none
*/
-void timer_struct_para_init(timer_parameter_struct* initpara)
+void timer_struct_para_init(timer_parameter_struct *initpara)
{
/* initialize the init parameter struct member with the default value */
initpara->prescaler = 0U;
@@ -146,24 +144,24 @@ void timer_struct_para_init(timer_parameter_struct* initpara)
\brief initialize TIMER counter
\param[in] timer_periph: TIMERx(x=0..13)
\param[in] initpara: init parameter struct
- prescaler: prescaler value of the counter clock,0~65535
- alignedmode: TIMER_COUNTER_EDGE,TIMER_COUNTER_CENTER_DOWN,TIMER_COUNTER_CENTER_UP,TIMER_COUNTER_CENTER_BOTH
- counterdirection: TIMER_COUNTER_UP,TIMER_COUNTER_DOWN
- period: counter auto reload value,0~65535
- clockdivision: TIMER_CKDIV_DIV1,TIMER_CKDIV_DIV2,TIMER_CKDIV_DIV4
- repetitioncounter: counter repetition value,0~255
+ prescaler: prescaler value of the counter clock,0~65535
+ alignedmode: TIMER_COUNTER_EDGE,TIMER_COUNTER_CENTER_DOWN,TIMER_COUNTER_CENTER_UP,TIMER_COUNTER_CENTER_BOTH
+ counterdirection: TIMER_COUNTER_UP,TIMER_COUNTER_DOWN
+ period: counter auto reload value,0~65535
+ clockdivision: TIMER_CKDIV_DIV1,TIMER_CKDIV_DIV2,TIMER_CKDIV_DIV4
+ repetitioncounter: counter repetition value,0~255
\param[out] none
\retval none
*/
-void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara)
+void timer_init(uint32_t timer_periph, timer_parameter_struct *initpara)
{
/* configure the counter prescaler value */
TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
/* configure the counter direction and aligned mode */
if((TIMER0 == timer_periph) || (TIMER1 == timer_periph) || (TIMER2 == timer_periph) || (TIMER3 == timer_periph) ||
- (TIMER4 == timer_periph) || (TIMER7 == timer_periph) || (TIMER8 == timer_periph) || (TIMER9 == timer_periph) ||
- (TIMER10 == timer_periph) || (TIMER11 == timer_periph) || (TIMER12 == timer_periph) || (TIMER13 == timer_periph)){
+ (TIMER4 == timer_periph) || (TIMER7 == timer_periph) || (TIMER8 == timer_periph) || (TIMER9 == timer_periph) ||
+ (TIMER10 == timer_periph) || (TIMER11 == timer_periph) || (TIMER12 == timer_periph) || (TIMER13 == timer_periph)) {
TIMER_CTL0(timer_periph) &= (~(uint32_t)(TIMER_CTL0_DIR | TIMER_CTL0_CAM));
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->alignedmode & ALIGNEDMODE_MASK);
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->counterdirection & COUNTERDIRECTION_MASK);
@@ -172,13 +170,13 @@ void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara)
/* configure the autoreload value */
TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
- if((TIMER5 != timer_periph) && (TIMER6 != timer_periph)){
+ if((TIMER5 != timer_periph) && (TIMER6 != timer_periph)) {
/* reset the CKDIV bit */
TIMER_CTL0(timer_periph) &= (~(uint32_t)TIMER_CTL0_CKDIV);
TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->clockdivision & CLOCKDIVISION_MASK);
}
- if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
+ if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)) {
/* configure the repetition counter value */
TIMER_CREP(timer_periph) = (uint32_t)initpara->repetitioncounter;
}
@@ -267,7 +265,7 @@ void timer_update_event_disable(uint32_t timer_periph)
*/
void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned)
{
- TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CAM;
+ TIMER_CTL0(timer_periph) &= (uint32_t)(~TIMER_CTL0_CAM);
TIMER_CTL0(timer_periph) |= (uint32_t)aligned;
}
@@ -296,7 +294,7 @@ void timer_counter_down_direction(uint32_t timer_periph)
/*!
\brief configure TIMER prescaler
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] prescaler: prescaler value
+ \param[in] prescaler: prescaler value, 0~65535
\param[in] pscreload: prescaler reload mode
only one parameter can be selected which is shown as below:
\arg TIMER_PSC_RELOAD_NOW: the prescaler is loaded right now
@@ -307,8 +305,8 @@ void timer_counter_down_direction(uint32_t timer_periph)
void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t pscreload)
{
TIMER_PSC(timer_periph) = (uint32_t)prescaler;
-
- if(TIMER_PSC_RELOAD_NOW == pscreload){
+
+ if(TIMER_PSC_RELOAD_NOW == pscreload) {
TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
}
}
@@ -316,22 +314,22 @@ void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t
/*!
\brief configure TIMER repetition register value
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] repetition: the counter repetition value,0~255
+ \param[in] repetition: the counter repetition value, 0~255
\param[out] none
\retval none
*/
-void timer_repetition_value_config(uint32_t timer_periph, uint8_t repetition)
+void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition)
{
TIMER_CREP(timer_periph) = (uint32_t)repetition;
-}
-
+}
+
/*!
\brief configure TIMER autoreload register value
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] autoreload: the counter auto-reload value
+ \param[in] autoreload: the counter auto-reload value, 0~65535
\param[out] none
\retval none
-*/
+*/
void timer_autoreload_value_config(uint32_t timer_periph, uint32_t autoreload)
{
TIMER_CAR(timer_periph) = (uint32_t)autoreload;
@@ -340,10 +338,10 @@ void timer_autoreload_value_config(uint32_t timer_periph, uint32_t autoreload)
/*!
\brief configure TIMER counter register value
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] counter: the counter value
+ \param[in] counter: the counter value, 0~65535
\param[out] none
\retval none
-*/
+*/
void timer_counter_value_config(uint32_t timer_periph, uint32_t counter)
{
TIMER_CNT(timer_periph) = (uint32_t)counter;
@@ -353,8 +351,8 @@ void timer_counter_value_config(uint32_t timer_periph, uint32_t counter)
\brief read TIMER counter value
\param[in] timer_periph: TIMERx(x=0..13)
\param[out] none
- \retval counter value
-*/
+ \retval counter value, 0~65535
+*/
uint32_t timer_counter_read(uint32_t timer_periph)
{
uint32_t count_value = 0U;
@@ -366,8 +364,8 @@ uint32_t timer_counter_read(uint32_t timer_periph)
\brief read TIMER prescaler value
\param[in] timer_periph: TIMERx(x=0..13)
\param[out] none
- \retval prescaler register value
-*/
+ \retval prescaler register value, 0~65535
+*/
uint16_t timer_prescaler_read(uint32_t timer_periph)
{
uint16_t prescaler_value = 0U;
@@ -387,17 +385,17 @@ uint16_t timer_prescaler_read(uint32_t timer_periph)
*/
void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
{
- if(TIMER_SP_MODE_SINGLE == spmode){
+ if(TIMER_SP_MODE_SINGLE == spmode) {
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_SPM;
- }else if(TIMER_SP_MODE_REPETITIVE == spmode){
+ } else if(TIMER_SP_MODE_REPETITIVE == spmode) {
TIMER_CTL0(timer_periph) &= ~((uint32_t)TIMER_CTL0_SPM);
- }else{
- /* illegal parameters */
+ } else {
+ /* illegal parameters */
}
}
/*!
- \brief configure TIMER update source
+ \brief configure TIMER update source
\param[in] timer_periph: TIMERx(x=0..13)
\param[in] update:
only one parameter can be selected which is shown as below:
@@ -409,19 +407,19 @@ void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
*/
void timer_update_source_config(uint32_t timer_periph, uint32_t update)
{
- if(TIMER_UPDATE_SRC_REGULAR == update){
+ if(TIMER_UPDATE_SRC_REGULAR == update) {
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPS;
- }else if(TIMER_UPDATE_SRC_GLOBAL == update){
+ } else if(TIMER_UPDATE_SRC_GLOBAL == update) {
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPS;
- }else{
+ } else {
/* illegal parameters */
}
}
/*!
\brief enable the TIMER DMA
- \param[in] timer_periph: TIMERx(x=0,1,2,5,14,15,16)
- \param[in] dma: timer DMA source enable
+ \param[in] timer_periph: TIMERx(x=0..7)
+ \param[in] dma: timer DMA source enable
only one parameter can be selected which is shown as below:
\arg TIMER_DMA_UPD: update DMA enable,TIMERx(x=0..7)
\arg TIMER_DMA_CH0D: channel 0 DMA enable,TIMERx(x=0..4,7)
@@ -435,12 +433,12 @@ void timer_update_source_config(uint32_t timer_periph, uint32_t update)
*/
void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
{
- TIMER_DMAINTEN(timer_periph) |= (uint32_t) dma;
+ TIMER_DMAINTEN(timer_periph) |= (uint32_t) dma;
}
/*!
\brief disable the TIMER DMA
- \param[in] timer_periph: please refer to the following parameters
+ \param[in] timer_periph: TIMERx(x=0..7)
\param[in] dma: timer DMA source disable
only one parameter can be selected which is shown as below:
\arg TIMER_DMA_UPD: update DMA disable,TIMERx(x=0..7)
@@ -448,14 +446,14 @@ void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
\arg TIMER_DMA_CH1D: channel 1 DMA disable,TIMERx(x=0..4,7)
\arg TIMER_DMA_CH2D: channel 2 DMA disable,TIMERx(x=0..4,7)
\arg TIMER_DMA_CH3D: channel 3 DMA disable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CMTD: commutation DMA request disable,TIMERx(x=0,7)
+ \arg TIMER_DMA_CMTD: commutation DMA request disable, TIMERx(x=0,7)
\arg TIMER_DMA_TRGD: trigger DMA disable,TIMERx(x=0..4,7)
\param[out] none
\retval none
*/
void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
{
- TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma));
+ TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma));
}
/*!
@@ -464,18 +462,18 @@ void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
\param[in] dma_request: channel DMA request source selection
only one parameter can be selected which is shown as below:
\arg TIMER_DMAREQUEST_CHANNELEVENT: DMA request of channel y is sent when channel y event occurs
- \arg TIMER_DMAREQUEST_UPDATEEVENT: DMA request of channel y is sent when update event occurs
+ \arg TIMER_DMAREQUEST_UPDATEEVENT: DMA request of channel y is sent when update event occurs
\param[out] none
\retval none
*/
void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma_request)
{
- if(TIMER_DMAREQUEST_UPDATEEVENT == dma_request){
+ if(TIMER_DMAREQUEST_UPDATEEVENT == dma_request) {
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_DMAS;
- }else if(TIMER_DMAREQUEST_CHANNELEVENT == dma_request){
+ } else if(TIMER_DMAREQUEST_CHANNELEVENT == dma_request) {
TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_DMAS;
- }else{
- /* illegal parameters */
+ } else {
+ /* illegal parameters */
}
}
@@ -512,21 +510,24 @@ void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma
*/
void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth)
{
- TIMER_DMACFG(timer_periph) &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
- TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_lenth);
+ uint32_t reg = 0U;
+ reg = TIMER_DMACFG(timer_periph);
+ reg &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
+ reg |= (uint32_t)(dma_baseaddr | dma_lenth);
+ TIMER_DMACFG(timer_periph) = (uint32_t)reg;
}
/*!
- \brief software generate events
+ \brief software generate events
\param[in] timer_periph: please refer to the following parameters
\param[in] event: the timer software event generation sources
one or more parameters can be selected which are shown as below:
\arg TIMER_EVENT_SRC_UPG: update event generation, TIMERx(x=0..13)
- \arg TIMER_EVENT_SRC_CH0G: channel 0 capture or compare event generation, TIMERx(x=0..4,7..13)
+ \arg TIMER_EVENT_SRC_CH0G: channel 0 capture or compare event generation, TIMERx(x=0..4,7..13)
\arg TIMER_EVENT_SRC_CH1G: channel 1 capture or compare event generation, TIMERx(x=0..4,7,8,11)
- \arg TIMER_EVENT_SRC_CH2G: channel 2 capture or compare event generation, TIMERx(x=0..4,7)
- \arg TIMER_EVENT_SRC_CH3G: channel 3 capture or compare event generation, TIMERx(x=0..4,7)
- \arg TIMER_EVENT_SRC_CMTG: channel commutation event generation, TIMERx(x=0,7)
+ \arg TIMER_EVENT_SRC_CH2G: channel 2 capture or compare event generation, TIMERx(x=0..4,7)
+ \arg TIMER_EVENT_SRC_CH3G: channel 3 capture or compare event generation, TIMERx(x=0..4,7)
+ \arg TIMER_EVENT_SRC_CMTG: channel commutation event generation, TIMERx(x=0,7)
\arg TIMER_EVENT_SRC_TRGG: trigger event generation, TIMERx(x=0..4,7,8,11)
\arg TIMER_EVENT_SRC_BRKG: break event generation, TIMERx(x=0,7)
\param[out] none
@@ -539,11 +540,11 @@ void timer_event_software_generate(uint32_t timer_periph, uint16_t event)
/*!
\brief initialize TIMER break parameter struct with a default value
- \param[in] breakpara: TIMER break parameter struct
- \param[out] none
+ \param[in] none
+ \param[out] breakpara: TIMER break parameter struct
\retval none
*/
-void timer_break_struct_para_init(timer_break_parameter_struct* breakpara)
+void timer_break_struct_para_init(timer_break_parameter_struct *breakpara)
{
/* initialize the break parameter struct member with the default value */
breakpara->runoffstate = TIMER_ROS_STATE_DISABLE;
@@ -556,20 +557,20 @@ void timer_break_struct_para_init(timer_break_parameter_struct* breakpara)
}
/*!
- \brief configure TIMER break function
+ \brief configure TIMER break function
\param[in] timer_periph: TIMERx(x=0,7)
\param[in] breakpara: TIMER break parameter struct
- runoffstate: TIMER_ROS_STATE_ENABLE,TIMER_ROS_STATE_DISABLE
- ideloffstate: TIMER_IOS_STATE_ENABLE,TIMER_IOS_STATE_DISABLE
+ runoffstate: TIMER_ROS_STATE_ENABLE, TIMER_ROS_STATE_DISABLE
+ ideloffstate: TIMER_IOS_STATE_ENABLE, TIMER_IOS_STATE_DISABLE
deadtime: 0~255
- breakpolarity: TIMER_BREAK_POLARITY_LOW,TIMER_BREAK_POLARITY_HIGH
- outputautostate: TIMER_OUTAUTO_ENABLE,TIMER_OUTAUTO_DISABLE
- protectmode: TIMER_CCHP_PROT_OFF,TIMER_CCHP_PROT_0,TIMER_CCHP_PROT_1,TIMER_CCHP_PROT_2
+ breakpolarity: TIMER_BREAK_POLARITY_LOW, TIMER_BREAK_POLARITY_HIGH
+ outputautostate: TIMER_OUTAUTO_ENABLE ,TIMER_OUTAUTO_DISABLE
+ protectmode: TIMER_CCHP_PROT_OFF,TIMER_CCHP_PROT_0, TIMER_CCHP_PROT_1, TIMER_CCHP_PROT_2
breakstate: TIMER_BREAK_ENABLE,TIMER_BREAK_DISABLE
\param[out] none
\retval none
*/
-void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara)
+void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct *breakpara)
{
TIMER_CCHP(timer_periph) = (uint32_t)(((uint32_t)(breakpara->runoffstate)) |
((uint32_t)(breakpara->ideloffstate)) |
@@ -625,7 +626,7 @@ void timer_automatic_output_disable(uint32_t timer_periph)
}
/*!
- \brief enable or disable TIMER primary output function
+ \brief configure TIMER primary output function
\param[in] timer_periph: TIMERx(x=0,7)
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
@@ -633,25 +634,25 @@ void timer_automatic_output_disable(uint32_t timer_periph)
*/
void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue)
{
- if(ENABLE == newvalue){
+ if(ENABLE == newvalue) {
TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_POEN;
- }else{
+ } else {
TIMER_CCHP(timer_periph) &= (~(uint32_t)TIMER_CCHP_POEN);
}
}
/*!
- \brief enable or disable channel capture/compare control shadow register
+ \brief enable or disable channel capture/compare control shadow register
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] newvalue: ENABLE or DISABLE
+ \param[in] newvalue: ENABLE or DISABLE
\param[out] none
\retval none
*/
void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue)
{
- if(ENABLE == newvalue){
+ if(ENABLE == newvalue) {
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCSE;
- }else{
+ } else {
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCSE);
}
}
@@ -662,28 +663,28 @@ void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus ne
\param[in] ccuctl: channel control shadow register update control
only one parameter can be selected which is shown as below:
\arg TIMER_UPDATECTL_CCU: the shadow registers update by when CMTG bit is set
- \arg TIMER_UPDATECTL_CCUTRI: the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs
+ \arg TIMER_UPDATECTL_CCUTRI: the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs
\param[out] none
\retval none
-*/
+*/
void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint32_t ccuctl)
{
- if(TIMER_UPDATECTL_CCU == ccuctl){
+ if(TIMER_UPDATECTL_CCU == ccuctl) {
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCUC);
- }else if(TIMER_UPDATECTL_CCUTRI == ccuctl){
+ } else if(TIMER_UPDATECTL_CCUTRI == ccuctl) {
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCUC;
- }else{
- /* illegal parameters */
+ } else {
+ /* illegal parameters */
}
}
/*!
\brief initialize TIMER channel output parameter struct with a default value
- \param[in] ocpara: TIMER channel n output parameter struct
- \param[out] none
+ \param[in] none
+ \param[out] ocpara: TIMER channel n output parameter struct
\retval none
*/
-void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara)
+void timer_channel_output_struct_para_init(timer_oc_parameter_struct *ocpara)
{
/* initialize the channel output parameter struct member with the default value */
ocpara->outputstate = TIMER_CCX_DISABLE;
@@ -704,18 +705,18 @@ void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara)
\arg TIMER_CH_2: TIMER channel 2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel 3(TIMERx(x=0..4,7))
\param[in] ocpara: TIMER channeln output parameter struct
- outputstate: TIMER_CCX_ENABLE,TIMER_CCX_DISABLE
- outputnstate: TIMER_CCXN_ENABLE,TIMER_CCXN_DISABLE
- ocpolarity: TIMER_OC_POLARITY_HIGH,TIMER_OC_POLARITY_LOW
- ocnpolarity: TIMER_OCN_POLARITY_HIGH,TIMER_OCN_POLARITY_LOW
- ocidlestate: TIMER_OC_IDLE_STATE_LOW,TIMER_OC_IDLE_STATE_HIGH
- ocnidlestate: TIMER_OCN_IDLE_STATE_LOW,TIMER_OCN_IDLE_STATE_HIGH
+ outputstate: TIMER_CCX_ENABLE, TIMER_CCX_DISABLE
+ outputnstate: TIMER_CCXN_ENABLE, TIMER_CCXN_DISABLE
+ ocpolarity: TIMER_OC_POLARITY_HIGH, TIMER_OC_POLARITY_LOW
+ ocnpolarity: TIMER_OCN_POLARITY_HIGH, TIMER_OCN_POLARITY_LOW
+ ocidlestate: TIMER_OC_IDLE_STATE_LOW, TIMER_OC_IDLE_STATE_HIGH
+ ocnidlestate: TIMER_OCN_IDLE_STATE_LOW, TIMER_OCN_IDLE_STATE_HIGH
\param[out] none
\retval none
*/
-void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct* ocpara)
+void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct *ocpara)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
/* reset the CH0EN bit */
@@ -728,7 +729,7 @@ void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_
/* set the CH0P bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->ocpolarity;
- if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
+ if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)) {
/* reset the CH0NEN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NEN);
/* set the CH0NEN bit */
@@ -757,25 +758,25 @@ void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_
/* reset the CH1P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1P);
/* set the CH1P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 4U);
- if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
+ if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)) {
/* reset the CH1NEN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NEN);
/* set the CH1NEN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate) << 4U);
/* reset the CH1NP bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NP);
/* set the CH1NP bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity) << 4U);
/* reset the ISO1 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1);
/* set the ISO1 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate)<< 2U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 2U);
/* reset the ISO1N bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1N);
/* set the ISO1N bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate)<< 2U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate) << 2U);
}
break;
/* configure TIMER_CH_2 */
@@ -788,44 +789,44 @@ void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_
/* reset the CH2P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2P);
/* set the CH2P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 8U);
- if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
+ if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)) {
/* reset the CH2NEN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NEN);
/* set the CH2NEN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate) << 8U);
/* reset the CH2NP bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NP);
/* set the CH2NP bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity) << 8U);
/* reset the ISO2 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO2);
/* set the ISO2 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate)<< 4U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 4U);
/* reset the ISO2N bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO2N);
/* set the ISO2N bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate)<< 4U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate) << 4U);
}
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
/* reset the CH3EN bit */
- TIMER_CHCTL2(timer_periph) &=(~(uint32_t)TIMER_CHCTL2_CH3EN);
+ TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH3MS;
/* set the CH3EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputstate) << 12U);
/* reset the CH3P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3P);
/* set the CH3P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity)<< 12U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 12U);
- if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
+ if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)) {
/* reset the ISO3 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO3);
/* set the ISO3 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate)<< 6U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 6U);
}
break;
default:
@@ -850,14 +851,14 @@ void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_
\arg TIMER_OC_MODE_TOGGLE: toggle mode
\arg TIMER_OC_MODE_LOW: force low mode
\arg TIMER_OC_MODE_HIGH: force high mode
- \arg TIMER_OC_MODE_PWM0: PWM0 mode
- \arg TIMER_OC_MODE_PWM1: PWM1 mode
+ \arg TIMER_OC_MODE_PWM0: PWM mode 0
+ \arg TIMER_OC_MODE_PWM1: PWM mode 1
\param[out] none
\retval none
*/
void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMCTL);
@@ -866,7 +867,7 @@ void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, u
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMCTL);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(ocmode)<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(ocmode) << 8U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
@@ -876,7 +877,7 @@ void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, u
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMCTL);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(ocmode)<< 8U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(ocmode) << 8U);
break;
default:
break;
@@ -892,13 +893,13 @@ void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, u
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] pulse: channel output pulse value
+ \param[in] pulse: channel output pulse value, 0~65535
\param[out] none
\retval none
*/
-void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint16_t pulse)
+void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
@@ -913,7 +914,7 @@ void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t cha
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
- TIMER_CH3CV(timer_periph) = (uint32_t)pulse;
+ TIMER_CH3CV(timer_periph) = (uint32_t)pulse;
break;
default:
break;
@@ -938,7 +939,7 @@ void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t cha
*/
void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMSEN);
@@ -982,7 +983,7 @@ void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel,
*/
void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMFEN);
@@ -1026,7 +1027,7 @@ void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, u
*/
void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel, uint16_t occlear)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMCEN);
@@ -1053,7 +1054,7 @@ void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel,
}
/*!
- \brief configure TIMER channel output polarity
+ \brief configure TIMER channel output polarity
\param[in] timer_periph: please refer to the following parameters
\param[in] channel:
only one parameter can be selected which is shown as below:
@@ -1070,7 +1071,7 @@ void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel,
*/
void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0P);
@@ -1097,14 +1098,14 @@ void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channe
}
/*!
- \brief configure TIMER channel complementary output polarity
+ \brief configure TIMER channel complementary output polarity
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] channel:
+ \param[in] channel:
only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
- \param[in] ocnpolarity: channel complementary output polarity
+ \param[in] ocnpolarity: channel complementary output polarity
only one parameter can be selected which is shown as below:
\arg TIMER_OCN_POLARITY_HIGH: channel complementary output polarity is high
\arg TIMER_OCN_POLARITY_LOW: channel complementary output polarity is low
@@ -1113,7 +1114,7 @@ void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channe
*/
void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NP);
@@ -1145,14 +1146,14 @@ void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, u
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
\param[in] state: TIMER channel enable state
only one parameter can be selected which is shown as below:
- \arg TIMER_CCX_ENABLE: channel enable
- \arg TIMER_CCX_DISABLE: channel disable
+ \arg TIMER_CCX_ENABLE: channel enable
+ \arg TIMER_CCX_DISABLE: channel disable
\param[out] none
\retval none
*/
void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
@@ -1188,14 +1189,14 @@ void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel,
\arg TIMER_CH_2: TIMER channel2
\param[in] ocnstate: TIMER channel complementary output enable state
only one parameter can be selected which is shown as below:
- \arg TIMER_CCXN_ENABLE: channel complementary enable
- \arg TIMER_CCXN_DISABLE: channel complementary disable
+ \arg TIMER_CCXN_ENABLE: channel complementary enable
+ \arg TIMER_CCXN_DISABLE: channel complementary disable
\param[out] none
\retval none
*/
void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NEN);
@@ -1218,11 +1219,11 @@ void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint
/*!
\brief initialize TIMER channel input parameter struct with a default value
- \param[in] icpara: TIMER channel intput parameter struct
- \param[out] none
+ \param[in] none
+ \param[out] icpara: TIMER channel intput parameter struct
\retval none
*/
-void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
+void timer_channel_input_struct_para_init(timer_ic_parameter_struct *icpara)
{
/* initialize the channel input parameter struct member with the default value */
icpara->icpolarity = TIMER_IC_POLARITY_RISING;
@@ -1232,17 +1233,17 @@ void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
}
/*!
- \brief configure TIMER input capture parameter
+ \brief configure TIMER input capture parameter
\param[in] timer_periph: please refer to the following parameters
\param[in] channel:
- only one parameter can be selected which is shown as below:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel 0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel 1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel 2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel 3(TIMERx(x=0..4,7))
\param[in] icpara: TIMER channel intput parameter struct
icpolarity: TIMER_IC_POLARITY_RISING, TIMER_IC_POLARITY_FALLING,
- TIMER_IC_POLARITY_BOTH_EDGE(only for TIMER1~TIMER8)
+ TIMER_IC_POLARITY_BOTH_EDGE(only for TIMERx(x=0, 7..13))
icselection: TIMER_IC_SELECTION_DIRECTTI, TIMER_IC_SELECTION_INDIRECTTI,
TIMER_IC_SELECTION_ITS
icprescaler: TIMER_IC_PSC_DIV1, TIMER_IC_PSC_DIV2, TIMER_IC_PSC_DIV4,
@@ -1251,9 +1252,9 @@ void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
\param[out] none
\retval none
*/
-void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpara)
+void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpara)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
/* reset the CH0EN bit */
@@ -1272,7 +1273,7 @@ void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_i
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
break;
-
+
/* configure TIMER_CH_1 */
case TIMER_CH_1:
/* reset the CH1EN bit */
@@ -1335,7 +1336,7 @@ void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_i
break;
}
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,channel,(uint16_t)(icpara->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, channel, (uint16_t)(icpara->icprescaler));
}
/*!
@@ -1358,7 +1359,7 @@ void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_i
*/
void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler)
{
- switch(channel){
+ switch(channel) {
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPPSC);
@@ -1394,13 +1395,13 @@ void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
\param[out] none
- \retval channel capture compare register value
+ \retval channel capture compare register value, 0~65535
*/
uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel)
{
uint32_t count_value = 0U;
- switch(channel){
+ switch(channel) {
case TIMER_CH_0:
/* read TIMER channel 0 capture compare register value */
count_value = TIMER_CH0CV(timer_periph);
@@ -1424,39 +1425,39 @@ uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16
}
/*!
- \brief configure TIMER input pwm capture function
+ \brief configure TIMER input pwm capture function
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
\param[in] channel:
only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0
\arg TIMER_CH_1: TIMER channel1
\param[in] icpwm:TIMER channel intput pwm parameter struct
- icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING
- icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI
- icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
+ icpolarity: TIMER_IC_POLARITY_RISING, TIMER_IC_POLARITY_FALLING
+ icselection: TIMER_IC_SELECTION_DIRECTTI, TIMER_IC_SELECTION_INDIRECTTI
+ icprescaler: TIMER_IC_PSC_DIV1, TIMER_IC_PSC_DIV2, TIMER_IC_PSC_DIV4, TIMER_IC_PSC_DIV8
icfilter: 0~15
\param[out] none
\retval none
*/
-void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm)
+void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpwm)
{
uint16_t icpolarity = 0x0U;
uint16_t icselection = 0x0U;
/* Set channel input polarity */
- if(TIMER_IC_POLARITY_RISING == icpwm->icpolarity){
+ if(TIMER_IC_POLARITY_RISING == icpwm->icpolarity) {
icpolarity = TIMER_IC_POLARITY_FALLING;
- }else{
+ } else {
icpolarity = TIMER_IC_POLARITY_RISING;
}
/* Set channel input mode selection */
- if(TIMER_IC_SELECTION_DIRECTTI == icpwm->icselection){
+ if(TIMER_IC_SELECTION_DIRECTTI == icpwm->icselection) {
icselection = TIMER_IC_SELECTION_INDIRECTTI;
- }else{
+ } else {
icselection = TIMER_IC_SELECTION_DIRECTTI;
}
- if(TIMER_CH_0 == channel){
+ if(TIMER_CH_0 == channel) {
/* reset the CH0EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
/* reset the CH0P and CH0NP bits */
@@ -1474,50 +1475,50 @@ void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, tim
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_0,(uint16_t)(icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_0, (uint16_t)(icpwm->icprescaler));
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
/* reset the CH1P and CH1NP bits */
- TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
+ TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
/* set the CH1P and CH1NP bits */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)icpolarity<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)icpolarity << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
/* set the CH1MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)icselection<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)icselection << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
/* set the CH1CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter)<< 12U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_1,(uint16_t)(icpwm->icprescaler));
- }else{
+ timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_1, (uint16_t)(icpwm->icprescaler));
+ } else {
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
/* reset the CH1P and CH1NP bits */
- TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
+ TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
/* set the CH1P and CH1NP bits */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icpolarity) << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
/* set the CH1MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icselection)<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icselection) << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
/* set the CH1CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter)<< 12U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_1,(uint16_t)(icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_1, (uint16_t)(icpwm->icprescaler));
/* reset the CH0EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
/* reset the CH0P and CH0NP bits */
- TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
+ TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
/* set the CH0P and CH0NP bits */
TIMER_CHCTL2(timer_periph) |= (uint32_t)icpolarity;
/* reset the CH0MS bit */
@@ -1531,7 +1532,7 @@ void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, tim
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_0,(uint16_t)(icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_0, (uint16_t)(icpwm->icprescaler));
}
}
@@ -1545,44 +1546,48 @@ void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, tim
\param[out] none
\retval none
*/
-void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
+void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
{
- if(TIMER_HALLINTERFACE_ENABLE == hallmode){
+ if(TIMER_HALLINTERFACE_ENABLE == hallmode) {
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_TI0S;
- }else if(TIMER_HALLINTERFACE_DISABLE == hallmode){
+ } else if(TIMER_HALLINTERFACE_DISABLE == hallmode) {
TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_TI0S;
- }else{
- /* illegal parameters */
+ } else {
+ /* illegal parameters */
}
}
/*!
- \brief select TIMER input trigger source
+ \brief select TIMER input trigger source
\param[in] timer_periph: please refer to the following parameters
\param[in] intrigger:
only one parameter can be selected which is shown as below:
- \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0,TIMERx(x=0..4,7,8,11)
- \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1,TIMERx(x=0..4,7,8,11)
- \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2,TIMERx(x=0..4,7,8,11)
- \arg TIMER_SMCFG_TRGSEL_ITI3: internal trigger 3,TIMERx(x=0..4,7,8,11)
- \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector,TIMERx(x=0..4,7,8,11)
- \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0,TIMERx(x=0..4,7,8,11)
- \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0, TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1, TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2, TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_ITI3: internal trigger 3, TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector, TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0, TIMERx(x=0..4,7,8,11)
+ \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1, TIMERx(x=0..4,7,8,11)
\arg TIMER_SMCFG_TRGSEL_ETIFP: external trigger,TIMERx(x=0..4,7)
\param[out] none
\retval none
*/
void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger)
{
- TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_TRGS);
- TIMER_SMCFG(timer_periph) |= (uint32_t)intrigger;
+ uint32_t reg;
+
+ reg = TIMER_SMCFG(timer_periph);
+ reg &= (~(uint32_t)TIMER_SMCFG_TRGS);
+ reg |= (uint32_t)intrigger;
+ TIMER_SMCFG(timer_periph) = reg;
}
/*!
- \brief select TIMER master mode output trigger source
+ \brief select TIMER master mode output trigger source
\param[in] timer_periph: TIMERx(x=0..7)
\param[in] outrigger:
- only one parameter can be selected which is shown as below:
+ only one parameter can be selected which is shown as below:
\arg TIMER_TRI_OUT_SRC_RESET: the UPG bit as trigger output(TIMERx(x=0..7))
\arg TIMER_TRI_OUT_SRC_ENABLE: the counter enable signal TIMER_CTL0_CEN as trigger output(TIMERx(x=0..7))
\arg TIMER_TRI_OUT_SRC_UPDATE: update event as trigger output(TIMERx(x=0..7))
@@ -1601,14 +1606,14 @@ void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t o
}
/*!
- \brief select TIMER slave mode
+ \brief select TIMER slave mode
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
\param[in] slavemode:
only one parameter can be selected which is shown as below:
\arg TIMER_SLAVE_MODE_DISABLE: slave mode disable
- \arg TIMER_ENCODER_MODE0: encoder mode 0
- \arg TIMER_ENCODER_MODE1: encoder mode 1
- \arg TIMER_ENCODER_MODE2: encoder mode 2
+ \arg TIMER_QUAD_DECODER_MODE0: quadrature decoder mode 0
+ \arg TIMER_QUAD_DECODER_MODE1: quadrature decoder mode 1
+ \arg TIMER_QUAD_DECODER_MODE2: quadrature decoder mode 2
\arg TIMER_SLAVE_MODE_RESTART: restart mode
\arg TIMER_SLAVE_MODE_PAUSE: pause mode
\arg TIMER_SLAVE_MODE_EVENT: event mode
@@ -1625,7 +1630,7 @@ void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
}
/*!
- \brief configure TIMER master slave mode
+ \brief configure TIMER master slave mode
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
\param[in] masterslave:
only one parameter can be selected which is shown as below:
@@ -1633,15 +1638,15 @@ void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
\arg TIMER_MASTER_SLAVE_MODE_DISABLE: master slave mode disable
\param[out] none
\retval none
-*/
+*/
void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
{
- if(TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave){
+ if(TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave) {
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_MSM;
- }else if(TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave){
+ } else if(TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave) {
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_MSM;
- }else{
- /* illegal parameters */
+ } else {
+ /* illegal parameters */
}
}
@@ -1662,7 +1667,7 @@ void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
\param[out] none
\retval none
*/
-void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint8_t extfilter)
+void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
{
TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_ETP | TIMER_SMCFG_ETPSC | TIMER_SMCFG_ETFC));
TIMER_SMCFG(timer_periph) |= (uint32_t)(extprescaler | extpolarity);
@@ -1671,12 +1676,12 @@ void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler,
/*!
\brief configure TIMER quadrature decoder mode
- \param[in] timer_periph: TIMERx(x=0..4,7,8,11)
+ \param[in] timer_periph: TIMERx(x=0..4,7)
\param[in] decomode:
only one parameter can be selected which is shown as below:
- \arg TIMER_ENCODER_MODE0: counter counts on CI0FE0 edge depending on CI1FE1 level
- \arg TIMER_ENCODER_MODE1: counter counts on CI1FE1 edge depending on CI0FE0 level
- \arg TIMER_ENCODER_MODE2: counter counts on both CI0FE0 and CI1FE1 edges depending on the level of the other input
+ \arg TIMER_QUAD_DECODER_MODE0: counter counts on CI0FE0 edge depending on CI1FE1 level
+ \arg TIMER_QUAD_DECODER_MODE1: counter counts on CI1FE1 edge depending on CI0FE0 level
+ \arg TIMER_QUAD_DECODER_MODE2: counter counts on both CI0FE0 and CI1FE1 edges depending on the level of the other input
\param[in] ic0polarity:
only one parameter can be selected which is shown as below:
\arg TIMER_IC_POLARITY_RISING: capture rising edge
@@ -1716,7 +1721,7 @@ void timer_internal_clock_config(uint32_t timer_periph)
/*!
\brief configure TIMER the internal trigger as external clock input
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] intrigger:
+ \param[in] intrigger:
only one parameter can be selected which is shown as below:
\arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0
\arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1
@@ -1727,7 +1732,7 @@ void timer_internal_clock_config(uint32_t timer_periph)
*/
void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger)
{
- timer_input_trigger_source_select(timer_periph,intrigger);
+ timer_input_trigger_source_select(timer_periph, intrigger);
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
}
@@ -1740,7 +1745,7 @@ void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint
\arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector
\arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0
\arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1
- \param[in] expolarity:
+ \param[in] extpolarity:
only one parameter can be selected which is shown as below:
\arg TIMER_IC_POLARITY_RISING: active high or rising edge active
\arg TIMER_IC_POLARITY_FALLING: active low or falling edge active
@@ -1748,30 +1753,30 @@ void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint
\param[out] none
\retval none
*/
-void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint8_t extfilter)
+void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint32_t extfilter)
{
- if(TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger){
+ if(TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger) {
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
/* reset the CH1NP bit */
- TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
+ TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
/* set the CH1NP bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)extpolarity << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
/* set the CH1MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)TIMER_IC_SELECTION_DIRECTTI<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
/* set the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) |= (uint32_t)(extfilter << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
- }else{
+ } else {
/* reset the CH0EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
/* reset the CH0P and CH0NP bits */
- TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
+ TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
/* set the CH0P and CH0NP bits */
TIMER_CHCTL2(timer_periph) |= (uint32_t)extpolarity;
/* reset the CH0MS bit */
@@ -1802,7 +1807,7 @@ void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint
\arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
\arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
\arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
- \param[in] expolarity:
+ \param[in] extpolarity:
only one parameter can be selected which is shown as below:
\arg TIMER_ETP_FALLING: active low or falling edge active
\arg TIMER_ETP_RISING: active high or rising edge active
@@ -1810,14 +1815,17 @@ void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint
\param[out] none
\retval none
*/
-void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint8_t extfilter)
+void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
{
+ uint32_t reg = 0U;
+ reg = TIMER_SMCFG(timer_periph);
+
/* configure TIMER external trigger input */
timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
- /* reset the SMC bit,TRGS bit */
- TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_SMC | TIMER_SMCFG_TRGS));
- /* set the SMC bit,TRGS bit */
- TIMER_SMCFG(timer_periph) |= (uint32_t)(TIMER_SLAVE_MODE_EXTERNAL0 | TIMER_SMCFG_TRGSEL_ETIFP);
+ /* set the SMC bit, TRGS bit */
+ reg &= (~(uint32_t)(TIMER_SMCFG_SMC | TIMER_SMCFG_TRGS));
+ reg |= (uint32_t)(TIMER_SLAVE_MODE_EXTERNAL0 | TIMER_SMCFG_TRGSEL_ETIFP);
+ TIMER_SMCFG(timer_periph) = reg;
}
/*!
@@ -1830,14 +1838,14 @@ void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extpresca
\arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
\arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
\param[in] extpolarity:
- only one parameter can be selected which is shown as below:
+ only one parameter can be selected which is shown as below:
\arg TIMER_ETP_FALLING: active low or falling edge active
\arg TIMER_ETP_RISING: active high or rising edge active
\param[in] extfilter: a value between 0 and 15
\param[out] none
\retval none
*/
-void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint8_t extfilter)
+void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
{
/* configure TIMER external trigger input */
timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
@@ -1855,9 +1863,64 @@ void timer_external_clock_mode1_disable(uint32_t timer_periph)
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC1;
}
+
+/*!
+ \brief get TIMER flags
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] flag: the timer interrupt flags
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_FLAG_UP: update flag,TIMERx(x=0..13)
+ \arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=0..4,7..13)
+ \arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=0..4,7)
+ \arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=0..4,7)
+ \arg TIMER_FLAG_CMT: channel commutation flag,TIMERx(x=0,7)
+ \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
+ \arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,7)
+ \arg TIMER_FLAG_CH0O: channel 0 overcapture flag,TIMERx(x=0..4,7..11)
+ \arg TIMER_FLAG_CH1O: channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_FLAG_CH2O: channel 2 overcapture flag,TIMERx(x=0..4,7)
+ \arg TIMER_FLAG_CH3O: channel 3 overcapture flag,TIMERx(x=0..4,7)
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
+{
+ if(RESET != (TIMER_INTF(timer_periph) & flag)) {
+ return SET;
+ } else {
+ return RESET;
+ }
+}
+
+/*!
+ \brief clear TIMER flags
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] flag: the timer interrupt flags
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_FLAG_UP: update flag,TIMERx(x=0..13)
+ \arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=0..4,7..13)
+ \arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=0..4,7)
+ \arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=0..4,7)
+ \arg TIMER_FLAG_CMT: channel control update flag,TIMERx(x=0,7)
+ \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
+ \arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,7)
+ \arg TIMER_FLAG_CH0O: channel 0 overcapture flag,TIMERx(x=0..4,7..11)
+ \arg TIMER_FLAG_CH1O: channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_FLAG_CH2O: channel 2 overcapture flag,TIMERx(x=0..4,7)
+ \arg TIMER_FLAG_CH3O: channel 3 overcapture flag,TIMERx(x=0..4,7)
+ \param[out] none
+ \retval none
+*/
+void timer_flag_clear(uint32_t timer_periph, uint32_t flag)
+{
+ TIMER_INTF(timer_periph) = (~(uint32_t)flag);
+}
+
/*!
\brief enable the TIMER interrupt
- \param[in] timer_periph: please refer to the following parameters
+ \param[in] timer_periph: please refer to the following parameters
\param[in] interrupt: timer interrupt enable source
only one parameter can be selected which is shown as below:
\arg TIMER_INT_UP: update interrupt enable, TIMERx(x=0..13)
@@ -1873,7 +1936,7 @@ void timer_external_clock_mode1_disable(uint32_t timer_periph)
*/
void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
{
- TIMER_DMAINTEN(timer_periph) |= (uint32_t) interrupt;
+ TIMER_DMAINTEN(timer_periph) |= (uint32_t) interrupt;
}
/*!
@@ -1894,32 +1957,32 @@ void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
*/
void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt)
{
- TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt);
+ TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt);
}
/*!
\brief get timer interrupt flag
\param[in] timer_periph: please refer to the following parameters
- \param[in] interrupt: the timer interrupt bits
+ \param[in] int_flag: the timer interrupt flag
only one parameter can be selected which is shown as below:
\arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=0..13)
\arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=0..4,7..13)
\arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
\arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=0..4,7)
\arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=0..4,7)
- \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
+ \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
\arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=0,7,8,11)
\arg TIMER_INT_FLAG_BRK: break interrupt flag,TIMERx(x=0,7)
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt)
+FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t int_flag)
{
uint32_t val;
- val = (TIMER_DMAINTEN(timer_periph) & interrupt);
- if((RESET != (TIMER_INTF(timer_periph) & interrupt) ) && (RESET != val)){
+ val = (TIMER_DMAINTEN(timer_periph) & int_flag);
+ if((RESET != (TIMER_INTF(timer_periph) & int_flag)) && (RESET != val)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -1927,74 +1990,20 @@ FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt)
/*!
\brief clear TIMER interrupt flag
\param[in] timer_periph: please refer to the following parameters
- \param[in] interrupt: the timer interrupt bits
+ \param[in] int_flag: the timer interrupt flag
only one parameter can be selected which is shown as below:
\arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=0..13)
\arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=0..4,7..13)
\arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
\arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=0..4,7)
\arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=0..4,7)
- \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
+ \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
\arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=0,7,8,11)
\arg TIMER_INT_FLAG_BRK: break interrupt flag,TIMERx(x=0,7)
\param[out] none
\retval none
*/
-void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt)
+void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t int_flag)
{
- TIMER_INTF(timer_periph) = (~(uint32_t)interrupt);
-}
-
-/*!
- \brief get TIMER flags
- \param[in] timer_periph: please refer to the following parameters
- \param[in] flag: the timer interrupt flags
- only one parameter can be selected which is shown as below:
- \arg TIMER_FLAG_UP: update flag,TIMERx(x=0..13)
- \arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=0..4,7..13)
- \arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=0..4,7,8,11)
- \arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CMT: channel commutation flag,TIMERx(x=0,7)
- \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
- \arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,7)
- \arg TIMER_FLAG_CH0O: channel 0 overcapture flag,TIMERx(x=0..4,7..11)
- \arg TIMER_FLAG_CH1O: channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
- \arg TIMER_FLAG_CH2O: channel 2 overcapture flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CH3O: channel 3 overcapture flag,TIMERx(x=0..4,7)
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
-{
- if(RESET != (TIMER_INTF(timer_periph) & flag)){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear TIMER flags
- \param[in] timer_periph: please refer to the following parameters
- \param[in] flag: the timer interrupt flags
- only one parameter can be selected which is shown as below:
- \arg TIMER_FLAG_UP: update flag,TIMERx(x=0..13)
- \arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=0..4,7..13)
- \arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=0..4,7,8,11)
- \arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CMT: channel control update flag,TIMERx(x=0,7)
- \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
- \arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,7)
- \arg TIMER_FLAG_CH0O: channel 0 overcapture flag,TIMERx(x=0..4,7..11)
- \arg TIMER_FLAG_CH1O: channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
- \arg TIMER_FLAG_CH2O: channel 2 overcapture flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CH3O: channel 3 overcapture flag,TIMERx(x=0..4,7)
- \param[out] none
- \retval none
-*/
-void timer_flag_clear(uint32_t timer_periph, uint32_t flag)
-{
- TIMER_INTF(timer_periph) = (~(uint32_t)flag);
+ TIMER_INTF(timer_periph) = (~(uint32_t)int_flag);
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_tli.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_tli.c
index 9b1362e..26dc3f0 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_tli.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_tli.c
@@ -2,43 +2,43 @@
\file gd32f20x_tli.c
\brief TLI driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_tli.h"
+#define TLI_DEFAULT_VALUE 0x00000000U
+#define TLI_OPAQUE_VALUE 0x000000FFU
+
/*!
- \brief deinitialize TLI registers
+ \brief deinitialize TLI registers
\param[in] none
\param[out] none
\retval none
@@ -50,22 +50,64 @@ void tli_deinit(void)
}
/*!
- \brief initialize TLI display timing parameters
- \param[in] tli_struct: the data needed to initialize tli
+ \brief initialize the parameters of TLI parameter structure with the default values, it is suggested
+ that call this function after a tli_parameter_struct structure is defined
+ \param[in] none
+ \param[out] tli_struct: the data needed to initialize TLI
synpsz_vpsz: size of the vertical synchronous pulse
synpsz_hpsz: size of the horizontal synchronous pulse
- backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
+ backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
- totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
+ totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
totalsz_htsz: vorizontal total size of the display, including active area, back porch, synchronous
backcolor_red: background value red
backcolor_green: background value green
backcolor_blue: background value blue
- signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGHT
- signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGHT
- signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGHT
+ signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGH
+ signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGH
+ signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGH
+ signalpolarity_pixelck: TLI_PIXEL_CLOCK_TLI,TLI_PIXEL_CLOCK_INVERTEDTLI
+ \retval none
+*/
+void tli_struct_para_init(tli_parameter_struct *tli_struct)
+{
+ /* initialize the struct parameters with default values */
+ tli_struct->synpsz_vpsz = TLI_DEFAULT_VALUE;
+ tli_struct->synpsz_hpsz = TLI_DEFAULT_VALUE;
+ tli_struct->backpsz_vbpsz = TLI_DEFAULT_VALUE;
+ tli_struct->backpsz_hbpsz = TLI_DEFAULT_VALUE;
+ tli_struct->activesz_vasz = TLI_DEFAULT_VALUE;
+ tli_struct->activesz_hasz = TLI_DEFAULT_VALUE;
+ tli_struct->totalsz_vtsz = TLI_DEFAULT_VALUE;
+ tli_struct->totalsz_htsz = TLI_DEFAULT_VALUE;
+ tli_struct->backcolor_red = TLI_DEFAULT_VALUE;
+ tli_struct->backcolor_green = TLI_DEFAULT_VALUE;
+ tli_struct->backcolor_blue = TLI_DEFAULT_VALUE;
+ tli_struct->signalpolarity_hs = TLI_HSYN_ACTLIVE_LOW;
+ tli_struct->signalpolarity_vs = TLI_VSYN_ACTLIVE_LOW;
+ tli_struct->signalpolarity_de = TLI_DE_ACTLIVE_LOW;
+ tli_struct->signalpolarity_pixelck = TLI_PIXEL_CLOCK_TLI;
+}
+
+/*!
+ \brief initialize TLI display timing parameters
+ \param[in] tli_struct: the data needed to initialize TLI
+ synpsz_vpsz: size of the vertical synchronous pulse
+ synpsz_hpsz: size of the horizontal synchronous pulse
+ backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
+ backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
+ activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
+ activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
+ totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
+ totalsz_htsz: horizontal total size of the display, including active area, back porch, synchronous
+ backcolor_red: background value red
+ backcolor_green: background value green
+ backcolor_blue: background value blue
+ signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGH
+ signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGH
+ signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGH
signalpolarity_pixelck: TLI_PIXEL_CLOCK_TLI,TLI_PIXEL_CLOCK_INVERTEDTLI
\param[out] none
\retval none
@@ -73,44 +115,45 @@ void tli_deinit(void)
void tli_init(tli_parameter_struct *tli_struct)
{
/* synchronous pulse size configuration */
- TLI_SPSZ &= ~(TLI_SPSZ_VPSZ|TLI_SPSZ_HPSZ);
- TLI_SPSZ = (tli_struct->synpsz_vpsz|(tli_struct->synpsz_hpsz<<16U));
+ TLI_SPSZ &= ~(TLI_SPSZ_VPSZ | TLI_SPSZ_HPSZ);
+ TLI_SPSZ = (uint32_t)((uint32_t)tli_struct->synpsz_vpsz | ((uint32_t)tli_struct->synpsz_hpsz << 16U));
/* back-porch size configuration */
- TLI_BPSZ &= ~(TLI_BPSZ_VBPSZ|TLI_BPSZ_HBPSZ);
- TLI_BPSZ = (tli_struct->backpsz_vbpsz|(tli_struct->backpsz_hbpsz<<16U));
- /* active size configuration */
- TLI_ASZ &= ~(TLI_ASZ_VASZ|TLI_ASZ_HASZ);
- TLI_ASZ = (tli_struct->activesz_vasz|(tli_struct->activesz_hasz<<16U));
- /* total size configuration */
- TLI_TSZ &= ~(TLI_TSZ_VTSZ|TLI_TSZ_HTSZ);
- TLI_TSZ = (tli_struct->totalsz_vtsz|(tli_struct->totalsz_htsz<<16U));
- /* background color configuration */
- TLI_BGC &= ~(TLI_BGC_BVB|(TLI_BGC_BVG)|(TLI_BGC_BVR));
- TLI_BGC = (tli_struct->backcolor_blue|(tli_struct->backcolor_green<<8U)|(tli_struct->backcolor_red<<16U));
- TLI_CTL &= ~(TLI_CTL_HPPS|TLI_CTL_VPPS|TLI_CTL_DEPS|TLI_CTL_CLKPS);
- TLI_CTL |= (tli_struct->signalpolarity_hs|tli_struct->signalpolarity_vs|\
- tli_struct->signalpolarity_de|tli_struct->signalpolarity_pixelck);
+ TLI_BPSZ &= ~(TLI_BPSZ_VBPSZ | TLI_BPSZ_HBPSZ);
+ TLI_BPSZ = (uint32_t)((uint32_t)tli_struct->backpsz_vbpsz | ((uint32_t)tli_struct->backpsz_hbpsz << 16U));
+ /* active size configuration */
+ TLI_ASZ &= ~(TLI_ASZ_VASZ | TLI_ASZ_HASZ);
+ TLI_ASZ = (tli_struct->activesz_vasz | (tli_struct->activesz_hasz << 16U));
+ /* total size configuration */
+ TLI_TSZ &= ~(TLI_TSZ_VTSZ | TLI_TSZ_HTSZ);
+ TLI_TSZ = (tli_struct->totalsz_vtsz | (tli_struct->totalsz_htsz << 16U));
+ /* background color configuration */
+ TLI_BGC &= ~(TLI_BGC_BVB | (TLI_BGC_BVG) | (TLI_BGC_BVR));
+ TLI_BGC = (tli_struct->backcolor_blue | (tli_struct->backcolor_green << 8U) | (tli_struct->backcolor_red << 16U));
+ TLI_CTL &= ~(TLI_CTL_HPPS | TLI_CTL_VPPS | TLI_CTL_DEPS | TLI_CTL_CLKPS);
+ TLI_CTL |= (tli_struct->signalpolarity_hs | tli_struct->signalpolarity_vs | \
+ tli_struct->signalpolarity_de | tli_struct->signalpolarity_pixelck);
}
/*!
- \brief configure TLI dither function
- \param[in] ditherstat
+ \brief configure TLI dither function
+ \param[in] dither_stat
+ only one parameter can be selected which is shown as below:
\arg TLI_DITHER_ENABLE
\arg TLI_DITHER_DISABLE
\param[out] none
\retval none
*/
-void tli_dither_config(uint8_t ditherstat)
+void tli_dither_config(uint8_t dither_stat)
{
- if(TLI_DITHER_ENABLE == ditherstat){
+ if(TLI_DITHER_ENABLE == dither_stat) {
TLI_CTL |= TLI_CTL_DFEN;
- }else{
+ } else {
TLI_CTL &= ~(TLI_CTL_DFEN);
}
}
/*!
- \brief TLI enable
+ \brief enable TLI
\param[in] none
\param[out] none
\retval none
@@ -121,7 +164,7 @@ void tli_enable(void)
}
/*!
- \brief TLI disable
+ \brief disable TLI
\param[in] none
\param[out] none
\retval none
@@ -132,118 +175,78 @@ void tli_disable(void)
}
/*!
- \brief configure TLI reload mode
- \param[in] reloadmode
+ \brief configure TLI reload mode
+ \param[in] reload_mod
+ only one parameter can be selected which is shown as below:
\arg TLI_FRAME_BLANK_RELOAD_EN
\arg TLI_REQUEST_RELOAD_EN
\param[out] none
\retval none
*/
-void tli_reload_config(uint8_t reloadmode)
+void tli_reload_config(uint8_t reload_mod)
{
- if(TLI_FRAME_BLANK_RELOAD_EN == reloadmode){
+ if(TLI_FRAME_BLANK_RELOAD_EN == reload_mod) {
+ /* the layer configuration will be reloaded at frame blank */
TLI_RL |= TLI_RL_FBR;
- }else{
+ } else {
+ /* the layer configuration will be reloaded after this bit sets */
TLI_RL |= TLI_RL_RQR;
}
}
/*!
- \brief set line mark value
- \param[in] linenum: line number
- \param[out] none
- \retval none
-*/
-void tli_line_mark_set(uint32_t linenum)
-{
- TLI_LM &= ~(TLI_LM_LM);
- TLI_LM = linenum;
-}
-
-/*!
- \brief get current displayed position
- \param[in] none
- \param[out] none
- \retval none
-*/
-uint32_t tli_current_pos_get(void)
-{
- return TLI_CPPOS;
-}
-
-/*!
- \brief TLI layer enable
- \param[in] layerx: LAYERx(x=0,1)
- \param[out] none
- \retval none
-*/
-void tli_layer_enable(uint32_t layerx)
-{
- TLI_LxCTL(layerx) |= TLI_LxCTL_LEN;
-}
-
-/*!
- \brief TLI layer disable
- \param[in] layerx: LAYERx(x=0,1)
- \param[out] none
- \retval none
-*/
-void tli_layer_disable(uint32_t layerx)
-{
- TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LEN);
-}
-
-/*!
- \brief TLI layer color keying enable
- \param[in] layerx: LAYERx(x=0,1)
- \param[out] none
- \retval none
-*/
-void tli_color_key_enable(uint32_t layerx)
-{
- TLI_LxCTL(layerx) |= TLI_LxCTL_CKEYEN;
-}
-
-/*!
- \brief TLI layer color keying disable
- \param[in] layerx: LAYERx(x=0,1)
- \param[out] none
- \retval none
-*/
-void tli_color_key_disable(uint32_t layerx)
-{
- TLI_LxCTL(layerx) &= ~(TLI_LxCTL_CKEYEN);
-}
-
-/*!
- \brief TLI layer LUT enable
- \param[in] layerx: LAYERx(x=0,1)
- \param[out] none
- \retval none
-*/
-void tli_lut_enable(uint32_t layerx)
-{
- TLI_LxCTL(layerx) |= TLI_LxCTL_LUTEN;
-}
-
-/*!
- \brief TLI layer LUT disable
- \param[in] layerx: LAYERx(x=0,1)
- \param[out] none
+ \brief initialize the parameters of TLI layer structure with the default values, it is suggested
+ that call this function after a tli_layer_parameter_struct structure is defined
+ \param[in] none
+ \param[out] layer_struct: TLI Layer parameter struct
+ layer_window_rightpos: window right position
+ layer_window_leftpos: window left position
+ layer_window_bottompos: window bottom position
+ layer_window_toppos: window top position
+ layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
+ LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
+ LAYER_PPF_AL44,LAYER_PPF_AL88
+ layer_sa: specified alpha
+ layer_default_alpha: the default color alpha
+ layer_default_red: the default color red
+ layer_default_green: the default color green
+ layer_default_blue: the default color blue
+ layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
+ layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
+ layer_frame_bufaddr: frame buffer base address
+ layer_frame_buf_stride_offset: frame buffer stride offset
+ layer_frame_line_length: frame line length
+ layer_frame_total_line_number: frame total line number
\retval none
*/
-void tli_lut_disable(uint32_t layerx)
+void tli_layer_struct_para_init(tli_layer_parameter_struct *layer_struct)
{
- TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LUTEN);
+ /* initialize the struct parameters with default values */
+ layer_struct->layer_window_rightpos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_window_leftpos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_window_bottompos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_window_toppos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_ppf = LAYER_PPF_ARGB8888;
+ layer_struct->layer_sa = TLI_OPAQUE_VALUE;
+ layer_struct->layer_default_alpha = TLI_DEFAULT_VALUE;
+ layer_struct->layer_default_red = TLI_DEFAULT_VALUE;
+ layer_struct->layer_default_green = TLI_DEFAULT_VALUE;
+ layer_struct->layer_default_blue = TLI_DEFAULT_VALUE;
+ layer_struct->layer_acf1 = LAYER_ACF1_PASA;
+ layer_struct->layer_acf2 = LAYER_ACF2_PASA;
+ layer_struct->layer_frame_bufaddr = TLI_DEFAULT_VALUE;
+ layer_struct->layer_frame_buf_stride_offset = TLI_DEFAULT_VALUE;
+ layer_struct->layer_frame_line_length = TLI_DEFAULT_VALUE;
+ layer_struct->layer_frame_total_line_number = TLI_DEFAULT_VALUE;
}
/*!
- \brief TLI layer initialize
+ \brief initialize TLI layer
\param[in] layerx: LAYERx(x=0,1)
\param[in] layer_struct: TLI Layer parameter struct
layer_window_rightpos: window right position
layer_window_leftpos: window left position
- layer_window_bottompos: window bottom position
+ layer_window_bottompos: window bottom position
layer_window_toppos: window top position
layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
@@ -262,14 +265,14 @@ void tli_lut_disable(uint32_t layerx)
\param[out] none
\retval none
*/
-void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct)
+void tli_layer_init(uint32_t layerx, tli_layer_parameter_struct *layer_struct)
{
/* configure layer window horizontal position */
- TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
- TLI_LxHPOS(layerx) = (layer_struct->layer_window_leftpos | (layer_struct->layer_window_rightpos<<16U));
+ TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP | (TLI_LxHPOS_WRP));
+ TLI_LxHPOS(layerx) = (uint32_t)((uint32_t)layer_struct->layer_window_leftpos | ((uint32_t)layer_struct->layer_window_rightpos << 16U));
/* configure layer window vertical position */
- TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
- TLI_LxVPOS(layerx) = (layer_struct->layer_window_toppos |(layer_struct->layer_window_bottompos<<16U));
+ TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP | (TLI_LxVPOS_WBP));
+ TLI_LxVPOS(layerx) = (uint32_t)((uint32_t)layer_struct->layer_window_toppos | ((uint32_t)layer_struct->layer_window_bottompos << 16U));
/* configure layer packeted pixel format */
TLI_LxPPF(layerx) &= ~(TLI_LxPPF_PPF);
TLI_LxPPF(layerx) = layer_struct->layer_ppf;
@@ -277,173 +280,252 @@ void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct)
TLI_LxSA(layerx) &= ~(TLI_LxSA_SA);
TLI_LxSA(layerx) = layer_struct->layer_sa;
/* configure layer default color */
- TLI_LxDC(layerx) &= ~(TLI_LxDC_DCB|(TLI_LxDC_DCG)|(TLI_LxDC_DCR)|(TLI_LxDC_DCA));
- TLI_LxDC(layerx) = (layer_struct->layer_default_blue |(layer_struct->layer_default_green<<8U)
- |(layer_struct->layer_default_red<<16U)
- |(layer_struct->layer_default_alpha<<24U));
+ TLI_LxDC(layerx) &= ~(TLI_LxDC_DCB | (TLI_LxDC_DCG) | (TLI_LxDC_DCR) | (TLI_LxDC_DCA));
+ TLI_LxDC(layerx) = (uint32_t)((uint32_t)layer_struct->layer_default_blue | ((uint32_t)layer_struct->layer_default_green << 8U)
+ | ((uint32_t)layer_struct->layer_default_red << 16U)
+ | ((uint32_t)layer_struct->layer_default_alpha << 24U));
/* configure layer alpha calculation factors */
- TLI_LxBLEND(layerx) &= ~(TLI_LxBLEND_ACF2|(TLI_LxBLEND_ACF1));
- TLI_LxBLEND(layerx) = ((layer_struct->layer_acf2)|(layer_struct->layer_acf1));
+ TLI_LxBLEND(layerx) &= ~(TLI_LxBLEND_ACF2 | (TLI_LxBLEND_ACF1));
+ TLI_LxBLEND(layerx) = ((layer_struct->layer_acf2) | (layer_struct->layer_acf1));
/* configure layer frame buffer base address */
TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
/* configure layer frame line length */
- TLI_LxFLLEN(layerx) &= ~(TLI_LxFLLEN_FLL|(TLI_LxFLLEN_STDOFF));
- TLI_LxFLLEN(layerx) = (layer_struct->layer_frame_line_length|(layer_struct->layer_frame_buf_stride_offset<<16U));
- /* configure layer frame buffer base address */
- TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
- TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
+ TLI_LxFLLEN(layerx) &= ~(TLI_LxFLLEN_FLL | (TLI_LxFLLEN_STDOFF));
+ TLI_LxFLLEN(layerx) = (uint32_t)((uint32_t)layer_struct->layer_frame_line_length | ((uint32_t)layer_struct->layer_frame_buf_stride_offset << 16U));
/* configure layer frame total line number */
- TLI_LxFTLN(layerx) &= ~(TLI_LxFTLN_FTLN);
- TLI_LxFTLN(layerx) = (layer_struct->layer_frame_total_line_number);
+ TLI_LxFTLN(layerx) &= ~(TLI_LxFTLN_FTLN);
+ TLI_LxFTLN(layerx) = (uint32_t)(layer_struct->layer_frame_total_line_number);
+
}
/*!
- \brief reconfigure window position
- \param[in] layerx: LAYERx(x=0,1)
- \param[in] offset_x: new horizontal offset
- \param[in] offset_y: new vertical offset
+ \brief reconfigure window position
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[in] offset_x: new horizontal offset
+ \param[in] offset_y: new vertical offset
\param[out] none
\retval none
*/
-void tli_layer_window_offset_modify(uint32_t layerx,uint32_t offset_x,uint32_t offset_y)
+void tli_layer_window_offset_modify(uint32_t layerx, uint16_t offset_x, uint16_t offset_y)
{
/* configure window start position */
- uint32_t layer_ppf,line_length,line_num,hstart,vstart;
- TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
- TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
- hstart = offset_x+(((TLI_BPSZ & TLI_BPSZ_HBPSZ)>>16U)+1U);
- vstart = offset_y+((TLI_BPSZ & TLI_BPSZ_VBPSZ)+1U);
+ uint32_t layer_ppf, line_num, hstart, vstart;
+ uint32_t line_length = 0U;
+ TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP | (TLI_LxHPOS_WRP));
+ TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP | (TLI_LxVPOS_WBP));
+ hstart = (uint32_t)offset_x + (((TLI_BPSZ & TLI_BPSZ_HBPSZ) >> 16U) + 1U);
+ vstart = (uint32_t)offset_y + ((TLI_BPSZ & TLI_BPSZ_VBPSZ) + 1U);
line_num = (TLI_LxFTLN(layerx) & TLI_LxFTLN_FTLN);
layer_ppf = (TLI_LxPPF(layerx) & TLI_LxPPF_PPF);
/* the bytes of a line equal TLI_LxFLLEN_FLL bits value minus 3 */
- switch(layer_ppf){
+ switch(layer_ppf) {
case LAYER_PPF_ARGB8888:
/* each pixel includes 4bytes,when pixel format is ARGB8888 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/4U);
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U) / 4U);
break;
case LAYER_PPF_RGB888:
/* each pixel includes 3bytes,when pixel format is RGB888 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/3U);
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U) / 3U);
break;
case LAYER_PPF_RGB565:
case LAYER_PPF_ARGB1555:
case LAYER_PPF_ARGB4444:
case LAYER_PPF_AL88:
/* each pixel includes 2bytes,when pixel format is RGB565,ARG1555,ARGB4444 or AL88 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/2U);
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U) / 2U);
break;
case LAYER_PPF_L8:
case LAYER_PPF_AL44:
/* each pixel includes 1byte,when pixel format is L8 or AL44 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U));
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL) - 3U));
break;
default:
break;
}
/* reconfigure window position */
- TLI_LxHPOS(layerx) = (hstart|((hstart+line_length-1U)<<16U));
- TLI_LxVPOS(layerx) = (vstart|((vstart+line_num-1U)<<16U));
+ TLI_LxHPOS(layerx) = (hstart | ((hstart + line_length - 1U) << 16U));
+ TLI_LxVPOS(layerx) = (vstart | ((vstart + line_num - 1U) << 16U));
}
/*!
- \brief TLI layer LUT initialize
+ \brief initialize the parameters of TLI layer LUT structure with the default values, it is suggested
+ that call this function after a tli_layer_lut_parameter_struct structure is defined
+ \param[in] none
+ \param[out] lut_struct: TLI layer LUT parameter struct
+ layer_table_addr: look up table write address
+ layer_lut_channel_red: red channel of a LUT entry
+ layer_lut_channel_green: green channel of a LUT entry
+ layer_lut_channel_blue: blue channel of a LUT entry
+ \retval none
+*/
+void tli_lut_struct_para_init(tli_layer_lut_parameter_struct *lut_struct)
+{
+ /* initialize the struct parameters with default values */
+ lut_struct->layer_table_addr = TLI_DEFAULT_VALUE;
+ lut_struct->layer_lut_channel_red = TLI_DEFAULT_VALUE;
+ lut_struct->layer_lut_channel_green = TLI_DEFAULT_VALUE;
+ lut_struct->layer_lut_channel_blue = TLI_DEFAULT_VALUE;
+}
+
+/*!
+ \brief initialize TLI layer LUT
\param[in] layerx: LAYERx(x=0,1)
\param[in] lut_struct: TLI layer LUT parameter struct
layer_table_addr: window right position
layer_lut_channel_red: window left position
- layer_window_bottompos: window bottom position
+ layer_window_bottompos: window bottom position
layer_window_toppos: window top position
\param[out] none
\retval none
*/
-void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct)
+void tli_lut_init(uint32_t layerx, tli_layer_lut_parameter_struct *lut_struct)
{
- TLI_LxLUT(layerx) &= ~(TLI_LxLUT_TB|TLI_LxLUT_TG|TLI_LxLUT_TR|TLI_LxLUT_TADD);
- TLI_LxLUT(layerx) = ((lut_struct->layer_lut_channel_blue)|(lut_struct->layer_lut_channel_green<<8)
- |(lut_struct->layer_lut_channel_red<<16
- |(lut_struct->layer_table_addr<<24)));
+ TLI_LxLUT(layerx) = (uint32_t)(((uint32_t)lut_struct->layer_lut_channel_blue) | ((uint32_t)lut_struct->layer_lut_channel_green << 8U)
+ | ((uint32_t)lut_struct->layer_lut_channel_red << 16U
+ | ((uint32_t)lut_struct->layer_table_addr << 24U)));
}
/*!
- \brief TLI layer key initialize
- \param[in] layerx: LAYERx(x=0,1)
- \param[in] redkey: color key red
- \param[in] greenkey: color key green
- \param[in] bluekey: color key blue
+ \brief initialize TLI layer color key
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[in] redkey: color key red
+ \param[in] greenkey: color key green
+ \param[in] bluekey: color key blue
\param[out] none
\retval none
*/
-void tli_ckey_init(uint32_t layerx,uint32_t redkey,uint32_t greenkey,uint32_t bluekey)
+void tli_color_key_init(uint32_t layerx, uint8_t redkey, uint8_t greenkey, uint8_t bluekey)
{
- TLI_LxCKEY(layerx) = ((bluekey)|(greenkey<<8U)|(redkey<<16U));
+ TLI_LxCKEY(layerx) = (((uint32_t)bluekey) | ((uint32_t)greenkey << 8U) | ((uint32_t)redkey << 16U));
}
/*!
- \brief get TLI flag or state
- \param[in] flag: TLI flags or states
- \arg TLI_FLAG_VDE: current VDE state
- \arg TLI_FLAG_HDE: current HDE state
- \arg TLI_FLAG_VS: current vs state
- \arg TLI_FLAG_HS: current hs state
- \arg TLI_FLAG_LM: line mark interrupt flag
- \arg TLI_FLAG_FE: FIFO error interrupt flag
- \arg TLI_FLAG_TE: transaction error interrupt flag
- \arg TLI_FLAG_LCR: layer configuration reloaded interrupt flag
+ \brief enable TLI layer
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
- \retval FlagStatus: SET or RESET
+ \retval none
*/
-FlagStatus tli_flag_get(uint32_t flag)
+void tli_layer_enable(uint32_t layerx)
{
- uint32_t stat;
- if(flag >> 31){
- /* get flag status from TLI_INTF register */
- stat = TLI_INTF;
- }else{
- /* get flag status from TLI_STAT register */
- stat = TLI_STAT;
- }
- if(flag & stat){
- return SET;
- }else{
- return RESET;
- }
+ TLI_LxCTL(layerx) |= TLI_LxCTL_LEN;
}
/*!
- \brief enable TLI interrupt
- \param[in] interrupt: TLI interrupt flags
- \arg TLI_INT_LM: line mark interrupt
- \arg TLI_INT_FE: FIFO error interrupt
- \arg TLI_INT_TE: transaction error interrupt
- \arg TLI_INT_LCR: layer configuration reloaded interrupt
+ \brief disable TLI layer
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
-void tli_interrupt_enable(uint32_t interrupt)
+void tli_layer_disable(uint32_t layerx)
{
- TLI_INTEN |= (interrupt);
+ TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LEN);
}
/*!
- \brief disable TLI interrupt
- \param[in] interrupt: TLI interrupt flags
- \arg TLI_INT_LM: line mark interrupt
- \arg TLI_INT_FE: FIFO error interrupt
- \arg TLI_INT_TE: transaction error interrupt
- \arg TLI_INT_LCR: layer configuration reloaded interrupt
+ \brief enable TLI layer color keying
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
-void tli_interrupt_disable(uint32_t interrupt)
+void tli_color_key_enable(uint32_t layerx)
{
- TLI_INTEN &= ~(interrupt);
+ TLI_LxCTL(layerx) |= TLI_LxCTL_CKEYEN;
}
/*!
- \brief get TLI interrupt flag
+ \brief disable TLI layer color keying
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[out] none
+ \retval none
+*/
+void tli_color_key_disable(uint32_t layerx)
+{
+ TLI_LxCTL(layerx) &= ~(TLI_LxCTL_CKEYEN);
+}
+
+/*!
+ \brief enable TLI layer LUT
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[out] none
+ \retval none
+*/
+void tli_lut_enable(uint32_t layerx)
+{
+ TLI_LxCTL(layerx) |= TLI_LxCTL_LUTEN;
+}
+
+/*!
+ \brief disable TLI layer LUT
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[out] none
+ \retval none
+*/
+void tli_lut_disable(uint32_t layerx)
+{
+ TLI_LxCTL(layerx) &= ~(TLI_LxCTL_LUTEN);
+}
+
+/*!
+ \brief set line mark value
+ \param[in] line_num: line number
+ \param[out] none
+ \retval none
+*/
+void tli_line_mark_set(uint16_t line_num)
+{
+ TLI_LM &= ~(TLI_LM_LM);
+ TLI_LM = (uint32_t)line_num;
+}
+
+/*!
+ \brief get current displayed position
+ \param[in] none
+ \param[out] none
+ \retval position of current pixel
+*/
+uint32_t tli_current_pos_get(void)
+{
+ return TLI_CPPOS;
+}
+
+/*!
+ \brief enable TLI interrupt
+ \param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg TLI_INT_LM: line mark interrupt
+ \arg TLI_INT_FE: FIFO error interrupt
+ \arg TLI_INT_TE: transaction error interrupt
+ \arg TLI_INT_LCR: layer configuration reloaded interrupt
+ \param[out] none
+ \retval none
+*/
+void tli_interrupt_enable(uint32_t int_flag)
+{
+ TLI_INTEN |= (int_flag);
+}
+
+/*!
+ \brief disable TLI interrupt
\param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg TLI_INT_LM: line mark interrupt
+ \arg TLI_INT_FE: FIFO error interrupt
+ \arg TLI_INT_TE: transaction error interrupt
+ \arg TLI_INT_LCR: layer configuration reloaded interrupt
+ \param[out] none
+ \retval none
+*/
+void tli_interrupt_disable(uint32_t int_flag)
+{
+ TLI_INTEN &= ~(int_flag);
+}
+
+/*!
+ \brief get TLI interrupt flag
+ \param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
\arg TLI_INT_FLAG_LM: line mark interrupt flag
\arg TLI_INT_FLAG_FE: FIFO error interrupt flag
\arg TLI_INT_FLAG_TE: transaction error interrupt flag
@@ -455,10 +537,10 @@ FlagStatus tli_interrupt_flag_get(uint32_t int_flag)
{
uint32_t state;
state = TLI_INTF;
- if(state & int_flag){
+ if(state & int_flag) {
state = TLI_INTEN;
/* check whether the corresponding bit in TLI_INTEN is set or not */
- if(state & int_flag){
+ if(state & int_flag) {
return SET;
}
}
@@ -466,8 +548,9 @@ FlagStatus tli_interrupt_flag_get(uint32_t int_flag)
}
/*!
- \brief clear TLI interrupt flag
+ \brief clear TLI interrupt flag
\param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
\arg TLI_INT_FLAG_LM: line mark interrupt flag
\arg TLI_INT_FLAG_FE: FIFO error interrupt flag
\arg TLI_INT_FLAG_TE: transaction error interrupt flag
@@ -479,3 +562,34 @@ void tli_interrupt_flag_clear(uint32_t int_flag)
{
TLI_INTC |= (int_flag);
}
+
+/*!
+ \brief get TLI flag or state in TLI_INTF register or TLI_STAT register
+ \param[in] flag: TLI flags or states
+ only one parameter can be selected which is shown as below:
+ \arg TLI_FLAG_VDE: current VDE state
+ \arg TLI_FLAG_HDE: current HDE state
+ \arg TLI_FLAG_VS: current VS status of the TLI
+ \arg TLI_FLAG_HS: current HS status of the TLI
+ \arg TLI_FLAG_LM: line mark interrupt flag
+ \arg TLI_FLAG_FE: FIFO error interrupt flag
+ \arg TLI_FLAG_TE: transaction error interrupt flag
+ \arg TLI_FLAG_LCR: layer configuration reloaded interrupt flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus tli_flag_get(uint32_t flag)
+{
+ uint32_t stat;
+ /* choose which register to get flag or state */
+ if(flag >> 31U) {
+ stat = TLI_INTF;
+ } else {
+ stat = TLI_STAT;
+ }
+ if(flag & stat) {
+ return SET;
+ } else {
+ return RESET;
+ }
+}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_trng.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_trng.c
index 0e098a5..35f5bb1 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_trng.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_trng.c
@@ -2,43 +2,40 @@
\file gd32f20x_trng.c
\brief TRNG driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_trng.h"
/*!
- \brief deinitialize the TRNG
+ \brief reset TRNG
\param[in] none
\param[out] none
\retval none
@@ -50,7 +47,7 @@ void trng_deinit(void)
}
/*!
- \brief enable the TRNG interface
+ \brief enable TRNG
\param[in] none
\param[out] none
\retval none
@@ -61,7 +58,7 @@ void trng_enable(void)
}
/*!
- \brief disable the TRNG interface
+ \brief disable TRNG
\param[in] none
\param[out] none
\retval none
@@ -75,7 +72,7 @@ void trng_disable(void)
\brief get the true random data
\param[in] none
\param[out] none
- \retval the generated random data
+ \retval the generated random data: 0 - 0xFFFFFFFF
*/
uint32_t trng_get_true_random_data(void)
{
@@ -83,7 +80,7 @@ uint32_t trng_get_true_random_data(void)
}
/*!
- \brief get the trng status flags
+ \brief get TRNG flag status
\param[in] flag: trng status flag, refer to trng_flag_enum
only one parameter can be selected which is shown as below:
\arg TRNG_FLAG_DRDY: Random Data ready status
@@ -94,37 +91,37 @@ uint32_t trng_get_true_random_data(void)
*/
FlagStatus trng_flag_get(trng_flag_enum flag)
{
- if(RESET != (TRNG_STAT & flag)){
+ if(RESET != (TRNG_STAT & flag)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief enable the TRNG interrupt
+ \brief enable TRNG interrupt
\param[in] none
\param[out] none
\retval none
*/
-void trng_interrupt_enable(void)
+void trng_interrupt_enable(void)
{
- TRNG_CTL |= TRNG_CTL_IE;
+ TRNG_CTL |= TRNG_CTL_TRNGIE;
}
/*!
- \brief disable the TRNG interrupt
+ \brief disable TRNG interrupt
\param[in] none
\param[out] none
\retval none
*/
void trng_interrupt_disable(void)
{
- TRNG_CTL &= ~TRNG_CTL_IE;
+ TRNG_CTL &= ~TRNG_CTL_TRNGIE;
}
/*!
- \brief get the trng interrupt flags
+ \brief get TRNG interrupt flag status
\param[in] int_flag: trng interrupt flag, refer to trng_int_flag_enum
only one parameter can be selected which is shown as below:
\arg TRNG_INT_FLAG_CE: clock error interrupt flag
@@ -134,15 +131,15 @@ void trng_interrupt_disable(void)
*/
FlagStatus trng_interrupt_flag_get(trng_int_flag_enum int_flag)
{
- if(RESET != (TRNG_STAT & int_flag)){
+ if(RESET != (TRNG_STAT & int_flag)) {
return SET;
- }else{
+ } else {
return RESET;
}
}
/*!
- \brief clear the trng interrupt flags
+ \brief clear TRNG interrupt flag status
\param[in] int_flag: trng interrupt flag, refer to trng_int_flag_enum
only one parameter can be selected which is shown as below:
\arg TRNG_INT_FLAG_CE: clock error interrupt flag
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_usart.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_usart.c
index 1674afa..2c82913 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_usart.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_usart.c
@@ -2,51 +2,52 @@
\file gd32f20x_usart.c
\brief USART driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
- \version 2019-04-11, V2.1.1, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_usart.h"
+/* USART register bit offset */
+#define GP_GUAT_OFFSET ((uint32_t)8U) /* bit offset of GUAT in USART_GP */
+#define CTL3_SCRTNUM_OFFSET ((uint32_t)1U) /* bit offset of SCRTNUM in USART_CTL3 */
+#define RT_BL_OFFSET ((uint32_t)24U) /* bit offset of BL in USART_RT */
+
/*!
- \brief reset USART/UART
+ \brief reset USART/UART
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
*/
void usart_deinit(uint32_t usart_periph)
{
- switch(usart_periph){
+ switch(usart_periph) {
case USART0:
/* reset USART0 */
rcu_periph_reset_enable(RCU_USART0RST);
@@ -98,80 +99,80 @@ void usart_deinit(uint32_t usart_periph)
\param[in] baudval: baud rate value
\param[out] none
\retval none
-*/
+*/
void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval)
{
- uint32_t uclk=0U, intdiv=0U, fradiv=0U, udiv=0U;
- switch(usart_periph){
- /* get clock frequency */
+ uint32_t uclk = 0U, intdiv = 0U, fradiv = 0U, udiv = 0U;
+ switch(usart_periph) {
+ /* get clock frequency */
case USART0:
- /* get USART0 clock */
- uclk=rcu_clock_freq_get(CK_APB2);
- break;
+ /* get USART0 clock */
+ uclk = rcu_clock_freq_get(CK_APB2);
+ break;
case USART5:
- /* get USART5 clock */
- uclk=rcu_clock_freq_get(CK_APB2);
- break;
+ /* get USART5 clock */
+ uclk = rcu_clock_freq_get(CK_APB2);
+ break;
case USART1:
- /* get USART1 clock */
- uclk=rcu_clock_freq_get(CK_APB1);
- break;
+ /* get USART1 clock */
+ uclk = rcu_clock_freq_get(CK_APB1);
+ break;
case USART2:
- /* get USART2 clock */
- uclk=rcu_clock_freq_get(CK_APB1);
- break;
+ /* get USART2 clock */
+ uclk = rcu_clock_freq_get(CK_APB1);
+ break;
case UART3:
- /* get UART3 clock */
- uclk=rcu_clock_freq_get(CK_APB1);
- break;
+ /* get UART3 clock */
+ uclk = rcu_clock_freq_get(CK_APB1);
+ break;
case UART4:
- /* get UART4 clock */
- uclk=rcu_clock_freq_get(CK_APB1);
- break;
+ /* get UART4 clock */
+ uclk = rcu_clock_freq_get(CK_APB1);
+ break;
case UART6:
- /* get UART6 clock */
- uclk=rcu_clock_freq_get(CK_APB1);
- break;
+ /* get UART6 clock */
+ uclk = rcu_clock_freq_get(CK_APB1);
+ break;
case UART7:
- /* get UART7 clock */
- uclk=rcu_clock_freq_get(CK_APB1);
- break;
+ /* get UART7 clock */
+ uclk = rcu_clock_freq_get(CK_APB1);
+ break;
default:
- break;
+ break;
}
- /* when oversampling by 16, configure the value of USART_BAUD */
- udiv = (uclk+baudval/2U)/baudval;
+ /* oversampling by 16, configure the value of USART_BAUD */
+ udiv = (uclk + baudval / 2U) / baudval;
intdiv = udiv & 0xfff0U;
fradiv = udiv & 0xfU;
USART_BAUD(usart_periph) = ((USART_BAUD_FRADIV | USART_BAUD_INTDIV) & (intdiv | fradiv));
}
/*!
- \brief configure USART parity
- \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] paritycfg: configure USART parity
- only one parameter can be selected which is shown as below:
- \arg USART_PM_NONE: no parity
- \arg USART_PM_ODD: odd parity
- \arg USART_PM_EVEN: even parity
+ \brief configure USART parity
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] paritycfg: configure USART parity
+ only one parameter can be selected which is shown as below:
+ \arg USART_PM_NONE: no parity
+ \arg USART_PM_ODD: odd parity
+ \arg USART_PM_EVEN: even parity
\param[out] none
\retval none
*/
void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg)
{
- /* clear USART_CTL0 PM,PCEN Bits */
+ /* clear USART_CTL0 PM,PCEN bits */
USART_CTL0(usart_periph) &= ~(USART_CTL0_PM | USART_CTL0_PCEN);
/* configure USART parity mode */
USART_CTL0(usart_periph) |= paritycfg;
}
/*!
- \brief configure USART word length
- \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] wlen: USART word length configure
- only one parameter can be selected which is shown as below:
- \arg USART_WL_8BIT: 8 bits
- \arg USART_WL_9BIT: 9 bits
+ \brief configure USART word length
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] wlen: USART word length configure
+ only one parameter can be selected which is shown as below:
+ \arg USART_WL_8BIT: 8 bits
+ \arg USART_WL_9BIT: 9 bits
\param[out] none
\retval none
*/
@@ -184,11 +185,11 @@ void usart_word_length_set(uint32_t usart_periph, uint32_t wlen)
}
/*!
- \brief configure USART stop bit length
- \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] stblen: USART stop bit configure
- only one parameter can be selected which is shown as below:
- \arg USART_STB_1BIT: 1 bit
+ \brief configure USART stop bit length
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] stblen: USART stop bit configure
+ only one parameter can be selected which is shown as below:
+ \arg USART_STB_1BIT: 1 bit
\arg USART_STB_0_5BIT: 0.5 bit(not available for UARTx(x=3,4,6,7))
\arg USART_STB_2BIT: 2 bits
\arg USART_STB_1_5BIT: 1.5 bits(not available for UARTx(x=3,4,6,7))
@@ -198,10 +199,11 @@ void usart_word_length_set(uint32_t usart_periph, uint32_t wlen)
void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen)
{
/* clear USART_CTL1 STB bits */
- USART_CTL1(usart_periph) &= ~USART_CTL1_STB;
+ USART_CTL1(usart_periph) &= ~USART_CTL1_STB;
/* configure USART stop bits */
USART_CTL1(usart_periph) |= stblen;
}
+
/*!
\brief enable USART
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
@@ -230,19 +232,14 @@ void usart_disable(uint32_t usart_periph)
\param[in] txconfig: enable or disable USART transmitter
only one parameter can be selected which is shown as below:
\arg USART_TRANSMIT_ENABLE: enable USART transmission
- \arg USART_TRANSMIT_DISABLE: enable USART transmission
+ \arg USART_TRANSMIT_DISABLE: disable USART transmission
\param[out] none
\retval none
*/
void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
{
- uint32_t ctl = 0U;
-
- ctl = USART_CTL0(usart_periph);
- ctl &= ~USART_CTL0_TEN;
- ctl |= txconfig;
- /* configure transfer mode */
- USART_CTL0(usart_periph) = ctl;
+ USART_CTL0(usart_periph) &= ~(USART_CTL0_TEN);
+ USART_CTL0(usart_periph) |= (USART_CTL0_TEN & txconfig);
}
/*!
@@ -257,19 +254,15 @@ void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
*/
void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
{
- uint32_t ctl = 0U;
-
- ctl = USART_CTL0(usart_periph);
- ctl &= ~USART_CTL0_REN;
- ctl |= rxconfig;
- /* configure receiver mode */
- USART_CTL0(usart_periph) = ctl;
+ USART_CTL0(usart_periph) &= ~(USART_CTL0_REN);
+ USART_CTL0(usart_periph) |= (USART_CTL0_REN & rxconfig);
}
/*!
\brief data is transmitted/received with the LSB/MSB first
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] msbf: LSB/MSB
+ only one parameter can be selected which is shown as below:
\arg USART_MSBF_LSB: LSB first
\arg USART_MSBF_MSB: MSB first
\param[out] none
@@ -277,14 +270,15 @@ void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
*/
void usart_data_first_config(uint32_t usart_periph, uint32_t msbf)
{
- USART_CTL3(usart_periph) &= ~(USART_CTL3_MSBF);
+ USART_CTL3(usart_periph) &= ~(USART_CTL3_MSBF);
USART_CTL3(usart_periph) |= msbf;
}
/*!
\brief configure USART inversion
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] invertpara: refer to enum USART_INVERT_CONFIG
+ \param[in] invertpara: refer to enum usart_invert_enum
+ only one parameter can be selected which is shown as below:
\arg USART_DINV_ENABLE: data bit level inversion
\arg USART_DINV_DISABLE: data bit level not inversion
\arg USART_TXPIN_ENABLE: TX pin level inversion
@@ -296,24 +290,30 @@ void usart_data_first_config(uint32_t usart_periph, uint32_t msbf)
*/
void usart_invert_config(uint32_t usart_periph, usart_invert_enum invertpara)
{
- /* inverted or not the specified siginal */
- switch(invertpara){
+ /* inverted or not the specified siginal */
+ switch(invertpara) {
case USART_DINV_ENABLE:
+ /* data bit level inversion */
USART_CTL3(usart_periph) |= USART_CTL3_DINV;
break;
case USART_TXPIN_ENABLE:
+ /* TX pin level inversion */
USART_CTL3(usart_periph) |= USART_CTL3_TINV;
break;
case USART_RXPIN_ENABLE:
+ /* RX pin level inversion */
USART_CTL3(usart_periph) |= USART_CTL3_RINV;
break;
case USART_DINV_DISABLE:
+ /* data bit level not inversion */
USART_CTL3(usart_periph) &= ~(USART_CTL3_DINV);
break;
case USART_TXPIN_DISABLE:
+ /* TX pin level not inversion */
USART_CTL3(usart_periph) &= ~(USART_CTL3_TINV);
break;
case USART_RXPIN_DISABLE:
+ /* RX pin level not inversion */
USART_CTL3(usart_periph) &= ~(USART_CTL3_RINV);
break;
default:
@@ -322,7 +322,7 @@ void usart_invert_config(uint32_t usart_periph, usart_invert_enum invertpara)
}
/*!
- \brief enable receiver timeout of USART
+ \brief enable receiver timeout
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[out] none
\retval none
@@ -333,7 +333,7 @@ void usart_receiver_timeout_enable(uint32_t usart_periph)
}
/*!
- \brief disable receiver timeout of USART
+ \brief disable receiver timeout
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[out] none
\retval none
@@ -344,7 +344,7 @@ void usart_receiver_timeout_disable(uint32_t usart_periph)
}
/*!
- \brief set the receiver timeout threshold of USART
+ \brief configure receiver timeout threshold
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] rtimeout: 0-0xFFFFFF
\param[out] none
@@ -359,13 +359,13 @@ void usart_receiver_timeout_threshold_config(uint32_t usart_periph, uint32_t rti
/*!
\brief USART transmit data function
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] data: data of transmission
+ \param[in] data: data to be transmitted
\param[out] none
\retval none
*/
void usart_data_transmit(uint32_t usart_periph, uint16_t data)
{
- USART_DATA(usart_periph) = ((uint16_t)USART_DATA_DATA & data);
+ USART_DATA(usart_periph) = USART_DATA_DATA & (uint32_t)data;
}
/*!
@@ -389,11 +389,11 @@ uint16_t usart_data_receive(uint32_t usart_periph)
void usart_address_config(uint32_t usart_periph, uint8_t addr)
{
USART_CTL1(usart_periph) &= ~(USART_CTL1_ADDR);
- USART_CTL1(usart_periph) |= (USART_CTL1_ADDR & addr);
+ USART_CTL1(usart_periph) |= (USART_CTL1_ADDR & (uint32_t)addr);
}
/*!
- \brief receiver in mute mode
+ \brief enable mute mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
@@ -404,7 +404,7 @@ void usart_mute_mode_enable(uint32_t usart_periph)
}
/*!
- \brief receiver in active mode
+ \brief disable mute mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
@@ -437,7 +437,7 @@ void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod)
\retval none
*/
void usart_lin_mode_enable(uint32_t usart_periph)
-{
+{
USART_CTL1(usart_periph) |= USART_CTL1_LMEN;
}
@@ -448,7 +448,7 @@ void usart_lin_mode_enable(uint32_t usart_periph)
\retval none
*/
void usart_lin_mode_disable(uint32_t usart_periph)
-{
+{
USART_CTL1(usart_periph) &= ~(USART_CTL1_LMEN);
}
@@ -480,18 +480,18 @@ void usart_send_break(uint32_t usart_periph)
}
/*!
- \brief enable half duplex mode
+ \brief enable half-duplex mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
*/
void usart_halfduplex_enable(uint32_t usart_periph)
-{
+{
USART_CTL2(usart_periph) |= USART_CTL2_HDEN;
}
/*!
- \brief disable half duplex mode
+ \brief disable half-duplex mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
@@ -528,43 +528,36 @@ void usart_synchronous_clock_disable(uint32_t usart_periph)
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] clen: CK length
only one parameter can be selected which is shown as below:
- \arg USART_CLEN_NONE: there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame
+ \arg USART_CLEN_NONE: there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame
\arg USART_CLEN_EN: there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame
\param[in] cph: clock phase
only one parameter can be selected which is shown as below:
- \arg USART_CPH_1CK: first clock transition is the first data capture edge
+ \arg USART_CPH_1CK: first clock transition is the first data capture edge
\arg USART_CPH_2CK: second clock transition is the first data capture edge
\param[in] cpl: clock polarity
only one parameter can be selected which is shown as below:
- \arg USART_CPL_LOW: steady low value on CK pin
+ \arg USART_CPL_LOW: steady low value on CK pin
\arg USART_CPL_HIGH: steady high value on CK pin
\param[out] none
\retval none
*/
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl)
{
- uint32_t ctl = 0U;
-
- /* read USART_CTL1 register */
- ctl = USART_CTL1(usart_periph);
- ctl &= ~(USART_CTL1_CLEN | USART_CTL1_CPH | USART_CTL1_CPL);
- /* set CK length, CK phase, CK polarity */
- ctl |= (USART_CTL1_CLEN & clen) | (USART_CTL1_CPH & cph) | (USART_CTL1_CPL & cpl);
-
- USART_CTL1(usart_periph) = ctl;
+ USART_CTL1(usart_periph) &= ~(USART_CTL1_CLEN | USART_CTL1_CPH | USART_CTL1_CPL);
+ USART_CTL1(usart_periph) |= (USART_CTL1_CLEN & clen) | (USART_CTL1_CPH & cph) | (USART_CTL1_CPL & cpl);
}
/*!
\brief configure guard time value in smartcard mode
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] guat: guard time value
+ \param[in] guat: guard time value, 0-0xFF
\param[out] none
\retval none
*/
-void usart_guard_time_config(uint32_t usart_periph,uint32_t guat)
+void usart_guard_time_config(uint32_t usart_periph, uint8_t guat)
{
USART_GP(usart_periph) &= ~(USART_GP_GUAT);
- USART_GP(usart_periph) |= (USART_GP_GUAT & ((guat)<<8));
+ USART_GP(usart_periph) |= (USART_GP_GUAT & ((uint32_t)guat << GP_GUAT_OFFSET));
}
/*!
@@ -618,23 +611,23 @@ void usart_smartcard_mode_nack_disable(uint32_t usart_periph)
\param[out] none
\retval none
*/
-void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t scrtnum)
+void usart_smartcard_autoretry_config(uint32_t usart_periph, uint8_t scrtnum)
{
USART_CTL3(usart_periph) &= ~(USART_CTL3_SCRTNUM);
- USART_CTL3(usart_periph) |= (USART_CTL3_SCRTNUM & ((scrtnum)<<1));
+ USART_CTL3(usart_periph) |= (USART_CTL3_SCRTNUM & ((uint32_t)scrtnum << CTL3_SCRTNUM_OFFSET));
}
/*!
- \brief configure block length in Smartcard T=1 reception
+ \brief configure block length
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] bl: block length
\param[out] none
\retval none
*/
-void usart_block_length_config(uint32_t usart_periph, uint32_t bl)
+void usart_block_length_config(uint32_t usart_periph, uint8_t bl)
{
USART_RT(usart_periph) &= ~(USART_RT_BL);
- USART_RT(usart_periph) |= (USART_RT_BL & ((bl)<<24));
+ USART_RT(usart_periph) |= (USART_RT_BL & ((uint32_t)bl << RT_BL_OFFSET));
}
/*!
@@ -660,7 +653,7 @@ void usart_irda_mode_disable(uint32_t usart_periph)
}
/*!
- \brief configure the peripheral clock prescaler in USART IrDA low-power mode
+ \brief configure the peripheral clock prescaler
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] psc: 0x00-0xFF
\param[out] none
@@ -669,7 +662,7 @@ void usart_irda_mode_disable(uint32_t usart_periph)
void usart_prescaler_config(uint32_t usart_periph, uint8_t psc)
{
USART_GP(usart_periph) &= ~(USART_GP_PSC);
- USART_GP(usart_periph) |= psc;
+ USART_GP(usart_periph) |= (uint32_t)psc;
}
/*!
@@ -691,7 +684,7 @@ void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp)
/*!
\brief configure hardware flow control RTS
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] hardwareflow: enable or disable RTS
+ \param[in] rtsconfig: enable or disable RTS
only one parameter can be selected which is shown as below:
\arg USART_RTS_ENABLE: enable RTS
\arg USART_RTS_DISABLE: disable RTS
@@ -700,19 +693,14 @@ void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp)
*/
void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
{
- uint32_t ctl = 0U;
-
- ctl = USART_CTL2(usart_periph);
- ctl &= ~USART_CTL2_RTSEN;
- ctl |= rtsconfig;
- /* configure RTS */
- USART_CTL2(usart_periph) = ctl;
+ USART_CTL2(usart_periph) &= ~(USART_CTL2_RTSEN);
+ USART_CTL2(usart_periph) |= (USART_CTL2_RTSEN & rtsconfig);
}
/*!
\brief configure hardware flow control CTS
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] hardwareflow: enable or disable CTS
+ \param[in] ctsconfig: enable or disable CTS
only one parameter can be selected which is shown as below:
\arg USART_CTS_ENABLE: enable CTS
\arg USART_CTS_DISABLE: disable CTS
@@ -721,55 +709,40 @@ void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
*/
void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig)
{
- uint32_t ctl = 0U;
-
- ctl = USART_CTL2(usart_periph);
- ctl &= ~USART_CTL2_CTSEN;
- ctl |= ctsconfig;
- /* configure CTS */
- USART_CTL2(usart_periph) = ctl;
+ USART_CTL2(usart_periph) &= ~(USART_CTL2_CTSEN);
+ USART_CTL2(usart_periph) |= (USART_CTL2_CTSEN & ctsconfig);
}
/*!
\brief configure USART DMA reception
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] dmacmd: enable or disable DMA for reception
+ \param[in] dmaconfig: USART DMA mode
only one parameter can be selected which is shown as below:
- \arg USART_DENR_ENABLE: DMA enable for reception
- \arg USART_DENR_DISABLE: DMA disable for reception
+ \arg USART_RECEIVE_DMA_ENABLE: enable USART DMA for reception
+ \arg USART_RECEIVE_DMA_DISABLE: disable USART DMA for reception
\param[out] none
\retval none
*/
-void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd)
+void usart_dma_receive_config(uint32_t usart_periph, uint8_t dmaconfig)
{
- uint32_t ctl = 0U;
-
- ctl = USART_CTL2(usart_periph);
- ctl &= ~USART_CTL2_DENR;
- ctl |= dmacmd;
- /* configure DMA reception */
- USART_CTL2(usart_periph) = ctl;
+ USART_CTL2(usart_periph) &= ~(USART_CTL2_DENR);
+ USART_CTL2(usart_periph) |= (USART_CTL2_DENR & dmaconfig);
}
/*!
\brief configure USART DMA transmission
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] dmacmd: enable or disable DMA for transmission
+ \param[in] dmaconfig: USART DMA mode
only one parameter can be selected which is shown as below:
- \arg USART_DENT_ENABLE: DMA enable for transmission
- \arg USART_DENT_DISABLE: DMA disable for transmission
+ \arg USART_TRANSMIT_DMA_ENABLE: enable USART DMA for transmission
+ \arg USART_TRANSMIT_DMA_DISABLE: disable USART DMA for transmission
\param[out] none
\retval none
*/
-void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd)
+void usart_dma_transmit_config(uint32_t usart_periph, uint8_t dmaconfig)
{
- uint32_t ctl = 0U;
-
- ctl = USART_CTL2(usart_periph);
- ctl &= ~USART_CTL2_DENT;
- ctl |= dmacmd;
- /* configure DMA transmission */
- USART_CTL2(usart_periph) = ctl;
+ USART_CTL2(usart_periph) &= ~(USART_CTL2_DENT);
+ USART_CTL2(usart_periph) |= (USART_CTL2_DENT & dmaconfig);
}
/*!
@@ -795,9 +768,9 @@ void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd)
*/
FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag)
{
- if(RESET != (USART_REG_VAL(usart_periph, flag) & BIT(USART_BIT_POS(flag)))){
+ if(RESET != (USART_REG_VAL(usart_periph, flag) & BIT(USART_BIT_POS(flag)))) {
return SET;
- }else{
+ } else {
return RESET;
}
}
@@ -807,8 +780,8 @@ FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag)
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] flag: USART flags, refer to usart_flag_enum
only one parameter can be selected which is shown as below:
- \arg USART_FLAG_CTS: CTS change flag
- \arg USART_FLAG_LBD: LIN break detected flag
+ \arg USART_FLAG_CTSF: CTS change flag
+ \arg USART_FLAG_LBDF: LIN break detected flag
\arg USART_FLAG_TC: transmission complete
\arg USART_FLAG_RBNE: read data buffer not empty
\arg USART_FLAG_EB: end of block flag
@@ -818,13 +791,13 @@ FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag)
*/
void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag)
{
- USART_REG_VAL(usart_periph, flag) &= ~BIT(USART_BIT_POS(flag));
+ USART_REG_VAL(usart_periph, flag) = ~BIT(USART_BIT_POS(flag));
}
/*!
\brief enable USART interrupt
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] int_flag
+ \param[in] interrupt: USART interrupts, refer to usart_interrupt_enum
only one parameter can be selected which is shown as below:
\arg USART_INT_PERR: parity error interrupt
\arg USART_INT_TBE: transmitter buffer empty interrupt
@@ -839,15 +812,15 @@ void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag)
\param[out] none
\retval none
*/
-void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag)
+void usart_interrupt_enable(uint32_t usart_periph, usart_interrupt_enum interrupt)
{
- USART_REG_VAL(usart_periph, int_flag) |= BIT(USART_BIT_POS(int_flag));
+ USART_REG_VAL(usart_periph, interrupt) |= BIT(USART_BIT_POS(interrupt));
}
/*!
\brief disable USART interrupt
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] int_flag
+ \param[in] interrupt: USART interrupts, refer to usart_interrupt_enum
only one parameter can be selected which is shown as below:
\arg USART_INT_PERR: parity error interrupt
\arg USART_INT_TBE: transmitter buffer empty interrupt
@@ -862,9 +835,9 @@ void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag)
\param[out] none
\retval none
*/
-void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag)
+void usart_interrupt_disable(uint32_t usart_periph, usart_interrupt_enum interrupt)
{
- USART_REG_VAL(usart_periph, int_flag) &= ~BIT(USART_BIT_POS(int_flag));
+ USART_REG_VAL(usart_periph, interrupt) &= ~BIT(USART_BIT_POS(interrupt));
}
/*!
@@ -886,9 +859,9 @@ void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag)
\arg USART_INT_FLAG_EB: interrupt enable bit of end of block event and flag
\arg USART_INT_FLAG_RT: interrupt enable bit of receive timeout event and flag
\param[out] none
- \retval FlagStatus
+ \retval FlagStatus: SET or RESET
*/
-FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag)
+FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, usart_interrupt_flag_enum int_flag)
{
uint32_t intenable = 0U, flagstatus = 0U;
/* get the interrupt enable bit status */
@@ -896,28 +869,28 @@ FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag)
/* get the corresponding flag bit status */
flagstatus = (USART_REG_VAL2(usart_periph, int_flag) & BIT(USART_BIT_POS2(int_flag)));
- if(flagstatus && intenable){
+ if((0U != flagstatus) && (0U != intenable)) {
return SET;
- }else{
- return RESET;
+ } else {
+ return RESET;
}
}
/*!
\brief clear USART interrupt flag in STAT0/STAT1 register
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] flag: USART interrupt flag
+ \param[in] int_flag: USART interrupt flags, refer to usart_interrupt_flag_enum
only one parameter can be selected which is shown as below:
- \arg USART_INT_FLAG_CTS: CTS interrupt and flag
- \arg USART_INT_FLAG_LBD: LIN break detected interrupt and flag
- \arg USART_INT_FLAG_TC: transmission complete interrupt and flag
- \arg USART_INT_FLAG_RBNE: read data buffer not empty interrupt and flag
- \arg USART_INT_FLAG_EB: interrupt enable bit of end of block event and flag
- \arg USART_INT_FLAG_RT: interrupt enable bit of receive timeout event and flag
+ \arg USART_INT_FLAG_CTS: CTS change flag
+ \arg USART_INT_FLAG_LBD: LIN break detected flag
+ \arg USART_INT_FLAG_TC: transmission complete
+ \arg USART_INT_FLAG_RBNE: read data buffer not empty
+ \arg USART_INT_FLAG_EB: end of block flag
+ \arg USART_INT_FLAG_RT: receiver timeout flag
\param[out] none
\retval none
*/
-void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t flag)
+void usart_interrupt_flag_clear(uint32_t usart_periph, usart_interrupt_flag_enum int_flag)
{
- USART_REG_VAL2(usart_periph, flag) &= ~BIT(USART_BIT_POS2(flag));
+ USART_REG_VAL2(usart_periph, int_flag) = ~BIT(USART_BIT_POS2(int_flag));
}
diff --git a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_wwdgt.c b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_wwdgt.c
index f205b0c..7c3f7a2 100644
--- a/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_wwdgt.c
+++ b/lib-gd32/gd32f20x/GD32F20x_standard_peripheral/Source/gd32f20x_wwdgt.c
@@ -2,46 +2,38 @@
\file gd32f20x_wwdgt.c
\brief WWDGT driver
- \version 2015-07-15, V1.0.0, firmware for GD32F20x
- \version 2017-06-05, V2.0.0, firmware for GD32F20x
- \version 2018-10-31, V2.1.0, firmware for GD32F20x
- \version 2020-09-30, V2.2.0, firmware for GD32F20x
+ \version 2023-06-30, V2.5.0, firmware for GD32F20x
*/
/*
- Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ Copyright (c) 2023, GigaDevice Semiconductor Inc.
- Redistribution and use in source and binary forms, with or without modification,
+ Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32f20x_wwdgt.h"
-/* write value to WWDGT_CTL_CNT bit field */
-#define CTL_CNT(regval) (BITS(0,6) & ((uint32_t)(regval) << 0))
-/* write value to WWDGT_CFG_WIN bit field */
-#define CFG_WIN(regval) (BITS(0,6) & ((uint32_t)(regval) << 0))
-
/*!
\brief reset the window watchdog timer configuration
\param[in] none
@@ -73,17 +65,12 @@ void wwdgt_enable(void)
*/
void wwdgt_counter_update(uint16_t counter_value)
{
- uint32_t reg = 0U;
-
- reg = (WWDGT_CTL & (~WWDGT_CTL_CNT));
- reg |= CTL_CNT(counter_value);
-
- WWDGT_CTL = reg;
+ WWDGT_CTL = (uint32_t)(CTL_CNT(counter_value));
}
/*!
- \brief configure counter value, window value, and prescaler divider value
- \param[in] counter: 0x00 - 0x7F
+ \brief configure counter value, window value, and prescaler divider value
+ \param[in] counter: 0x00 - 0x7F
\param[in] window: 0x00 - 0x7F
\param[in] prescaler: wwdgt prescaler value
only one parameter can be selected which is shown as below:
@@ -96,41 +83,36 @@ void wwdgt_counter_update(uint16_t counter_value)
*/
void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler)
{
- uint32_t reg_cfg = 0U, reg_ctl = 0U;
-
- /* clear WIN and PSC bits, clear CNT bit */
- reg_cfg = (WWDGT_CFG &(~(WWDGT_CFG_WIN|WWDGT_CFG_PSC)));
- reg_ctl = (WWDGT_CTL &(~WWDGT_CTL_CNT));
-
- /* configure WIN and PSC bits, configure CNT bit */
- reg_cfg |= CFG_WIN(window);
- reg_cfg |= prescaler;
- reg_ctl |= CTL_CNT(counter);
-
- WWDGT_CTL = reg_ctl;
- WWDGT_CFG = reg_cfg;
+ WWDGT_CTL = (uint32_t)(CTL_CNT(counter));
+ WWDGT_CFG = (uint32_t)(CFG_WIN(window) | prescaler);
}
/*!
- \brief enable early wakeup interrupt of WWDGT
+ \brief get early wakeup interrupt flag of WWDGT
\param[in] none
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void wwdgt_interrupt_enable(void)
+FlagStatus wwdgt_interrupt_flag_get(void)
{
- WWDGT_CFG |= WWDGT_CFG_EWIE;
+ uint32_t state;
+ state = WWDGT_STAT & WWDGT_STAT_EWIF;
+ if((WWDGT_CFG & WWDGT_CFG_EWIE) & state) {
+ return SET;
+ }
+
+ return RESET;
}
/*!
- \brief check early wakeup interrupt state of WWDGT
+ \brief get early wakeup flag of WWDGT
\param[in] none
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus wwdgt_flag_get(void)
{
- if(WWDGT_STAT & WWDGT_STAT_EWIF){
+ if(WWDGT_STAT & WWDGT_STAT_EWIF) {
return SET;
}
@@ -145,5 +127,16 @@ FlagStatus wwdgt_flag_get(void)
*/
void wwdgt_flag_clear(void)
{
- WWDGT_STAT &= (~WWDGT_STAT_EWIF);
+ WWDGT_STAT = (uint32_t)(RESET);
+}
+
+/*!
+ \brief enable early wakeup interrupt of WWDGT
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void wwdgt_interrupt_enable(void)
+{
+ WWDGT_CFG |= WWDGT_CFG_EWIE;
}
diff --git a/lib-gd32/include/FreeRTOSConfig.h b/lib-gd32/include/FreeRTOSConfig.h
new file mode 100644
index 0000000..28b79c8
--- /dev/null
+++ b/lib-gd32/include/FreeRTOSConfig.h
@@ -0,0 +1,164 @@
+/*
+ FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
+ All rights reserved
+
+ VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
+
+ This file is part of the FreeRTOS distribution.
+
+ FreeRTOS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License (version 2) as published by the
+ Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
+
+ ***************************************************************************
+ >>! NOTE: The modification to the GPL is included to allow you to !<<
+ >>! distribute a combined work that includes FreeRTOS without being !<<
+ >>! obliged to provide the source code for proprietary components !<<
+ >>! outside of the FreeRTOS kernel. !<<
+ ***************************************************************************
+
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. Full license text is available on the following
+ link: http://www.freertos.org/a00114.html
+
+ ***************************************************************************
+ * *
+ * FreeRTOS provides completely free yet professionally developed, *
+ * robust, strictly quality controlled, supported, and cross *
+ * platform software that is more than just the market leader, it *
+ * is the industry's de facto standard. *
+ * *
+ * Help yourself get started quickly while simultaneously helping *
+ * to support the FreeRTOS project by purchasing a FreeRTOS *
+ * tutorial book, reference manual, or both: *
+ * http://www.FreeRTOS.org/Documentation *
+ * *
+ ***************************************************************************
+
+ http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
+ the FAQ page "My application does not run, what could be wrong?". Have you
+ defined configASSERT()?
+
+ http://www.FreeRTOS.org/support - In return for receiving this top quality
+ embedded software for free we request you assist our global community by
+ participating in the support forum.
+
+ http://www.FreeRTOS.org/training - Investing in training allows your team to
+ be as productive as possible as early as possible. Now you can receive
+ FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
+ Ltd, and the world's leading authority on the world's leading RTOS.
+
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
+ including FreeRTOS+Trace - an indispensable productivity tool, a DOS
+ compatible FAT file system, and our tiny thread aware UDP/IP stack.
+
+ http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
+ Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
+
+ http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
+ Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
+ licenses offer ticketed support, indemnification and commercial middleware.
+
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety
+ engineered and independently SIL3 certified version for use in safety and
+ mission critical applications that require provable dependability.
+
+ 1 tab == 4 spaces!
+*/
+
+
+#ifndef FREERTOS_CONFIG_H
+#define FREERTOS_CONFIG_H
+
+#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__TASKING__) || defined(__GNUC__)
+#include
+extern uint32_t SystemCoreClock;
+#endif
+
+
+#define configUSE_PREEMPTION 1
+#define configCPU_CLOCK_HZ ( SystemCoreClock )
+#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
+#define configMAX_PRIORITIES ( 8 )
+#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 )
+#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 30 * 1024 ) )
+#define configMAX_TASK_NAME_LEN ( 16 )
+#define configUSE_16_BIT_TICKS 0
+#define configIDLE_SHOULD_YIELD 1
+#define configUSE_MUTEXES 1
+#define configUSE_RECURSIVE_MUTEXES 1
+#define configUSE_COUNTING_SEMAPHORES 1
+#define configQUEUE_REGISTRY_SIZE 8
+#define configUSE_APPLICATION_TASK_TAG 0
+
+
+/* hook function related definitions */
+#define configUSE_IDLE_HOOK 0
+#define configUSE_TICK_HOOK 0
+#define configCHECK_FOR_STACK_OVERFLOW 0
+#define configUSE_MALLOC_FAILED_HOOK 0
+
+/* run time and task stats gathering related definitions */
+#define configGENERATE_RUN_TIME_STATS 0
+#define configUSE_TRACE_FACILITY 1
+
+
+/* co-routine definitions */
+#define configUSE_CO_ROUTINES 0
+#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
+
+/* software timer definitions */
+#define configUSE_TIMERS 1
+#define configTIMER_TASK_PRIORITY ( 2 )
+#define configTIMER_QUEUE_LENGTH 10
+#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
+
+/* set to 1 to include the API function, or 0 to exclude the API function */
+#define INCLUDE_vTaskPrioritySet 1
+#define INCLUDE_uxTaskPriorityGet 1
+#define INCLUDE_vTaskDelete 1
+#define INCLUDE_vTaskCleanUpResources 0
+#define INCLUDE_vTaskSuspend 1
+#define INCLUDE_vTaskDelayUntil 1
+#define INCLUDE_vTaskDelay 1
+
+
+
+
+/* Cortex-M specific definitions */
+#ifdef __NVIC_PRIO_BITS
+ /* __NVIC_PRIO_BITS will be specified when CMSIS is being used. */
+ #define configPRIO_BITS __NVIC_PRIO_BITS
+#else
+ #define configPRIO_BITS 4 /* 15 priority levels */
+#endif
+
+/* the lowest interrupt priority that can be used in a call to a "set priority" function */
+#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
+
+/* The highest interrupt priority that can be used by any interrupt service
+routine that makes calls to interrupt safe FreeRTOS API functions. Do not call
+interrupt safe freertos api functions from any interrupt that has a higher
+priority than this! (higher priorities are lower numeric values. */
+#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 2
+
+/* interrupt priorities used by the kernel port layer itself */
+#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero */
+#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+
+
+
+
+/* normal assert() semantics without relying on the provision of an assert.h header file */
+#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
+
+/* map the FreeRTOS port interrupt handlers to CMSIS standard names */
+#define vPortSVCHandler SVC_Handler
+#define xPortPendSVHandler PendSV_Handler
+#define xPortSysTickHandler SysTick_Handler
+
+
+
+#endif /* FREERTOS_CONFIG_H */
diff --git a/lib-gd32/include/board/gd32f207c_eval.h b/lib-gd32/include/board/gd32f207c_eval.h
index 17de81c..52e0765 100644
--- a/lib-gd32/include/board/gd32f207c_eval.h
+++ b/lib-gd32/include/board/gd32f207c_eval.h
@@ -2,7 +2,7 @@
* @file gd32f207c_eval.h
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,8 @@
#ifndef BOARD_GD32F207C_EVAL_H_
#define BOARD_GD32F207C_EVAL_H_
+#include
+
#if !defined(BOARD_GD32F207C_EVAL)
# error This file should not be included
#endif
@@ -62,60 +64,72 @@
* KEYs
*/
-#define KEY1_PINx GPIO_PIN_0
-#define KEY1_GPIOx GPIOA
-#define KEY1_RCU_GPIOx RCU_GPIOA
+#define KEY1_PINx GPIO_PIN_0
+#define KEY1_GPIOx GPIOA
+#define KEY1_RCU_GPIOx RCU_GPIOA
-#define KEY2_PINx GPIO_PIN_13
-#define KEY2_GPIOx GPIOC
-#define KEY2_RCU_GPIOx RCU_GPIOC
+#define KEY2_PINx GPIO_PIN_13
+#define KEY2_GPIOx GPIOC
+#define KEY2_RCU_GPIOx RCU_GPIOC
-#define KEY3_PINx GPIO_PIN_14
-#define KEY3_GPIOx GPIOB
-#define KEY3_RCU_GPIOx RCU_GPIOB
+#define KEY3_PINx GPIO_PIN_14
+#define KEY3_GPIOx GPIOB
+#define KEY3_RCU_GPIOx RCU_GPIOB
-# define KEY_BOOTLOADER_TFTP_GPIO_PINx KEY3_PINx
-# define KEY_BOOTLOADER_TFTP_GPIOx KEY3_GPIOx
-# define KEY_BOOTLOADER_TFTP_RCU_GPIOx KEY3_RCU_GPIOx
+#define KEY_BOOTLOADER_TFTP_GPIO_PINx KEY2_PINx
+#define KEY_BOOTLOADER_TFTP_GPIOx KEY2_GPIOx
+#define KEY_BOOTLOADER_TFTP_RCU_GPIOx KEY2_RCU_GPIOx
/**
* I2C
*/
-#define I2C0_REMAP
-#if defined (I2C0_REMAP)
-# define I2C_REMAP GPIO_I2C0_REMAP
-#endif
+#define I2C_REMAP GPIO_I2C0_REMAP
#define I2C_PERIPH I2C0_PERIPH
-#define I2C_RCU_CLK I2C0_RCU_CLK
-#define I2C_GPIO_SCL_PORT I2C0_SCL_GPIOx
-#define I2C_GPIO_SCL_CLK I2C0_SCL_RCU_GPIOx
-#define I2C_GPIO_SDA_PORT I2C0_SDA_GPIOx
-#define I2C_GPIO_SDA_CLK I2C0_SDA_RCU_GPIOx
-#define I2C_SCL_PIN I2C0_SCL_GPIO_PINx
-#define I2C_SDA_PIN I2C0_SDA_GPIO_PINx
+#define I2C_RCU_I2Cx I2C0_RCU_I2C0
+#define I2C_SCL_GPIOx I2C0_SCL_GPIOx
+#define I2C_SCL_RCU_GPIOx I2C0_SCL_RCU_GPIOx
+#define I2C_SDA_GPIOx I2C0_SDA_GPIOx
+#define I2C_SDA_RCU_GPIOx I2C0_SDA_RCU_GPIOx
+#define I2C_SCL_GPIO_PINx I2C0_SCL_GPIO_PINx
+#define I2C_SDA_GPIO_PINx I2C0_SDA_GPIO_PINx
/**
* SPI
*/
-
-#define SPI2_REMAP
-#if defined (SPI2_REMAP)
-# define SPI_REMAP SPI2_REMAP_GPIO
-#endif
+
#define SPI_PERIPH SPI2_PERIPH
+#define SPI_RCU_SPIx SPI2_RCU_SPI2
#define SPI_NSS_GPIOx SPI2_NSS_GPIOx
#define SPI_NSS_RCU_GPIOx SPI2_NSS_RCU_GPIOx
#define SPI_NSS_GPIO_PINx SPI2_NSS_GPIO_PINx
-#define SPI_RCU_CLK SPI2_RCU_CLK
+#define SPI_RCU_SPIx SPI2_RCU_SPI2
#define SPI_GPIOx SPI2_GPIOx
#define SPI_RCU_GPIOx SPI2_RCU_GPIOx
-#define SPI_SCK_PIN SPI2_SCK_GPIO_PINx
-#define SPI_MISO_PIN SPI2_MISO_GPIO_PINx
-#define SPI_MOSI_PIN SPI2_MOSI_GPIO_PINx
+#define SPI_SCK_GPIO_PINx SPI2_SCK_GPIO_PINx
+#define SPI_MISO_GPIO_PINx SPI2_MISO_GPIO_PINx
+#define SPI_MOSI_GPIO_PINx SPI2_MOSI_GPIO_PINx
+#define SPI_IO2_PIN SPI2_IO2_GPIO_PINx
+#define SPI_IO3_PIN SPI2_IO3_GPIO_PINx
#define SPI_DMAx SPI2_DMAx
#define SPI_DMA_CHx SPI2_TX_DMA_CHx
+/**
+ * I2S
+ */
+
+#define I2S_PERIPH SPI2_PERIPH
+#define I2S_RCU_SPIx SPI2_RCU_SPI2
+#define I2S_RCU_GPIOx SPI2_RCU_GPIOx
+#define I2S_GPIOx SPI2_GPIOx
+#define I2S_CK_GPIO_PINx SPI2_SCK_GPIO_PINx
+#define I2S_SD_GPIO_PINx SPI2_MOSI_GPIO_PINx
+#define I2S_WS_RCU_GPIOx SPI2_NSS_RCU_GPIOx
+#define I2S_WS_GPIOx SPI2_NSS_GPIOx
+#define I2S_WS_GPIO_PINx SPI2_NSS_GPIO_PINx
+#define I2S_DMAx SPI2_DMAx
+#define I2S_DMA_CHx SPI2_TX_DMA_CHx
+
/**
* U(S)ART
*/
@@ -131,6 +145,7 @@
/**
* Panel LEDs
*/
+
#ifdef __cplusplus
namespace hal {
namespace panelled {
@@ -156,9 +171,22 @@ static constexpr uint32_t PORT_A_TX = 0;
* SPI flash
*/
-#define SPI_FLASH_CS_GPIOx SPI_NSS_GPIOx
-#define SPI_FLASH_CS_RCU_GPIOx SPI_NSS_RCU_GPIOx
-#define SPI_FLASH_CS_GPIO_PINx SPI_NSS_GPIO_PINx
+#define SPI_FLASH_CS_GPIOx GPIOE
+#define SPI_FLASH_CS_RCU_GPIOx RCU_GPIOE
+#define SPI_FLASH_CS_GPIO_PINx GPIO_PIN_3
+
+/*
+#define SPI_FLASH_WP_GPIO_PINx SPI_IO3_PIN
+#define SPI_FLASH_HOLD_GPIO_PINx SPI_IO4_PIN
+*/
+
+/**
+ * USB
+ */
+
+#define USB_HOST_VBUS_GPIOx GPIOD
+#define USB_HOST_VBUS_RCU_GPIOx RCU_GPIOD
+#define USB_HOST_VBUS_GPIO_PINx GPIO_PIN_13
/**
* EXT PHY
@@ -184,7 +212,7 @@ static constexpr uint32_t PORT_A_TX = 0;
#define GD32_MCU_NAME "GD32F207"
#define GD32_BOARD_NAME "GD32F207C_EVAL"
-#include "mcu/gd32f20x_mcu.h"
+#include "mcu/gd32f207_mcu.h"
#include "gd32_gpio.h"
#define GD32_BOARD_LED1 GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 0)
@@ -193,17 +221,36 @@ static constexpr uint32_t PORT_A_TX = 0;
#define GD32_BOARD_LED4 GD32_PORT_TO_GPIO(GD32_GPIO_PORTE, 1)
#define GD32_BOARD_STATUS_LED GD32_BOARD_LED1
+/**
+ * LCD
+ */
+
+#define DISPLAYTIMEOUT_GPIO GD32_PORT_TO_GPIO(GD32_GPIO_PORTC, 13) // KEY2
+
+/**
+ * Pixel DMX
+ */
+
+#define PIXELDMXSTARTSTOP_GPIO GD32_BOARD_LED2
+
/**
* SPI LCD
*/
-#define SPI_LCD_RST_PIN GPIO_EXT_7
-#define SPI_LCD_DC_PIN GPIO_EXT_26
-#define SPI_LCD_BL_PIN GPIO_EXT_22
-#if defined(SPI_LCD_HAVE_CS_PIN)
-# define SPI_LCD_CS_PIN GPIO_EXT_24
+#define SPI_LCD_RST_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 6)
+#define SPI_LCD_DC_GPIO GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 14)
+#define SPI_LCD_BL_GPIO GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 11)
+#if defined(SPI_LCD_HAVE_CS_GPIO)
+# define SPI_LCD_CS_GPIO GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 15)
#endif
+/**
+ * FT8xx LCD
+ */
+
+#define FT8XX_LCD_DC_GPIO GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 14)
+#define FT8XX_LCD_CS_GPIO GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 15)
+
#include "gpio_header.h"
#endif /* BOARD_GD32F207C_EVAL_H_ */
diff --git a/lib-gd32/include/board/gd32f207vc_2.h b/lib-gd32/include/board/gd32f207vc_2.h
deleted file mode 100644
index 71cd14b..0000000
--- a/lib-gd32/include/board/gd32f207vc_2.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/**
- * @file gd32f207vc_2.h
- *
- */
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef BOARD_GD32F207VC_2_H_
-#define BOARD_GD32F207VC_2_H_
-
-#if !defined(BOARD_GD32F207VC_2)
-# error This file should not be included
-#endif
-
-#if defined (MCU_GD32F20X_MCU_H_)
-# error This file should be included later
-#endif
-
-/**
- * LEDs
- */
-
-#define LED1_GPIO_PINx GPIO_PIN_0
-#define LED1_GPIOx GPIOC
-#define LED1_RCU_GPIOx RCU_GPIOC
-
-#define LED2_GPIO_PINx GPIO_PIN_2
-#define LED2_GPIOx GPIOC
-#define LED2_RCU_GPIOx RCU_GPIOC
-
-#define LED3_GPIO_PINx GPIO_PIN_0
-#define LED3_GPIOx GPIOE
-#define LED3_RCU_GPIOx RCU_GPIOE
-
-#define LED4_GPIO_PINx GPIO_PIN_1
-#define LED4_GPIOx GPIOE
-#define LED4_RCU_GPIOx RCU_GPIOE
-
-#define LED_BLINK_PIN LED1_GPIO_PINx
-#define LED_BLINK_GPIO_PORT LED1_GPIOx
-#define LED_BLINK_GPIO_CLK LED1_RCU_GPIOx
-
-/**
- * LEDs bit-banging 595
- */
-
-#define LED595_DATA_GPIO_PINx GPIO_PIN_2
-#define LED595_DATA_RCU_GPIOx RCU_GPIOE
-#define LED595_DATA_GPIOx GPIOE
-
-#define LED595_CLK_GPIO_PINx GPIO_PIN_3
-#define LED595_CLK_RCU_GPIOx RCU_GPIOE
-#define LED595_CLK_GPIOx GPIOE
-
-#define LED595_LOAD_GPIO_PINx GPIO_PIN_4
-#define LED595_LOAD_RCU_GPIOx RCU_GPIOE
-#define LED595_LOAD_GPIOx GPIOE
-
-/**
- * TACT_SW
- */
-
-#define KEY1_PINx GPIO_PIN_4
-#define KEY1_GPIOx GPIOA
-#define KEY1_RCU_GPIOx RCU_GPIOA
-
-#define KEY_BOOTLOADER_TFTP_GPIOx KEY1_GPIOx
-#define KEY_BOOTLOADER_TFTP_GPIO_PINx KEY1_PINx
-#define KEY_BOOTLOADER_TFTP_RCU_GPIOx KEY1_RCU_GPIOx
-
-/**
- * I2C
- */
-
-#define I2C0_REMAP
-#if defined (I2C0_REMAP)
-# define I2C_REMAP GPIO_I2C0_REMAP
-#endif
-#define I2C_PERIPH I2C0_PERIPH
-#define I2C_RCU_CLK I2C0_RCU_CLK
-#define I2C_GPIO_SCL_PORT I2C0_SCL_GPIOx
-#define I2C_GPIO_SCL_CLK I2C0_SCL_RCU_GPIOx
-#define I2C_GPIO_SDA_PORT I2C0_SDA_GPIOx
-#define I2C_GPIO_SDA_CLK I2C0_SDA_RCU_GPIOx
-#define I2C_SCL_PIN I2C0_SCL_GPIO_PINx
-#define I2C_SDA_PIN I2C0_SDA_GPIO_PINx
-
-/**
- * SPI
- */
-
-// #define SPI2_REMAP
-#if defined (SPI2_REMAP)
-# define SPI_REMAP SPI2_REMAP_GPIO
-#endif
-#define SPI_PERIPH SPI2_PERIPH
-#define SPI_NSS_GPIOx SPI2_NSS_GPIOx
-#define SPI_NSS_RCU_GPIOx SPI2_NSS_RCU_GPIOx
-#define SPI_NSS_GPIO_PINx SPI2_NSS_GPIO_PINx
-#define SPI_RCU_CLK SPI2_RCU_CLK
-#define SPI_GPIOx SPI2_GPIOx
-#define SPI_RCU_GPIOx SPI2_RCU_GPIOx
-#define SPI_SCK_PIN SPI2_SCK_GPIO_PINx
-#define SPI_MISO_PIN SPI2_MISO_GPIO_PINx
-#define SPI_MOSI_PIN SPI2_MOSI_GPIO_PINx
-#define SPI_DMAx SPI2_DMAx
-#define SPI_DMA_CHx SPI2_TX_DMA_CHx
-
-/**
- * U(S)ART
- */
-
-#define USART0_REMAP
-#define USART1_REMAP
-#define USART2_FULL_REMAP
-// #define USART2_PARTIAL_REMAP
-// #define UART3_REMAP
-// #define USART5_REMAP
-// #define UART6_REMAP
-
-/**
- * Panel LEDs
- */
-
-#ifdef __cplusplus
-namespace hal {
-namespace panelled {
-static constexpr uint32_t PORT_A_TX = (1U << 0);
-static constexpr uint32_t PORT_A_RX = (1U << 2);
-
-static constexpr uint32_t ACTIVITY = (7U << 4); //TODO Change
-
-static constexpr uint32_t SACN = (0U << 0);
-static constexpr uint32_t ARTNET = (0U << 0);
-} // namespace panelled
-} // namespace hal
-#endif
-
-/**
- * SPI flash
- */
-
-#define SPI_FLASH_CS_GPIO_PINx GPIO_PIN_6
-#define SPI_FLASH_CS_RCU_GPIOx RCU_GPIOE
-#define SPI_FLASH_CS_GPIOx GPIOE
-
-/**
- * EXT PHY
- */
-
-#define LINK_CHECK_GPIO_CLK RCU_GPIOB
-#define LINK_CHECK_GPIO_PORT GPIOB
-#define LINK_CHECK_GPIO_PIN GPIO_PIN_0
-#define LINK_CHECK_EXTI_LINE EXTI_0
-#define LINK_CHECK_EXTI_IRQn EXTI0_IRQn
-#define LINK_CHECK_IRQ_HANDLE EXTI0_IRQHandler
-
-#define LINK_CHECK_EXTI_CLK RCU_AF
-#define LINK_CHECK_EXTI_PORT_SOURCE GPIO_PORT_SOURCE_GPIOB
-#define LINK_CHECK_EXTI_PIN_SOURCE GPIO_PIN_SOURCE_0
-#define LINK_CHECK_EXTI_SOURCE_CONFIG gpio_exti_source_select
-#define LINK_CHECK_GPIO_CONFIG gpio_init(LINK_CHECK_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, LINK_CHECK_GPIO_PIN);
-
-/**
- * MCU and BOARD name
- */
-
-#define GD32_MCU_NAME "GD32F207VC"
-#define GD32_BOARD_NAME "TWIN DMX"
-
-#include "mcu/gd32f20x_mcu.h"
-#include "gd32_gpio.h"
-
-/**
- * SPI LCD
- */
-
-#define SPI_LCD_DC_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 1)
-#define SPI_LCD_BL_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 3)
-#define SPI_LCD_CS_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTE, 5)
-
-#endif /* BOARD_GD32F207V_H_ */
diff --git a/lib-gd32/include/board/gd32f207vc_4.h b/lib-gd32/include/board/gd32f207vc_4.h
deleted file mode 100644
index 36283ff..0000000
--- a/lib-gd32/include/board/gd32f207vc_4.h
+++ /dev/null
@@ -1,209 +0,0 @@
-/**
- * @file gd32f207vc_4.h
- *
- */
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef BOARD_GD32F207VC_4_H_
-#define BOARD_GD32F207VC_4_H_
-
-#if !defined(BOARD_GD32F207VC_4)
-# error This file should not be included
-#endif
-
-#if defined (MCU_GD32F20X_MCU_H_)
-# error This file should be included later
-#endif
-
-/**
- * LEDs
- */
-
-#define LED1_GPIO_PINx GPIO_PIN_0
-#define LED1_GPIOx GPIOC
-#define LED1_RCU_GPIOx RCU_GPIOC
-
-#define LED2_GPIO_PINx GPIO_PIN_2
-#define LED2_GPIOx GPIOC
-#define LED2_RCU_GPIOx RCU_GPIOC
-
-#define LED3_GPIO_PINx GPIO_PIN_0
-#define LED3_GPIOx GPIOE
-#define LED3_RCU_GPIOx RCU_GPIOE
-
-#define LED4_GPIO_PINx GPIO_PIN_1
-#define LED4_GPIOx GPIOE
-#define LED4_RCU_GPIOx RCU_GPIOE
-
-#define LED_BLINK_PIN LED1_GPIO_PINx
-#define LED_BLINK_GPIO_PORT LED1_GPIOx
-#define LED_BLINK_GPIO_CLK LED1_RCU_GPIOx
-
-/**
- * LEDs bit-banging 595
- */
-
-#define LED595_DATA_GPIO_PINx GPIO_PIN_2
-#define LED595_DATA_RCU_GPIOx RCU_GPIOE
-#define LED595_DATA_GPIOx GPIOE
-
-#define LED595_CLK_GPIO_PINx GPIO_PIN_3
-#define LED595_CLK_RCU_GPIOx RCU_GPIOE
-#define LED595_CLK_GPIOx GPIOE
-
-#define LED595_LOAD_GPIO_PINx GPIO_PIN_4
-#define LED595_LOAD_RCU_GPIOx RCU_GPIOE
-#define LED595_LOAD_GPIOx GPIOE
-
-/**
- * KEYs
- */
-
-#define KEY1_PINx GPIO_PIN_0
-#define KEY1_GPIOx GPIOA
-#define KEY1_RCU_GPIOx RCU_GPIOA
-
-#define KEY2_PINx GPIO_PIN_13
-#define KEY2_GPIOx GPIOC
-#define KEY2_RCU_GPIOx RCU_GPIOC
-
-#define KEY3_PINx GPIO_PIN_14
-#define KEY3_GPIOx GPIOB
-#define KEY3_RCU_GPIOx RCU_GPIOB
-
-#define KEY_BOOTLOADER_TFTP_GPIO_PINx GPIO_PIN_3
-#define KEY_BOOTLOADER_TFTP_RCU_GPIOx RCU_GPIOD
-#define KEY_BOOTLOADER_TFTP_GPIOx GPIOD
-
-/**
- * I2C
- */
-
-#define I2C0_REMAP
-#if defined (I2C0_REMAP)
-# define I2C_REMAP GPIO_I2C0_REMAP
-#endif
-#define I2C_PERIPH I2C0_PERIPH
-#define I2C_RCU_CLK I2C0_RCU_CLK
-#define I2C_GPIO_SCL_PORT I2C0_SCL_GPIOx
-#define I2C_GPIO_SCL_CLK I2C0_SCL_RCU_GPIOx
-#define I2C_GPIO_SDA_PORT I2C0_SDA_GPIOx
-#define I2C_GPIO_SDA_CLK I2C0_SDA_RCU_GPIOx
-#define I2C_SCL_PIN I2C0_SCL_GPIO_PINx
-#define I2C_SDA_PIN I2C0_SDA_GPIO_PINx
-
-/**
- * SPI
- */
-
-// #define SPI2_REMAP
-#if defined (SPI2_REMAP)
-# define SPI_REMAP SPI2_REMAP_GPIO
-#endif
-#define SPI_PERIPH SPI2_PERIPH
-#define SPI_NSS_GPIOx SPI2_NSS_GPIOx
-#define SPI_NSS_RCU_GPIOx SPI2_NSS_RCU_GPIOx
-#define SPI_NSS_GPIO_PINx SPI2_NSS_GPIO_PINx
-#define SPI_RCU_CLK SPI2_RCU_CLK
-#define SPI_GPIOx SPI2_GPIOx
-#define SPI_RCU_GPIOx SPI2_RCU_GPIOx
-#define SPI_SCK_PIN SPI2_SCK_GPIO_PINx
-#define SPI_MISO_PIN SPI2_MISO_GPIO_PINx
-#define SPI_MOSI_PIN SPI2_MOSI_GPIO_PINx
-#define SPI_DMAx SPI2_DMAx
-#define SPI_DMA_CHx SPI2_TX_DMA_CHx
-
-/**
- * U(S)ART
- */
-
-#define USART0_REMAP
-#define USART1_REMAP
-#define USART2_FULL_REMAP
-// #define USART2_PARTIAL_REMAP
-// #define UART3_REMAP
-// #define USART5_REMAP
-// #define UART6_REMAP
-
-/**
- * Panel LEDs
- */
-
-#ifdef __cplusplus
-namespace hal {
-namespace panelled {
-static constexpr uint32_t SACN = (1U << 0);
-static constexpr uint32_t ARTNET = (1U << 1);
-static constexpr uint32_t USB = (1U << 2);
-static constexpr uint32_t RDM = (1U << 3);
-static constexpr uint32_t PORT_A_TX = (1U << 8);
-static constexpr uint32_t PORT_A_RX = (1U << 12);
-
-static constexpr uint32_t ACTIVITY = (3U << 0); //TODO Remove
-} // namespace panelled
-} // namespace hal
-#endif
-
-/**
- * SPI flash
- */
-
-#define SPI_FLASH_CS_GPIO_PINx GPIO_PIN_6
-#define SPI_FLASH_CS_RCU_GPIOx RCU_GPIOE
-#define SPI_FLASH_CS_GPIOx GPIOE
-
-/**
- * EXT PHY
- */
-
-#define LINK_CHECK_GPIO_CLK RCU_GPIOB
-#define LINK_CHECK_GPIO_PORT GPIOB
-#define LINK_CHECK_GPIO_PIN GPIO_PIN_0
-#define LINK_CHECK_EXTI_LINE EXTI_0
-#define LINK_CHECK_EXTI_IRQn EXTI0_IRQn
-#define LINK_CHECK_IRQ_HANDLE EXTI0_IRQHandler
-
-#define LINK_CHECK_EXTI_CLK RCU_AF
-#define LINK_CHECK_EXTI_PORT_SOURCE GPIO_PORT_SOURCE_GPIOB
-#define LINK_CHECK_EXTI_PIN_SOURCE GPIO_PIN_SOURCE_0
-#define LINK_CHECK_EXTI_SOURCE_CONFIG gpio_exti_source_select
-#define LINK_CHECK_GPIO_CONFIG gpio_init(LINK_CHECK_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, LINK_CHECK_GPIO_PIN);
-
-/**
- * MCU and BOARD name
- */
-
-#define GD32_MCU_NAME "GD32F207VC"
-#define GD32_BOARD_NAME "QUAD DMX"
-
-#include "mcu/gd32f20x_mcu.h"
-#include "gd32_gpio.h"
-
-/**
- * SPI LCD
- */
-
-#define SPI_LCD_DC_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTB, 1)
-#define SPI_LCD_BL_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTA, 3)
-#define SPI_LCD_CS_PIN GD32_PORT_TO_GPIO(GD32_GPIO_PORTE, 5)
-
-#endif /* BOARD_GD32F207V_H_ */
diff --git a/lib-gd32/include/board/logic_analyzer.h b/lib-gd32/include/board/logic_analyzer.h
index e3bc5fa..9c2ab50 100644
--- a/lib-gd32/include/board/logic_analyzer.h
+++ b/lib-gd32/include/board/logic_analyzer.h
@@ -2,7 +2,7 @@
* @file logic_analyzer.h
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,60 +26,31 @@
#ifndef BOARD_LOGIC_ANALYZER_H_
#define BOARD_LOGIC_ANALYZER_H_
-#if defined (BOARD_GD32F207C_EVAL)
-# define LOGIC_ANALYZER_CH0_GPIO_PINx GPIO_PIN_0
-# define LOGIC_ANALYZER_CH1_GPIO_PINx GPIO_PIN_1
-# define LOGIC_ANALYZER_CH2_GPIO_PINx GPIO_PIN_7
-//#define LOGIC_ANALYZER_CH3_GPIO_PINx
-//#define LOGIC_ANALYZER_CH4_GPIO_PINx
-//#define LOGIC_ANALYZER_CH5_GPIO_PINx
-//#define LOGIC_ANALYZER_CH6_GPIO_PINx
-//#define LOGIC_ANALYZER_CH7_GPIO_PINx
-
-# define LOGIC_ANALYZER_CH0_GPIOx GPIOE
-# define LOGIC_ANALYZER_CH1_GPIOx GPIOE
-# define LOGIC_ANALYZER_CH2_GPIOx GPIOD
-# define LOGIC_ANALYZER_CH3_GPIOx
-# define LOGIC_ANALYZER_CH4_GPIOx
-# define LOGIC_ANALYZER_CH5_GPIOx
-# define LOGIC_ANALYZER_CH6_GPIOx
-# define LOGIC_ANALYZER_CH7_GPIOx
-
-# define LOGIC_ANALYZER_CH0_RCU_GPIOx RCU_GPIOE
-# define LOGIC_ANALYZER_CH1_RCU_GPIOx RCU_GPIOE
-# define LOGIC_ANALYZER_CH2_RCU_GPIOx RCU_GPIOD
-# define LOGIC_ANALYZER_CH3_RCU_GPIOx
-# define LOGIC_ANALYZER_CH4_RCU_GPIOx
-# define LOGIC_ANALYZER_CH5_RCU_GPIOx
-# define LOGIC_ANALYZER_CH6_RCU_GPIOx
-# define LOGIC_ANALYZER_CH7_RCU_GPIOx
-#else
-# define LOGIC_ANALYZER_CH0_GPIO_PINx GPIO_PIN_8 // PC8
-# define LOGIC_ANALYZER_CH1_GPIO_PINx GPIO_PIN_9 // PC9
-# define LOGIC_ANALYZER_CH2_GPIO_PINx GPIO_PIN_13 // PC13
-# define LOGIC_ANALYZER_CH3_GPIO_PINx GPIO_PIN_4 // PA4
-# define LOGIC_ANALYZER_CH4_GPIO_PINx GPIO_PIN_5 // PA5
-# define LOGIC_ANALYZER_CH5_GPIO_PINx GPIO_PIN_13 // PA13
-//# define LOGIC_ANALYZER_CH6_GPIO_PINx GPIO_PIN_
-//# define LOGIC_ANALYZER_CH7_GPIO_PINx GPIO_PIN_
-
-# define LOGIC_ANALYZER_CH0_GPIOx GPIOC
-# define LOGIC_ANALYZER_CH1_GPIOx GPIOC
-# define LOGIC_ANALYZER_CH2_GPIOx GPIOC
-# define LOGIC_ANALYZER_CH3_GPIOx GPIOA
-# define LOGIC_ANALYZER_CH4_GPIOx GPIOA
-# define LOGIC_ANALYZER_CH5_GPIOx GPIOA
-# define LOGIC_ANALYZER_CH6_GPIOx GPIO
-# define LOGIC_ANALYZER_CH7_GPIOx GPIO
-
-# define LOGIC_ANALYZER_CH0_RCU_GPIOx RCU_GPIOC
-# define LOGIC_ANALYZER_CH1_RCU_GPIOx RCU_GPIOC
-# define LOGIC_ANALYZER_CH2_RCU_GPIOx RCU_GPIOC
-# define LOGIC_ANALYZER_CH3_RCU_GPIOx RCU_GPIOA
-# define LOGIC_ANALYZER_CH4_RCU_GPIOx RCU_GPIOA
-# define LOGIC_ANALYZER_CH5_RCU_GPIOx RCU_GPIOA
-# define LOGIC_ANALYZER_CH6_RCU_GPIOx RCU_GPIO
-# define LOGIC_ANALYZER_CH7_RCU_GPIOx RCU_GPIO
-#endif
+#define LOGIC_ANALYZER_CH0_GPIO_PINx GPIO_PIN_3
+#define LOGIC_ANALYZER_CH1_GPIO_PINx GPIO_PIN_4
+#define LOGIC_ANALYZER_CH2_GPIO_PINx GPIO_PIN_5
+#define LOGIC_ANALYZER_CH3_GPIO_PINx GPIO_PIN_8
+#define LOGIC_ANALYZER_CH4_GPIO_PINx GPIO_PIN_9
+#define LOGIC_ANALYZER_CH5_GPIO_PINx GPIO_PIN_13
+#define LOGIC_ANALYZER_CH6_GPIO_PINx GPIO_PIN_11
+#define LOGIC_ANALYZER_CH7_GPIO_PINx GPIO_PIN_15
+
+#define LOGIC_ANALYZER_CH0_GPIOx GPIOB
+#define LOGIC_ANALYZER_CH1_GPIOx GPIOB
+#define LOGIC_ANALYZER_CH2_GPIOx GPIOB
+#define LOGIC_ANALYZER_CH3_GPIOx GPIOC
+#define LOGIC_ANALYZER_CH4_GPIOx GPIOC
+#define LOGIC_ANALYZER_CH5_GPIOx GPIOC
+#define LOGIC_ANALYZER_CH6_GPIOx GPIOA
+#define LOGIC_ANALYZER_CH7_GPIOx GPIOA
+
+#define LOGIC_ANALYZER_CH0_RCU_GPIOx RCU_GPIOB
+#define LOGIC_ANALYZER_CH1_RCU_GPIOx RCU_GPIOB
+#define LOGIC_ANALYZER_CH2_RCU_GPIOx RCU_GPIOB
+#define LOGIC_ANALYZER_CH3_RCU_GPIOx RCU_GPIOC
+#define LOGIC_ANALYZER_CH4_RCU_GPIOx RCU_GPIOC
+#define LOGIC_ANALYZER_CH5_RCU_GPIOx RCU_GPIOC
+#define LOGIC_ANALYZER_CH6_RCU_GPIOx RCU_GPIOA
+#define LOGIC_ANALYZER_CH7_RCU_GPIOx RCU_GPIOA
#endif /* BOARD_LOGIC_ANALYZER_H_ */
diff --git a/lib-gd32/include/gd32.h b/lib-gd32/include/gd32.h
index b13f5dc..c138dad 100644
--- a/lib-gd32/include/gd32.h
+++ b/lib-gd32/include/gd32.h
@@ -2,7 +2,7 @@
* @file gd32.h
*
*/
-/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,17 +26,22 @@
#ifndef GD32_H_
#define GD32_H_
-#include
+# include
-#if !defined __cplusplus
- void udelay(uint32_t us);
-#else
-# if !defined(GD32_UDELAY)
-# define GD32_UDELAY
+#ifdef __cplusplus
+# if !defined(UDELAY)
+# define UDELAY
void udelay(uint32_t us, uint32_t offset = 0);
# endif
#endif
+struct HwTimersSeconds {
+#if !defined (CONFIG_ENET_ENABLE_PTP)
+ volatile uint32_t nTimeval;
+#endif
+ volatile uint32_t nUptime;
+};
+
/*
* Needed for GD32 Firmware and CMSIS
*/
@@ -45,25 +50,23 @@
#ifdef __cplusplus
# pragma GCC diagnostic ignored "-Wold-style-cast"
# pragma GCC diagnostic ignored "-Wuseless-cast"
+# if __cplusplus > 201402
+// error: compound assignment with 'volatile'-qualified left operand is deprecated
+# pragma GCC diagnostic ignored "-Wvolatile"
+# endif
extern "C" {
#endif
-#if defined (GD32F10X_HD) || defined (GD32F10X_CL)
-# define GD32F10X
+#if defined (GD32F10X_HD) || defined (GD32F10X_CL)
# include "gd32f10x.h"
-# include "gd32f10x_libopt.h"
#elif defined (GD32F20X_CL)
-# define GD32F20X
# include "gd32f20x.h"
-# include "gd32f20x_libopt.h"
#elif defined (GD32F30X_HD)
-# define GD32F30X
# include "gd32f30x.h"
-# include "gd32f30x_libopt.h"
-#elif defined (GD32F407) || defined (GD32F450)
-# define GD32F4XX
+#elif defined (GD32F407) || defined (GD32F450) || defined (GD32F470)
# include "gd32f4xx.h"
-# include "gd32f4xx_libopt.h"
+#elif defined (GD32H759)
+# include "gd32h7xx.h"
#else
# error MCU is not supported
#endif
@@ -77,7 +80,7 @@ extern "C" {
# define bkp_data_read bkp_read_data
#endif
-#if defined(GD32F4XX) && defined(__cplusplus)
+#if (defined(GD32F4XX) || defined (GD32H7XX)) && defined(__cplusplus)
typedef enum
{
BKP_DATA_0,
@@ -87,6 +90,34 @@ void bkp_data_write(bkp_data_register_enum register_number, uint16_t data);
uint16_t bkp_data_read(bkp_data_register_enum register_number);
#endif
+#if !(defined (GD32F4XX) || defined (GD32H7XX))
+#define GPIO_INIT
+#endif
+
+#if defined (GD32H7XX)
+# define GPIO_OSPEED GPIO_OSPEED_60MHZ
+#else
+# define GPIO_OSPEED GPIO_OSPEED_50MHZ
+#endif
+
+#define GD32_PORT_TO_GPIO(p,n) ((p * 16) + n)
+#define GD32_GPIO_TO_PORT(g) (uint8_t)(g / 16)
+#define GD32_GPIO_TO_NUMBER(g) (uint8_t)(g - (16 * GD32_GPIO_TO_PORT(g)))
+
+typedef enum T_GD32_Port {
+ GD32_GPIO_PORTA = 0,
+ GD32_GPIO_PORTB,
+ GD32_GPIO_PORTC,
+ GD32_GPIO_PORTD,
+ GD32_GPIO_PORTE,
+ GD32_GPIO_PORTF,
+ GD32_GPIO_PORTG,
+ GD32_GPIO_PORTH,
+ GD32_GPIO_PORTI,
+ GD32_GPIO_PORTJ,
+ GD32_GPIO_PORTK
+} GD32_Port_TypeDef;
+
#include "gd32_board.h"
#endif /* GD32_H_ */
diff --git a/lib-gd32/include/gd32_adc.h b/lib-gd32/include/gd32_adc.h
index d637dc6..fc66537 100644
--- a/lib-gd32/include/gd32_adc.h
+++ b/lib-gd32/include/gd32_adc.h
@@ -26,10 +26,10 @@
#ifndef GD32_ADC_H_
#define GD32_ADC_H_
-float gd32_adc_gettemp(void);
-float gd32_adc_getvref(void);
+float gd32_adc_gettemp();
+float gd32_adc_getvref();
#if defined (GD32F4XX)
-float gd32_adc_getvbat(void);
+float gd32_adc_getvbat();
#endif
#ifdef __cplusplus
diff --git a/lib-gd32/include/gd32_board.h b/lib-gd32/include/gd32_board.h
index bb1ec55..f07b59e 100644
--- a/lib-gd32/include/gd32_board.h
+++ b/lib-gd32/include/gd32_board.h
@@ -2,7 +2,7 @@
* @file gd32_board.h
*
*/
-/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -46,8 +46,14 @@
# include "board/gd32f450vi.h"
#elif defined (BOARD_16X4U_PIXEL)
# include "board/16x4u-pixel.h"
+#elif defined (BOARD_GD32F470VG)
+# include "board/gd32f470vg.h"
#elif defined (BOARD_GD32F207C_EVAL)
# include "board/gd32f207c_eval.h"
+#elif defined (BOARD_GD32F470Z_EVAL)
+# include "board/gd32f470z_eval.h"
+#elif defined (BOARD_GD32H759I_EVAL)
+# include "board/gd32h759i_eval.h"
#elif defined (BOARD_BW_OPIDMX4)
# include "board/bw_opidmx4.h"
#elif defined (BOARD_DMX3)
@@ -64,4 +70,22 @@
# error Configuration error
#endif
+#if defined (GD32H7XX)
+# ifdef USE_ENET0
+# define ENETx ENET0
+# define RCU_ENET RCU_ENET0
+# define RCU_ENETTX RCU_ENET0TX
+# define RCU_ENETRX RCU_ENET0RX
+# elif USE_ENET1
+# define ENETx ENET1
+# define RCU_ENET RCU_ENET1
+# define RCU_ENETTX RCU_ENET1TX
+# define RCU_ENETRX RCU_ENET1RX
+# else
+# error
+# endif
+#else
+# define ENETx
+#endif
+
#endif /* GD32_BOARD_H_ */
diff --git a/lib-gd32/include/gd32_dma.h b/lib-gd32/include/gd32_dma.h
new file mode 100644
index 0000000..fbad893
--- /dev/null
+++ b/lib-gd32/include/gd32_dma.h
@@ -0,0 +1,225 @@
+/**
+ * @file gd32_dma.h
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef GD32_DMA_H_
+#define GD32_DMA_H_
+
+#include
+#include
+
+#include "gd32.h"
+
+#if defined (GD32F4XX) || defined (GD32H7XX)
+# define DMA_PARAMETER_STRUCT dma_single_data_parameter_struct
+# define DMA_CHMADDR DMA_CHM0ADDR
+# define DMA_MEMORY_TO_PERIPHERAL DMA_MEMORY_TO_PERIPH
+# define DMA_PERIPHERAL_WIDTH_8BIT DMA_PERIPH_WIDTH_8BIT
+# define dma_init dma_single_data_mode_init
+# define dma_memory_to_memory_disable(x,y)
+#else
+# define DMA_PARAMETER_STRUCT dma_parameter_struct
+#endif
+
+#if defined (GD32F10X) || defined (GD32F30X)
+template
+bool gd32_dma_interrupt_flag_get() {
+ uint32_t interrupt_enable = 0, interrupt_flag = 0;
+
+ switch (flag) {
+ case DMA_INT_FLAG_FTF:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE;
+ break;
+ case DMA_INT_FLAG_HTF:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INT_FLAG_ERR:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_ERRIE;
+ break;
+ default:
+ assert(0);
+ }
+
+ return interrupt_flag && interrupt_enable;
+}
+#elif defined (GD32F20X)
+template
+bool gd32_dma_interrupt_flag_get() {
+ uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
+ uint32_t gif_check = 0x0FU, gif_enable = 0x0EU;
+
+ switch (flag) {
+ case DMA_INT_FLAG_FTF:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE;
+ break;
+ case DMA_INT_FLAG_HTF:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INT_FLAG_ERR:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_ERRIE;
+ break;
+ case DMA_INT_FLAG_G:
+ interrupt_flag = DMA_INTF(dma_periph) & DMA_FLAG_ADD(gif_check, channelx);
+ interrupt_flag = interrupt_flag >> ((channelx) * 4U);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & gif_enable;
+ break;
+ default:
+ assert(0);
+ }
+
+ return (interrupt_flag && interrupt_enable);
+}
+#elif defined (GD32F4XX) || defined (GD32H7XX)
+template
+bool gd32_dma_interrupt_flag_get() {
+ uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
+
+ if constexpr (channelx < DMA_CH4) {
+ switch (flag) {
+ case DMA_INTF_FEEIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHFCTL(dma_periph, channelx) & DMA_CHXFCTL_FEEIE;
+ break;
+ case DMA_INTF_SDEIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_SDEIE;
+ break;
+ case DMA_INTF_TAEIF:
+ interrupt_flag = DMA_INTF0( dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_TAEIE;
+ break;
+ case DMA_INTF_HTFIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(flag, channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INTF_FTFIF:
+ interrupt_flag = (DMA_INTF0(dma_periph) & DMA_FLAG_ADD(flag, channelx));
+ interrupt_enable = (DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ } else if constexpr (channelx <= DMA_CH7) {
+ constexpr uint32_t channel_flag_offset = static_cast(channelx) - 4;
+ switch (flag) {
+ case DMA_INTF_FEEIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag, channel_flag_offset);
+ interrupt_enable = DMA_CHFCTL(dma_periph, channelx) & DMA_CHXFCTL_FEEIE;
+ break;
+ case DMA_INTF_SDEIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag, channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_SDEIE;
+ break;
+ case DMA_INTF_TAEIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag, channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_TAEIE;
+ break;
+ case DMA_INTF_HTFIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag, channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INTF_FTFIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag, channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph, channelx) & DMA_CHXCTL_FTFIE;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ } else {
+ assert(0);
+ }
+
+ return (interrupt_flag && interrupt_enable);
+}
+#else
+# error
+#endif
+
+#if defined (GD32F10X) || defined (GD32F30X) || defined (GD32F20X)
+template
+void gd32_dma_interrupt_flag_clear() {
+ DMA_INTC(peripheral) |= DMA_FLAG_ADD(nFlag, channel);
+}
+#elif defined (GD32F4XX) || defined (GD32H7XX)
+template
+inline void gd32_dma_interrupt_flag_clear() {
+ if constexpr (channel < DMA_CH4) {
+ DMA_INTC0(peripheral) |= DMA_FLAG_ADD(nFlag, channel);
+ } else {
+ DMA_INTC1(peripheral) |= DMA_FLAG_ADD(nFlag, static_cast(channel) - 4U);
+ }
+}
+#else
+# error
+#endif
+
+#if defined (GD32F10X) || defined (GD32F30X)
+template
+void gd32_dma_interrupt_disable() {
+ if constexpr (DMA1 == peripheral) {
+ static_assert(channel <= DMA_CH4, "for DMA1, the channel is from DMA_CH0 to DMA_CH4");
+ }
+
+ DMA_CHCTL(peripheral, channel) &= static_cast(~nSource);
+}
+#elif defined (GD32F20X)
+template
+void gd32_dma_interrupt_disable() {
+ DMA_CHCTL(peripheral, channel) &= static_cast(~nSource);
+}
+#elif defined (GD32F4XX)
+template
+void gd32_dma_interrupt_disable() {
+ if constexpr (DMA_CHXFCTL_FEEIE != nSource) {
+ DMA_CHCTL(peripheral, channel) &= static_cast(~nSource);
+ } else {
+ DMA_CHFCTL(peripheral, channel) &= static_cast(~nSource);
+ }
+}
+#elif defined (GD32H7XX)
+template
+void gd32_dma_interrupt_disable() {
+ if constexpr (DMA_CHXFCTL_FEEIE != (DMA_CHXFCTL_FEEIE & nSource)) {
+ DMA_CHCTL(peripheral, channel) &= static_cast(~nSource);
+ } else {
+ DMA_CHFCTL(peripheral, channel) &= static_cast(~DMA_CHXFCTL_FEEIE);
+ DMA_CHCTL(peripheral, channel) &= static_cast(~(nSource & (~DMA_CHXFCTL_FEEIE)));
+ }
+}
+#else
+# error
+#endif
+
+#endif /* GD32_DMA_H_ */
diff --git a/lib-gd32/include/gd32_dma_memcpy32.h b/lib-gd32/include/gd32_dma_memcpy32.h
new file mode 100644
index 0000000..c7936c1
--- /dev/null
+++ b/lib-gd32/include/gd32_dma_memcpy32.h
@@ -0,0 +1,56 @@
+/*
+ * gd32_dma_memcpy32.h
+ */
+
+#ifndef GD32_DMA_MEMCPY32_H_
+#define GD32_DMA_MEMCPY32_H_
+
+#include
+#include
+
+#include "gd32.h"
+
+namespace dma {
+void memcpy32_init() ;
+
+inline void memcpy32(const void *pDestination, const void *pSource, const uint32_t nLength) {
+ assert((reinterpret_cast(pSource) & 0x3) == 0);
+ assert((reinterpret_cast(pDestination) & 0x3) == 0);
+
+#if !defined (GD32F4XX)
+ uint32_t dmaCHCTL = DMA_CHCTL(DMA0, DMA_CH3);
+ dmaCHCTL &= ~DMA_CHXCTL_CHEN;
+ DMA_CHCTL(DMA0, DMA_CH3) = dmaCHCTL;
+
+ DMA_CHPADDR(DMA0, DMA_CH3) = reinterpret_cast(pSource);
+ DMA_CHMADDR(DMA0, DMA_CH3) = reinterpret_cast(pDestination);
+ DMA_CHCNT(DMA0, DMA_CH3) = (nLength & DMA_CHXCNT_CNT);
+
+ dmaCHCTL |= DMA_CHXCTL_CHEN;
+ DMA_CHCTL(DMA0, DMA_CH3) = dmaCHCTL;
+#else
+ uint32_t dmaCHCTL = DMA_CHCTL(DMA1, DMA_CH0);
+ dmaCHCTL &= ~DMA_CHXCTL_CHEN;
+ DMA_CHCTL(DMA1, DMA_CH0) = dmaCHCTL;
+
+ DMA_INTC0(DMA1) |= DMA_FLAG_ADD(DMA_CHINTF_RESET_VALUE, DMA_CH0);
+
+ DMA_CHM0ADDR(DMA1, DMA_CH0) = reinterpret_cast(pDestination);
+ DMA_CHPADDR(DMA1, DMA_CH0) = reinterpret_cast(pSource);
+ DMA_CHCNT(DMA1, DMA_CH0) = nLength;
+
+ dmaCHCTL |= DMA_CHXCTL_CHEN;
+ DMA_CHCTL(DMA1, DMA_CH0) = dmaCHCTL;
+#endif
+}
+
+inline bool memcpy32_is_active() {
+#if !defined (GD32F4XX)
+ return DMA_CHCNT(DMA0, DMA_CH3) != 0;
+#else
+ return DMA_CHCNT(DMA1, DMA_CH0) != 0;
+#endif
+}
+} // namespace dma
+
+#endif /* GD32_DMA_MEMCPY32_H_ */
diff --git a/lib-gd32/include/gd32_gpio.h b/lib-gd32/include/gd32_gpio.h
index 7591f93..71ec42c 100644
--- a/lib-gd32/include/gd32_gpio.h
+++ b/lib-gd32/include/gd32_gpio.h
@@ -2,7 +2,7 @@
* @file gd32_gpio.h
*
*/
-/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,20 +27,7 @@
#define GD32_GPIO_H_
#include
-
-#define GD32_PORT_TO_GPIO(p,n) ((p * 16) + n)
-#define GD32_GPIO_TO_PORT(g) (uint8_t)(g / 16)
-#define GD32_GPIO_TO_NUMBER(g) (uint8_t)(g - (16 * GD32_GPIO_TO_PORT(g)))
-
-typedef enum T_GD32_Port {
- GD32_GPIO_PORTA = 0,
- GD32_GPIO_PORTB,
- GD32_GPIO_PORTC,
- GD32_GPIO_PORTD,
- GD32_GPIO_PORTE,
- GD32_GPIO_PORTF,
- GD32_GPIO_PORTG,
-} GD32_Port_TypeDef;
+#include
#include "gd32.h"
@@ -52,7 +39,7 @@ typedef enum T_GD32_Port {
# define GPIO_PULL_DISABLE GPIO_MODE_IN_FLOATING
# define GPIO_INT_CFG_NEG_EDGE EXTI_TRIG_FALLING
# define GPIO_INT_CFG_BOTH EXTI_TRIG_BOTH
-#elif defined (GD32F407) || defined (GD32F450)
+#elif defined (GD32F407) || defined (GD32F450) || defined (GD32F470) || defined (GD32F470) || defined (GD32H759)
# define GPIO_FSEL_OUTPUT GPIO_MODE_OUTPUT
# define GPIO_FSEL_INPUT GPIO_MODE_INPUT
# define GPIO_PULL_UP GPIO_PUPD_PULLUP
@@ -60,7 +47,8 @@ typedef enum T_GD32_Port {
# define GPIO_PULL_DISABLE GPIO_PUPD_NONE
#endif
-inline static void gpio_fsel(const uint32_t gpio_periph, const uint32_t pin, const uint32_t fsel) {
+#ifdef __cplusplus
+inline void gpio_fsel(const uint32_t gpio_periph, const uint32_t pin, const uint32_t fsel) {
switch (gpio_periph) {
case GPIOA:
rcu_periph_clock_enable(RCU_GPIOA);
@@ -80,11 +68,32 @@ inline static void gpio_fsel(const uint32_t gpio_periph, const uint32_t pin, con
case GPIOF:
rcu_periph_clock_enable(RCU_GPIOF);
break;
+ case GPIOG:
+ rcu_periph_clock_enable(RCU_GPIOG);
+ break;
+#if !(defined (GD32F10X) || defined (GD32F30X))
+ case GPIOH:
+ rcu_periph_clock_enable(RCU_GPIOH);
+ break;
+# if !defined (GD32H7XX)
+ case GPIOI:
+ rcu_periph_clock_enable(RCU_GPIOI);
+ break;
+# endif
+#endif
+#if defined (GD32H7XX)
+ case GPIOJ:
+ rcu_periph_clock_enable(RCU_GPIOJ);
+ break;
+ case GPIOK:
+ rcu_periph_clock_enable(RCU_GPIOK);
+ break;
+#endif
default:
break;
}
-#if defined (GD32F10X) || defined (GD32F20X) || defined (GD32F30X)
+#if defined (GD32F10X) || defined (GD32F20X) || defined (GD32F30X)
if (gpio_periph == GPIOA) {
if ((pin == GPIO_PIN_13) || (pin == GPIO_PIN_14)) {
rcu_periph_clock_enable(RCU_AF);
@@ -93,10 +102,10 @@ inline static void gpio_fsel(const uint32_t gpio_periph, const uint32_t pin, con
}
gpio_init(gpio_periph, fsel, GPIO_OSPEED_50MHZ, pin);
-#elif defined (GD32F4XX)
+#elif defined (GD32F4XX) || defined (GD32H7XX)
if (fsel == GPIO_FSEL_OUTPUT) {
gpio_mode_set(gpio_periph, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, pin);
- gpio_output_options_set(gpio_periph, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
+ gpio_output_options_set(gpio_periph, GPIO_OTYPE_PP, GPIO_OSPEED, pin);
} else {
gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, pin);
}
@@ -105,31 +114,8 @@ inline static void gpio_fsel(const uint32_t gpio_periph, const uint32_t pin, con
#endif
}
-inline static void gd32_gpio_fsel(const uint32_t gpio, const uint32_t fsel) {
- const uint32_t gpio_periph = GPIOA + (GD32_GPIO_TO_PORT(gpio) * 0x400);
- const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
-
- gpio_fsel(gpio_periph, pin, fsel);
-}
-
-inline static void gd32_gpio_pud(const uint32_t gpio, const uint32_t pud) {
- const uint32_t gpio_periph = GPIOA + (GD32_GPIO_TO_PORT(gpio) * 0x400);
- const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
-
-#if defined (GD32F10X) || defined (GD32F20X) || defined (GD32F30X)
- gpio_init(gpio_periph, pud, GPIO_OSPEED_50MHZ, pin);
-#elif defined (GD32F4XX)
- if (pud == GPIO_PULL_UP) {
- gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, pin);
- } else if (pud == GPIO_PULL_DOWN) {
- gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN, pin);
- } else {
- gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_NONE, pin);
- }
-#endif
-}
-
-inline static void gd32_gpio_int_cfg(const uint32_t gpio, const uint32_t trig_type) {
+#if !defined (GD32H7XX)
+inline void gd32_gpio_int_cfg(const uint32_t gpio, const uint32_t trig_type) {
const uint32_t linex = BIT(GD32_GPIO_TO_NUMBER(gpio));
switch(trig_type){
@@ -158,22 +144,66 @@ inline static void gd32_gpio_int_cfg(const uint32_t gpio, const uint32_t trig_ty
syscfg_exti_line_config(output_port, output_pin);
#endif
}
+#endif
-inline static void gd32_gpio_clr(const uint32_t gpio) {
- const uint32_t gpio_periph = GPIOA + (GD32_GPIO_TO_PORT(gpio) * 0x400);
+inline uint32_t gd32_gpio_to_periph(const uint32_t gpio) {
+ switch ((GD32_Port_TypeDef) GD32_GPIO_TO_PORT(gpio)) {
+ case GD32_GPIO_PORTA:
+ case GD32_GPIO_PORTB:
+ case GD32_GPIO_PORTC:
+ case GD32_GPIO_PORTD:
+ case GD32_GPIO_PORTE:
+ case GD32_GPIO_PORTF:
+ case GD32_GPIO_PORTG:
+ return GPIOA + (GD32_GPIO_TO_PORT(gpio) * 0x400);
+ break;
+#if !(defined (GD32F10X) || defined (GD32F30X))
+ case GD32_GPIO_PORTH:
+ return GPIOH;
+ break;
+# if !defined (GD32H7XX)
+ case GD32_GPIO_PORTI:
+ return GPIOI;
+ break;
+# endif
+#endif
+#if defined (GD32H7XX)
+ case GD32_GPIO_PORTJ:
+ return GPIOJ;
+ break;
+ case GD32_GPIO_PORTK:
+ return GPIOK;
+ break;
+#endif
+ default:
+ assert(0);
+ return 0;
+ break;
+ }
+}
+
+inline void gd32_gpio_fsel(const uint32_t gpio, const uint32_t fsel) {
+ const uint32_t gpio_periph = gd32_gpio_to_periph(gpio);
const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
- GPIO_BC(gpio_periph) = (uint32_t) pin;
+ gpio_fsel(gpio_periph, pin, fsel);
}
-inline static void gd32_gpio_set(const uint32_t gpio) {
- const uint32_t gpio_periph = GPIOA + (GD32_GPIO_TO_PORT(gpio) * 0x400);
+inline void gd32_gpio_clr(const uint32_t gpio) {
+ const uint32_t gpio_periph = gd32_gpio_to_periph(gpio);
const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
- GPIO_BOP(gpio_periph) = (uint32_t) pin;
+ GPIO_BC(gpio_periph) = pin;
}
-inline static void gd32_gpio_write(const uint32_t gpio, const uint32_t level) {
+inline void gd32_gpio_set(const uint32_t gpio) {
+ const uint32_t gpio_periph = gd32_gpio_to_periph(gpio);
+ const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
+
+ GPIO_BOP(gpio_periph) = pin;
+}
+
+inline void gd32_gpio_write(const uint32_t gpio, const uint32_t level) {
if (level == 0) {
gd32_gpio_clr(gpio);
} else {
@@ -181,10 +211,135 @@ inline static void gd32_gpio_write(const uint32_t gpio, const uint32_t level) {
}
}
-inline static uint32_t gd32_gpio_lev(const uint32_t gpio) {
- const uint32_t gpio_periph = GPIOA + (GD32_GPIO_TO_PORT(gpio) * 0x400);
+inline uint32_t gd32_gpio_lev(const uint32_t gpio) {
+ const uint32_t gpio_periph = gd32_gpio_to_periph(gpio);
const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
- return (uint32_t) ((uint32_t) 0 != (GPIO_ISTAT(gpio_periph) & pin));
+
+ return (uint32_t)(0 != (GPIO_ISTAT(gpio_periph) & pin));
}
+inline void gd32_gpio_set_pud(const uint32_t gpio, const uint32_t pud) {
+ const uint32_t gpio_periph = gd32_gpio_to_periph(gpio);
+ const uint32_t pin = BIT(GD32_GPIO_TO_NUMBER(gpio));
+
+#if defined (GD32F10X) || defined (GD32F20X) || defined (GD32F30X)
+ gpio_init(gpio_periph, pud, GPIO_OSPEED_50MHZ, pin);
+#elif defined (GD32F4XX) || defined (GD32H7XX)
+ if (pud == GPIO_PULL_UP) {
+ gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, pin);
+ } else if (pud == GPIO_PULL_DOWN) {
+ gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN, pin);
+ } else {
+ gpio_mode_set(gpio_periph, GPIO_MODE_INPUT, GPIO_PUPD_NONE, pin);
+ }
+#endif
+}
+
+#if defined (GD32F4XX) || defined (GD32H7XX)
+template
+inline void gd32_gpio_mode_set() {
+ static_assert(pin != 0, "pin cannot be zero");
+ static_assert(pin == (1U << __builtin_ctz(pin)), "Only single pin values are allowed");
+
+ uint32_t ctl = GPIO_CTL(gpio_periph);
+ uint32_t pupd = GPIO_PUD(gpio_periph);
+
+ constexpr auto i = 31U - __builtin_clz(pin);
+
+ /* clear the specified pin mode bits */
+ ctl &= ~GPIO_MODE_MASK(i);
+ /* set the specified pin mode bits */
+ ctl |= GPIO_MODE_SET(i, mode);
+
+ /* clear the specified pin pupd bits */
+ pupd &= ~GPIO_PUPD_MASK(i);
+ /* set the specified pin pupd bits */
+ pupd |= GPIO_PUPD_SET(i, pull_up_down);
+
+ GPIO_CTL(gpio_periph) = ctl;
+ GPIO_PUD(gpio_periph) = pupd;
+}
+
+template
+inline void gd32_gpio_af_set() {
+ static_assert(pin != 0, "pin cannot be zero");
+ static_assert(pin == (1U << __builtin_ctz(pin)), "Only single pin values are allowed");
+
+ constexpr uint32_t i = 31U - __builtin_clz(pin);
+
+ auto afrl = GPIO_AFSEL0(gpio_periph);
+ auto afrh = GPIO_AFSEL1(gpio_periph);
+
+ if constexpr(i < 8U) {
+ /* clear the specified pin alternate function bits */
+ afrl &= ~GPIO_AFR_MASK(i);
+ afrl |= GPIO_AFR_SET(i, alt_func_num);
+ } else if constexpr(i < 16U) {
+ /* clear the specified pin alternate function bits */
+ afrh &= ~GPIO_AFR_MASK(i - 8U);
+ afrh |= GPIO_AFR_SET(i - 8U, alt_func_num);
+ }
+
+ GPIO_AFSEL0(gpio_periph) = afrl;
+ GPIO_AFSEL1(gpio_periph) = afrh;
+}
+#else
+template
+inline void gd32_gpio_init() {
+ /* GPIO mode configuration */
+ auto temp_mode = (mode & 0x0F);
+
+ /* GPIO speed configuration */
+ if constexpr ((0x00U) != (mode & (0x10U))) {
+ /* output mode max speed: 10MHz, 2MHz, 50MHz */
+ temp_mode |= speed;
+ }
+
+ constexpr uint32_t pin_pos = 31U - __builtin_clz(pin);
+
+ if constexpr (pin_pos < 8U) {
+ uint32_t reg = GPIO_CTL0(gpio_periph);
+ /* clear the specified pin mode bits */
+ reg &= ~GPIO_MODE_MASK(pin_pos);
+ /* set the specified pin mode bits */
+ reg |= GPIO_MODE_SET(pin_pos, temp_mode);
+
+ /* set IPD or IPU */
+ if constexpr (GPIO_MODE_IPD == mode) {
+ /* reset the corresponding OCTL bit */
+ GPIO_BC(gpio_periph) = (1U << pin_pos);
+ } else {
+ /* set the corresponding OCTL bit */
+ if constexpr (GPIO_MODE_IPU == mode) {
+ GPIO_BOP(gpio_periph) = (1U << pin_pos);
+ }
+ }
+ /* set GPIO_CTL0 register */
+ GPIO_CTL0(gpio_periph) = reg;
+ } else {
+ /* configure the eight high port pins with GPIO_CTL1 */
+ constexpr uint32_t high_pin_pos = pin_pos - 8U;
+ uint32_t reg = GPIO_CTL1(gpio_periph);
+ /* clear the specified pin mode bits */
+ reg &= ~GPIO_MODE_MASK(high_pin_pos);
+ /* set the specified pin mode bits */
+ reg |= GPIO_MODE_SET(high_pin_pos, temp_mode);
+
+ /* set IPD or IPU */
+ if constexpr (GPIO_MODE_IPD == mode) {
+ /* reset the corresponding OCTL bit */
+ GPIO_BC(gpio_periph) = (1U << pin_pos);
+ } else {
+ /* set the corresponding OCTL bit */
+ if (GPIO_MODE_IPU == mode) {
+ GPIO_BOP(gpio_periph) = (1U << pin_pos);
+ }
+ }
+ /* set GPIO_CTL1 register */
+ GPIO_CTL1(gpio_periph) = reg;
+ }
+}
+#endif
+#endif
+
#endif /* GD32_GPIO_H_ */
diff --git a/lib-gd32/include/gd32_ptp.h b/lib-gd32/include/gd32_ptp.h
new file mode 100644
index 0000000..c1eb623
--- /dev/null
+++ b/lib-gd32/include/gd32_ptp.h
@@ -0,0 +1,98 @@
+/**
+ * @file gd32_ptp.h
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef GD32_PTP_H_
+#define GD32_PTP_H_
+
+#include
+
+#include "gd32.h"
+
+namespace gd32 {
+namespace ptp {
+#if !defined(MCU_CLOCK_FREQ)
+# error MCU_CLOCK_FREQ is not defined
+#endif
+#if !defined(PTP_ACCARACY_NS)
+ static constexpr uint8_t PTP_TICK = 20;
+#else
+ static constexpr uint8_t PTP_TICK = PTP_ACCARACY_NS;
+#endif
+static constexpr uint8_t ADJ_FREQ_BASE_INCREMENT = static_cast((PTP_TICK * static_cast(1ULL << 31) / 1E9) + 0.5f);
+static constexpr uint32_t ADJ_FREQ_BASE_ADDEND = (static_cast(1ULL << 63) / AHB_CLOCK_FREQ) / ADJ_FREQ_BASE_INCREMENT;
+static constexpr int32_t ADJ_FREQ_MAX = 5120000;
+
+struct time_t {
+ int32_t tv_sec;
+ int32_t tv_nsec;
+};
+
+struct ptptime {
+ uint32_t tv_sec;
+ uint32_t tv_nsec;
+};
+} // namespace ptp
+
+inline uint32_t ptp_nanosecond_2_subsecond(const uint32_t nanosecond) {
+ uint64_t val = nanosecond * 0x80000000Ull;
+ val /= 1000000000U;
+ return static_cast(val);
+}
+
+inline uint32_t ptp_subsecond_2_nanosecond(const uint32_t subsecond) {
+ uint64_t val = subsecond * 1000000000Ull;
+ val >>= 31U;
+ return (uint32_t) val;
+}
+
+inline void normalize_time(ptp::time_t *r) {
+ r->tv_sec += r->tv_nsec / 1000000000;
+ r->tv_nsec -= r->tv_nsec / 1000000000 * 1000000000;
+
+ if (r->tv_sec > 0 && r->tv_nsec < 0) {
+ r->tv_sec -= 1;
+ r->tv_nsec += 1000000000;
+ } else if (r->tv_sec < 0 && r->tv_nsec > 0) {
+ r->tv_sec += 1;
+ r->tv_nsec -= 1000000000;
+ }
+}
+
+inline void sub_time(struct ptp::time_t *r, const struct ptp::time_t *x, const struct ptp::time_t *y) {
+ r->tv_sec = x->tv_sec - y->tv_sec;
+ r->tv_nsec = x->tv_nsec - y->tv_nsec;
+
+ normalize_time(r);
+}
+
+} // namespace gd32
+
+void gd32_ptp_start();
+void gd32_ptp_get_time(gd32::ptp::ptptime *ptp_time);
+void gd32_ptp_set_time(const gd32::ptp::ptptime *ptp_time);
+void gd32_ptp_update_time(const gd32::ptp::time_t *ptp_time);
+bool gd32_adj_frequency(const int32_t adjust_pbb);
+
+#endif /* GD32_PTP_H_ */
diff --git a/lib-network/src/networkconst.cpp b/lib-gd32/include/gd32_pwm.h
similarity index 73%
rename from lib-network/src/networkconst.cpp
rename to lib-gd32/include/gd32_pwm.h
index b70872e..5e3cf8c 100644
--- a/lib-network/src/networkconst.cpp
+++ b/lib-gd32/include/gd32_pwm.h
@@ -1,8 +1,8 @@
/**
- * @file networkconst.cpp
+ * @file gd32_pwm.h
*
*/
-/* Copyright (C) 2019-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,10 +23,21 @@
* THE SOFTWARE.
*/
-#include "networkconst.h"
+#ifndef GD32_PWM_H_
+#define GD32_PWM_H_
-const char NetworkConst::MSG_NETWORK_INIT[] = "Network init";
-const char NetworkConst::MSG_NETWORK_STARTED[] = "Network started";
+#include
-const char NetworkConst::MSG_MDNS_CONFIG[] = "Configuring MDNS";
-const char NetworkConst::MSG_MDNS_STARTED[] = "MDNS started";
+namespace pwm {
+enum class Channel {
+ PWM_CHANNEL_0,
+ PWM_CHANNEL_1,
+ PWM_CHANNEL_2,
+ PWM_CHANNEL_3
+};
+} // namespace pwm
+
+void gd32_pwm_begin();
+void gd32_pwm_set_duty_cycle(const pwm::Channel channel, const uint32_t nDutyCycle);
+
+#endif /* GD32_PWM_H_ */
diff --git a/lib-gd32/include/gd32_spi.h b/lib-gd32/include/gd32_spi.h
index 9b1f8ad..10d410f 100644
--- a/lib-gd32/include/gd32_spi.h
+++ b/lib-gd32/include/gd32_spi.h
@@ -2,7 +2,7 @@
* @file gd32_spi.h
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -62,10 +62,21 @@ void gd32_spi_writenb(const char *pTxBuffer, uint32_t nDataLength);
* DMA support
*/
+const uint8_t *gd32_spi_dma_tx_prepare(uint32_t& nLength);
+void gd32_spi_dma_tx_start(const uint8_t *pTxBuffer, uint32_t nLength);
+bool gd32_spi_dma_tx_is_active();
+
+/**
+ * SPI DMA implementation using I2S.
+ * Limitation SPI is that you cannot set the speed exactly.
+ * Exact speed is needed for pixels (WS2812B, etc).
+ */
+namespace i2s {
void gd32_spi_dma_begin();
-void gd32_spi_dma_set_speed_hz(uint32_t speed_hz);
-const uint8_t *gd32_spi_dma_tx_prepare(uint32_t *data_length);
-void gd32_spi_dma_tx_start(const uint8_t *tx_buffer, uint32_t length);
+void gd32_spi_dma_set_speed_hz(uint32_t nSpeedHz);
+const uint8_t *gd32_spi_dma_tx_prepare(uint32_t *pLength);
+void gd32_spi_dma_tx_start(const uint8_t *pTxBuffer, uint32_t nLength);
bool gd32_spi_dma_tx_is_active();
+} // namespace i2s
#endif /* GD32_SPI_H_ */
diff --git a/lib-gd32/include/gd32_uart.h b/lib-gd32/include/gd32_uart.h
index 5f3c759..f562f6c 100644
--- a/lib-gd32/include/gd32_uart.h
+++ b/lib-gd32/include/gd32_uart.h
@@ -2,7 +2,7 @@
* @file gd32_uart.h
*
*/
-/* Copyright (C) 2021 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,13 @@
#ifndef GD32_UART_H_
#define GD32_UART_H_
+#if !defined (GD32H7XX)
+# define USART_TDATA USART_DATA
+# define USART_RDATA USART_DATA
+# define USART_TDATA_TDATA USART_DATA_DATA
+# define USART_RDATA_TDATA USART_DATA_DATA
+#endif
+
typedef enum GD32_UART_BITS {
GD32_UART_BITS_8 = 8,
GD32_UART_BITS_9 = 9
@@ -42,27 +49,75 @@ typedef enum GD32_UART_STOPBITS {
GD32_UART_STOP_2BITS = 2
} gd32_uart_stopbits_t;
-#include
+#include
#include "gd32.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void gd32_uart_begin(const uint32_t usart_periph, uint32_t baudrate, uint32_t bits, uint32_t parity, uint32_t stop_bits);
-extern void gd32_uart_set_baudrate(const uint32_t usart_periph, uint32_t baudrate);
-extern void gd32_uart_transmit(const uint32_t usart_periph, const uint8_t *data, uint32_t length);
-extern void gd32_uart_transmit_string(const uint32_t uart_base, const char *data);
+void gd32_uart_begin(const uint32_t usart_periph, uint32_t baudrate, uint32_t bits, uint32_t parity, uint32_t stop_bits);
+void gd32_uart_set_baudrate(const uint32_t usart_periph, uint32_t baudrate);
+void gd32_uart_transmit(const uint32_t usart_periph, const uint8_t *data, uint32_t length);
+void gd32_uart_transmit_string(const uint32_t usart_periph, const char *data);
-static inline uint32_t gd32_uart_get_rx_fifo_level(__attribute__((unused)) const uint32_t usart_periph) {
+inline uint32_t gd32_uart_get_rx_fifo_level(__attribute__((unused)) const uint32_t usart_periph) {
return 1;
}
-static inline uint8_t gd32_uart_get_rx_data(const uint32_t uart_base) {
- return (uint8_t)(GET_BITS(USART_DATA(uart_base), 0U, 8U));
+inline uint8_t gd32_uart_get_rx_data(const uint32_t usart_periph) {
+ return static_cast(GET_BITS(USART_RDATA(usart_periph), 0U, 8U));
+}
+
+template
+bool gd32_usart_flag_get(const uint32_t usart_periph) {
+ return (0 != (USART_REG_VAL(usart_periph, flag) & BIT(USART_BIT_POS(flag))));
+}
+
+template
+void gd32_usart_flag_clear(const uint32_t usart_periph) {
+#if defined (GD32F10X) || defined (GD32F30X) || defined (GD32F20X)
+ USART_REG_VAL(usart_periph, flag) = ~BIT(USART_BIT_POS(flag));
+#elif defined (GD32F4XX)
+ USART_REG_VAL(usart_periph, flag) &= ~BIT(USART_BIT_POS(flag));
+#elif defined (GD32H7XX)
+ if constexpr (USART_FLAG_AM1 == flag) {
+ USART_INTC(usart_periph) |= USART_INTC_AMC1;
+ } else if constexpr (USART_FLAG_EPERR == flag) {
+ USART_CHC(usart_periph) &= (uint32_t) (~USART_CHC_EPERR);
+ } else if constexpr (USART_FLAG_TFE == flag) {
+ USART_FCS(usart_periph) |= USART_FCS_TFEC;
+ } else {
+ USART_INTC(usart_periph) |= BIT(USART_BIT_POS(flag));
+ }
+#else
+# error
+#endif
+}
+
+template
+void gd32_usart_interrupt_enable(const uint32_t usart_periph) {
+ USART_REG_VAL(usart_periph, interrupt) |= BIT(USART_BIT_POS(interrupt));
}
-#ifdef __cplusplus
+template
+void gd32_usart_interrupt_disable(const uint32_t usart_periph) {
+ USART_REG_VAL(usart_periph, interrupt) &= ~BIT(USART_BIT_POS(interrupt));
}
+
+template
+void gd32_usart_interrupt_flag_clear(const uint32_t usart_periph) {
+#if defined (GD32F10X) || defined (GD32F30X) || defined (GD32F20X)
+ USART_REG_VAL2(usart_periph, flag) = ~BIT(USART_BIT_POS2(flag));
+#elif defined (GD32F4XX)
+ USART_REG_VAL2(usart_periph, flag) &= ~BIT(USART_BIT_POS2(flag));
+#elif defined (GD32H7XX)
+ if constexpr (USART_INT_FLAG_TFE == flag) {
+ USART_FCS(usart_periph) |= USART_FCS_TFEC;
+ } else if constexpr (USART_INT_FLAG_RFF == flag) {
+ USART_FCS(usart_periph) &= (~USART_FCS_RFFIF);
+ } else {
+ USART_INTC(usart_periph) |= BIT(USART_BIT_POS2(flag));
+ }
+#else
+# error
#endif
+}
+
#endif /* GD32_UART_H_ */
diff --git a/lib-gd32/include/logic_analyzer.h b/lib-gd32/include/logic_analyzer.h
index ff116a0..c70ef0b 100644
--- a/lib-gd32/include/logic_analyzer.h
+++ b/lib-gd32/include/logic_analyzer.h
@@ -2,7 +2,7 @@
* @file logic_analyzer.h
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,96 +26,96 @@
#ifndef LOGIC_ANALYZER_H_
#define LOGIC_ANALYZER_H_
+#include "board/logic_analyzer.h"
#include "gd32.h"
namespace logic_analyzer {
-
-static void init() {
+inline void init() {
#if defined (LOGIC_ANALYZER)
# if defined (LOGIC_ANALYZER_CH0_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH0_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH0_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH0_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH0_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH0_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH0_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH0_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH0_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH0_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH0_GPIOx) = LOGIC_ANALYZER_CH0_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH1_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH1_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH1_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH1_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH1_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH1_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH1_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH1_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH1_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH1_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH1_GPIOx) = LOGIC_ANALYZER_CH1_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH2_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH2_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH2_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH2_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH2_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH2_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH2_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH2_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH2_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH2_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH2_GPIOx) = LOGIC_ANALYZER_CH2_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH3_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH3_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH3_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH3_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH3_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH3_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH3_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH3_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH3_GPIOx) = LOGIC_ANALYZER_CH3_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH4_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH4_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH4_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH4_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH4_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH4_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH4_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH4_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH4_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH4_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH4_GPIOx) = LOGIC_ANALYZER_CH4_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH5_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH5_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH5_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH5_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH5_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH5_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH5_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH5_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH5_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH5_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH5_GPIOx) = LOGIC_ANALYZER_CH5_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH6_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH6_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH6_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH6_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH6_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH6_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH6_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH6_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH6_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH6_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH6_GPIOx) = LOGIC_ANALYZER_CH6_GPIO_PINx;
# endif
# if defined (LOGIC_ANALYZER_CH7_GPIO_PINx)
rcu_periph_clock_enable(LOGIC_ANALYZER_CH7_RCU_GPIOx);
-# if !defined (GD32F4XX)
+# if defined (GPIO_INIT)
gpio_init(LOGIC_ANALYZER_CH7_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH7_GPIO_PINx);
# else
gpio_mode_set(LOGIC_ANALYZER_CH7_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LOGIC_ANALYZER_CH7_GPIO_PINx);
- gpio_output_options_set(LOGIC_ANALYZER_CH7_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LOGIC_ANALYZER_CH7_GPIO_PINx);
+ gpio_output_options_set(LOGIC_ANALYZER_CH7_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LOGIC_ANALYZER_CH7_GPIO_PINx);
# endif
GPIO_BC(LOGIC_ANALYZER_CH7_GPIOx) = LOGIC_ANALYZER_CH7_GPIO_PINx;
# endif
@@ -123,103 +123,101 @@ static void init() {
#endif
}
-static void ch0_clear() {
-#if defined (LOGIC_ANALYZER_CH0_GPIO_PINx)
+inline void ch0_clear() {
+#if defined (LOGIC_ANALYZER_CH0_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH0_GPIOx) = LOGIC_ANALYZER_CH0_GPIO_PINx;
#endif
}
-static void ch0_set() {
-#if defined (LOGIC_ANALYZER_CH0_GPIO_PINx)
+inline void ch0_set() {
+#if defined (LOGIC_ANALYZER_CH0_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH0_GPIOx) = LOGIC_ANALYZER_CH0_GPIO_PINx;
#endif
}
-static void ch1_clear() {
-#if defined (LOGIC_ANALYZER_CH1_GPIO_PINx)
+inline void ch1_clear() {
+#if defined (LOGIC_ANALYZER_CH1_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH1_GPIOx) = LOGIC_ANALYZER_CH1_GPIO_PINx;
#endif
}
-static void ch1_set() {
-#if defined (LOGIC_ANALYZER_CH1_GPIO_PINx)
+inline void ch1_set() {
+#if defined (LOGIC_ANALYZER_CH1_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH1_GPIOx) = LOGIC_ANALYZER_CH1_GPIO_PINx;
#endif
}
-static void ch2_clear() {
-#if defined (LOGIC_ANALYZER_CH2_GPIO_PINx)
+inline void ch2_clear() {
+#if defined (LOGIC_ANALYZER_CH2_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH2_GPIOx) = LOGIC_ANALYZER_CH2_GPIO_PINx;
#endif
}
-static void ch2_set() {
-#if defined (LOGIC_ANALYZER_CH2_GPIO_PINx)
+inline void ch2_set() {
+#if defined (LOGIC_ANALYZER_CH2_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH2_GPIOx) = LOGIC_ANALYZER_CH2_GPIO_PINx;
#endif
}
-static void ch3_clear() {
-#if defined (LOGIC_ANALYZER_CH3_GPIO_PINx)
+inline void ch3_clear() {
+#if defined (LOGIC_ANALYZER_CH3_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH3_GPIOx) = LOGIC_ANALYZER_CH3_GPIO_PINx;
#endif
}
-static void ch3_set() {
-#if defined (LOGIC_ANALYZER_CH3_GPIO_PINx)
+inline void ch3_set() {
+#if defined (LOGIC_ANALYZER_CH3_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH3_GPIOx) = LOGIC_ANALYZER_CH3_GPIO_PINx;
#endif
}
-//
-static void ch4_clear() {
-#if defined (LOGIC_ANALYZER_CH4_GPIO_PINx)
+inline void ch4_clear() {
+#if defined (LOGIC_ANALYZER_CH4_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH4_GPIOx) = LOGIC_ANALYZER_CH4_GPIO_PINx;
#endif
}
-static void ch4_set() {
-#if defined (LOGIC_ANALYZER_CH4_GPIO_PINx)
+inline void ch4_set() {
+#if defined (LOGIC_ANALYZER_CH4_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH4_GPIOx) = LOGIC_ANALYZER_CH4_GPIO_PINx;
#endif
}
-static void ch5_clear() {
-#if defined (LOGIC_ANALYZER_CH5_GPIO_PINx)
+inline void ch5_clear() {
+#if defined (LOGIC_ANALYZER_CH5_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH5_GPIOx) = LOGIC_ANALYZER_CH5_GPIO_PINx;
#endif
}
-static void ch5_set() {
-#if defined (LOGIC_ANALYZER_CH5_GPIO_PINx)
+inline void ch5_set() {
+#if defined (LOGIC_ANALYZER_CH5_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH5_GPIOx) = LOGIC_ANALYZER_CH5_GPIO_PINx;
#endif
}
-static void ch6_clear() {
-#if defined (LOGIC_ANALYZER_CH6_GPIO_PINx)
+inline void ch6_clear() {
+#if defined (LOGIC_ANALYZER_CH6_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH6_GPIOx) = LOGIC_ANALYZER_CH6_GPIO_PINx;
#endif
}
-static void ch6_set() {
-#if defined (LOGIC_ANALYZER_CH6_GPIO_PINx)
+inline void ch6_set() {
+#if defined (LOGIC_ANALYZER_CH6_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH6_GPIOx) = LOGIC_ANALYZER_CH6_GPIO_PINx;
#endif
}
-static void ch7_clear() {
-#if defined (LOGIC_ANALYZER_CH7_GPIO_PINx)
+inline void ch7_clear() {
+#if defined (LOGIC_ANALYZER_CH7_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BC(LOGIC_ANALYZER_CH7_GPIOx) = LOGIC_ANALYZER_CH7_GPIO_PINx;
#endif
}
-static void ch7_set() {
-#if defined (LOGIC_ANALYZER_CH7_GPIO_PINx)
+inline void ch7_set() {
+#if defined (LOGIC_ANALYZER_CH7_GPIO_PINx) && defined (LOGIC_ANALYZER)
GPIO_BOP(LOGIC_ANALYZER_CH7_GPIOx) = LOGIC_ANALYZER_CH7_GPIO_PINx;
#endif
}
-
} // namespace logic_analyzer
#endif /* LOGIC_ANALYZER_H_ */
diff --git a/lib-gd32/include/mcu/gd32f207_mcu.h b/lib-gd32/include/mcu/gd32f207_mcu.h
new file mode 100644
index 0000000..ae85691
--- /dev/null
+++ b/lib-gd32/include/mcu/gd32f207_mcu.h
@@ -0,0 +1,44 @@
+/**
+ * @file gd32f207_mcu.h
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MCU_GD32F207_MCU_H_
+#define MCU_GD32F207_MCU_H_
+
+#if !defined(GD32F20X_CL)
+# error This file should not be included
+#endif
+
+#include
+
+#define MCU_CLOCK_FREQ (uint32_t)(120000000)
+#define AHB_CLOCK_FREQ (uint32_t)(120000000)
+#define APB1_CLOCK_FREQ (uint32_t)(60000000)
+#define APB2_CLOCK_FREQ (uint32_t)(120000000)
+#define TIMER_PSC_1MHZ (uint16_t)(119)
+#define TIMER_PSC_10KHZ (uint16_t)(11999)
+
+#include "gd32f20x_mcu.h"
+
+#endif /* MCU_GD32F207_MCU_H_ */
diff --git a/lib-gd32/include/mcu/gd32f20x_mcu.h b/lib-gd32/include/mcu/gd32f20x_mcu.h
index ce26b13..1ab03b7 100644
--- a/lib-gd32/include/mcu/gd32f20x_mcu.h
+++ b/lib-gd32/include/mcu/gd32f20x_mcu.h
@@ -2,7 +2,7 @@
* @file gd32f20x_mcu.h
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,14 +32,6 @@
#include
-#define MCU_CLOCK_FREQ (uint32_t)(120000000)
-#define APB1_CLOCK_FREQ (uint32_t)(60000000)
-#define APB2_CLOCK_FREQ (uint32_t)(120000000)
-#define TIMER_PSC_1MHZ (uint16_t)(119)
-#define TIMER_PSC_10KHZ (uint16_t)(11999)
-
-#include "gd32f20x_libopt.h"
-
/**
*
*/
@@ -50,113 +42,113 @@
* U(S)ART
*/
-#define USART0_RCU_CLK RCU_USART0
+#define USART0_RCU_USART0 RCU_USART0
#if defined (USART0_REMAP)
-# define USART0_GPIO_PORT GPIOB
-# define USART0_GPIO_CLK RCU_GPIOB
-# define USART0_TX_PIN GPIO_PIN_6
-# define USART0_RX_PIN GPIO_PIN_7
+# define USART0_RCU_GPIOx RCU_GPIOB
+# define USART0_GPIOx GPIOB
+# define USART0_TX_GPIO_PINx GPIO_PIN_6
+# define USART0_RX_GPIO_PINx GPIO_PIN_7
#else
-# define USART0_GPIO_PORT GPIOA
-# define USART0_GPIO_CLK RCU_GPIOA
-# define USART0_TX_PIN GPIO_PIN_9
-# define USART0_RX_PIN GPIO_PIN_10
+# define USART0_RCU_GPIOx RCU_GPIOA
+# define USART0_GPIOx GPIOA
+# define USART0_TX_GPIO_PINx GPIO_PIN_9
+# define USART0_RX_GPIO_PINx GPIO_PIN_10
#endif
-#define USART1_RCU_CLK RCU_USART1
+#define USART1_RCU_USART1 RCU_USART1
#if defined (USART1_REMAP)
-# define USART1_GPIO_PORT GPIOD
-# define USART1_GPIO_CLK RCU_GPIOD
-# define USART1_TX_PIN GPIO_PIN_5
-# define USART1_RX_PIN GPIO_PIN_6
+# define USART1_RCU_GPIOx RCU_GPIOD
+# define USART1_GPIOx GPIOD
+# define USART1_TX_GPIO_PINx GPIO_PIN_5
+# define USART1_RX_GPIO_PINx GPIO_PIN_6
#else
-# define USART1_GPIO_PORT GPIOA
-# define USART1_GPIO_CLK RCU_GPIOA
-# define USART1_TX_PIN GPIO_PIN_2
-# define USART1_RX_PIN GPIO_PIN_3
+# define USART1_RCU_GPIOx RCU_GPIOA
+# define USART1_GPIOx GPIOA
+# define USART1_TX_GPIO_PINx GPIO_PIN_2
+# define USART1_RX_GPIO_PINx GPIO_PIN_3
#endif
-#define USART2_RCU_CLK RCU_USART2
+#define USART2_RCU_USART2 RCU_USART2
#if defined (USART2_FULL_REMAP)
-# define USART2_GPIO_PORT GPIOD
-# define USART2_GPIO_CLK RCU_GPIOD
-# define USART2_TX_PIN GPIO_PIN_8
-# define USART2_RX_PIN GPIO_PIN_9
+# define USART2_RCU_GPIOx RCU_GPIOD
+# define USART2_GPIOx GPIOD
+# define USART2_TX_GPIO_PINx GPIO_PIN_8
+# define USART2_RX_GPIO_PINx GPIO_PIN_9
#elif defined (USART2_PARTIAL_REMAP)
-# define USART2_GPIO_PORT GPIOC
-# define USART2_GPIO_CLK RCU_GPIOC
-# define USART2_TX_PIN GPIO_PIN_10
-# define USART2_RX_PIN GPIO_PIN_11
+# define USART2_RCU_GPIOx RCU_GPIOC
+# define USART2_GPIOx GPIOC
+# define USART2_TX_GPIO_PINx GPIO_PIN_10
+# define USART2_RX_GPIO_PINx GPIO_PIN_11
#else
-# define USART2_GPIO_PORT GPIOB
-# define USART2_GPIO_CLK RCU_GPIOB
-# define USART2_TX_PIN GPIO_PIN_10
-# define USART2_RX_PIN GPIO_PIN_11
+# define USART2_RCU_GPIOx RCU_GPIOB
+# define USART2_GPIOx GPIOB
+# define USART2_TX_GPIO_PINx GPIO_PIN_10
+# define USART2_RX_GPIO_PINx GPIO_PIN_11
#endif
-#define UART3_RCU_CLK RCU_UART3
+#define UART3_RCU_UART3 RCU_UART3
#if defined (UART3_REMAP)
-# define UART3_GPIO_PORT GPIOA
-# define UART3_GPIO_CLK RCU_GPIOA
-# define UART3_TX_PIN GPIO_PIN_0
-# define UART3_RX_PIN GPIO_PIN_1
+# define UART3_RCU_GPIOx RCU_GPIOA
+# define UART3_GPIOx GPIOA
+# define UART3_TX_GPIO_PINx GPIO_PIN_0
+# define UART3_RX_GPIO_PINx GPIO_PIN_1
#else
-# define UART3_GPIO_PORT GPIOC
-# define UART3_GPIO_CLK RCU_GPIOC
-# define UART3_TX_PIN GPIO_PIN_10
-# define UART3_RX_PIN GPIO_PIN_11
+# define UART3_RCU_GPIOx RCU_GPIOC
+# define UART3_GPIOx GPIOC
+# define UART3_TX_GPIO_PINx GPIO_PIN_10
+# define UART3_RX_GPIO_PINx GPIO_PIN_11
#endif
-#define UART4_RCU_CLK RCU_UART4
-#define UART4_GPIO_TX_PORT GPIOC
-#define UART4_GPIO_TX_CLK RCU_GPIOC
-#define UART4_GPIO_RX_PORT GPIOD
-#define UART4_GPIO_RX_CLK RCU_GPIOD
-#define UART4_TX_PIN GPIO_PIN_12
-#define UART4_RX_PIN GPIO_PIN_2
+#define UART4_RCU_UART4 RCU_UART4
+#define UART4_TX_RCU_GPIOx RCU_GPIOC
+#define UART4_TX_GPIOx GPIOC
+#define UART4_TX_GPIO_PINx GPIO_PIN_12
+#define UART4_RX_RCU_GPIOx RCU_GPIOD
+#define UART4_RX_GPIOx GPIOD
+#define UART4_RX_GPIO_PINx GPIO_PIN_2
-#define USART5_RCU_CLK RCU_USART5
+#define USART5_RCU_USART5 RCU_USART5
#if defined (USART5_REMAP)
-# define USART5_GPIO_PORT GPIOG
-# define USART5_GPIO_CLK RCU_GPIOG
-# define USART5_TX_PIN GPIO_PIN_14
-# define USART5_RX_PIN GPIO_PIN_9
+# define USART5_RCU_GPIOx RCU_GPIOG
+# define USART5_GPIOx GPIOG
+# define USART5_TX_GPIO_PINx GPIO_PIN_14
+# define USART5_RX_GPIO_PINx GPIO_PIN_9
#else
-# define USART5_GPIO_PORT GPIOC
-# define USART5_GPIO_CLK RCU_GPIOC
-# define USART5_TX_PIN GPIO_PIN_6
-# define USART5_RX_PIN GPIO_PIN_7
+# define USART5_RCU_GPIOx RCU_GPIOC
+# define USART5_GPIOx GPIOC
+# define USART5_TX_GPIO_PINx GPIO_PIN_6
+# define USART5_RX_GPIO_PINx GPIO_PIN_7
#endif
-#define UART6_RCU_CLK RCU_UART6
+#define UART6_RCU_UART6 RCU_UART6
#if defined (UART6_REMAP)
-# define UART6_GPIO_PORT GPIOF
-# define UART6_GPIO_CLK RCU_GPIOF
-# define UART6_TX_PIN GPIO_PIN_7
-# define UART6_RX_PIN GPIO_PIN_6
+# define UART6_RCU_GPIOx RCU_GPIOF
+# define UART6_GPIOx GPIOF
+# define UART6_TX_GPIO_PINx GPIO_PIN_7
+# define UART6_RX_GPIO_PINx GPIO_PIN_6
#else
-# define UART6_GPIO_PORT GPIOE
-# define UART6_GPIO_CLK RCU_GPIOE
-# define UART6_TX_PIN GPIO_PIN_8
-# define UART6_RX_PIN GPIO_PIN_7
+# define UART6_RCU_GPIOx RCU_GPIOE
+# define UART6_GPIOx GPIOE
+# define UART6_TX_GPIO_PINx GPIO_PIN_8
+# define UART6_RX_GPIO_PINx GPIO_PIN_7
#endif
-#define UART7_RCU_CLK RCU_UART7
-#define UART7_GPIO_PORT GPIOE
-#define UART7_GPIO_CLK RCU_GPIOE
-#define UART7_TX_PIN GPIO_PIN_1
-#define UART7_RX_PIN GPIO_PIN_0
+#define UART7_RCU_UART7 RCU_UART7
+#define UART7_RCU_GPIOx RCU_GPIOE
+#define UART7_GPIOx GPIOE
+#define UART7_TX_GPIO_PINx GPIO_PIN_1
+#define UART7_RX_GPIO_PINx GPIO_PIN_0
/**
* I2C
*/
#define I2C0_PERIPH I2C0
-#define I2C0_RCU_CLK RCU_I2C0
-#define I2C0_SCL_GPIOx GPIOB
+#define I2C0_RCU_I2C0 RCU_I2C0
#define I2C0_SCL_RCU_GPIOx RCU_GPIOB
-#define I2C0_SDA_GPIOx GPIOB
+#define I2C0_SCL_GPIOx GPIOB
#define I2C0_SDA_RCU_GPIOx RCU_GPIOB
+#define I2C0_SDA_GPIOx GPIOB
#if defined (I2C0_REMAP)
# define I2C0_SCL_GPIO_PINx GPIO_PIN_8
# define I2C0_SDA_GPIO_PINx GPIO_PIN_9
@@ -166,186 +158,239 @@
#endif
#define I2C1_PERIPH I2C1
-#define I2C1_RCU_CLK RCU_I2C1
+#define I2C1_RCU_I2C1 RCU_I2C1
#if defined (I2C1_REMAP10)
-# define I2C1_SCL_GPIOx GPIOH
# define I2C1_SCL_RCU_GPIOx RCU_GPIOH
-# define I2C1_SDA_GPIOx GPIOH
-# define I2C1_SDA_RCU_GPIOx RCU_GPIOH
+# define I2C1_SCL_GPIOx GPIOH
# define I2C1_SCL_GPIO_PINx GPIO_PIN_4
+# define I2C1_SDA_RCU_GPIOx RCU_GPIOH
+# define I2C1_SDA_GPIOx GPIOH
# define I2C1_SDA_GPIO_PINx GPIO_PIN_5
#elif defined (I2C1_REMAP11)
-# define I2C1_SCL_GPIOx GPIOF
# define I2C1_SCL_RCU_GPIOx RCU_GPIOF
-# define I2C1_SDA_GPIOx GPIOF
-# define I2C1_SDA_RCU_GPIOx RCU_GPIOF
+# define I2C1_SCL_GPIOx GPIOF
# define I2C1_SCL_GPIO_PINx GPIO_PIN_0
+# define I2C1_SDA_RCU_GPIOx RCU_GPIOF
+# define I2C1_SDA_GPIOx GPIOF
# define I2C1_SDA_GPIO_PINx GPIO_PIN_1
#else
-# define I2C1_SCL_GPIOx GPIOB
# define I2C1_SCL_RCU_GPIOx RCU_GPIOB
-# define I2C1_SDA_GPIOx GPIOB
-# define I2C1_SDA_RCU_GPIOx RCU_GPIOB
+# define I2C1_SCL_GPIOx GPIOB
# define I2C1_SCL_GPIO_PINx GPIO_PIN_10
+# define I2C1_SDA_RCU_GPIOx RCU_GPIOB
+# define I2C1_SDA_GPIOx GPIOB
# define I2C1_SDA_GPIO_PINx GPIO_PIN_11
#endif
#define I2C2_PERIPH I2C2
-#define I2C2_RCU_CLK RCU_I2C2
+#define I2C2_RCU_I2C2 RCU_I2C2
#if defined (I2C2_REMAP)
-# define I2C2_GPIO_SCL_PORT GPIOH
-# define I2C2_GPIO_SCL_CLK RCU_GPIOH
-# define I2C2_SCL_PIN GPIO_PIN_7
-# define I2C2_GPIO_SDA_PORT GPIOH
-# define I2C2_GPIO_SDA_CLK RCU_GPIOH
-# define I2C2_SDA_PIN GPIO_PIN_8
+# define I2C2_SCL_GPIOx GPIOH
+# define I2C2_SCL_RCU_GPIOx RCU_GPIOH
+# define I2C2_SCL_GPIO_PINx GPIO_PIN_7
+# define I2C2_SDA_GPIOx GPIOH
+# define I2C2_SDA_RCU_GPIOx RCU_GPIOH
+# define I2C2_SDA_GPIO_PINx GPIO_PIN_8
#else
-# define I2C2_GPIO_SCL_PORT GPIOA
-# define I2C2_GPIO_SCL_CLK RCU_GPIOA
-# define I2C2_SCL_PIN GPIO_PIN_8
-# define I2C2_GPIO_SDA_PORT GPIOC
-# define I2C2_GPIO_SDA_CLK RCU_GPIOC
-# define I2C2_SDA_PIN GPIO_PIN_9
+# define I2C2_SCL_GPIOx GPIOA
+# define I2C2_SCL_RCU_GPIOx RCU_GPIOA
+# define I2C2_SCL_GPIO_PINx GPIO_PIN_8
+# define I2C2_SDA_GPIOx GPIOC
+# define I2C2_SDA_RCU_GPIOx RCU_GPIOC
+# define I2C2_SDA_GPIO_PINx GPIO_PIN_9
#endif
/**
* SPI
*/
-#define SPI0_PERiPH SPI0
-#define SPI0_RCU_CLK RCU_SPI0
+#define SPI0_PERIPH SPI0
+#define SPI0_RCU_SPI0 RCU_SPI0
#if defined (SPI0_REMAP)
# define SPI0_REMAP_GPIO GPIO_SPI0_REMAP
-# define SPI0_NSS_GPIOx GPIOA
-# define SPI0_NSS_RCU_GPIOx RCU_GPIOA
-# define SPI0_NSS_GPIO_PINx GPIO_PIN_15
# define SPI0_GPIOx GPIOB
# define SPI0_RCU_GPIOx RCU_GPIOB
# define SPI0_SCK_GPIO_PINx GPIO_PIN_3
# define SPI0_MISO_GPIO_PINx GPIO_PIN_4
# define SPI0_MOSI_GPIO_PINx GPIO_PIN_5
-#else
-# define SPI0_NSS_GPIOx GPIOA
# define SPI0_NSS_RCU_GPIOx RCU_GPIOA
-# define SPI0_NSS_GPIO_PINx GPIO_PIN_4
+# define SPI0_NSS_GPIOx GPIOA
+# define SPI0_NSS_GPIO_PINx GPIO_PIN_15
+#else
# define SPI0_GPIOx GPIOA
# define SPI0_RCU_GPIOx RCU_GPIOA
# define SPI0_SCK_GPIO_PINx GPIO_PIN_5
# define SPI0_MISO_GPIO_PINx GPIO_PIN_6
# define SPI0_MOSI_GPIO_PINx GPIO_PIN_7
+# define SPI0_IO3_GPIO_PINx GPIO_PIN_2
+# define SPI0_IO4_GPIO_PINx GPIO_PIN_3
+# define SPI0_NSS_RCU_GPIOx RCU_GPIOA
+# define SPI0_NSS_GPIOx GPIOA
+# define SPI0_NSS_GPIO_PINx GPIO_PIN_4
#endif
#define SPI1_PERIPH SPI1
-#define SPI1_RCU_CLK RCU_SPI1
+#define SPI1_RCU_SPI1 RCU_SPI1
#if defined (SPI1_REMAP10)
-# define SPI1_NSS_GPIOx GPIOI
-# define SPI1_NSS_RCU_GPIOx RCU_GPIOI
-# define SPI1_NSS_GPIO_PINx GPIO_PIN_0
-# define SPI1_GPIOx GPIOI
# define SPI1_RCU_GPIOx RCU_GPIOI
+# define SPI1_GPIOx GPIOI
# define SPI1_SCK_GPIO_PINx GPIO_PIN_1
# define SPI1_MISO_GPIO_PINx GPIO_PIN_2
# define SPI1_MOSI_GPIO_PINx GPIO_PIN_3
+# define SPI1_NSS_RCU_GPIOx RCU_GPIOI
+# define SPI1_NSS_GPIOx GPIOI
+# define SPI1_NSS_GPIO_PINx GPIO_PIN_0
#elif defined (SPI1_REMAP11)
# error SPI1_REMAP11 is not defined
#else
-# define SPI1_NSS_GPIOx GPIOB
-# define SPI1_NSS_RCU_GPIOx RCU_GPIOB
-# define SPI1_NSS_GPIO_PINx GPIO_PIN_12
-# define SPI1_GPIOx GPIOB
# define SPI1_RCU_GPIOx RCU_GPIOB
+# define SPI1_GPIOx GPIOB
# define SPI1_SCK_GPIO_PINx GPIO_PIN_13
# define SPI1_MISO_GPIO_PINx GPIO_PIN_14
# define SPI1_MOSI_GPIO_PINx GPIO_PIN_15
+# define SPI1_NSS_RCU_GPIOx RCU_GPIOB
+# define SPI1_NSS_GPIOx GPIOB
+# define SPI1_NSS_GPIO_PINx GPIO_PIN_12
#endif
#define SPI2_PERIPH SPI2
-#define SPI2_RCU_CLK RCU_SPI2
+#define SPI2_RCU_SPI2 RCU_SPI2
#if defined (SPI2_REMAP)
# define SPI2_REMAP_GPIO GPIO_SPI2_REMAP
-# define SPI2_NSS_GPIOx GPIOA
-# define SPI2_NSS_RCU_GPIOx RCU_GPIOA
-# define SPI2_NSS_GPIO_PINx GPIO_PIN_4
-# define SPI2_GPIOx GPIOC
# define SPI2_RCU_GPIOx RCU_GPIOC
+# define SPI2_GPIOx GPIOC
# define SPI2_SCK_GPIO_PINx GPIO_PIN_10
# define SPI2_MISO_GPIO_PINx GPIO_PIN_11
# define SPI2_MOSI_GPIO_PINx GPIO_PIN_12
-#else
-# define SPI2_NSS_GPIOx GPIOA
# define SPI2_NSS_RCU_GPIOx RCU_GPIOA
-# define SPI2_NSS_GPIO_PINx GPIO_PIN_15
-# define SPI2_GPIOx GPIOB
+# define SPI2_NSS_GPIOx GPIOA
+# define SPI2_NSS_GPIO_PINx GPIO_PIN_4
+#else
# define SPI2_RCU_GPIOx RCU_GPIOB
+# define SPI2_GPIOx GPIOB
# define SPI2_SCK_GPIO_PINx GPIO_PIN_3
# define SPI2_MISO_GPIO_PINx GPIO_PIN_4
# define SPI2_MOSI_GPIO_PINx GPIO_PIN_5
+# define SPI2_NSS_RCU_GPIOx RCU_GPIOA
+# define SPI2_NSS_GPIOx GPIOA
+# define SPI2_NSS_GPIO_PINx GPIO_PIN_15
#endif
/**
* TIMER GPIO
*/
-#define TIMER2CH0_RCU_GPIOx RCU_GPIOA
-#define TIMER2CH0_GPIOx GPIOA
-#define TIMER2CH0_GPIO_PINx GPIO_PIN_6
+#define TIMER2CH0_RCU_GPIOx RCU_GPIOA
+#define TIMER2CH0_GPIOx GPIOA
+#define TIMER2CH0_GPIO_PINx GPIO_PIN_6
+
+#if defined(TIMER2_FULL_REMAP)
+# define TIMER2_REMAP GPIO_TIMER2_FULL_REMAP
+# define TIMER2_CH0_RCU_GPIOx RCU_GPIOC
+# define TIMER2_CH0_GPIOx GPIOC
+# define TIMER2_CH0_GPIO_PINx GPIO_PIN_6
+
+# define TIMER2_CH1_RCU_GPIOx RCU_GPIOC
+# define TIMER2_CH1_GPIOx GPIOC
+# define TIMER2_CH1_GPIO_PINx GPIO_PIN_7
+
+# define TIMER2_CH2_RCU_GPIOx RCU_GPIOC
+# define TIMER2_CH2_GPIOx GPIOC
+# define TIMER2_CH2_GPIO_PINx GPIO_PIN_8
+
+# define TIMER2_CH3_RCU_GPIOx RCU_GPIOC
+# define TIMER2_CH3_GPIOx GPIOC
+# define TIMER2_CH3_GPIO_PINx GPIO_PIN_9
+#elif defined(TIMER2_PARTIAL_REMAP)
+# define TIMER2_REMAP GPIO_TIMER2_PARTIAL_REMAP
+# define TIMER2_CH0_RCU_GPIOx RCU_GPIOB
+# define TIMER2_CH0_GPIOx GPIOB
+# define TIMER2_CH0_GPIO_PINx GPIO_PIN_4
+
+# define TIMER2_CH1_RCU_GPIOx RCU_GPIOB
+# define TIMER2_CH1_GPIOx GPIOB
+# define TIMER2_CH1_GPIO_PINx GPIO_PIN_5
+
+# define TIMER2_CH2_RCU_GPIOx RCU_GPIOB
+# define TIMER2_CH2_GPIOx GPIOB
+# define TIMER2_CH2_GPIO_PINx GPIO_PIN_0
+
+# define TIMER2_CH3_RCU_GPIOx RCU_GPIOB
+# define TIMER2_CH3_GPIOx GPIOB
+# define TIMER2_CH3_GPIO_PINx GPIO_PIN_1
+#else
+# define TIMER2_CH0_RCU_GPIOx RCU_GPIOA
+# define TIMER2_CH0_GPIOx GPIOA
+# define TIMER2_CH0_GPIO_PINx GPIO_PIN_6
+
+# define TIMER2_CH1_RCU_GPIOx RCU_GPIOA
+# define TIMER2_CH1_GPIOx GPIOA
+# define TIMER2_CH1_GPIO_PINx GPIO_PIN_7
+
+# define TIMER2_CH2_RCU_GPIOx RCU_GPIOB
+# define TIMER2_CH2_GPIOx GPIOB
+# define TIMER2_CH2_GPIO_PINx GPIO_PIN_0
+
+# define TIMER2_CH3_RCU_GPIOx RCU_GPIOB
+# define TIMER2_CH3_GPIOx GPIOB
+# define TIMER2_CH3_GPIO_PINx GPIO_PIN_1
+#endif
/**
* DMA
*/
-#define SPI0_DMAx DMA0
-#define SPI0_TX_DMA_CHx DMA_CH2
+#define SPI0_DMAx DMA0
+#define SPI0_TX_DMA_CHx DMA_CH2
-#define SPI1_DMAx DMA0
-#define SPI1_TX_DMA_CHx DMA_CH4
+#define SPI1_DMAx DMA0
+#define SPI1_TX_DMA_CHx DMA_CH4
-#define SPI2_DMAx DMA1
-#define SPI2_TX_DMA_CHx DMA_CH1
+#define SPI2_DMAx DMA1
+#define SPI2_TX_DMA_CHx DMA_CH1
-#define TIMER2_RCU_DMAx RCU_DMA0
-#define TIMER2_DMAx DMA0
-#define TIMER2_CH0_DMA_CHx DMA_CH5
-// #define TIMER2_CH1_DMA_CHx
-#define TIMER2_CH2_DMA_CHx DMA_CH1
-#define TIMER2_CH3_DMA_CHx DMA_CH2
+#define TIMER2_RCU_DMAx RCU_DMA0
+#define TIMER2_DMAx DMA0
+#define TIMER2_CH0_DMA_CHx DMA_CH5
+#define TIMER2_CH2_DMA_CHx DMA_CH1
+#define TIMER2_CH3_DMA_CHx DMA_CH2
-#define TIMER7_RCU_DMAx RCU_DMA1
-#define TIMER7_DMAx DMA1
-#define TIMER7_CH0_DMA_CHx DMA_CH2
-#define TIMER7_CH1_DMA_CHx DMA_CH4
-#define TIMER7_CH2_DMA_CHx DMA_CH0
+#define TIMER7_RCU_DMAx RCU_DMA1
+#define TIMER7_DMAx DMA1
+#define TIMER7_CH0_DMA_CHx DMA_CH2
+#define TIMER7_CH1_DMA_CHx DMA_CH4
+#define TIMER7_CH2_DMA_CHx DMA_CH0
-#define USART0_DMA DMA0
-#define USART0_TX_DMA_CH DMA_CH3
-#define USART0_RX_DMA_CH DMA_CH4
+#define USART0_DMAx DMA0
+#define USART0_TX_DMA_CHx DMA_CH3
+#define USART0_RX_DMA_CHx DMA_CH4
-#define USART1_DMA DMA0
-#define USART1_TX_DMA_CH DMA_CH6
-#define USART1_RX_DMA_CH DMA_CH5
+#define USART1_DMAx DMA0
+#define USART1_TX_DMA_CHx DMA_CH6
+#define USART1_RX_DMA_CHx DMA_CH5
-#define USART2_DMA DMA0
-#define USART2_TX_DMA_CH DMA_CH1
-#define USART2_RX_DMA_CH DMA_CH2
+#define USART2_DMAx DMA0
+#define USART2_TX_DMA_CHx DMA_CH1
+#define USART2_RX_DMA_CHx DMA_CH2
-#define UART3_DMA DMA1
-#define UART3_TX_DMA_CH DMA_CH4
-#define UART3_RX_DMA_CH DMA_CH2
+#define UART3_DMAx DMA1
+#define UART3_TX_DMA_CHx DMA_CH4
+#define UART3_RX_DMA_CHx DMA_CH2
-#define UART4_DMA DMA1
-#define UART4_TX_DMA_CH DMA_CH3
-#define UART4_RX_DMA_CH DMA_CH1
+#define UART4_DMAx DMA1
+#define UART4_TX_DMA_CHx DMA_CH3
+#define UART4_RX_DMA_CHx DMA_CH1
-#define USART5_DMA DMA1
-#define USART5_TX_DMA_CH DMA_CH6
-#define USART5_RX_DMA_CH DMA_CH5
+#define USART5_DMAx DMA1
+#define USART5_TX_DMA_CHx DMA_CH6
+#define USART5_RX_DMA_CHx DMA_CH5
-#define UART6_DMA DMA1
-#define UART6_TX_DMA_CH DMA_CH4
-#define UART6_RX_DMA_CH DMA_CH2
+#define UART6_DMAx DMA1
+#define UART6_TX_DMA_CHx DMA_CH4
+#define UART6_RX_DMA_CHx DMA_CH2
-#define UART7_DMA DMA1
-#define UART7_TX_DMA_CH DMA_CH3
-#define UART7_RX_DMA_CH DMA_CH1
+#define UART7_DMAx DMA1
+#define UART7_TX_DMA_CHx DMA_CH3
+#define UART7_RX_DMA_CHx DMA_CH1
#endif /* MCU_GD32F20X_MCU_H_ */
diff --git a/lib-gd32/src/bkp.cpp b/lib-gd32/src/bkp.cpp
index 74349c5..bd4d57d 100644
--- a/lib-gd32/src/bkp.cpp
+++ b/lib-gd32/src/bkp.cpp
@@ -2,7 +2,7 @@
* @file bkp.cpp
*
*/
-/* Copyright (C) 2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,18 +23,39 @@
* THE SOFTWARE.
*/
+#include
+
#include "gd32.h"
-#if defined (GD32F4XX)
+#if defined (GD32F4XX) || defined (GD32H7XX)
void bkp_data_write(bkp_data_register_enum register_number, uint16_t data) {
- if ((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_1)) {
- REG16((BKPSRAM_BASE) + 16 + (register_number) * 2) = data;
+ switch (register_number) {
+ case BKP_DATA_0:
+ RTC_BKP0 = (uint32_t) data;
+ break;
+ case BKP_DATA_1:
+ RTC_BKP1 = (uint32_t) data;
+ break;
+ default:
+ assert(0);
+ break;
}
}
+
uint16_t bkp_data_read(bkp_data_register_enum register_number) {
- if ((register_number >= BKP_DATA_0) && (register_number <= BKP_DATA_1)) {
- return REG16((BKPSRAM_BASE) + 16 + (register_number) * 2);
+ switch (register_number) {
+ case BKP_DATA_0:
+ return RTC_BKP0;
+ break;
+ case BKP_DATA_1:
+ return RTC_BKP1;
+ break;
+ default:
+ assert(0);
+ break;
}
+
+ assert(0);
return 0;
}
#endif
diff --git a/lib-gd32/src/gd32_adc.cpp b/lib-gd32/src/f/gd32_adc.cpp
similarity index 96%
rename from lib-gd32/src/gd32_adc.cpp
rename to lib-gd32/src/f/gd32_adc.cpp
index 4347921..294b295 100644
--- a/lib-gd32/src/gd32_adc.cpp
+++ b/lib-gd32/src/f/gd32_adc.cpp
@@ -27,7 +27,7 @@
#include "gd32.h"
-void gd32_adc_init(void) {
+void gd32_adc_init() {
rcu_periph_clock_enable(RCU_ADC0);
#if !defined (GD32F4XX)
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV12);
@@ -86,21 +86,20 @@ void gd32_adc_init(void) {
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
}
-float gd32_adc_gettemp(void) {
- /* value convert */
+float gd32_adc_gettemp() {
const float temperature = (1.43f - ADC_IDATA0(ADC0) * 3.3f / 4096) * 1000 / 4.3f + 25;
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
return temperature;
}
-float gd32_adc_getvref(void) {
+float gd32_adc_getvref() {
const float vref_value = (ADC_IDATA1(ADC0) * 3.3f / 4096);
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
return vref_value;
}
#if defined (GD32F4XX)
-float gd32_adc_getvbat(void) {
+float gd32_adc_getvbat() {
const float vref_value = (ADC_IDATA2(ADC0) * 3.3f / 4096) * 4;
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
return vref_value;
diff --git a/lib-gd32/src/f/gd32_dma_memcpy32.cpp b/lib-gd32/src/f/gd32_dma_memcpy32.cpp
new file mode 100644
index 0000000..55625b3
--- /dev/null
+++ b/lib-gd32/src/f/gd32_dma_memcpy32.cpp
@@ -0,0 +1,55 @@
+/*
+ * gd32_dma_memcpy32.cpp
+ */
+
+#include
+#include
+
+#include "gd32.h"
+
+namespace dma {
+void memcpy32_init() {
+#if !defined (GD32F4XX)
+ rcu_periph_clock_enable(RCU_DMA0);
+ dma_deinit(DMA0, DMA_CH3);
+
+ dma_parameter_struct dma_init_struct;
+ dma_struct_para_init(&dma_init_struct);
+
+ dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY;
+// dma_init_struct.memory_addr = destination;
+ dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
+ dma_init_struct.memory_width = DMA_MEMORY_WIDTH_32BIT;
+ dma_init_struct.number = 0; // BUFFER_SIZE;
+// dma_init_struct.periph_addr = source
+ dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
+ dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_32BIT;
+ dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
+
+ dma_init(DMA0, DMA_CH3, &dma_init_struct);
+ dma_circulation_disable(DMA0, DMA_CH3);
+ dma_memory_to_memory_enable(DMA0, DMA_CH3);
+#else
+ rcu_periph_clock_enable(RCU_DMA1);
+ dma_deinit(DMA1, DMA_CH0);
+
+ dma_multi_data_parameter_struct dma_init_parameter;
+
+// dma_init_parameter.periph_addr = source;
+ dma_init_parameter.periph_width = DMA_PERIPH_WIDTH_32BIT;
+ dma_init_parameter.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
+// dma_init_parameter.memory0_addr = destination;
+ dma_init_parameter.memory_width = DMA_MEMORY_WIDTH_32BIT;
+ dma_init_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
+ dma_init_parameter.memory_burst_width = DMA_MEMORY_BURST_4_BEAT;
+ dma_init_parameter.periph_burst_width = DMA_PERIPH_BURST_4_BEAT;
+ dma_init_parameter.critical_value = DMA_FIFO_4_WORD;
+ dma_init_parameter.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
+ dma_init_parameter.direction = DMA_MEMORY_TO_MEMORY;
+ dma_init_parameter.number = 0; // BUFFER_SIZE;
+ dma_init_parameter.priority = DMA_PRIORITY_ULTRA_HIGH;
+
+ dma_multi_data_mode_init(DMA1, DMA_CH0, &dma_init_parameter);
+#endif
+}
+} // namespace dma
diff --git a/lib-gd32/src/gd32_i2c.cpp b/lib-gd32/src/f/gd32_i2c.cpp
similarity index 67%
rename from lib-gd32/src/gd32_i2c.cpp
rename to lib-gd32/src/f/gd32_i2c.cpp
index 2a23399..880f114 100644
--- a/lib-gd32/src/gd32_i2c.cpp
+++ b/lib-gd32/src/f/gd32_i2c.cpp
@@ -2,7 +2,7 @@
* @file gd32_i2c.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,7 @@
*/
#include
+#include
#include "gd32_i2c.h"
#include "gd32.h"
@@ -32,21 +33,18 @@ static constexpr int32_t TIMEOUT = 0xfff;
static uint8_t s_nAddress;
-static int32_t _sendstart(void) {
+static int32_t send_start() {
auto nTimeout = TIMEOUT;
- /* wait until I2C bus is idle */
while (i2c_flag_get(I2C_PERIPH, I2C_FLAG_I2CBSY)) {
if (--nTimeout <= 0) {
return -GD32_I2C_NOK_TOUT;
}
}
- nTimeout = TIMEOUT;
-
- /* send a start condition to I2C bus */
i2c_start_on_bus(I2C_PERIPH);
+ nTimeout = TIMEOUT;
/* wait until SBSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_SBSEND)) {
if (--nTimeout <= 0) {
@@ -57,25 +55,22 @@ static int32_t _sendstart(void) {
return GD32_I2C_OK;
}
-static int32_t _sendslaveaddr(void) {
- auto nTimeout = TIMEOUT;
-
- /* send slave address to I2C bus */
+static int32_t send_slaveaddr() {
i2c_master_addressing(I2C_PERIPH, s_nAddress, I2C_TRANSMITTER);
- /* wait until ADDSEND bit is set */
+ auto nTimeout = TIMEOUT;
+
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_ADDSEND)) {
if (--nTimeout <= 0) {
return -GD32_I2C_NOK_TOUT;
}
}
- /* clear the ADDSEND bit */
+
i2c_flag_clear(I2C_PERIPH, I2C_FLAG_ADDSEND);
nTimeout = TIMEOUT;
- /* wait until the transmit data buffer is empty */
while (SET != i2c_flag_get(I2C_PERIPH, I2C_FLAG_TBE)) {
if (--nTimeout <= 0) {
return -GD32_I2C_NOK_TOUT;
@@ -85,10 +80,9 @@ static int32_t _sendslaveaddr(void) {
return GD32_I2C_OK;
}
-static int32_t _stop(void) {
+static int32_t send_stop() {
auto nTimeout = TIMEOUT;
- /* send a stop condition to I2C bus */
i2c_stop_on_bus(I2C_PERIPH);
/* wait until the stop condition is finished */
@@ -101,18 +95,12 @@ static int32_t _stop(void) {
return GD32_I2C_OK;
}
-static int32_t _senddata(uint8_t *pData, uint32_t nCount) {
- int32_t nTimeout;
-
+static int32_t send_data(const uint8_t *pData, const uint32_t nCount) {
for (uint32_t i = 0; i < nCount; i++) {
i2c_data_transmit(I2C_PERIPH, *pData);
-
- /* point to the next byte to be written */
pData++;
+ auto nTimeout = TIMEOUT;
- nTimeout = TIMEOUT;
-
- /* wait until BTC bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_BTC)) {
if (--nTimeout <= 0) {
return -GD32_I2C_NOK_TOUT;
@@ -123,60 +111,72 @@ static int32_t _senddata(uint8_t *pData, uint32_t nCount) {
return GD32_I2C_OK;
}
-static int _write(char *pBuffer, int nLength) {
- if (_sendstart() != GD32_I2C_OK) {
- _stop();
+static int32_t write(const char *pBuffer, const int nLength) {
+ if (send_start() != GD32_I2C_OK) {
+ send_stop();
return -1;
}
- if (_sendslaveaddr() != GD32_I2C_OK) {
- _stop();
+ if (send_slaveaddr() != GD32_I2C_OK) {
+ send_stop();
return -1;
}
- if (_senddata((uint8_t*) pBuffer, (uint32_t) nLength) != GD32_I2C_OK) {
- _stop();
+ if (send_data((uint8_t*) pBuffer, (uint32_t) nLength) != GD32_I2C_OK) {
+ send_stop();
return -1;
}
- _stop();
+ send_stop();
return 0;
}
-/*
- * Public API's
- */
-
-void gd32_i2c_begin(void) {
- rcu_periph_clock_enable(I2C_RCU_CLK);
- rcu_periph_clock_enable(I2C_GPIO_SCL_CLK);
- rcu_periph_clock_enable(I2C_GPIO_SDA_CLK);
+static void rcu_config() {
+ rcu_periph_clock_enable(I2C_RCU_I2Cx);
+ rcu_periph_clock_enable(I2C_SCL_RCU_GPIOx);
+ rcu_periph_clock_enable(I2C_SDA_RCU_GPIOx);
+}
-#if !defined (GD32F4XX)
- gpio_init(I2C_GPIO_SCL_PORT, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, I2C_SCL_PIN);
- gpio_init(I2C_GPIO_SDA_PORT, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, I2C_SDA_PIN);
+static void gpio_config() {
+#if defined (GPIO_INIT)
+ gpio_init(I2C_SCL_GPIOx, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, I2C_SCL_GPIO_PINx);
+ gpio_init(I2C_SDA_GPIOx, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, I2C_SDA_GPIO_PINx);
# if defined (I2C_REMAP)
if (I2C_REMAP == GPIO_I2C0_REMAP) {
gpio_pin_remap_config(GPIO_I2C0_REMAP, ENABLE);
+ } else {
+ assert(0);
}
# endif
#else
- gpio_af_set(I2C_GPIO_SCL_PORT, GPIO_AF_4, I2C_SCL_PIN);
- gpio_af_set(I2C_GPIO_SCL_PORT, GPIO_AF_4, I2C_SDA_PIN);
+ gpio_af_set(I2C_SCL_GPIOx, I2C_GPIO_AFx, I2C_SCL_GPIO_PINx);
+ gpio_mode_set(I2C_SCL_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, I2C_SCL_GPIO_PINx);
+ gpio_output_options_set(I2C_SCL_GPIOx, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, I2C_SCL_GPIO_PINx);
- gpio_mode_set(I2C_GPIO_SCL_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, I2C_SCL_PIN);
- gpio_output_options_set(I2C_GPIO_SCL_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, I2C_SCL_PIN);
- gpio_mode_set(I2C_GPIO_SDA_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, I2C_SDA_PIN);
- gpio_output_options_set(I2C_GPIO_SDA_PORT, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, I2C_SDA_PIN);
+ gpio_af_set(I2C_SDA_GPIOx, I2C_GPIO_AFx, I2C_SDA_GPIO_PINx);
+ gpio_mode_set(I2C_SDA_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, I2C_SDA_GPIO_PINx);
+ gpio_output_options_set(I2C_SDA_GPIOx, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, I2C_SDA_GPIO_PINx);
#endif
+}
+static void i2c_config() {
i2c_clock_config(I2C_PERIPH, GD32_I2C_FULL_SPEED, I2C_DTCY_2);
i2c_enable(I2C_PERIPH);
i2c_ack_config(I2C_PERIPH, I2C_ACK_ENABLE);
}
+/*
+ * Public API's
+ */
+
+void gd32_i2c_begin() {
+ rcu_config();
+ gpio_config();
+ i2c_config();
+}
+
void gd32_i2c_set_baudrate(uint32_t nBaudrate) {
i2c_clock_config(I2C_PERIPH, nBaudrate, I2C_DTCY_2);
}
@@ -186,18 +186,16 @@ void gd32_i2c_set_address(uint8_t nAddress) {
}
uint8_t gd32_i2c_write(const char *pBuffer, uint32_t nLength) {
- const auto ret = _write((char *)pBuffer, (int) nLength);
-
+ const auto ret = write((char *)pBuffer, (int) nLength);
return (uint8_t)-ret;
}
uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
auto nTimeout = TIMEOUT;
- /* wait until I2C bus is idle */
while (i2c_flag_get(I2C_PERIPH, I2C_FLAG_I2CBSY)) {
if (--nTimeout <= 0) {
- _stop();
+ send_stop();
return GD32_I2C_NOK_TOUT;
}
}
@@ -206,79 +204,67 @@ uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
i2c_ackpos_config(I2C_PERIPH, I2C_ACKPOS_NEXT);
}
- /* send a start condition to I2C bus */
i2c_start_on_bus(I2C_PERIPH);
nTimeout = TIMEOUT;
- /* wait until SBSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_SBSEND)) {
if (--nTimeout <= 0) {
- _stop();
+ send_stop();
return GD32_I2C_NOK_TOUT;
}
}
- /* send slave address to I2C bus */
i2c_master_addressing(I2C_PERIPH, s_nAddress, I2C_RECEIVER);
if (nLength < 3) {
- /* disable acknowledge */
i2c_ack_config(I2C_PERIPH, I2C_ACK_DISABLE);
}
nTimeout = TIMEOUT;
- /* wait until ADDSEND bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_ADDSEND)) {
if (--nTimeout <= 0) {
- _stop();
+ send_stop();
return GD32_I2C_NOK_TOUT;
}
}
- /* clear the ADDSEND bit */
i2c_flag_clear(I2C_PERIPH, I2C_FLAG_ADDSEND);
if (1 == nLength) {
- /* send a stop condition to I2C bus */
i2c_stop_on_bus(I2C_PERIPH);
}
auto nTimeoutLoop = TIMEOUT;
- /* while there is data to be read */
while (nLength) {
if (3 == nLength) {
nTimeout = TIMEOUT;
- /* wait until BTC bit is set */
+
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_BTC)) {
if (--nTimeout <= 0) {
- _stop();
+ send_stop();
return GD32_I2C_NOK_TOUT;
}
}
- /* disable acknowledge */
i2c_ack_config(I2C_PERIPH, I2C_ACK_DISABLE);
}
if (2 == nLength) {
nTimeout = TIMEOUT;
- /* wait until BTC bit is set */
while (!i2c_flag_get(I2C_PERIPH, I2C_FLAG_BTC)) {
if (--nTimeout <= 0) {
- _stop();
+ send_stop();
return GD32_I2C_NOK_TOUT;
}
}
- /* send a stop condition to I2C bus */
i2c_stop_on_bus(I2C_PERIPH);
}
- /* wait until the RBNE bit is set and clear it */
if (i2c_flag_get(I2C_PERIPH, I2C_FLAG_RBNE)) {
*pBuffer = i2c_data_receive(I2C_PERIPH);
pBuffer++;
@@ -287,23 +273,20 @@ uint8_t gd32_i2c_read(char *pBuffer, uint32_t nLength) {
}
if (--nTimeoutLoop <= 0) {
- _stop();
+ send_stop();
return GD32_I2C_NOK_TOUT;
}
}
nTimeout = TIMEOUT;
- /* wait until the stop condition is finished */
while (I2C_CTL0(I2C_PERIPH) & 0x0200) {
if (--nTimeout <= 0) {
return GD32_I2C_NOK_TOUT;
}
}
- /* enable acknowledge */
i2c_ack_config(I2C_PERIPH, I2C_ACK_ENABLE);
-
i2c_ackpos_config(I2C_PERIPH, I2C_ACKPOS_CURRENT);
return GD32_I2C_OK;
diff --git a/lib-gd32/src/gd32_spi.cpp b/lib-gd32/src/f/gd32_spi.cpp
similarity index 70%
rename from lib-gd32/src/gd32_spi.cpp
rename to lib-gd32/src/f/gd32_spi.cpp
index 74a9828..5e16577 100644
--- a/lib-gd32/src/gd32_spi.cpp
+++ b/lib-gd32/src/f/gd32_spi.cpp
@@ -2,7 +2,7 @@
* @file gd32_spi.cpp
*
*/
-/* Copyright (C) 2021-2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,19 +32,19 @@
static uint8_t s_nChipSelect = GD32_SPI_CS0;
-static inline void _cs_high() {
+static void cs_high() {
if (s_nChipSelect == GD32_SPI_CS0) {
- GPIO_BOP(SPI_NSS_GPIOx) = static_cast(SPI_NSS_GPIO_PINx);
+ GPIO_BOP(SPI_NSS_GPIOx) = SPI_NSS_GPIO_PINx;
}
}
-static inline void _cs_low() {
+static void cs_low() {
if (s_nChipSelect == GD32_SPI_CS0) {
- GPIO_BC(SPI_NSS_GPIOx) = static_cast(SPI_NSS_GPIO_PINx);
+ GPIO_BC(SPI_NSS_GPIOx) = SPI_NSS_GPIO_PINx;
}
}
-static uint8_t _send_byte(uint8_t byte) {
+static uint8_t send_byte(uint8_t byte) {
while (RESET == (SPI_STAT(SPI_PERIPH) & SPI_FLAG_TBE))
;
@@ -56,37 +56,44 @@ static uint8_t _send_byte(uint8_t byte) {
return static_cast(static_cast(SPI_DATA(SPI_PERIPH)));
}
-void gd32_spi_begin() {
+static void rcu_config() {
+ rcu_periph_clock_enable(SPI_RCU_SPIx);
rcu_periph_clock_enable(SPI_RCU_GPIOx);
- rcu_periph_clock_enable(SPI_RCU_CLK);
+ rcu_periph_clock_enable(SPI_NSS_RCU_GPIOx);
-#if !defined (GD32F4XX)
+#if defined (GPIO_INIT)
rcu_periph_clock_enable(RCU_AF);
+#endif
+}
- gpio_init(SPI_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
-
-# if defined (SPI_REMAP)
- gpio_pin_remap_config(SPI_REMAP, ENABLE);
+static void gpio_config() {
+#if defined (GPIO_INIT)
+# if defined (SPI_REMAP_GPIO)
+ gpio_pin_remap_config(SPI_REMAP_GPIO, ENABLE);
+ if (SPI_PERIPH == SPI0) {
+ gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
+ }
# else
if (SPI_PERIPH == SPI2) {
gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
}
# endif
+ gpio_init(SPI_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, SPI_SCK_GPIO_PINx | SPI_MOSI_GPIO_PINx);
+ gpio_init(SPI_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, SPI_MISO_GPIO_PINx);
+ gpio_init(SPI_NSS_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SPI_NSS_GPIO_PINx);
#else
- if (SPI_PERIPH == SPI2) {
- gpio_af_set(SPI_GPIOx, GPIO_AF_6, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- } else {
- gpio_af_set(SPI_GPIOx, GPIO_AF_5, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- }
+ gpio_af_set(SPI_GPIOx, SPI_GPIO_AFx, SPI_SCK_GPIO_PINx | SPI_MISO_GPIO_PINx | SPI_MOSI_GPIO_PINx);
+ gpio_mode_set(SPI_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, SPI_SCK_GPIO_PINx | SPI_MISO_GPIO_PINx | SPI_MOSI_GPIO_PINx);
+ gpio_output_options_set(SPI_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SPI_SCK_GPIO_PINx | SPI_MOSI_GPIO_PINx);
- gpio_mode_set(SPI_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- gpio_output_options_set(SPI_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
+ gpio_mode_set(SPI_NSS_GPIOx, GPIO_MODE_OUTPUT,GPIO_PUPD_NONE, SPI_NSS_GPIO_PINx);
+ gpio_output_options_set(SPI_NSS_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, SPI_NSS_GPIO_PINx);
#endif
- gpio_fsel(SPI_NSS_GPIOx, SPI_NSS_GPIO_PINx, GPIO_FSEL_OUTPUT);
-
- _cs_high();
+ cs_high();
+}
+static void spi_config() {
spi_disable(SPI_PERIPH);
spi_i2s_deinit(SPI_PERIPH);
@@ -103,15 +110,23 @@ void gd32_spi_begin() {
spi_enable(SPI_PERIPH);
}
+/*
+ * Public API's
+ */
+
+void gd32_spi_begin() {
+ rcu_config();
+ gpio_config();
+ spi_config();
+}
+
void gd32_spi_end() {
- spi_i2s_deinit(SPI_PERIPH);
-#if !defined (GD32F4XX)
- gpio_init(SPI_GPIOx, GPIO_MODE_IPD, GPIO_OSPEED_50MHZ, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
+ spi_disable(SPI_PERIPH);
+#if defined (GPIO_INIT)
+ gpio_init(SPI_GPIOx, GPIO_MODE_IPD, GPIO_OSPEED_50MHZ, SPI_SCK_GPIO_PINx | SPI_MISO_GPIO_PINx | SPI_MOSI_GPIO_PINx);
gpio_init(SPI_NSS_GPIOx, GPIO_MODE_IPD, GPIO_OSPEED_50MHZ, SPI_NSS_GPIO_PINx);
#else
- gpio_af_set(SPI_GPIOx, GPIO_AF_0, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- gpio_mode_set(SPI_GPIOx, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
-
+ gpio_mode_set(SPI_GPIOx, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SPI_SCK_GPIO_PINx | SPI_MISO_GPIO_PINx | SPI_MOSI_GPIO_PINx);
gpio_mode_set(SPI_NSS_GPIOx, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SPI_NSS_GPIO_PINx);
#endif
}
@@ -165,21 +180,27 @@ void gd32_spi_setDataMode(uint8_t nMode) {
void gd32_spi_chipSelect(uint8_t nChipSelect) {
s_nChipSelect = nChipSelect;
+
+ if (nChipSelect == GD32_SPI_CS0) {
+ spi_nss_output_enable(SPI_PERIPH);
+ } else {
+ spi_nss_output_disable(SPI_PERIPH);
+ }
}
void gd32_spi_transfernb(const char *pTxBuffer, char *pRxBuffer, uint32_t nDataLength) {
assert(pTxBuffer != nullptr);
assert(pRxBuffer != nullptr);
- _cs_low();
+ cs_low();
while (nDataLength-- > 0) {
- *pRxBuffer = _send_byte(static_cast(*pTxBuffer));
+ *pRxBuffer = send_byte(static_cast(*pTxBuffer));
pRxBuffer++;
pTxBuffer++;
}
- _cs_high();
+ cs_high();
}
void gd32_spi_transfern(char *pTxBuffer, uint32_t nDataLength) {
@@ -187,23 +208,23 @@ void gd32_spi_transfern(char *pTxBuffer, uint32_t nDataLength) {
}
void gd32_spi_write(const uint16_t nData) {
- _cs_low();
+ cs_low();
- _send_byte(static_cast(nData >> 8));
- _send_byte(static_cast(nData & 0xFF));
+ send_byte(static_cast(nData >> 8));
+ send_byte(static_cast(nData & 0xFF));
- _cs_high();
+ cs_high();
}
void gd32_spi_writenb(const char *pTxBuffer, uint32_t nDataLength) {
assert(pTxBuffer != nullptr);
- _cs_low();
+ cs_low();
while (nDataLength-- > 0) {
- _send_byte(static_cast(*pTxBuffer));
+ send_byte(static_cast(*pTxBuffer));
pTxBuffer++;
}
- _cs_high();
+ cs_high();
}
diff --git a/lib-gd32/src/i2s_psc_config_dump.cpp b/lib-gd32/src/f/i2s_psc_config_dump.cpp
similarity index 96%
rename from lib-gd32/src/i2s_psc_config_dump.cpp
rename to lib-gd32/src/f/i2s_psc_config_dump.cpp
index e364ec2..e8d7235 100644
--- a/lib-gd32/src/i2s_psc_config_dump.cpp
+++ b/lib-gd32/src/f/i2s_psc_config_dump.cpp
@@ -45,7 +45,7 @@
#define RCU_CFG1_PREDV1_OFFSET 4U /* PREDV1 offset in RCU_CFG1 */
#define RCU_CFG1_PLL2MF_OFFSET 12U /* PLL2MF offset in RCU_CFG1 */
-void i2s_psc_config_dump(__attribute__((unused)) uint32_t spi_periph, uint32_t audiosample, uint32_t frameformat, uint32_t mckout) {
+void i2s_psc_config_dump([[maybe_unused]] uint32_t spi_periph, uint32_t audiosample, uint32_t frameformat, uint32_t mckout) {
uint32_t i2sdiv = 2U, i2sof = 0U;
uint32_t clks = 0U;
uint32_t i2sclock = 0U;
diff --git a/lib-gd32/src/gd32_gpio_mode_set.cpp b/lib-gd32/src/gd32_gpio_mode_set.cpp
new file mode 100644
index 0000000..bf8f480
--- /dev/null
+++ b/lib-gd32/src/gd32_gpio_mode_set.cpp
@@ -0,0 +1,75 @@
+#if defined (GD32F4XX) || defined (GD32H7XX)
+/**
+ * @file gd32_gpio_mode_set.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+
+#include "gd32.h"
+
+void gd32_gpio_mode_set_output(const uint32_t gpio_periph, const uint32_t pin) {
+ assert(pin != 0);
+ assert(__builtin_popcount(static_cast(pin)) == 1);
+
+ auto ctl = GPIO_CTL(gpio_periph);
+ auto pupd = GPIO_PUD(gpio_periph);
+
+ const auto i = 31 - __builtin_clz(pin);
+
+ /* clear the specified pin mode bits */
+ ctl &= ~GPIO_MODE_MASK(i);
+ /* set the specified pin mode bits */
+ ctl |= GPIO_MODE_SET(i, GPIO_MODE_OUTPUT);
+ /* clear the specified pin pupd bits */
+ pupd &= ~GPIO_PUPD_MASK(i);
+ /* set the specified pin pupd bits */
+ pupd |= GPIO_PUPD_SET(i, GPIO_PUPD_NONE);
+
+ GPIO_CTL(gpio_periph) = ctl;
+ GPIO_PUD(gpio_periph) = pupd;
+}
+
+void gd32_gpio_mode_set_af(const uint32_t gpio_periph, const uint32_t pin) {
+ assert(pin != 0);
+ assert(__builtin_popcount(static_cast(pin)) == 1);
+
+ auto ctl = GPIO_CTL(gpio_periph);
+ auto pupd = GPIO_PUD(gpio_periph);
+
+ const auto i = 31 - __builtin_clz(pin);
+
+ /* clear the specified pin mode bits */
+ ctl &= ~GPIO_MODE_MASK(i);
+ /* set the specified pin mode bits */
+ ctl |= GPIO_MODE_SET(i, GPIO_MODE_AF);
+ /* clear the specified pin pupd bits */
+ pupd &= ~GPIO_PUPD_MASK(i);
+ /* set the specified pin pupd bits */
+ pupd |= GPIO_PUPD_SET(i, GPIO_PUPD_PULLUP);
+
+ GPIO_CTL(gpio_periph) = ctl;
+ GPIO_PUD(gpio_periph) = pupd;
+}
+#endif
diff --git a/lib-gd32/src/gd32_pwm.cpp b/lib-gd32/src/gd32_pwm.cpp
new file mode 100644
index 0000000..44c8da3
--- /dev/null
+++ b/lib-gd32/src/gd32_pwm.cpp
@@ -0,0 +1,300 @@
+/**
+ * @file gd32_pwm.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if 0
+#undef NDEBUG
+
+#define PWM_TIMERx TIMER2
+#define PWM_RCU_TIMERx RCU_TIMER2
+
+#define TIMER2_FULL_REMAP
+#define PWM_TIMER_REMAP TIMER2_REMAP
+#define PWM_GPIO_AFx TIMER2_GPIO_AFx
+
+#define PWM_CH0_RCU_GPIOx TIMER2_CH0_RCU_GPIOx
+#define PWM_CH0_GPIOx TIMER2_CH0_GPIOx
+#define PWM_CH0_GPIO_PINx TIMER2_CH0_GPIO_PINx
+
+#define PWM_CH1_RCU_GPIOx TIMER2_CH1_RCU_GPIOx
+#define PWM_CH1_GPIOx TIMER2_CH1_GPIOx
+#define PWM_CH1_GPIO_PINx TIMER2_CH1_GPIO_PINx
+
+#define PWM_CH2_RCU_GPIOx TIMER2_CH2_RCU_GPIOx
+#define PWM_CH2_GPIOx TIMER2_CH2_GPIOx
+#define PWM_CH2_GPIO_PINx TIMER2_CH2_GPIO_PINx
+
+#define PWM_CH3_RCU_GPIOx TIMER2_CH3_RCU_GPIOx
+#define PWM_CH3_GPIOx TIMER2_CH3_GPIOx
+#define PWM_CH3_GPIO_PINx TIMER2_CH3_GPIO_PINx
+#endif
+
+#include
+#ifndef NDEBUG
+# include
+#endif
+
+#include "gd32_pwm.h"
+#include "gd32.h"
+
+#include "debug.h"
+
+namespace pwm {
+#if !defined(PWM_CHANNEL_0_DUTYCYCLE)
+# define PWM_CHANNEL_0_DUTYCYCLE 50
+#endif
+#if !defined(PWM_CHANNEL_1_DUTYCYCLE)
+# define PWM_CHANNEL_1_DUTYCYCLE 50
+#endif
+#if !defined(PWM_CHANNEL_2_DUTYCYCLE)
+# define PWM_CHANNEL_2_DUTYCYCLE 50
+#endif
+#if !defined(PWM_CHANNEL_3_DUTYCYCLE)
+# define PWM_CHANNEL_3_DUTYCYCLE 50
+#endif
+#if defined (PWM_CH0_RCU_GPIOx)
+static constexpr uint32_t DEFAUL_CHANNEL_0_DUTYCYCLE = PWM_CHANNEL_0_DUTYCYCLE;
+#endif
+#if defined (PWM_CH1_RCU_GPIOx)
+static constexpr uint32_t DEFAUL_CHANNEL_1_DUTYCYCLE = PWM_CHANNEL_1_DUTYCYCLE;
+#endif
+#if defined (PWM_CH2_RCU_GPIOx)
+static constexpr uint32_t DEFAUL_CHANNEL_2_DUTYCYCLE = PWM_CHANNEL_2_DUTYCYCLE;
+#endif
+#if defined (PWM_CH3_RCU_GPIOx)
+static constexpr uint32_t DEFAUL_CHANNEL_3_DUTYCYCLE = PWM_CHANNEL_3_DUTYCYCLE;
+#endif
+#if defined (PWM_RCU_TIMERx) && defined (PWM_TIMERx)
+static constexpr uint32_t TIMER_PERIOD = 19999; // 50KHz
+#endif
+} // namespace pwm
+
+#if defined (PWM_RCU_TIMERx) && defined (PWM_TIMERx)
+
+static void dump() {
+#if 1
+ DEBUG_ENTRY
+#ifndef NDEBUG
+ printf("PWM_TIMERx=0x%.8X\n", PWM_TIMERx - TIMER_BASE);
+ printf("PWM_RCU_TIMERx=0x%.8X\n", PWM_RCU_TIMERx);
+# if defined (GPIO_INIT)
+ printf("PWM_TIMER_REMAP=0x%.8X\n", PWM_TIMER_REMAP);
+# endif
+ puts("--------------------------------");
+# if defined (PWM_CH0_RCU_GPIOx)
+ printf("PWM_CH0_RCU_GPIOx=0x%.8X\n", PWM_CH0_RCU_GPIOx);
+ printf("PWM_CH0_GPIOx=0x%.8X\n", PWM_CH0_GPIOx);
+ printf("PWM_CH0_GPIO_PINx=0x%.4X\n", PWM_CH0_GPIO_PINx);
+ puts("--------------------------------");
+# endif
+# if defined (PWM_CH1_RCU_GPIOx)
+ printf("PWM_CH1_RCU_GPIOx=0x%.8X\n", PWM_CH1_RCU_GPIOx);
+ printf("PWM_CH1_GPIOx=0x%.8X\n", PWM_CH1_GPIOx);
+ printf("PWM_CH1_GPIO_PINx=0x%.4X\n", PWM_CH1_GPIO_PINx);
+ puts("--------------------------------");
+# endif
+# if defined (PWM_CH2_RCU_GPIOx)
+ printf("PWM_CH2_RCU_GPIOx=0x%.8X\n", PWM_CH2_RCU_GPIOx);
+ printf("PWM_CH2_GPIOx=0x%.8X\n", PWM_CH2_GPIOx);
+ printf("PWM_CH2_GPIO_PINx=0x%.4X\n", PWM_CH2_GPIO_PINx);
+ puts("--------------------------------");
+# endif
+# if defined (PWM_CH3_RCU_GPIOx)
+ printf("PWM_CH3_RCU_GPIOx=0x%.8X\n", PWM_CH3_RCU_GPIOx);
+ printf("PWM_CH3_GPIOx=0x%.8X\n", PWM_CH3_GPIOx);
+ printf("PWM_CH3_GPIO_PINx=0x%.4X\n", PWM_CH3_GPIO_PINx);
+# endif
+#endif
+ DEBUG_EXIT
+#endif
+}
+
+static void gpio_config() {
+#if defined (PWM_CH0_RCU_GPIOx)
+ rcu_periph_clock_enable(PWM_CH0_RCU_GPIOx);
+#endif
+#if defined (PWM_CH1_RCU_GPIOx)
+ rcu_periph_clock_enable(PWM_CH1_RCU_GPIOx);
+#endif
+#if defined (PWM_CH2_RCU_GPIOx)
+ rcu_periph_clock_enable(PWM_CH2_RCU_GPIOx);
+#endif
+#if defined (PWM_CH3_RCU_GPIOx)
+ rcu_periph_clock_enable(PWM_CH3_RCU_GPIOx);
+#endif
+
+#if defined (GPIO_INIT)
+ rcu_periph_clock_enable(RCU_AF);
+# if defined(PWM_TIMER_REMAP)
+ gpio_pin_remap_config(PWM_TIMER_REMAP, ENABLE);
+# endif
+# if defined (PWM_CH0_GPIOx) && defined (PWM_CH0_GPIO_PINx)
+ gpio_init(PWM_CH0_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, PWM_CH0_GPIO_PINx);
+# endif
+# if defined (PWM_CH1_GPIOx) && defined (PWM_CH1_GPIO_PINx)
+ gpio_init(PWM_CH1_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, PWM_CH1_GPIO_PINx);
+# endif
+# if defined (PWM_CH2_GPIOx) && defined (PWM_CH2_GPIO_PINx)
+ gpio_init(PWM_CH2_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, PWM_CH2_GPIO_PINx);
+# endif
+# if defined (PWM_CH3_GPIOx) && defined (PWM_CH3_GPIO_PINx)
+ gpio_init(PWM_CH3_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, PWM_CH3_GPIO_PINx);
+# endif
+#else
+# if defined (PWM_CH0_GPIOx) && defined (PWM_CH0_GPIO_PINx)
+ gpio_af_set(PWM_CH0_GPIOx, PWM_GPIO_AFx, PWM_CH0_GPIO_PINx);
+ gpio_mode_set(PWM_CH0_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_CH0_GPIO_PINx);
+ gpio_output_options_set(PWM_CH0_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, PWM_CH0_GPIO_PINx);
+# endif
+# if defined (PWM_CH1_GPIOx) && defined (PWM_CH1_GPIO_PINx)
+ gpio_af_set(PWM_CH1_GPIOx, PWM_GPIO_AFx, PWM_CH1_GPIO_PINx);
+ gpio_mode_set(PWM_CH1_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_CH1_GPIO_PINx);
+ gpio_output_options_set(PWM_CH1_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, PWM_CH1_GPIO_PINx);
+# endif
+# if defined (PWM_CH2_GPIOx) && defined (PWM_CH2_GPIO_PINx)
+ gpio_af_set(PWM_CH2_GPIOx, PWM_GPIO_AFx, PWM_CH2_GPIO_PINx);
+ gpio_mode_set(PWM_CH2_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_CH2_GPIO_PINx);
+ gpio_output_options_set(PWM_CH2_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, PWM_CH2_GPIO_PINx);
+# endif
+# if defined (PWM_CH3_GPIOx) && defined (PWM_CH3_GPIO_PINx)
+ gpio_af_set(PWM_CH3_GPIOx, PWM_GPIO_AFx, PWM_CH3_GPIO_PINx);
+ gpio_mode_set(PWM_CH3_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_CH3_GPIO_PINx);
+ gpio_output_options_set(PWM_CH3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, PWM_CH3_GPIO_PINx);
+# endif
+#endif
+}
+
+static void timer_config() {
+#if defined (PWM_RCU_TIMERx) && defined (PWM_TIMERx)
+ rcu_periph_clock_enable(PWM_RCU_TIMERx);
+
+ timer_deinit(PWM_TIMERx);
+
+ timer_parameter_struct timer_initpara;
+ timer_initpara.prescaler = TIMER_PSC_1MHZ;
+ timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
+ timer_initpara.counterdirection = TIMER_COUNTER_UP;
+ timer_initpara.period = pwm::TIMER_PERIOD;
+ timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
+ timer_initpara.repetitioncounter = 0;
+ timer_init(PWM_TIMERx, &timer_initpara);
+
+# if defined (PWM_CH0_RCU_GPIOx) || defined (PWM_CH1_RCU_GPIOx) || defined (PWM_CH2_RCU_GPIOx) || defined (PWM_CH3_RCU_GPIOx)
+ timer_oc_parameter_struct timer_ocintpara;
+ timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
+ timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
+ timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
+ timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
+ timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
+ timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
+# endif
+# if defined (PWM_CH0_RCU_GPIOx)
+ timer_channel_output_config(PWM_TIMERx, TIMER_CH_0, &timer_ocintpara);
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_0, 1999);
+ timer_channel_output_mode_config(PWM_TIMERx, TIMER_CH_0, TIMER_OC_MODE_PWM0);
+ timer_channel_output_shadow_config(PWM_TIMERx, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
+# endif
+# if defined (PWM_CH1_RCU_GPIOx)
+ timer_channel_output_config(PWM_TIMERx, TIMER_CH_1, &timer_ocintpara);
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_1, 3999);
+ timer_channel_output_mode_config(PWM_TIMERx, TIMER_CH_1, TIMER_OC_MODE_PWM0);
+ timer_channel_output_shadow_config(PWM_TIMERx, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
+# endif
+# if defined (PWM_CH2_RCU_GPIOx)
+ timer_channel_output_config(PWM_TIMERx, TIMER_CH_2, &timer_ocintpara);
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_2, 7999);
+ timer_channel_output_mode_config(PWM_TIMERx, TIMER_CH_2, TIMER_OC_MODE_PWM0);
+ timer_channel_output_shadow_config(PWM_TIMERx, TIMER_CH_2, TIMER_OC_SHADOW_DISABLE);
+# endif
+# if defined (PWM_CH3_RCU_GPIOx)
+ timer_channel_output_config(PWM_TIMERx, TIMER_CH_3, &timer_ocintpara);
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_3, 11999);
+ timer_channel_output_mode_config(PWM_TIMERx, TIMER_CH_3, TIMER_OC_MODE_PWM0);
+ timer_channel_output_shadow_config(PWM_TIMERx, TIMER_CH_3, TIMER_OC_SHADOW_DISABLE);
+# endif
+
+ timer_auto_reload_shadow_enable(PWM_TIMERx);
+ timer_enable(PWM_TIMERx);
+#endif
+}
+
+void gd32_pwm_begin() {
+ DEBUG_ENTRY
+
+ dump();
+
+ gpio_config();
+ timer_config();
+
+#if defined (PWM_CH0_RCU_GPIOx)
+ gd32_pwm_set_duty_cycle(pwm::Channel::PWM_CHANNEL_0, pwm::DEFAUL_CHANNEL_0_DUTYCYCLE);
+#endif
+#if defined (PWM_CH1_RCU_GPIOx)
+ gd32_pwm_set_duty_cycle(pwm::Channel::PWM_CHANNEL_1, pwm::DEFAUL_CHANNEL_1_DUTYCYCLE);
+#endif
+#if defined (PWM_CH2_RCU_GPIOx)
+ gd32_pwm_set_duty_cycle(pwm::Channel::PWM_CHANNEL_2, pwm::DEFAUL_CHANNEL_2_DUTYCYCLE);
+#endif
+#if defined (PWM_CH3_RCU_GPIOx)
+ gd32_pwm_set_duty_cycle(pwm::Channel::PWM_CHANNEL_3, pwm::DEFAUL_CHANNEL_3_DUTYCYCLE);
+#endif
+
+ DEBUG_EXIT
+}
+
+void gd32_pwm_set_duty_cycle(const pwm::Channel channel, const uint32_t nDutyCycle) {
+ DEBUG_ENTRY
+
+ const uint32_t nPulse = (nDutyCycle > 100 ? 100 : nDutyCycle) * (pwm::TIMER_PERIOD / 100U);
+
+ DEBUG_PRINTF("Channel=%u, nDutyCycle=%u, nPulse=%u", static_cast(channel), nDutyCycle, static_cast(nPulse));
+
+ switch (channel) {
+#if defined (PWM_CH0_RCU_GPIOx)
+ case pwm::Channel::PWM_CHANNEL_0:
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_0, nPulse);
+ break;
+#endif
+#if defined (PWM_CH1_RCU_GPIOx)
+ case pwm::Channel::PWM_CHANNEL_1:
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_1, nPulse);
+ break;
+#endif
+#if defined (PWM_CH2_RCU_GPIOx)
+ case pwm::Channel::PWM_CHANNEL_2:
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_2, nPulse);
+ break;
+#endif
+#if defined (PWM_CH3_RCU_GPIOx)
+ case pwm::Channel::PWM_CHANNEL_3:
+ timer_channel_output_pulse_value_config(PWM_TIMERx, TIMER_CH_3, nPulse);
+ break;
+#endif
+ default:
+ break;
+ }
+
+ DEBUG_EXIT
+}
+#endif
diff --git a/lib-gd32/src/gd32_spi_dma_i2s.cpp b/lib-gd32/src/gd32_spi_dma_i2s.cpp
index e25feda..6ddfbd5 100644
--- a/lib-gd32/src/gd32_spi_dma_i2s.cpp
+++ b/lib-gd32/src/gd32_spi_dma_i2s.cpp
@@ -2,7 +2,7 @@
* @file gd32_spi_dma_i2s.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,143 +28,156 @@
#include "gd32.h"
-#if defined (GD32F4XX)
-# define DMA_PARAMETER_STRUCT dma_single_data_parameter_struct
-# define DMA_CHMADDR DMA_CHM0ADDR
-# define DMA_MEMORY_TO_PERIPHERAL DMA_MEMORY_TO_PERIPH
-# define DMA_PERIPHERAL_WIDTH_16BIT DMA_PERIPH_WIDTH_16BIT
-# define dma_init dma_single_data_mode_init
-# define dma_struct_para_init dma_single_data_para_struct_init
-# define dma_memory_to_memory_disable(x,y)
+#if defined (I2S_PERIPH)
+
+# if defined (GD32H7XX)
+ static_assert(I2S_PERIPH != SPI3);
+ static_assert(I2S_PERIPH != SPI4);
+# else
+ static_assert(I2S_PERIPH != SPI0);
+# endif
+
+# if defined (GD32F4XX) || defined (GD32H7XX)
+# define DMA_PARAMETER_STRUCT dma_single_data_parameter_struct
+# define DMA_CHMADDR DMA_CHM0ADDR
+# define DMA_MEMORY_TO_PERIPHERAL DMA_MEMORY_TO_PERIPH
+# define DMA_PERIPHERAL_WIDTH_16BIT DMA_PERIPH_WIDTH_16BIT
+# define dma_init dma_single_data_mode_init
+# define dma_struct_para_init dma_single_data_para_struct_init
+# define dma_memory_to_memory_disable(x,y)
+# else
+# define DMA_PARAMETER_STRUCT dma_parameter_struct
+# endif
+
+# ifndef NDEBUG
+# if !defined (GD32H7XX)
+ void i2s_psc_config_dump(uint32_t spi_periph, uint32_t audiosample, uint32_t frameformat, uint32_t mckout);
+# endif
+# endif
+
+# if !defined(SPI_BUFFER_SIZE)
+# define SPI_BUFFER_SIZE ((24 * 1024) / 2)
+# endif
+
+static uint16_t s_TxBuffer[SPI_BUFFER_SIZE] __attribute__ ((aligned (4)));
+
+static void rcu_config() {
+ rcu_periph_clock_enable(I2S_WS_RCU_GPIOx);
+
+#if defined (GPIO_INIT)
+ rcu_periph_clock_enable(RCU_AF);
+ rcu_periph_clock_enable(I2S_RCU_SPIx);
+ rcu_periph_clock_enable(I2S_RCU_GPIOx);
#else
-# define DMA_PARAMETER_STRUCT dma_parameter_struct
+ rcu_periph_clock_enable(I2S_CK_RCU_GPIOx);
+ rcu_periph_clock_enable(I2S_SD_RCU_GPIOx);
#endif
-#ifndef NDEBUG
-void i2s_psc_config_dump(uint32_t spi_periph, uint32_t audiosample, uint32_t frameformat, uint32_t mckout);
-#endif
+ if (I2S_DMAx == DMA0) {
+ rcu_periph_clock_enable(RCU_DMA0);
+ } else {
+ rcu_periph_clock_enable(RCU_DMA1);
+ }
-#if !defined(SPI_BUFFER_SIZE)
-# define SPI_BUFFER_SIZE ((24 * 1024) / 2)
+#if defined (GD32H7XX)
+ rcu_periph_clock_enable(RCU_DMAMUX);
#endif
+}
-static uint16_t s_TxBuffer[SPI_BUFFER_SIZE] __attribute__ ((aligned (4)));
+static void gpio_config() {
+#if defined (GPIO_INIT)
+# if defined (I2S_REMAP_GPIO)
+ gpio_pin_remap_config(I2S_REMAP_GPIO, ENABLE);
+ if (I2S_PERIPH == SPI0) {
+ gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
+ }
+# else
+ if (I2S_PERIPH == SPI2) {
+ gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
+ }
+# endif
+ gpio_init(I2S_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, I2S_CK_GPIO_PINx | I2S_SD_GPIO_PINx);
+ gpio_init(I2S_WS_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, I2S_WS_GPIO_PINx);
+#else
+ gpio_af_set(I2S_CK_GPIOx, I2S_GPIO_AFx, I2S_CK_GPIO_PINx);
+ gpio_mode_set(I2S_CK_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, I2S_CK_GPIO_PINx);
+ gpio_output_options_set(I2S_CK_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, I2S_CK_GPIO_PINx);
+
+ gpio_af_set(I2S_SD_GPIOx, I2S_GPIO_AFx, I2S_SD_GPIO_PINx);
+ gpio_mode_set(I2S_SD_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, I2S_SD_GPIO_PINx);
+ gpio_output_options_set(I2S_SD_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, I2S_SD_GPIO_PINx);
-static void _spi_i2s_dma_config() {
- rcu_periph_clock_enable(RCU_DMA1);
+ gpio_af_set(I2S_WS_GPIOx, I2S_GPIO_AFx, I2S_WS_GPIO_PINx);
+ gpio_mode_set(I2S_WS_GPIOx, GPIO_MODE_OUTPUT,GPIO_PUPD_NONE, I2S_WS_GPIO_PINx);
+ gpio_output_options_set(I2S_WS_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, I2S_WS_GPIO_PINx);
+#endif
+}
- dma_deinit(SPI_DMAx, SPI_DMA_CHx);
+static void spi_i2s_dma_config() {
+ dma_deinit(I2S_DMAx, I2S_DMA_CHx);
DMA_PARAMETER_STRUCT dma_init_struct;
dma_struct_para_init(&dma_init_struct);
+
+#if defined (GD32H7XX)
+ dma_init_struct.request = I2S_DMA_REQUEST_I2S_TX;
+#endif
dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
-#if !defined (GD32F4XX)
+# if defined (GD32F4XX) || defined (GD32H7XX)
+# else
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_16BIT;
#endif
- dma_init_struct.periph_addr = SPI_PERIPH + 0x0CU;
- dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
-#if !defined (GD32F4XX)
- dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
+#if defined (GD32H7XX)
+ dma_init_struct.periph_addr = (uint32_t)&SPI_TDATA(I2S_PERIPH);
#else
+ dma_init_struct.periph_addr = I2S_PERIPH + 0x0CU;
+#endif
+ dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
+#if defined (GD32F4XX) || defined (GD32H7XX)
dma_init_struct.periph_memory_width = DMA_PERIPHERAL_WIDTH_16BIT;
+#else
+ dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
#endif
dma_init_struct.priority = DMA_PRIORITY_HIGH;
- dma_init(SPI_DMAx, SPI_DMA_CHx, &dma_init_struct);
- /* configure DMA mode */
- dma_circulation_disable(SPI_DMAx, SPI_DMA_CHx);
- dma_memory_to_memory_disable(SPI_DMAx, SPI_DMA_CHx);
+ dma_init(I2S_DMAx, I2S_DMA_CHx, &dma_init_struct);
+
+ dma_circulation_disable(I2S_DMAx, I2S_DMA_CHx);
+ dma_memory_to_memory_disable(I2S_DMAx, I2S_DMA_CHx);
#if defined (GD32F4XX)
- dma_channel_subperipheral_select(SPI_DMAx, SPI_DMA_CHx, SPI_DMA_SUBPERIx);
+ dma_channel_subperipheral_select(I2S_DMAx, I2S_DMA_CHx, I2S_DMA_SUBPERIx);
#endif
- DMA_CHCNT(SPI_DMAx, SPI_DMA_CHx) = 0;
+ DMA_CHCNT(I2S_DMAx, I2S_DMA_CHx) = 0;
}
-
+namespace i2s {
void gd32_spi_dma_begin() {
- assert(SPI_PERIPH != SPI0);
-
- rcu_periph_clock_enable(SPI_NSS_RCU_GPIOx);
- rcu_periph_clock_enable(SPI_RCU_GPIOx);
- rcu_periph_clock_enable(SPI_RCU_CLK);
-
-#if !defined (GD32F4XX)
- rcu_periph_clock_enable(RCU_AF);
-
- gpio_init(SPI_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- gpio_init(SPI_NSS_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, SPI_NSS_GPIO_PINx);
-
-# if defined (SPI2_REMAP)
- gpio_pin_remap_config(GPIO_SPI2_REMAP, ENABLE);
-# else
- if (SPI_PERIPH == SPI2) {
- gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);
- }
-# endif
-#else
- if (SPI_PERIPH == SPI2) {
- gpio_af_set(SPI_GPIOx, GPIO_AF_6, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- } else {
- gpio_af_set(SPI_GPIOx, GPIO_AF_5, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- }
- gpio_mode_set(SPI_GPIOx, GPIO_MODE_AF, GPIO_PUPD_NONE, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
- gpio_output_options_set(SPI_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SPI_SCK_PIN | SPI_MISO_PIN | SPI_MOSI_PIN);
-
- gpio_mode_set(SPI_NSS_GPIOx, GPIO_MODE_OUTPUT,GPIO_PUPD_NONE, SPI_NSS_GPIO_PINx);
- gpio_output_options_set(SPI_NSS_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SPI_NSS_GPIO_PINx);
-#endif
-
-#if defined (GD32F10X_CL) || defined (GD32F20X_CL)
- /**
- * Setup PLL2
- *
- * i2sclock=160000000
- * i2sdiv=12, i2sof=256
- */
-
- RCU_CTL &= ~RCU_CTL_PLL2EN;
-
- rcu_pll2_config(RCU_PLL2_MUL16);
+ rcu_config();
+ gpio_config();
- RCU_CTL |= RCU_CTL_PLL2EN;
+ i2s_disable(I2S_PERIPH);
+ i2s_psc_config(I2S_PERIPH, 200000, I2S_FRAMEFORMAT_DT16B_CH16B, I2S_MCKOUT_DISABLE);
+ i2s_init(I2S_PERIPH, I2S_MODE_MASTERTX, I2S_STD_MSB, I2S_CKPL_LOW);
+ i2s_enable(I2S_PERIPH);
- while ((RCU_CTL & RCU_CTL_PLL2STB) == 0U) {
- }
-
- if (SPI_PERIPH == SPI2) {
- rcu_i2s2_clock_config(RCU_I2S2SRC_CKPLL2_MUL2);
- } else {
- rcu_i2s1_clock_config(RCU_I2S1SRC_CKPLL2_MUL2);
- }
-#endif
-
- i2s_disable(SPI_PERIPH);
- i2s_psc_config(SPI_PERIPH, 200000, I2S_FRAMEFORMAT_DT16B_CH16B, I2S_MCKOUT_DISABLE);
- i2s_init(SPI_PERIPH, I2S_MODE_MASTERTX, I2S_STD_MSB, I2S_CKPL_LOW);
- i2s_enable(SPI_PERIPH);
-
- _spi_i2s_dma_config();
+ spi_i2s_dma_config();
#ifndef NDEBUG
- i2s_psc_config_dump(SPI_PERIPH, 200000, I2S_FRAMEFORMAT_DT16B_CH16B, I2S_MCKOUT_DISABLE);
+ i2s_psc_config_dump(I2S_PERIPH, 200000, I2S_FRAMEFORMAT_DT16B_CH16B, I2S_MCKOUT_DISABLE);
#endif
}
void gd32_spi_dma_set_speed_hz(uint32_t nSpeedHz) {
- const auto audiosample = nSpeedHz / 16 / 2 ;
+ const auto audiosample = nSpeedHz / 16U / 2U ;
- i2s_disable(SPI_PERIPH);
- i2s_psc_config(SPI2, audiosample, I2S_FRAMEFORMAT_DT16B_CH16B, I2S_MCKOUT_DISABLE);
- i2s_enable(SPI_PERIPH);
+ i2s_disable(I2S_PERIPH);
+ i2s_psc_config(I2S_PERIPH, audiosample, I2S_FRAMEFORMAT_DT16B_CH16B, I2S_MCKOUT_DISABLE);
+ i2s_enable(I2S_PERIPH);
}
-/**
- * DMA
- */
-
const uint8_t *gd32_spi_dma_tx_prepare(uint32_t *nLength) {
*nLength = (sizeof(s_TxBuffer) / sizeof(s_TxBuffer[0])) * 2;
- return (const uint8_t*) s_TxBuffer;
+ return (const uint8_t *) s_TxBuffer;
}
void gd32_spi_dma_tx_start(const uint8_t *pTxBuffer, uint32_t nLength) {
@@ -172,24 +185,27 @@ void gd32_spi_dma_tx_start(const uint8_t *pTxBuffer, uint32_t nLength) {
assert((uint32_t )pTxBuffer >= (uint32_t )s_TxBuffer);
assert(nLength != 0);
+#if defined (GD32F4XX) || defined (GD32H7XX)
+ dma_flag_clear(I2S_DMAx, I2S_DMA_CHx, DMA_FLAG_FTF);
+#endif
+
const auto dma_chcnt = (((nLength + 1) / 2) & DMA_CHXCNT_CNT);
- auto nDmaChCTL = DMA_CHCTL(SPI_DMAx, SPI_DMA_CHx);
+ auto nDmaChCTL = DMA_CHCTL(I2S_DMAx, I2S_DMA_CHx);
nDmaChCTL &= ~DMA_CHXCTL_CHEN;
- DMA_CHCTL(SPI_DMAx, SPI_DMA_CHx) = nDmaChCTL;
- DMA_CHMADDR(SPI_DMAx, SPI_DMA_CHx) = (uint32_t)pTxBuffer;
- DMA_CHCNT(SPI_DMAx, SPI_DMA_CHx) = dma_chcnt;
+ DMA_CHCTL(I2S_DMAx, I2S_DMA_CHx) = nDmaChCTL;
+
+ DMA_CHMADDR(I2S_DMAx, I2S_DMA_CHx) = (uint32_t)pTxBuffer;
+ DMA_CHCNT(I2S_DMAx, I2S_DMA_CHx) = dma_chcnt;
+
nDmaChCTL |= DMA_CHXCTL_CHEN;
- DMA_CHCTL(SPI_DMAx, SPI_DMA_CHx) = nDmaChCTL;
- spi_dma_enable(SPI_PERIPH, SPI_DMA_TRANSMIT);
-}
+ DMA_CHCTL(I2S_DMAx, I2S_DMA_CHx) = nDmaChCTL;
-bool gd32_spi_dma_tx_is_active(void) {
- return (uint32_t) DMA_CHCNT(SPI_DMAx, SPI_DMA_CHx) != 0;
+ spi_dma_enable(I2S_PERIPH, SPI_DMA_TRANSMIT);
}
-/**
- * /CS
- */
-
-//TODO Implement /CS
+bool gd32_spi_dma_tx_is_active() {
+ return DMA_CHCNT(I2S_DMAx, I2S_DMA_CHx) != 0;
+}
+} // namespace i2s
+#endif
diff --git a/lib-gd32/src/gd32_uart.cpp b/lib-gd32/src/gd32_uart.cpp
index 7620cdd..41ef6a8 100644
--- a/lib-gd32/src/gd32_uart.cpp
+++ b/lib-gd32/src/gd32_uart.cpp
@@ -2,7 +2,7 @@
* @file gd32_uart.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,51 +29,51 @@
#include "gd32_uart.h"
#include "gd32.h"
-static void _rcu_periph_clock_enable(const uint32_t usart_periph) {
+static void rcu_config(const uint32_t usart_periph) {
#ifndef NDEBUG
bool isSet = false;
#endif
switch (usart_periph) {
case USART0:
- rcu_periph_clock_enable(USART0_RCU_CLK);
- rcu_periph_clock_enable(USART0_GPIO_CLK);
+ rcu_periph_clock_enable(USART0_RCU_USART0);
+ rcu_periph_clock_enable(USART0_RCU_GPIOx);
#ifndef NDEBUG
isSet = true;
#endif
break;
case USART1:
- rcu_periph_clock_enable(USART1_RCU_CLK);
- rcu_periph_clock_enable(USART1_GPIO_CLK);
+ rcu_periph_clock_enable(USART1_RCU_USART1);
+ rcu_periph_clock_enable(USART1_RCU_GPIOx);
#ifndef NDEBUG
isSet = true;
#endif
break;
case USART2:
- rcu_periph_clock_enable(USART2_RCU_CLK);
- rcu_periph_clock_enable(USART2_GPIO_CLK);
+ rcu_periph_clock_enable(USART2_RCU_USART2);
+ rcu_periph_clock_enable(USART2_RCU_GPIOx);
#ifndef NDEBUG
isSet = true;
#endif
break;
case UART3:
- rcu_periph_clock_enable(UART3_RCU_CLK);
- rcu_periph_clock_enable(UART3_GPIO_CLK);
+ rcu_periph_clock_enable(UART3_RCU_UART3);
+ rcu_periph_clock_enable(UART3_RCU_GPIOx);
#ifndef NDEBUG
isSet = true;
#endif
break;
case UART4:
- rcu_periph_clock_enable(UART4_RCU_CLK);
- rcu_periph_clock_enable(UART4_GPIO_TX_CLK);
- rcu_periph_clock_enable(UART4_GPIO_RX_CLK);
+ rcu_periph_clock_enable(UART4_RCU_UART4);
+ rcu_periph_clock_enable(UART4_TX_RCU_GPIOx);
+ rcu_periph_clock_enable(UART4_RX_RCU_GPIOx);
#ifndef NDEBUG
isSet = true;
#endif
break;
#if defined (USART5)
case USART5:
- rcu_periph_clock_enable(USART5_RCU_CLK);
- rcu_periph_clock_enable(USART5_GPIO_CLK);
+ rcu_periph_clock_enable(USART5_RCU_USART5);
+ rcu_periph_clock_enable(USART5_RCU_GPIOx);
# ifndef NDEBUG
isSet = true;
# endif
@@ -81,8 +81,8 @@ static void _rcu_periph_clock_enable(const uint32_t usart_periph) {
#endif
#if defined (UART6)
case UART6:
- rcu_periph_clock_enable(UART6_RCU_CLK);
- rcu_periph_clock_enable(UART6_GPIO_CLK);
+ rcu_periph_clock_enable(UART6_RCU_UART6);
+ rcu_periph_clock_enable(UART6_RCU_GPIOx);
# ifndef NDEBUG
isSet = true;
# endif
@@ -90,8 +90,8 @@ static void _rcu_periph_clock_enable(const uint32_t usart_periph) {
#endif
#if defined (UART7)
case UART7:
- rcu_periph_clock_enable(UART7_RCU_CLK);
- rcu_periph_clock_enable(UART7_GPIO_CLK);
+ rcu_periph_clock_enable(UART7_RCU_UART7);
+ rcu_periph_clock_enable(UART7_RCU_GPIOx);
# ifndef NDEBUG
isSet = true;
# endif
@@ -106,28 +106,28 @@ static void _rcu_periph_clock_enable(const uint32_t usart_periph) {
assert(isSet);
}
-#if !defined (GD32F4XX)
-static void _gpio_init(const uint32_t usart_periph) {
+#if !(defined (GD32F4XX) || defined (GD32H7XX))
+static void gpio_config(const uint32_t usart_periph) {
rcu_periph_clock_enable(RCU_AF);
switch (usart_periph) {
case USART0:
- gpio_init(USART0_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART0_TX_PIN);
- gpio_init(USART0_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART0_RX_PIN);
+ gpio_init(USART0_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART0_TX_GPIO_PINx);
+ gpio_init(USART0_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART0_RX_GPIO_PINx);
#if defined (USART0_REMAP)
gpio_pin_remap_config(GPIO_USART0_REMAP, ENABLE);
#endif
break;
case USART1:
- gpio_init(USART1_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART1_TX_PIN);
- gpio_init(USART1_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART1_RX_PIN);
+ gpio_init(USART1_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART1_TX_GPIO_PINx);
+ gpio_init(USART1_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART1_RX_GPIO_PINx);
#if defined (USART1_REMAP)
gpio_pin_remap_config(GPIO_USART1_REMAP, ENABLE);
#endif
break;
case USART2:
- gpio_init(USART2_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART2_TX_PIN);
- gpio_init(USART2_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART2_RX_PIN);
+ gpio_init(USART2_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART2_TX_GPIO_PINx);
+ gpio_init(USART2_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART2_RX_GPIO_PINx);
#if defined (USART2_FULL_REMAP)
gpio_pin_remap_config(GPIO_USART2_FULL_REMAP, ENABLE);
#elif defined (USART2_PARTIAL_REMAP)
@@ -135,20 +135,20 @@ static void _gpio_init(const uint32_t usart_periph) {
#endif
break;
case UART3:
- gpio_init(UART3_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART3_TX_PIN);
- gpio_init(UART3_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART3_RX_PIN);
+ gpio_init(UART3_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART3_TX_GPIO_PINx);
+ gpio_init(UART3_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART3_RX_GPIO_PINx);
#if defined (UART3_REMAP)
gpio_pin_remap_config(GPIO_PCF5_UART3_REMAP, ENABLE);
#endif
break;
case UART4:
- gpio_init(UART4_GPIO_TX_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART4_TX_PIN);
- gpio_init(UART4_GPIO_RX_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART4_RX_PIN);
+ gpio_init(UART4_TX_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART4_TX_GPIO_PINx);
+ gpio_init(UART4_RX_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART4_RX_GPIO_PINx);
break;
#if defined (USART5)
case USART5:
- gpio_init(USART5_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART5_TX_PIN);
- gpio_init(USART5_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART5_RX_PIN);
+ gpio_init(USART5_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, USART5_TX_GPIO_PINx);
+ gpio_init(USART5_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, USART5_RX_GPIO_PINx);
# if defined (USART5_REMAP)
gpio_pin_remap_config(GPIO_PCF5_USART5_TX_PG14_REMAP, ENABLE);
gpio_pin_remap_config(GPIO_PCF5_USART5_RX_PG9_REMAP, ENABLE);
@@ -157,8 +157,8 @@ static void _gpio_init(const uint32_t usart_periph) {
#endif
#if defined (UART6)
case UART6:
- gpio_init(UART6_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART6_TX_PIN);
- gpio_init(UART6_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART6_RX_PIN);
+ gpio_init(UART6_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART6_TX_GPIO_PINx);
+ gpio_init(UART6_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART6_RX_GPIO_PINx);
# if defined (UART6_REMAP)
gpio_pin_remap_config(GPIO_PCF5_UART6_REMAP, ENABLE);
# endif
@@ -166,8 +166,8 @@ static void _gpio_init(const uint32_t usart_periph) {
#endif
#if defined (UART7)
case UART7:
- gpio_init(UART7_GPIO_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART7_TX_PIN);
- gpio_init(UART7_GPIO_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART7_RX_PIN);
+ gpio_init(UART7_GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, UART7_TX_GPIO_PINx);
+ gpio_init(UART7_GPIOx, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, UART7_RX_GPIO_PINx);
break;
#endif
default:
@@ -177,77 +177,77 @@ static void _gpio_init(const uint32_t usart_periph) {
}
}
#else
-void _gpio_init(const uint32_t usart_periph) {
+static void gpio_config(const uint32_t usart_periph) {
switch (usart_periph) {
case USART0:
- gpio_af_set(USART0_GPIO_PORT, GPIO_AF_7, USART0_TX_PIN);
- gpio_mode_set(USART0_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART0_TX_PIN);
- gpio_output_options_set(USART0_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART0_TX_PIN);
- gpio_af_set(USART0_GPIO_PORT, GPIO_AF_7, USART0_RX_PIN);
- gpio_mode_set(USART0_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART0_RX_PIN);
- gpio_output_options_set(USART0_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART0_RX_PIN);
+ gpio_af_set(USART0_GPIOx, USART0_GPIO_AFx, USART0_TX_GPIO_PINx);
+ gpio_mode_set(USART0_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART0_TX_GPIO_PINx);
+ gpio_output_options_set(USART0_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART0_TX_GPIO_PINx);
+ gpio_af_set(USART0_GPIOx, USART0_GPIO_AFx, USART0_RX_GPIO_PINx);
+ gpio_mode_set(USART0_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART0_RX_GPIO_PINx);
+ gpio_output_options_set(USART0_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART0_RX_GPIO_PINx);
break;
case USART1:
- gpio_af_set(USART1_GPIO_PORT, GPIO_AF_7, USART1_TX_PIN);
- gpio_mode_set(USART1_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART1_TX_PIN);
- gpio_output_options_set(USART1_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART1_TX_PIN);
- gpio_af_set(USART1_GPIO_PORT, GPIO_AF_7, USART1_RX_PIN);
- gpio_mode_set(USART1_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART1_RX_PIN);
- gpio_output_options_set(USART1_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART1_RX_PIN);
+ gpio_af_set(USART1_GPIOx, USART1_GPIO_AFx, USART1_TX_GPIO_PINx);
+ gpio_mode_set(USART1_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART1_TX_GPIO_PINx);
+ gpio_output_options_set(USART1_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART1_TX_GPIO_PINx);
+ gpio_af_set(USART1_GPIOx, USART1_GPIO_AFx, USART1_RX_GPIO_PINx);
+ gpio_mode_set(USART1_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART1_RX_GPIO_PINx);
+ gpio_output_options_set(USART1_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART1_RX_GPIO_PINx);
break;
case USART2:
- gpio_af_set(USART2_GPIO_PORT, GPIO_AF_7, USART2_TX_PIN);
- gpio_mode_set(USART2_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART2_TX_PIN);
- gpio_output_options_set(USART2_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART2_TX_PIN);
- gpio_af_set(USART2_GPIO_PORT, GPIO_AF_7, USART2_RX_PIN);
- gpio_mode_set(USART2_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART2_RX_PIN);
- gpio_output_options_set(USART2_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART2_RX_PIN);
+ gpio_af_set(USART2_GPIOx, USART2_GPIO_AFx, USART2_TX_GPIO_PINx);
+ gpio_mode_set(USART2_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART2_TX_GPIO_PINx);
+ gpio_output_options_set(USART2_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART2_TX_GPIO_PINx);
+ gpio_af_set(USART2_GPIOx, USART2_GPIO_AFx, USART2_RX_GPIO_PINx);
+ gpio_mode_set(USART2_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART2_RX_GPIO_PINx);
+ gpio_output_options_set(USART2_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART2_RX_GPIO_PINx);
break;
case UART3:
- gpio_af_set(UART3_GPIO_PORT, GPIO_AF_8, UART3_TX_PIN);
- gpio_mode_set(UART3_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART3_TX_PIN);
- gpio_output_options_set(UART3_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART3_TX_PIN);
- gpio_af_set(UART3_GPIO_PORT, GPIO_AF_8, UART3_RX_PIN);
- gpio_mode_set(UART3_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART3_RX_PIN);
- gpio_output_options_set(UART3_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART3_RX_PIN);
+ gpio_af_set(UART3_GPIOx, UART3_GPIO_AFx, UART3_TX_GPIO_PINx);
+ gpio_mode_set(UART3_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART3_TX_GPIO_PINx);
+ gpio_output_options_set(UART3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART3_TX_GPIO_PINx);
+ gpio_af_set(UART3_GPIOx, UART3_GPIO_AFx, UART3_RX_GPIO_PINx);
+ gpio_mode_set(UART3_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART3_RX_GPIO_PINx);
+ gpio_output_options_set(UART3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART3_RX_GPIO_PINx);
break;
case UART4:
- gpio_af_set(UART4_GPIO_TX_PORT, GPIO_AF_8, UART4_TX_PIN);
- gpio_mode_set(UART4_GPIO_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART4_TX_PIN);
- gpio_output_options_set(UART4_GPIO_TX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART4_TX_PIN);
- gpio_af_set(UART4_GPIO_RX_PORT, GPIO_AF_8, UART4_RX_PIN);
- gpio_mode_set(UART4_GPIO_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART4_RX_PIN);
- gpio_output_options_set(UART4_GPIO_RX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART4_RX_PIN);
+ gpio_af_set(UART4_TX_GPIOx, UART4_GPIO_AFx, UART4_TX_GPIO_PINx);
+ gpio_mode_set(UART4_TX_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART4_TX_GPIO_PINx);
+ gpio_output_options_set(UART4_TX_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART4_TX_GPIO_PINx);
+ gpio_af_set(UART4_RX_GPIOx, UART4_GPIO_AFx, UART4_RX_GPIO_PINx);
+ gpio_mode_set(UART4_RX_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART4_RX_GPIO_PINx);
+ gpio_output_options_set(UART4_RX_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART4_RX_GPIO_PINx);
break;
#if defined (USART5)
case USART5:
- gpio_af_set(USART5_GPIO_PORT, GPIO_AF_8, USART5_TX_PIN);
- gpio_mode_set(USART5_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART5_TX_PIN);
- gpio_output_options_set(USART5_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART5_TX_PIN);
- gpio_af_set(USART5_GPIO_PORT, GPIO_AF_8, USART5_RX_PIN);
- gpio_mode_set(USART5_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART5_RX_PIN);
- gpio_output_options_set(USART5_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART5_RX_PIN);
+ gpio_af_set(USART5_GPIOx, USART5_GPIO_AFx, USART5_TX_GPIO_PINx);
+ gpio_mode_set(USART5_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART5_TX_GPIO_PINx);
+ gpio_output_options_set(USART5_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART5_TX_GPIO_PINx);
+ gpio_af_set(USART5_GPIOx, USART5_GPIO_AFx, USART5_RX_GPIO_PINx);
+ gpio_mode_set(USART5_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART5_RX_GPIO_PINx);
+ gpio_output_options_set(USART5_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, USART5_RX_GPIO_PINx);
break;
#endif
#if defined (UART6)
case UART6:
- gpio_af_set(UART6_GPIO_PORT, GPIO_AF_8, UART6_TX_PIN);
- gpio_mode_set(UART6_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART6_TX_PIN);
- gpio_output_options_set(UART6_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART6_TX_PIN);
- gpio_af_set(UART6_GPIO_PORT, GPIO_AF_8, UART6_RX_PIN);
- gpio_mode_set(UART6_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART6_RX_PIN);
- gpio_output_options_set(UART6_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART6_RX_PIN);
+ gpio_af_set(UART6_GPIOx, UART6_GPIO_AFx, UART6_TX_GPIO_PINx);
+ gpio_mode_set(UART6_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART6_TX_GPIO_PINx);
+ gpio_output_options_set(UART6_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART6_TX_GPIO_PINx);
+ gpio_af_set(UART6_GPIOx, UART6_GPIO_AFx, UART6_RX_GPIO_PINx);
+ gpio_mode_set(UART6_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART6_RX_GPIO_PINx);
+ gpio_output_options_set(UART6_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART6_RX_GPIO_PINx);
break;
#endif
#if defined (UART7)
case UART7:
- gpio_af_set(UART7_GPIO_PORT, GPIO_AF_8, UART7_TX_PIN);
- gpio_mode_set(UART7_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART7_TX_PIN);
- gpio_output_options_set(UART7_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART7_TX_PIN);
- gpio_af_set(UART7_GPIO_PORT, GPIO_AF_8, UART7_RX_PIN);
- gpio_mode_set(UART7_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART7_RX_PIN);
- gpio_output_options_set(UART7_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART7_RX_PIN);
+ gpio_af_set(UART7_GPIOx, UART7_GPIO_AFx, UART7_TX_GPIO_PINx);
+ gpio_mode_set(UART7_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART7_TX_GPIO_PINx);
+ gpio_output_options_set(UART7_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART7_TX_GPIO_PINx);
+ gpio_af_set(UART7_GPIOx, UART7_GPIO_AFx, UART7_RX_GPIO_PINx);
+ gpio_mode_set(UART7_GPIOx, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART7_RX_GPIO_PINx);
+ gpio_output_options_set(UART7_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, UART7_RX_GPIO_PINx);
break;
#endif
default:
@@ -259,8 +259,8 @@ void _gpio_init(const uint32_t usart_periph) {
#endif
void gd32_uart_begin(const uint32_t usart_periph, uint32_t baudrate, uint32_t bits, uint32_t parity, uint32_t stop_bits) {
- _rcu_periph_clock_enable(usart_periph);
- _gpio_init(usart_periph);
+ rcu_config(usart_periph);
+ gpio_config(usart_periph);
usart_deinit(usart_periph);
@@ -307,7 +307,11 @@ void gd32_uart_transmit(const uint32_t usart_periph, const uint8_t *data, uint32
while (length-- != 0) {
while (RESET == usart_flag_get(usart_periph, USART_FLAG_TBE))
;
- USART_DATA(usart_periph) = ((uint16_t) USART_DATA_DATA & *data++);
+#if defined (GD32H7XX)
+ USART_TDATA(usart_periph) = USART_TDATA_TDATA & (uint32_t)*data++;
+#else
+ USART_DATA(usart_periph) = (USART_DATA_DATA & *data++);
+#endif
}
}
@@ -318,6 +322,10 @@ void gd32_uart_transmit_string(const uint32_t usart_periph, const char *data) {
while (*data != '\0') {
while (RESET == usart_flag_get(USART0, USART_FLAG_TBE))
;
- USART_DATA(usart_periph) = ((uint16_t) USART_DATA_DATA & *data++);
+#if defined (GD32H7XX)
+ USART_TDATA(usart_periph) = USART_TDATA_TDATA & (uint32_t)*data++;
+#else
+ USART_DATA(usart_periph) = (USART_DATA_DATA & *data++);
+#endif
}
}
diff --git a/lib-gd32/src/mac_address.cpp b/lib-gd32/src/mac_address.cpp
index fe9b2d4..0306485 100644
--- a/lib-gd32/src/mac_address.cpp
+++ b/lib-gd32/src/mac_address.cpp
@@ -2,7 +2,7 @@
* @file mac_address.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,12 +29,15 @@
#include "debug.h"
void mac_address_get(uint8_t paddr[]) {
-#if !defined (GD32F4XX)
- const auto mac_hi = *(volatile uint32_t *) (0x1FFFF7E8);
- const auto mac_lo = *(volatile uint32_t *) (0x1FFFF7EC);
-#else
+#if defined (GD32H7XX)
+ const auto mac_hi = *(volatile uint32_t *) (0x1FF0F7E8);
+ const auto mac_lo = *(volatile uint32_t *) (0x1FF0F7EC);
+#elif defined (GD32F4XX)
const auto mac_hi = *(volatile uint32_t *) (0x1FFF7A10);
const auto mac_lo = *(volatile uint32_t *) (0x1FFF7A14);
+#else
+ const auto mac_hi = *(volatile uint32_t *) (0x1FFFF7E8);
+ const auto mac_lo = *(volatile uint32_t *) (0x1FFFF7EC);
#endif
paddr[0] = 2;
diff --git a/lib-gd32/src/ptp/gd32_ptp.cpp b/lib-gd32/src/ptp/gd32_ptp.cpp
new file mode 100644
index 0000000..a027d5c
--- /dev/null
+++ b/lib-gd32/src/ptp/gd32_ptp.cpp
@@ -0,0 +1,183 @@
+/**
+ * @file gd32_ptp.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include
+#include
+#include
+#include
+
+#include "gd32_ptp.h"
+#include "gd32.h"
+
+#include "debug.h"
+
+extern "C" void console_error(const char *);
+
+#if defined (GD32H7XX)
+# define enet_interrupt_disable(x) enet_interrupt_disable(ENETx, x)
+# define enet_ptp_feature_enable(x) enet_ptp_feature_enable(ENETx, x)
+# define enet_ptp_subsecond_increment_config(x) enet_ptp_subsecond_increment_config(ENETx, x)
+# define enet_ptp_timestamp_function_config(x) enet_ptp_timestamp_function_config(ENETx, x)
+# define enet_ptp_timestamp_addend_config(x) enet_ptp_timestamp_addend_config(ENETx, x)
+# define enet_ptp_timestamp_update_config(x,y,z) enet_ptp_timestamp_update_config(ENETx, x, y, z)
+# define enet_ptp_system_time_get(x) enet_ptp_system_time_get(ENETx, x)
+static FlagStatus enet_ptpflagstatus_get(const uint32_t flag) {
+ FlagStatus bitstatus = RESET;
+
+ if (0 != (ENET_PTP_TSCTL(ENETx) & flag)) {
+ bitstatus = SET;
+ }
+
+ return bitstatus;
+}
+#else
+static FlagStatus enet_ptpflagstatus_get(const uint32_t flag) {
+ FlagStatus bitstatus = RESET;
+
+ if (0 != (ENET_PTP_TSCTL & flag)) {
+ bitstatus = SET;
+ }
+
+ return bitstatus;
+}
+#endif
+
+static void ptp_start(const uint32_t init_sec, const uint32_t init_subsec, [[maybe_unused]] const uint32_t carry_cfg, const uint32_t accuracy_cfg) {
+ DEBUG_ENTRY
+
+ enet_interrupt_disable(ENET_MAC_INT_TMSTIM);
+
+#if defined(GD32F4XX) || defined (GD32H7XX)
+ enet_ptp_feature_enable(ENET_ALL_RX_TIMESTAMP | ENET_RXTX_TIMESTAMP);
+#else
+ enet_ptp_feature_enable(ENET_RXTX_TIMESTAMP);
+#endif
+ enet_ptp_subsecond_increment_config(accuracy_cfg);
+
+ enet_ptp_timestamp_addend_config(carry_cfg);
+
+ enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
+ while(enet_ptpflagstatus_get(ENET_PTP_ADDEND_UPDATE) == SET);
+
+ enet_ptp_timestamp_function_config(ENET_PTP_FINEMODE);
+
+ enet_ptp_timestamp_update_config(ENET_PTP_ADD_TO_TIME, init_sec, init_subsec);
+ enet_ptp_timestamp_function_config(ENET_PTP_SYSTIME_INIT);
+ while(enet_ptpflagstatus_get(ENET_PTP_SYSTIME_INIT) == SET);
+
+ DEBUG_EXIT
+}
+
+void gd32_ptp_start() {
+ DEBUG_ENTRY
+ DEBUG_PRINTF("PTP_TICK=%u", gd32::ptp::PTP_TICK);
+ DEBUG_PRINTF("ADJ_FREQ_BASE_INCREMENT=%u", gd32::ptp::ADJ_FREQ_BASE_INCREMENT);
+ DEBUG_PRINTF("ADJ_FREQ_BASE_ADDEND=x%X", gd32::ptp::ADJ_FREQ_BASE_ADDEND);
+
+ struct tm tmbuf;
+ memset(&tmbuf, 0, sizeof(struct tm));
+ tmbuf.tm_mday = _TIME_STAMP_DAY_; // The day of the month, in the range 1 to 31.
+ tmbuf.tm_mon = _TIME_STAMP_MONTH_ - 1; // The number of months since January, in the range 0 to 11.
+ tmbuf.tm_year = _TIME_STAMP_YEAR_ - 1900; // The number of years since 1900.
+
+ ptp_start(mktime(&tmbuf), 0, gd32::ptp::ADJ_FREQ_BASE_ADDEND, gd32::ptp::ADJ_FREQ_BASE_INCREMENT);
+
+#ifndef NDEBUG
+ struct timeval tv;
+ gettimeofday(&tv, nullptr);
+ auto *tm = localtime(&tv.tv_sec);
+
+ DEBUG_PRINTF("%.2d-%.2d-%.4d %.2d:%.2d:%.2d.%.6d", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec, static_cast(tv.tv_usec));
+#endif
+ DEBUG_EXIT
+}
+
+void gd32_ptp_get_time(gd32::ptp::ptptime *ptp_time) {
+ enet_ptp_systime_struct systime;
+
+ enet_ptp_system_time_get(&systime);
+
+ ptp_time->tv_sec = systime.second;
+#if !defined (GD32F4XX)
+ ptp_time->tv_nsec = systime.nanosecond;
+#else
+ ptp_time->tv_nsec = gd32::ptp_subsecond_2_nanosecond(systime.subsecond);
+#endif
+}
+
+void gd32_ptp_set_time(const gd32::ptp::ptptime *ptp_time) {
+ const auto nSign = ENET_PTP_ADD_TO_TIME;
+ const auto nSecond = ptp_time->tv_sec;
+ const auto nNanoSecond = ptp_time->tv_nsec;
+ const auto nSubSecond = gd32::ptp_nanosecond_2_subsecond(nNanoSecond);
+
+ enet_ptp_timestamp_update_config(nSign, nSecond, nSubSecond);
+ enet_ptp_timestamp_function_config(ENET_PTP_SYSTIME_INIT);
+ while(enet_ptpflagstatus_get(ENET_PTP_SYSTIME_INIT) == SET);
+}
+
+void gd32_ptp_update_time(const gd32::ptp::time_t *pTime) {
+ uint32_t nSign;
+ uint32_t nSecond;
+ uint32_t nNanoSecond;
+
+ if (pTime->tv_sec < 0 || (pTime->tv_sec == 0 && pTime->tv_nsec < 0)) {
+ nSign = ENET_PTP_SUBSTRACT_FROM_TIME;
+ nSecond = -pTime->tv_sec;
+ nNanoSecond = -pTime->tv_nsec;
+ } else {
+ nSign = ENET_PTP_ADD_TO_TIME;
+ nSecond = pTime->tv_sec;
+ nNanoSecond = pTime->tv_nsec;
+ }
+
+ const auto nSubSecond = gd32::ptp_nanosecond_2_subsecond(nNanoSecond);
+#if defined (GD32H7XX)
+ const auto nAddend = ENET_PTP_TSADDEND(ENETx);
+#else
+ const auto nAddend = ENET_PTP_TSADDEND;
+#endif
+
+ enet_ptp_timestamp_update_config(nSign, nSecond, nSubSecond);
+ enet_ptp_timestamp_function_config(ENET_PTP_SYSTIME_UPDATE);
+ while(enet_ptpflagstatus_get(ENET_PTP_SYSTIME_UPDATE) == SET);
+
+ enet_ptp_timestamp_addend_config(nAddend);
+ enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
+}
+
+bool gd32_adj_frequency(const int32_t adjust_ppb) {
+ const uint32_t addend = gd32::ptp::ADJ_FREQ_BASE_ADDEND + static_cast((((static_cast(gd32::ptp::ADJ_FREQ_BASE_ADDEND)) * adjust_ppb) / 1000000000ULL));
+
+ enet_ptp_timestamp_addend_config(addend);
+
+ const auto reval = enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
+
+ if (reval == ERROR) {
+ console_error("enet_ptp_timestamp_addend_config\n");
+ }
+
+ return reval != ERROR;
+}
diff --git a/lib-gd32/src/softuart0/gd32_uart0.c b/lib-gd32/src/softuart0/gd32_uart0.c
deleted file mode 100644
index 7f8dee8..0000000
--- a/lib-gd32/src/softuart0/gd32_uart0.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/**
- * @file gd32_uart0.c
- *
- */
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#if defined (NDEBUG)
-# undef NDEBUG
-#endif
-
-#include
-#include
-#include
-
-#include "gd32.h"
-
-#if !defined (SOFTUART_TX_PINx)
-# define SOFTUART_TX_PINx GPIO_PIN_9
-# define SOFTUART_TX_GPIOx GPIOA
-# define SOFTUART_TX_RCU_GPIOx RCU_GPIOA
-#endif
-
-#if defined (GD32F4XX)
-# define TIMER_CLOCK (APB2_CLOCK_FREQ * 2)
-#else
-# define TIMER_CLOCK (APB2_CLOCK_FREQ)
-#endif
-
-#define BAUD_RATE (115200U)
-#define TIMER_PERIOD ((TIMER_CLOCK / BAUD_RATE) - 1U)
-#define BUFFER_SIZE (128U)
-
-typedef enum {
- SOFTUART_IDLE,
- SOFTUART_START_BIT,
- SOFTUART_DATA,
- SOFTUART_STOP_BIT,
-} softuart_state;
-
-struct circular_buffer {
- uint8_t buffer[BUFFER_SIZE];
- uint32_t head;
- uint32_t tail;
- bool full;
-};
-
-static volatile softuart_state s_state;
-static volatile struct circular_buffer s_circular_buffer;
-static volatile uint8_t s_data;
-static volatile uint8_t s_shift;
-
-static bool is_circular_buffer_empty() {
- return (!s_circular_buffer.full && (s_circular_buffer.head == s_circular_buffer.tail));
-}
-
-void TIMER0_UP_TIMER9_IRQHandler() {
- GPIO_BOP(LED3_GPIOx) = LED3_GPIO_PINx;
-
- switch (s_state) {
- case SOFTUART_IDLE:
- break;
- case SOFTUART_START_BIT:
- GPIO_BC(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
-
- s_state = SOFTUART_DATA;
- s_data = s_circular_buffer.buffer[s_circular_buffer.tail];
- s_circular_buffer.tail = (s_circular_buffer.tail + 1) & (BUFFER_SIZE - 1);
- s_circular_buffer.full = false;
- s_shift = 0;
- break;
- case SOFTUART_DATA:
- if (s_data & (1U << s_shift)) {
- GPIO_BOP(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
- } else {
- GPIO_BC(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
- }
-
- s_shift++;
-
- if (s_shift == 8) {
- s_state = SOFTUART_STOP_BIT;
- }
- break;
- case SOFTUART_STOP_BIT:
- GPIO_BOP(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
-
- if (is_circular_buffer_empty()) {
- s_state = SOFTUART_IDLE;
- timer_disable(TIMER9);
- } else {
- s_state = SOFTUART_START_BIT;
- }
- break;
- default:
- break;
- }
-
- timer_interrupt_flag_clear(TIMER9, TIMER_INT_FLAG_UP);
-
- GPIO_BC(LED3_GPIOx) = LED3_GPIO_PINx;
-}
-
-void uart0_init() {
- rcu_periph_clock_enable (LED3_RCU_GPIOx);
-#if !defined (GD32F4XX)
- gpio_init(LED3_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LED3_GPIO_PINx);
-#else
- gpio_mode_set(LED3_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, LED3_GPIO_PINx);
- gpio_output_options_set(LED3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LED3_GPIO_PINx);
- gpio_af_set(LED3_GPIOx, GPIO_AF_0, LED3_GPIO_PINx);
-#endif
-
- GPIO_BC(LED3_GPIOx) = LED3_GPIO_PINx;
-
- rcu_periph_clock_enable (SOFTUART_TX_RCU_GPIOx);
-
-#if !defined (GD32F4XX)
- gpio_init(SOFTUART_TX_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SOFTUART_TX_PINx);
-#else
- gpio_mode_set(SOFTUART_TX_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, SOFTUART_TX_PINx);
- gpio_output_options_set(SOFTUART_TX_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SOFTUART_TX_PINx);
- gpio_af_set(SOFTUART_TX_GPIOx, GPIO_AF_0, SOFTUART_TX_PINx);
-#endif
-
- GPIO_BOP(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
-
- rcu_periph_clock_enable(RCU_TIMER9);
-
- timer_deinit(TIMER9);
-
- timer_parameter_struct timer_initpara;
- timer_initpara.prescaler = 0;
- timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
- timer_initpara.counterdirection = TIMER_COUNTER_UP;
- timer_initpara.period = TIMER_PERIOD;
- timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
-
- timer_init(TIMER9, &timer_initpara);
-
- timer_flag_clear(TIMER9, ~0);
- timer_interrupt_flag_clear(TIMER9, ~0);
-
- timer_interrupt_enable(TIMER9, TIMER_INT_UP);
-
- NVIC_SetPriority(TIMER0_UP_TIMER9_IRQn, 2);
- NVIC_EnableIRQ(TIMER0_UP_TIMER9_IRQn);
-}
-
-static void _putc(int c) {
- while (s_circular_buffer.full)
- ;
-
- s_circular_buffer.buffer[s_circular_buffer.head] = (uint8_t) c;
- s_circular_buffer.head = (s_circular_buffer.head + 1) & (BUFFER_SIZE - 1);
- s_circular_buffer.full = s_circular_buffer.head == s_circular_buffer.tail;
-
- if (s_state == SOFTUART_IDLE) {
- timer_counter_value_config(TIMER9, 0);
- timer_enable(TIMER9);
- s_state = SOFTUART_START_BIT;
- }
-}
-
-void uart0_putc(int c) {
- if (c == '\n') {
- _putc('\r');
- }
-
- _putc(c);
-}
diff --git a/lib-gd32/src/softuart0/uart0.cpp b/lib-gd32/src/softuart0/uart0.cpp
new file mode 100644
index 0000000..1402773
--- /dev/null
+++ b/lib-gd32/src/softuart0/uart0.cpp
@@ -0,0 +1,234 @@
+/**
+ * @file uart0.c
+ *
+ */
+/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if !defined (CONFIG_REMOTECONFIG_MINIMUM)
+# pragma GCC push_options
+# pragma GCC optimize ("O2")
+#endif
+
+#include
+#include
+
+#include "gd32.h"
+
+#include "debug.h"
+
+#if defined (GD32H7XX)
+# define TIMERx TIMER15
+# define RCU_TIMERx RCU_TIMER15
+# define TIMERx_IRQHandler TIMER15_IRQHandler
+# define TIMERx_IRQn TIMER15_IRQn
+#else
+# define TIMERx TIMER9
+# define RCU_TIMERx RCU_TIMER9
+# define TIMERx_IRQHandler TIMER0_UP_TIMER9_IRQHandler
+# define TIMERx_IRQn TIMER0_UP_TIMER9_IRQn
+#endif
+
+#if defined (GD32H7XX)
+# define TIMER_CLOCK_FREQ (AHB_CLOCK_FREQ)
+#elif defined (GD32F4XX)
+# define TIMER_CLOCK_FREQ (APB2_CLOCK_FREQ * 2)
+#else
+# define TIMER_CLOCK_FREQ (APB2_CLOCK_FREQ)
+#endif
+
+#if !defined (SOFTUART_TX_PINx)
+# define SOFTUART_TX_PINx GPIO_PIN_9
+# define SOFTUART_TX_GPIOx GPIOA
+# define SOFTUART_TX_RCU_GPIOx RCU_GPIOA
+#endif
+
+#define BAUD_RATE (115200U)
+#define TIMER_PERIOD ((TIMER_CLOCK_FREQ / BAUD_RATE) - 1U)
+#define BUFFER_SIZE (128U)
+
+typedef enum {
+ SOFTUART_IDLE, SOFTUART_START_BIT, SOFTUART_DATA, SOFTUART_STOP_BIT,
+} softuart_state;
+
+struct circular_buffer {
+ uint8_t buffer[BUFFER_SIZE];
+ uint32_t head;
+ uint32_t tail;
+ bool full;
+};
+
+static volatile softuart_state s_state;
+static volatile struct circular_buffer s_circular_buffer;
+static volatile uint8_t s_data;
+static volatile uint8_t s_shift;
+
+static bool is_circular_buffer_empty() {
+ return (!s_circular_buffer.full && (s_circular_buffer.head == s_circular_buffer.tail));
+}
+
+extern "C" {
+void TIMERx_IRQHandler() {
+ const auto nIntFlag = TIMER_INTF(TIMERx);
+
+ if ((nIntFlag & TIMER_INT_FLAG_UP) == TIMER_INT_FLAG_UP) {
+#if defined (LED3_GPIO_PINx)
+ GPIO_BOP(LED3_GPIOx) = LED3_GPIO_PINx;
+#endif
+
+ switch (s_state) {
+ case SOFTUART_IDLE:
+ break;
+ case SOFTUART_START_BIT:
+ GPIO_BC(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
+
+ s_state = SOFTUART_DATA;
+ s_data = s_circular_buffer.buffer[s_circular_buffer.tail];
+ s_circular_buffer.tail = (s_circular_buffer.tail + 1) & (BUFFER_SIZE - 1);
+ s_circular_buffer.full = false;
+ s_shift = 0;
+ break;
+ case SOFTUART_DATA:
+ if (s_data & (1U << s_shift)) {
+ GPIO_BOP(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
+ } else {
+ GPIO_BC(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
+ }
+
+ s_shift++;
+
+ if (s_shift == 8) {
+ s_state = SOFTUART_STOP_BIT;
+ }
+ break;
+ case SOFTUART_STOP_BIT:
+ GPIO_BOP(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
+
+ if (is_circular_buffer_empty()) {
+ s_state = SOFTUART_IDLE;
+ timer_disable(TIMERx);
+ } else {
+ s_state = SOFTUART_START_BIT;
+ }
+ break;
+ default:
+ break;
+ }
+
+#if defined (LED3_GPIO_PINx)
+ GPIO_BC(LED3_GPIOx) = LED3_GPIO_PINx;
+#endif
+ }
+
+ TIMER_INTF(TIMERx) = static_cast(~nIntFlag);
+}
+
+void uart0_init() {
+ s_state = SOFTUART_IDLE;
+ s_circular_buffer.head = 0;
+ s_circular_buffer.tail = 0;
+ s_circular_buffer.full = false;
+
+#if defined (LED3_GPIO_PINx)
+ rcu_periph_clock_enable (LED3_RCU_GPIOx);
+# if defined (GPIO_INIT)
+ gpio_init(LED3_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LED3_GPIO_PINx);
+# else
+ gpio_mode_set(LED3_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, LED3_GPIO_PINx);
+ gpio_output_options_set(LED3_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, LED3_GPIO_PINx);
+# endif
+
+ GPIO_BC(LED3_GPIOx) = LED3_GPIO_PINx;
+#endif
+
+ rcu_periph_clock_enable (SOFTUART_TX_RCU_GPIOx);
+
+#if defined (GPIO_INIT)
+ gpio_init(SOFTUART_TX_GPIOx, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SOFTUART_TX_PINx);
+#else
+ gpio_mode_set(SOFTUART_TX_GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLDOWN, SOFTUART_TX_PINx);
+ gpio_output_options_set(SOFTUART_TX_GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED, SOFTUART_TX_PINx);
+#endif
+
+ GPIO_BOP(SOFTUART_TX_GPIOx) = SOFTUART_TX_PINx;
+
+ rcu_periph_clock_enable(RCU_TIMERx);
+
+ timer_deinit(TIMERx);
+
+ timer_parameter_struct timer_initpara;
+ timer_struct_para_init(&timer_initpara);
+
+ timer_initpara.prescaler = 0;
+ timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
+ timer_initpara.counterdirection = TIMER_COUNTER_UP;
+ timer_initpara.period = TIMER_PERIOD;
+ timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
+ timer_initpara.repetitioncounter = 0;
+
+ timer_init(TIMERx, &timer_initpara);
+
+ timer_flag_clear(TIMERx, ~0);
+ timer_interrupt_flag_clear(TIMERx, ~0);
+
+ timer_interrupt_enable(TIMERx, TIMER_INT_UP);
+
+ NVIC_SetPriority(TIMERx_IRQn, 2);
+ NVIC_EnableIRQ(TIMERx_IRQn);
+}
+
+static void _putc(const int c) {
+ //FIXME deadlock when timer is not running
+ while (s_circular_buffer.full)
+ ;
+
+ s_circular_buffer.buffer[s_circular_buffer.head] = (uint8_t) c;
+ s_circular_buffer.head = (s_circular_buffer.head + 1) & (BUFFER_SIZE - 1);
+ s_circular_buffer.full = s_circular_buffer.head == s_circular_buffer.tail;
+
+ if (s_state == SOFTUART_IDLE) {
+ timer_counter_value_config(TIMERx, 0);
+ timer_enable(TIMERx);
+ s_state = SOFTUART_START_BIT;
+ }
+}
+
+void uart0_putc(int c) {
+ if (c == '\n') {
+ _putc('\r');
+ }
+
+ _putc(c);
+}
+
+void uart0_puts(const char *s) {
+ while (*s != '\0') {
+ if (*s == '\n') {
+ uart0_putc('\r');
+ }
+ uart0_putc(*s++);
+ }
+
+ do {
+ __DMB();
+ } while (!is_circular_buffer_empty());
+}
+}
diff --git a/lib-gd32/src/systick.c b/lib-gd32/src/systick/systick.cpp
similarity index 77%
rename from lib-gd32/src/systick.c
rename to lib-gd32/src/systick/systick.cpp
index 2e9e672..f269c58 100644
--- a/lib-gd32/src/systick.c
+++ b/lib-gd32/src/systick/systick.cpp
@@ -2,7 +2,7 @@
* @file systick.c
*
*/
-/* Copyright (C) 2021 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,23 +23,24 @@
* THE SOFTWARE.
*/
-#include
+#include
#include "gd32.h"
-volatile uint32_t s_nSysTickMillis;
+volatile uint32_t gv_nSysTickMillis;
-void systick_config(void) {
- /* setup systick timer for 1000Hz interrupts */
+extern "C" {
+void systick_config() {
+ /* Setup systick timer for 1000Hz interrupts */
if (SysTick_Config(SystemCoreClock / 1000U)) {
- /* capture error */
while (1) {
}
}
- /* configure the systick handler priority */
- NVIC_SetPriority(SysTick_IRQn, 0x00U);
+
+ NVIC_SetPriority(SysTick_IRQn, (1UL<<__NVIC_PRIO_BITS)-1UL); // Lowest priority
}
-void SysTick_Handler(void) {
- s_nSysTickMillis++;
+void SysTick_Handler() {
+ gv_nSysTickMillis++;
+}
}
diff --git a/lib-gd32/src/timer6.cpp b/lib-gd32/src/timer6.cpp
new file mode 100644
index 0000000..0cbf908
--- /dev/null
+++ b/lib-gd32/src/timer6.cpp
@@ -0,0 +1,86 @@
+/**
+ * @file timer6.cpp
+ *
+ */
+/* Copyright (C) 2024 by Arjan van Vught mailto:info@gd32-dmx.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma GCC push_options
+#pragma GCC optimize ("O2")
+
+#include "gd32.h"
+
+struct HwTimersSeconds g_Seconds;
+
+extern "C" {
+#if defined (CONFIG_TIMER6_HAVE_NO_IRQ_HANDLER)
+void TIMER6_IRQHandler() {
+ const auto nIntFlag = TIMER_INTF(TIMER6);
+
+ if ((nIntFlag & TIMER_INT_FLAG_UP) == TIMER_INT_FLAG_UP) {
+ g_Seconds.nUptime++;
+ }
+
+ TIMER_INTF(TIMER6) = static_cast(~nIntFlag);
+}
+#endif
+}
+
+void timer6_config() {
+ g_Seconds.nUptime = 0;
+
+ rcu_periph_clock_enable(RCU_TIMER6);
+ timer_deinit(TIMER6);
+
+ timer_parameter_struct timer_initpara;
+ timer_struct_para_init(&timer_initpara);
+
+ timer_initpara.prescaler = TIMER_PSC_10KHZ;
+ timer_initpara.period = (10000 - 1); // 1 second
+ timer_init(TIMER6, &timer_initpara);
+
+ timer_counter_value_config(TIMER6, 0);
+
+ timer_interrupt_flag_clear(TIMER6, ~0);
+
+ timer_interrupt_enable(TIMER6, TIMER_INT_UP);
+
+ NVIC_SetPriority(TIMER6_IRQn, (1UL<<__NVIC_PRIO_BITS)-1UL); // Lowest priority
+ NVIC_EnableIRQ(TIMER6_IRQn);
+
+ timer_enable(TIMER6);
+}
+
+uint32_t timer6_get_elapsed_milliseconds() {
+ const auto nUptimeFirst = g_Seconds.nUptime;
+ auto nTimerCount = TIMER_CNT(TIMER6);
+ const auto nUptimeSecond = g_Seconds.nUptime;
+
+ // Check for consistency
+ if (__builtin_expect((nUptimeFirst == nUptimeSecond), 1)) {
+ // No overflow detected, return the calculated time
+ return (nUptimeFirst * 1000U) + (nTimerCount / 10U);
+ }
+
+ // Potential overflow detected, re-read the timer count
+ nTimerCount = TIMER_CNT(TIMER6);
+ return (nUptimeSecond * 1000U) + (nTimerCount / 10U);
+}
diff --git a/lib-gd32/src/gd32_uart0.c b/lib-gd32/src/uart0.cpp
similarity index 81%
rename from lib-gd32/src/gd32_uart0.c
rename to lib-gd32/src/uart0.cpp
index 17335bd..7562f3b 100644
--- a/lib-gd32/src/gd32_uart0.c
+++ b/lib-gd32/src/uart0.cpp
@@ -1,8 +1,8 @@
/**
- * @file gd32_uart0.c
+ * @file uart0.cpp
*
*/
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,23 +23,13 @@
* THE SOFTWARE.
*/
-#include
-#include
-
-extern void uart0_putc(int);
+#include
+#include
static char s_buffer[128];
-void uart0_puts(const char *s) {
- while (*s != '\0') {
- if (*s == '\n') {
- uart0_putc('\r');
- }
- uart0_putc(*s++);
- }
-
-// uart0_putc('\n'); //TODO Add '\n'
-}
+extern "C" {
+void uart0_putc(int);
int uart0_printf(const char *fmt, ...) {
va_list arp;
@@ -61,3 +51,4 @@ int uart0_printf(const char *fmt, ...) {
return i;
}
+}
diff --git a/lib-gd32/src/uart0/gd32_uart0.c b/lib-gd32/src/uart0/uart0.cpp
similarity index 66%
rename from lib-gd32/src/uart0/gd32_uart0.c
rename to lib-gd32/src/uart0/uart0.cpp
index e7c531f..4adcc13 100644
--- a/lib-gd32/src/uart0/gd32_uart0.c
+++ b/lib-gd32/src/uart0/uart0.cpp
@@ -1,8 +1,8 @@
/**
- * @file gd32_uart0.c
+ * @file uart0.cpp
*
*/
-/* Copyright (C) 2021 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,12 +23,13 @@
* THE SOFTWARE.
*/
-#include
-#include
+#include
+#include
#include "gd32.h"
#include "gd32_uart.h"
+extern "C" {
void uart0_init(void) {
gd32_uart_begin(USART0, 115200U, GD32_UART_BITS_8, GD32_UART_PARITY_NONE, GD32_UART_STOP_1BIT);
}
@@ -37,11 +38,46 @@ void uart0_putc(int c) {
if (c == '\n') {
while (RESET == usart_flag_get(USART0, USART_FLAG_TBE))
;
+#if defined (GD32H7XX)
+ USART_TDATA(USART0) = USART_TDATA_TDATA & (uint32_t)'\r';
+#else
USART_DATA(USART0) = ((uint16_t) USART_DATA_DATA & (uint8_t) '\r');
+#endif
}
while (RESET == usart_flag_get(USART0, USART_FLAG_TBE))
;
-
+#if defined (GD32H7XX)
+ USART_TDATA(USART0) = USART_TDATA_TDATA & (uint32_t) c;
+#else
USART_DATA(USART0) = ((uint16_t) USART_DATA_DATA & (uint8_t) c);
+#endif
+}
+
+void uart0_puts(const char *s) {
+ while (*s != '\0') {
+ if (*s == '\n') {
+ uart0_putc('\r');
+ }
+ uart0_putc(*s++);
+ }
+}
+
+int uart0_getc(void) {
+ if (__builtin_expect((!gd32_usart_flag_get(USART0)), 1)) {
+ return EOF;
+ }
+
+#if defined (GD32H7XX)
+ const auto c = static_cast(USART_RDATA(USART0));
+#else
+ const auto c = static_cast(USART_DATA(USART0));
+#endif
+
+#if defined (UART0_ECHO)
+ uart0_putc(c);
+#endif
+
+ return c;
+}
}
diff --git a/lib-gd32/src/udelay.cpp b/lib-gd32/src/udelay.cpp
index 81cb713..737780d 100644
--- a/lib-gd32/src/udelay.cpp
+++ b/lib-gd32/src/udelay.cpp
@@ -2,7 +2,7 @@
* @file udelay.cpp
*
*/
-/* Copyright (C) 2021-2022 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,9 +28,9 @@
#include "gd32.h"
-static constexpr auto TICKS_PER_US = (MCU_CLOCK_FREQ / 1000000U);
+static constexpr uint32_t TICKS_PER_US = (MCU_CLOCK_FREQ / 1000000U);
-void udelay_init(void) {
+void udelay_init() {
assert(MCU_CLOCK_FREQ == SystemCoreClock);
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
@@ -38,21 +38,20 @@ void udelay_init(void) {
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
}
-void udelay(uint32_t nUs, uint32_t nOffsetCYCCNT) {
- const auto nTicks = nUs * TICKS_PER_US;
+void udelay(uint32_t nMicros, uint32_t nOffsetMicros) {
+ const auto nTicks = nMicros * TICKS_PER_US;
uint32_t nTicksCount = 0;
- uint32_t nTicksNow;
uint32_t nTicksPrevious;
- if (nOffsetCYCCNT == 0) {
+ if (nOffsetMicros == 0) {
nTicksPrevious = DWT->CYCCNT;
} else {
- nTicksPrevious = nOffsetCYCCNT;
+ nTicksPrevious = nOffsetMicros;
}
while (1) {
- nTicksNow = DWT->CYCCNT;
+ const auto nTicksNow = DWT->CYCCNT;
if (nTicksNow != nTicksPrevious) {
if (nTicksNow > nTicksPrevious) {
diff --git a/lib-hal/.cproject b/lib-hal/.cproject
index 49fbcf9..e87ad7c 100644
--- a/lib-hal/.cproject
+++ b/lib-hal/.cproject
@@ -5,7 +5,7 @@
-
+
@@ -16,48 +16,130 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
+
+
-
-
+
-
-
+
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib-hal/.settings/language.settings.xml b/lib-hal/.settings/language.settings.xml
index e0cd202..f2f25c8 100644
--- a/lib-hal/.settings/language.settings.xml
+++ b/lib-hal/.settings/language.settings.xml
@@ -2,7 +2,10 @@
-
+
+
+
+
diff --git a/lib-hal/.settings/org.eclipse.ltk.core.refactoring.prefs b/lib-hal/.settings/org.eclipse.ltk.core.refactoring.prefs
new file mode 100644
index 0000000..b196c64
--- /dev/null
+++ b/lib-hal/.settings/org.eclipse.ltk.core.refactoring.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
diff --git a/lib-hal/Makefile.GD32 b/lib-hal/Makefile.GD32
index a03d2ca..449d03e 100644
--- a/lib-hal/Makefile.GD32
+++ b/lib-hal/Makefile.GD32
@@ -1,26 +1,39 @@
DEFINES=NDEBUG
-ifneq ($(MAKE_FLAGS),)
- ifeq ($(findstring USE_LEDBLINK_BITBANGING595,$(MAKE_FLAGS)), USE_LEDBLINK_BITBANGING595)
- EXTRA_SRCDIR=src/gd32/bitbanging
+EXTRA_SRCDIR=
+
+ifneq ($(MAKE_FLAGS),)
+ ifeq (,$(findstring DISABLE_RTC,$(MAKE_FLAGS)))
+ ifeq (,$(findstring DISABLE_INTERNAL_RTC,$(MAKE_FLAGS)))
+ EXTRA_SRCDIR+=rtc/gd32
+ endif
+ endif
+
+ ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
+ ifeq ($(findstring gd32h7xx,$(FAMILY)), gd32h7xx)
+ EXTRA_SRCDIR+=device/usb/host/gd32/h
+ EXTRA_INCLUDES+=device/usb/host/gd32/h
+ else
+ EXTRA_SRCDIR+=device/usb/host/gd32/f
+ EXTRA_INCLUDES+=device/usb/host/gd32/f
+ endif
+ EXTRA_SRCDIR+=device/usb/host/gd32
+ EXTRA_INCLUDES+=device/usb/host/gd32
endif
-
- ifneq (,$(findstring DEBUG_EMAC,$(MAKE_FLAGS)))
+
+ ifneq (,$(findstring DEBUG_EMAC,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=debug/emac/gd32
endif
-
- ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
- EXTRA_SRCDIR+=device/usb/host/gd32
- EXTRA_INCLUDES+=device/usb/host/gd32
- endif
else
- EXTRA_SRCDIR+=debug/emac/gd32
- EXTRA_SRCDIR+=ff12c ff12c/option
-
- EXTRA_SRCDIR+=device/usb/host/gd32
- EXTRA_INCLUDES+=device/usb/host/gd32
+ ifneq (, $(shell test -d '../lib-network/src/noemac' && echo -n yes))
+ else
+ EXTRA_SRCDIR+=debug/emac/gd32
+ endif
+ EXTRA_SRCDIR+=rtc/gd32
+# EXTRA_SRCDIR+=device/usb/host/gd32
+# EXTRA_INCLUDES+=device/usb/host/gd32
- DEFINES=ENABLE_USB_HOST CONFIG_USB_HOST_MSC
+# DEFINES=ENABLE_USB_HOST CONFIG_USB_HOST_MSC
endif
include Rules.mk
diff --git a/lib-hal/Rules.mk b/lib-hal/Rules.mk
old mode 100644
new mode 100755
index cea16ff..0ae3fce
--- a/lib-hal/Rules.mk
+++ b/lib-hal/Rules.mk
@@ -1,5 +1,7 @@
$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
+EXTRA_SRCDIR+=debug
+
ifneq ($(MAKE_FLAGS),)
ifneq (,$(findstring CONSOLE_I2C,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=console/i2c
@@ -14,23 +16,43 @@ ifneq ($(MAKE_FLAGS),)
endif
endif
endif
- ifneq ($(findstring DISABLE_RTC,$(MAKE_FLAGS)), DISABLE_RTC)
+
+ FATFS=
+ ifeq ($(findstring CONFIG_USB_HOST_MSC,$(MAKE_FLAGS)), CONFIG_USB_HOST_MSC)
+ FATFS=1
+ endif
+
+ ifeq (,$(findstring DISABLE_FS,$(MAKE_FLAGS)))
+ FATFS=1
+ endif
+
+ ifdef FATFS
+ EXTRA_SRCDIR+=ff14b/source
+ EXTRA_SRCDIR+=posix
+ endif
+
+ ifeq (,$(findstring DISABLE_RTC,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=rtc
- ifeq ($(findstring DISABLE_INTERNAL_RTC,$(MAKE_FLAGS)), DISABLE_INTERNAL_RTC)
+ ifneq (,$(findstring DISABLE_INTERNAL_RTC,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=rtc/i2c
- else
- EXTRA_SRCDIR+=rtc/gd32
endif
+ EXTRA_INCLUDES+=../lib-properties/include
endif
+
ifneq (,$(findstring DEBUG_I2C,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=debug/i2c
EXTRA_INCLUDES+=debug/i2c
endif
+
ifneq (,$(findstring DEBUG_STACK,$(MAKE_FLAGS)))
EXTRA_SRCDIR+=debug/stack
endif
else
- DEFINES+=DEBUG_I2C DEBUG_STACK
- EXTRA_INCLUDES+=debug/i2c
- EXTRA_SRCDIR+=console/i2c console/null console/uart0 rtc debug/stack debug/i2c
+ DEFINES+=DEBUG_I2C DEBUG_STACK DEBUG_POSIX
+ DEFINES+=LOGIC_ANALYZER
+ EXTRA_INCLUDES+=debug/i2c debug/stack
+ EXTRA_SRCDIR+=console/i2c console/null console/uart0
+ EXTRA_SRCDIR+=posix
+ EXTRA_SRCDIR+=rtc rtc/i2c
+ EXTRA_INCLUDES+=../lib-properties/include
endif
diff --git a/lib-hal/console/h3/console.c b/lib-hal/console/h3/console.c
deleted file mode 100644
index 809a5be..0000000
--- a/lib-hal/console/h3/console.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/**
- * @file console.c
- *
- */
-/* Copyright (C) 2019-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include
-#include
-
-#include "console.h"
-
-#include "device/fb.h"
-
-#include "arm/arm.h"
-
-extern unsigned char FONT[] __attribute__((aligned(4)));
-
-static const uint32_t FB_CHAR_W = 8;
-static const uint32_t FB_CHAR_H = 16;
-
-static uint32_t current_x = 0;
-static uint32_t current_y = 0;
-static uint32_t saved_x = 0;
-static uint32_t saved_y = 0;
-
-static uint32_t top_row = 0;
-
-static uint32_t cur_fore = CONSOLE_WHITE;
-static uint32_t cur_back = CONSOLE_BLACK;
-static uint32_t saved_fore = CONSOLE_WHITE;
-static uint32_t saved_back = CONSOLE_BLACK;
-
-#if defined(USE_UBOOT_HDMI)
-#undef FB_WIDTH
-#define FB_WIDTH fb_width
-
-#undef FB_HEIGHT
-#define FB_HEIGHT fb_height
-
-#undef FB_PITCH
-#define FB_PITCH fb_pitch
-
-#undef FB_ADDRESS
-#define FB_ADDRESS fb_addr
-#endif
-
-void __attribute__((cold)) console_init(void) {
- const int r = fb_init();
-
- if (r == FB_OK) {
- console_clear();
- }
-}
-
-uint32_t console_get_line_width(void) {
- return FB_WIDTH / FB_CHAR_W;
-}
-
-void console_set_top_row(uint32_t row) {
- if (row > FB_HEIGHT / FB_CHAR_H) {
- top_row = 0;
- } else {
- top_row = row;
- }
-
- current_x = 0;
- current_y = row;
-}
-
-inline static void clear_row(uint32_t *address) {
- uint32_t i;
-
- for (i = 0 ; i < (FB_CHAR_H * FB_WIDTH) ; i++) {
- *address++ = cur_back;
- }
-}
-
-inline static void newline(void) {
- uint32_t i;
- uint32_t *address;
- uint32_t *to;
- uint32_t *from;
-
- current_y++;
- current_x = 0;
-
- if (current_y == FB_HEIGHT / FB_CHAR_H) {
- if (top_row == 0) {
- /* Pointer to row = 0 */
- to = (uint32_t *) (FB_ADDRESS);
- /* Pointer to row = 1 */
- from = to + (FB_CHAR_H * FB_WIDTH);
- /* Copy block from {row = 1, rows} to {row = 0, rows - 1} */
- i = ((FB_HEIGHT - FB_CHAR_H) * FB_WIDTH);
- } else {
- to = (uint32_t *) (FB_ADDRESS) + ((FB_CHAR_H * FB_WIDTH) * top_row);
- from = to + (FB_CHAR_H * FB_WIDTH);
- i = ((FB_HEIGHT - FB_CHAR_H) * FB_WIDTH - ((FB_CHAR_H * FB_WIDTH) * top_row));
- }
-
- memcpy_blk(to, from, i/8);
-
- /* Clear last row */
- address = (uint32_t *)(FB_ADDRESS) + ((FB_HEIGHT - FB_CHAR_H) * FB_WIDTH);
- clear_row(address);
-
- current_y--;
- }
-}
-
-inline static void draw_pixel(uint32_t x, uint32_t y, uint32_t color) {
- volatile uint32_t *address = (volatile uint32_t *)(FB_ADDRESS + (x * FB_BYTES_PER_PIXEL) + (y * FB_WIDTH * FB_BYTES_PER_PIXEL));
- *address = (uint32_t) color;
-}
-
-inline static void draw_char(int c, uint32_t x, uint32_t y, uint32_t fore, uint32_t back) {
- uint32_t i, j;
- uint8_t line;
- unsigned char *p = FONT + (c * (int) FB_CHAR_H);
-
- for (i = 0; i < FB_CHAR_H; i++) {
- line = (uint8_t) *p++;
- for (j = x; j < (FB_CHAR_W + x); j++) {
- if ((line & 0x1) != 0) {
- draw_pixel(j, y, fore);
- } else {
- draw_pixel(j, y, back);
- }
- line >>= 1;
- }
- y++;
- }
-}
-
-int console_draw_char(int ch, uint16_t x, uint16_t y, uint32_t fore, uint32_t back) {
- draw_char(ch, x * FB_CHAR_W, y * FB_CHAR_H, fore, back);
- return (int)ch;
-}
-
-void console_putc(int ch) {
- if (ch == (int)'\n') {
- newline();
- } else if (ch == (int)'\r') {
- current_x = 0;
- } else if (ch == (int)'\t') {
- current_x += 4;
- } else {
- draw_char(ch, current_x * FB_CHAR_W, current_y * FB_CHAR_H, cur_fore, cur_back);
- current_x++;
- if (current_x == FB_WIDTH / FB_CHAR_W) {
- newline();
- }
- }
-}
-
-void console_puts(const char *s) {
- char c;
- while ((c = *s++) != (char) 0) {
- console_putc((int) c);
- }
-}
-
-void console_write(const char *s, unsigned int n) {
- char c;
-
- while (((c = *s++) != (char) 0) && (n-- != 0)) {
- console_putc((int) c);
- }
-}
-
-void console_error(const char *s) {
- uint32_t fore_current = cur_fore;
- uint32_t back_current = cur_back;
-
- cur_fore = CONSOLE_RED;
- cur_back = CONSOLE_BLACK;
-
- console_puts("Error <");
- console_puts((char *) s);
- console_puts(">\n");
-
- cur_fore = fore_current;
- cur_back = back_current;
-}
-
-void console_status(uint32_t color, const char *s) {
- const uint32_t fore_current = cur_fore;
- const uint32_t back_current = cur_back;
-
- const uint32_t s_y = current_y;
- const uint32_t s_x = current_x;
-
- console_clear_line(29);
-
- cur_fore = color;
- cur_back = CONSOLE_BLACK;
-
- console_puts((char *)s);
-
- current_y = s_y;
- current_x = s_x;
-
- cur_fore = fore_current;
- cur_back = back_current;
-}
-
-#define TO_HEX(i) ((i) < 10) ? (uint8_t)'0' + (i) : (uint8_t)'A' + ((i) - (uint8_t)10)
-
-void console_puthex(uint8_t data) {
- console_putc((int) (TO_HEX(((data & 0xF0) >> 4))));
- console_putc((int) (TO_HEX(data & 0x0F)));
-}
-
-void console_puthex_fg_bg(uint8_t data, uint32_t fore, uint32_t back) {
- uint32_t fore_current = cur_fore;
- uint32_t back_current = cur_back;
-
- cur_fore = fore;
- cur_back = back;
-
- (void) console_putc((int) (TO_HEX(((data & 0xF0) >> 4))));
- (void) console_putc((int) (TO_HEX(data & 0x0F)));
-
- cur_fore = fore_current;
- cur_back = back_current;
-}
-
-void console_putpct_fg_bg(uint8_t data, uint32_t fore, uint32_t back) {
- uint32_t fore_current = cur_fore;
- uint32_t back_current = cur_back;
-
- cur_fore = fore;
- cur_back = back;
-
- if (data < 100) {
- console_putc((int) ((char) '0' + (char) (data / 10)));
- console_putc((int) ((char) '0' + (char) (data % 10)));
- } else {
- console_puts("%%");
- }
-
- cur_fore = fore_current;
- cur_back = back_current;
-}
-
-void console_put3dec_fg_bg(uint8_t data, uint32_t fore, uint32_t back) {
- uint32_t fore_current = cur_fore;
- uint32_t back_current = cur_back;
-
- cur_fore = fore;
- cur_back = back;
-
- const uint8_t i = data / 100;
-
- (void) console_putc((int) ((char) '0' + (char) i));
-
- data = (uint8_t)(data - (i * 100));
-
- console_putc((int) ((char) '0' + (char) (data / 10)));
- console_putc((int) ((char) '0' + (char) (data % 10)));
-
- cur_fore = fore_current;
- cur_back = back_current;
-}
-
-void console_newline(void){
- newline();
-}
-
-void console_clear(void) {
- uint32_t *address = (uint32_t *)(fb_addr);
- uint32_t i;
-
- for (i = 0; i < (FB_HEIGHT * FB_WIDTH); i++) {
- *address++ = (uint32_t) cur_back;
- }
-
- current_x = 0;
- current_y = 0;
-}
-
-void console_set_cursor(uint32_t x, uint32_t y) {
- if (x > FB_WIDTH / FB_CHAR_W)
- current_x = 0;
- else
- current_x = x;
-
- if (y > FB_HEIGHT / FB_CHAR_H)
- current_y = 0;
- else
- current_y = y;
-}
-
-void console_save_cursor(void) {
- saved_y = current_y;
- saved_x = current_x;
- saved_back = cur_back;
- saved_fore = cur_fore;
-}
-
-void console_restore_cursor(void) {
- current_y = saved_y;
- current_x = saved_x;
- cur_back = saved_back;
- cur_fore = saved_fore;
-}
-
-void console_save_color(void) {
- saved_back = cur_back;
- saved_fore = cur_fore;
-}
-
-void console_restore_color(void) {
- cur_back = saved_back;
- cur_fore = saved_fore;
-}
-
-void console_set_fg_color(uint32_t fore) {
- cur_fore = fore;
-}
-
-void console_set_bg_color(uint32_t back) {
- cur_back = back;
-}
-
-void console_set_fg_bg_color(uint32_t fore, uint32_t back) {
- cur_fore = fore;
- cur_back = back;
-}
-
-void console_clear_line(uint32_t line) {
- uint32_t *address;
-
- if (line > FB_HEIGHT / FB_CHAR_H) {
- return;
- } else {
- current_y = line;
- }
-
- current_x = 0;
-
- address = (uint32_t *)(fb_addr) + (line * FB_CHAR_H * FB_WIDTH);
- clear_row(address);
-}
-
-void console_clear_top_row(void) {
- uint32_t line;
- uint32_t *address;
-
- for (line = top_row; line < (FB_HEIGHT / FB_CHAR_H) - 1; line++) {
- address = (uint32_t*) (fb_addr) + (line * FB_CHAR_H * FB_WIDTH);
- clear_row(address);
- }
-
- current_x = 0;
- current_y = top_row;
-}
-
-void console_putpixel(uint32_t x, uint32_t y, uint32_t color) {
- draw_pixel(x, y, color);
-}
-
diff --git a/lib-hal/console/i2c/console.c b/lib-hal/console/i2c/console.cpp
similarity index 77%
rename from lib-hal/console/i2c/console.c
rename to lib-hal/console/i2c/console.cpp
index d33e8a7..37be38b 100644
--- a/lib-hal/console/i2c/console.c
+++ b/lib-hal/console/i2c/console.cpp
@@ -1,8 +1,8 @@
/**
- * @file console.c
+ * @file console.cpp
*
*/
-/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2022-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,9 +23,8 @@
* THE SOFTWARE.
*/
-#include
-#include
-#include
+#include
+#include
#include "console.h"
@@ -34,57 +33,57 @@
static bool s_isConnected;
#if !defined (CONSOLE_I2C_ADDRESS)
-# define CONSOLE_I2C_ADDRESS ((uint8_t)0x4D)
+# define CONSOLE_I2C_ADDRESS (0x4D)
#endif
#if !defined (CONSOLE_I2C_ONBOARD_CRYSTAL)
-# define CONSOLE_I2C_ONBOARD_CRYSTAL 14745600UL
+# define CONSOLE_I2C_ONBOARD_CRYSTAL (14745600UL)
#endif
#if !defined (CONSOLE_I2C_BAUDRATE)
-# define CONSOLE_I2C_BAUDRATE 115200U
+# define CONSOLE_I2C_BAUDRATE (115200U)
#endif
#define SC16IS7X0_REG_SHIFT 3
-#define SC16IS7X0_THR ((uint8_t)(0x00 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_FCR ((uint8_t)(0x02 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_LCR ((uint8_t)(0x03 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_MCR ((uint8_t)(0x04 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_SPR ((uint8_t)(0x07 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_TLR ((uint8_t)(0x07 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_TXLVL ((uint8_t)(0x08 << SC16IS7X0_REG_SHIFT))
+#define SC16IS7X0_THR (0x00 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_FCR (0x02 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_LCR (0x03 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_MCR (0x04 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_SPR (0x07 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_TLR (0x07 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_TXLVL (0x08 << SC16IS7X0_REG_SHIFT)
-#define SC16IS7X0_DLL ((uint8_t)(0x00 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_DLH ((uint8_t)(0x01 << SC16IS7X0_REG_SHIFT))
-#define SC16IS7X0_EFR ((uint8_t)(0x02 << SC16IS7X0_REG_SHIFT))
+#define SC16IS7X0_DLL (0x00 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_DLH (0x01 << SC16IS7X0_REG_SHIFT)
+#define SC16IS7X0_EFR (0x02 << SC16IS7X0_REG_SHIFT)
/** See section 8.3 of the datasheet for definitions
* of bits in the FIFO Control Register (FCR)
*/
-#define FCR_TX_FIFO_RST ((uint8_t)(1U << 2))
-#define FCR_ENABLE_FIFO ((uint8_t)(1U << 0))
+#define FCR_TX_FIFO_RST (1U << 2)
+#define FCR_ENABLE_FIFO (1U << 0)
/** See section 8.4 of the datasheet for definitions
* of bits in the Line Control Register (LCR)
*/
-#define LCR_BITS8 ((uint8_t)0x03)
-#define LCR_BITS1 ((uint8_t)0x00)
-#define LCR_NONE ((uint8_t)0x00)
-#define LCR_ENABLE_DIV ((uint8_t)0x80)
+#define LCR_BITS8 (0x03)
+#define LCR_BITS1 (0x00)
+#define LCR_NONE (0x00)
+#define LCR_ENABLE_DIV (0x80)
/**
* 8.6 Modem Control Register (MCR)
*/
//MCR[2] only accessible when EFR[4] is set
-#define MCR_ENABLE_TCR_TLR ((uint8_t)(1U << 2))
-#define MCR_PRESCALE_4 ((uint8_t)(1U << 7))
+#define MCR_ENABLE_TCR_TLR (1U << 2)
+#define MCR_PRESCALE_4 (1U << 7)
/**
* 8.11 Enhanced Features Register (EFR)
*/
-#define EFR_ENABLE_ENHANCED_FUNCTIONS ((uint8_t)(1U << 4))
+#define EFR_ENABLE_ENHANCED_FUNCTIONS (1U << 4)
static bool is_connected(const uint8_t address, const uint32_t baudrate) {
char buf;
@@ -97,7 +96,7 @@ static bool is_connected(const uint8_t address, const uint32_t baudrate) {
}
/* This is known to corrupt the Atmel AT24RF08 EEPROM */
- return FUNC_PREFIX(i2c_write(NULL, 0)) == 0;
+ return FUNC_PREFIX(i2c_write(nullptr, 0)) == 0;
}
static void setup() {
@@ -108,8 +107,8 @@ static void setup() {
static void write_register(uint8_t nRegister, uint8_t nValue) {
char buffer[2];
- buffer[0] = (char)(nRegister);
- buffer[1] = (char)(nValue);
+ buffer[0] = static_cast(nRegister);
+ buffer[1] = static_cast(nValue);
setup();
FUNC_PREFIX(i2c_write(buffer, 2));
@@ -121,13 +120,13 @@ static uint8_t read_byte() {
setup();
FUNC_PREFIX(i2c_read(buffer, 1));
- return (uint8_t) (buffer[0]);
+ return static_cast(buffer[0]);
}
static uint8_t read_register(uint8_t nRegister) {
char buffer[1];
- buffer[0] = (char) (nRegister);
+ buffer[0] = static_cast(nRegister);
setup();
FUNC_PREFIX(i2c_write(buffer, 1));
@@ -135,7 +134,7 @@ static uint8_t read_register(uint8_t nRegister) {
return read_byte();
}
-inline static bool is_writable() {
+static bool is_writable() {
return (read_register(SC16IS7X0_TXLVL) != 0);
}
@@ -157,7 +156,7 @@ static void set_baud(uint32_t nBaud) {
write_register(SC16IS7X0_LCR, nRegisterLCR);
}
-void __attribute__((cold)) console_init(void) {
+void __attribute__((cold)) console_init() {
FUNC_PREFIX(i2c_begin());
s_isConnected = is_connected(CONSOLE_I2C_ADDRESS, 100000);
@@ -198,6 +197,7 @@ void __attribute__((cold)) console_init(void) {
write_register(SC16IS7X0_FCR, FCR_ENABLE_FIFO);
}
+extern "C" {
void console_putc(int c) {
if (!s_isConnected) {
return;
@@ -303,14 +303,15 @@ void console_set_bg_color(uint16_t bg) {
}
}
-void console_status(uint32_t color, const char *s) {
+void console_status(uint32_t nColour, const char *s) {
if (!s_isConnected) {
return;
}
- console_set_fg_color((uint16_t) color);
+ console_set_fg_color(static_cast(nColour));
console_set_bg_color(CONSOLE_BLACK);
console_puts(s);
console_putc('\n');
console_set_fg_color(CONSOLE_WHITE);
}
+}
diff --git a/lib-debug/src/debug_print_bits.c b/lib-hal/console/null/console.cpp
similarity index 69%
rename from lib-debug/src/debug_print_bits.c
rename to lib-hal/console/null/console.cpp
index 4874795..c0cf5ec 100755
--- a/lib-debug/src/debug_print_bits.c
+++ b/lib-hal/console/null/console.cpp
@@ -1,8 +1,8 @@
/**
- * @file debug_print_bits.c
+ * @file console.cpp
*
*/
-/* Copyright (C) 2018-2021 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,26 +23,14 @@
* THE SOFTWARE.
*/
-#include
-#include
+#include
-#if defined (H3)
-extern int uart0_printf(const char* fmt, ...);
-# define printf uart0_printf
-#endif
+void console_init() {}
-void debug_print_bits(uint32_t u) {
- uint32_t i;
-
- uint32_t b = 1U << 31;
-
- for (i = 0; i < 32; i++) {
- if ((b & u) == b) {
- uint32_t bit_number = 31 - i;
- printf("%-2d ", bit_number);
- }
- b = b >> 1;
- }
-
- printf("\n");
+extern "C" {
+void console_puts([[maybe_unused]] const char *p) {}
+void console_write([[maybe_unused]] const char *p, [[maybe_unused]] unsigned int i) {}
+void console_status([[maybe_unused]] uint32_t i, [[maybe_unused]] const char *p) {}
+void console_error([[maybe_unused]] const char *p) {}
+void console_putc([[maybe_unused]] int i) {}
}
diff --git a/lib-hal/console/uart0/console.c b/lib-hal/console/uart0/console.cpp
similarity index 83%
rename from lib-hal/console/uart0/console.c
rename to lib-hal/console/uart0/console.cpp
index 9fca1a3..cbb2cdf 100644
--- a/lib-hal/console/uart0/console.c
+++ b/lib-hal/console/uart0/console.cpp
@@ -1,8 +1,8 @@
/**
- * @file console.c
+ * @file console.cpp
*
*/
-/* Copyright (C) 2018-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,20 +23,14 @@
* THE SOFTWARE.
*/
-#include
+#include
#include "console.h"
-extern void uart0_init(void);
-extern void uart0_putc(int);
-extern void uart0_puts(const char *);
-
-void __attribute__((cold)) console_init(void) {
- uart0_init();
-
- console_set_fg_color(CONSOLE_WHITE);
- console_set_bg_color(CONSOLE_BLACK);
-}
+extern "C" {
+void uart0_init();
+void uart0_putc(int);
+void uart0_puts(const char *);
void console_putc(int c) {
uart0_putc(c);
@@ -46,6 +40,12 @@ void console_puts(const char *s) {
uart0_puts(s);
}
+void console_error(const char *s) {
+ uart0_puts("\x1b[31m");
+ uart0_puts(s);
+ uart0_puts("\x1b[37m");
+}
+
void console_set_fg_color(uint16_t fg) {
switch (fg) {
case CONSOLE_BLACK:
@@ -89,19 +89,13 @@ void console_set_bg_color(uint16_t bg) {
void console_write(const char *s, unsigned int n) {
char c;
- while (((c = *s++) != (char) 0) && (n-- != 0)) {
- console_putc((int) c);
+ while (((c = *s++) != 0) && (n-- != 0)) {
+ console_putc(static_cast(c));
}
}
-void console_error(const char *s) {
- uart0_puts("\x1b[31m");
- uart0_puts(s);
- uart0_puts("\x1b[37m");
-}
-
-void console_status(uint32_t color, const char *s) {
- console_set_fg_color((uint16_t) color);
+void console_status(uint32_t nColour, const char *s) {
+ console_set_fg_color(static_cast(nColour));
console_set_bg_color(CONSOLE_BLACK);
uart0_puts(s);
@@ -109,3 +103,11 @@ void console_status(uint32_t color, const char *s) {
console_set_fg_color(CONSOLE_WHITE);
}
+}
+
+void __attribute__((cold)) console_init() {
+ uart0_init();
+
+ console_set_fg_color(CONSOLE_WHITE);
+ console_set_bg_color(CONSOLE_BLACK);
+}
diff --git a/lib-debug/src/debug_dump.c b/lib-hal/debug/debug_dump.cpp
similarity index 74%
rename from lib-debug/src/debug_dump.c
rename to lib-hal/debug/debug_dump.cpp
index e2383f8..b69df49 100755
--- a/lib-debug/src/debug_dump.c
+++ b/lib-hal/debug/debug_dump.cpp
@@ -1,8 +1,8 @@
/**
- * @file debug_dump.c
+ * @file debug_dump.cpp
*
*/
-/* Copyright (C) 2018-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,32 +23,31 @@
* THE SOFTWARE.
*/
+#include
+#include
#include
-#include
-#include
#if defined (H3)
-extern int uart0_printf(const char* fmt, ...);
+extern "C" int uart0_printf(const char* fmt, ...);
# define printf uart0_printf
#endif
-#define CHARS_PER_LINE 16
+static constexpr uint32_t CHARS_PER_LINE = 16;
-void debug_dump(const void *packet, uint16_t len) {
- uint16_t chars = 0;
- uint16_t chars_this_line = 0;
- const uint8_t *p = (const uint8_t *) packet;
+void debug_dump(const void *pData, uint32_t nSize) {
+ uint32_t chars = 0;
+ const auto *p = reinterpret_cast(pData);
- printf("%p:%d\n", packet, len);
+ printf("%p:%d\n", pData, nSize);
do {
- chars_this_line = 0;
+ uint32_t chars_this_line = 0;
printf("%04x ", chars);
- const uint8_t *q = p;
+ const auto *q = p;
- while ((chars_this_line < CHARS_PER_LINE) && (chars < len)) {
+ while ((chars_this_line < CHARS_PER_LINE) && (chars < nSize)) {
if (chars_this_line % 8 == 0) {
printf(" ");
}
@@ -60,7 +59,7 @@ void debug_dump(const void *packet, uint16_t len) {
p++;
}
- uint16_t chars_dot_line = chars_this_line;
+ auto chars_dot_line = chars_this_line;
for (; chars_this_line < CHARS_PER_LINE; chars_this_line++) {
if (chars_this_line % 8 == 0) {
@@ -88,8 +87,8 @@ void debug_dump(const void *packet, uint16_t len) {
q++;
}
- printf("\n");
+ puts("");
- } while (chars < len);
+ } while (chars < nSize);
}
diff --git a/lib-network/src/emac/gd32/debug_print_bits.c b/lib-hal/debug/debug_print_bits.cpp
old mode 100644
new mode 100755
similarity index 89%
rename from lib-network/src/emac/gd32/debug_print_bits.c
rename to lib-hal/debug/debug_print_bits.cpp
index 4874795..07a758a
--- a/lib-network/src/emac/gd32/debug_print_bits.c
+++ b/lib-hal/debug/debug_print_bits.cpp
@@ -1,8 +1,8 @@
/**
- * @file debug_print_bits.c
+ * @file debug_print_bits.cpp
*
*/
-/* Copyright (C) 2018-2021 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +27,7 @@
#include
#if defined (H3)
-extern int uart0_printf(const char* fmt, ...);
+extern "C" int uart0_printf(const char* fmt, ...);
# define printf uart0_printf
#endif
@@ -44,5 +44,5 @@ void debug_print_bits(uint32_t u) {
b = b >> 1;
}
- printf("\n");
+ puts("");
}
diff --git a/lib-hal/debug/emac/gd32/emac_debug.cpp b/lib-hal/debug/emac/gd32/emac_debug.cpp
old mode 100644
new mode 100755
index b42aa6c..ef37b87
--- a/lib-hal/debug/emac/gd32/emac_debug.cpp
+++ b/lib-hal/debug/emac/gd32/emac_debug.cpp
@@ -2,7 +2,7 @@
* @file emac_debug.cpp
*
*/
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
+/* Copyright (C) 2023-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +32,11 @@ static uint32_t s_nCounter;
void emac_debug_run() {
uint32_t rxfifo_drop;
uint32_t rxdma_drop;
+#if defined (GD32H7XX)
+ enet_missed_frame_counter_get(ENETx, &rxfifo_drop, &rxdma_drop);
+#else
enet_missed_frame_counter_get(&rxfifo_drop, &rxdma_drop);
+#endif
if ((rxfifo_drop != 0) || (rxdma_drop != 0)) {
printf("%u: RxFIFO: %u RxDMA: %u\n", ++s_nCounter, rxfifo_drop, rxdma_drop);
diff --git a/lib-hal/debug/i2c/i2cdetect.cpp b/lib-hal/debug/i2c/i2cdetect.cpp
old mode 100644
new mode 100755
index 90c0e24..90c647d
--- a/lib-hal/debug/i2c/i2cdetect.cpp
+++ b/lib-hal/debug/i2c/i2cdetect.cpp
@@ -2,7 +2,7 @@
* @file i2cdetect.cpp
*
*/
-/* Copyright (C) 2020-2022 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2020-2023 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,12 +23,16 @@
* THE SOFTWARE.
*/
+#undef NDEBUG
+
#include
#include "i2cdetect.h"
#include "hal_i2c.h"
+#include "debug.h"
+
inline static bool i2c_is_connected(uint8_t nAddress) {
uint8_t nResult;
char buffer;
diff --git a/lib-hal/debug/i2c/i2cdetect.h b/lib-hal/debug/i2c/i2cdetect.h
old mode 100644
new mode 100755
index 68bf63e..f7f4449
--- a/lib-hal/debug/i2c/i2cdetect.h
+++ b/lib-hal/debug/i2c/i2cdetect.h
@@ -2,7 +2,7 @@
* @file i2cdetect.h
*
*/
-/* Copyright (C) 2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2020 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/lib-hal/debug/stack/stack_debug.cpp b/lib-hal/debug/stack/stack_debug.cpp
old mode 100644
new mode 100755
index 45eac74..b106c33
--- a/lib-hal/debug/stack/stack_debug.cpp
+++ b/lib-hal/debug/stack/stack_debug.cpp
@@ -2,7 +2,7 @@
* @file stack_debug.cpp
*
*/
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
+/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -66,6 +66,7 @@ void stack_debug_print() {
if (s_nUsedBytesPrevious != nUsedBytes) {
s_nUsedBytesPrevious = nUsedBytes;
+
if (nFreePct == 0) {
printf("\x1b[31m");
} else if (nFreePct == 1) {
diff --git a/lib-hal/device/usb/host/gd32/usb_host.cpp b/lib-hal/device/usb/host/gd32/usb_host.cpp
deleted file mode 100644
index c0b2ff5..0000000
--- a/lib-hal/device/usb/host/gd32/usb_host.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * usb_host.cpp
- *
- */
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include
-
-#include "gd32.h"
-
-extern "C" {
-#include "usbh_core.h"
-#include "usbh_msc_core.h"
-
-#include "drv_usbh_int.h"
-}
-
-static void usb_gpio_config() {
-#if !defined (GD32F4XX)
-#else
- rcu_periph_clock_enable(RCU_SYSCFG);
-
- rcu_periph_clock_enable(RCU_GPIOA);
-
- /* USBFS_DM(PA11) and USBFS_DP(PA12) GPIO pin configuration */
- gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_11 | GPIO_PIN_12);
- gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_200MHZ, GPIO_PIN_11 | GPIO_PIN_12);
-
- gpio_af_set(GPIOA, GPIO_AF_10, GPIO_PIN_11 | GPIO_PIN_12);
-#endif
-}
-
-#if !defined (GD32F4XX)
-__IO uint32_t usbfs_prescaler = 0U;
-__IO uint16_t timer_prescaler = 5U;
-#else
-#endif
-
-static void usb_rcu_config() {
-#if !defined (GD32F4XX)
- uint32_t system_clock = rcu_clock_freq_get(CK_SYS);
-
- if (48000000U == system_clock) {
- timer_prescaler = 3U;
- usbfs_prescaler = RCU_CKUSB_CKPLL_DIV1;
- } else if (72000000U == system_clock) {
- timer_prescaler = 5U;
- usbfs_prescaler = RCU_CKUSB_CKPLL_DIV1_5;
- } else if (96000000U == system_clock) {
- timer_prescaler = 7U;
- usbfs_prescaler = RCU_CKUSB_CKPLL_DIV2;
- } else if (120000000U == system_clock) {
- timer_prescaler = 9U;
- usbfs_prescaler = RCU_CKUSB_CKPLL_DIV2_5;
- } else {
- /* reserved */
- }
-
- rcu_usbfs_trng_clock_config(usbfs_prescaler);
- rcu_periph_clock_enable(RCU_USBFS);
-#else
- rcu_pll48m_clock_config(RCU_PLL48MSRC_PLLQ);
- rcu_ck48m_clock_config(RCU_CK48MSRC_PLL48M);
-
- rcu_periph_clock_enable(RCU_USBFS);
-#endif
-}
-
-static void usb_intr_config() {
- nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
- nvic_irq_enable((uint8_t)USBFS_IRQn, 2U, 0U);
-
-#if !defined (GD32F4XX)
-#else
-#endif
-}
-
-usbh_host usb_host_msc;
-#if !defined (GD32F4XX)
-extern usb_core_driver usbh_core;
-#else
-usb_core_driver usbh_core;
-#endif
-extern usbh_user_cb usr_cb;
-
-void usb_init() {
- usb_gpio_config();
- usb_rcu_config();
-
- usbh_class_register(&usb_host_msc, &usbh_msc);
-
-#if !defined (GD32F4XX)
- usbh_init (&usb_host_msc, &usr_cb);
-#else
- usbh_init(&usb_host_msc,
- &usbh_core,
- USB_CORE_ENUM_FS,
- &usr_cb);
-#endif
-
- usb_intr_config ();
-}
-
-extern "C" {
-void USBFS_IRQHandler(void) {
- usbh_isr (&usbh_core);
-}
-}
diff --git a/lib-hal/device/usb/host/gd32/usb_host_msc.cpp b/lib-hal/device/usb/host/gd32/usb_host_msc.cpp
deleted file mode 100644
index 227d0b1..0000000
--- a/lib-hal/device/usb/host/gd32/usb_host_msc.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/**
- * usb_host_msc.cpp
- *
- */
-/* Copyright (C) 2023 by Arjan van Vught mailto:info@gd32-dmx.org
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
-
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include
-#include
-
-#include "gd32.h"
-
-extern "C" {
-#include "usb_host_msc.h"
-#include "usbh_core.h"
-}
-
-usbh_user_cb usr_cb = {
- usbh_user_init,
- usbh_user_deinit,
- usbh_user_device_connected,
- usbh_user_device_reset,
- usbh_user_device_disconnected,
- usbh_user_over_current_detected,
- usbh_user_device_speed_detected,
- usbh_user_device_desc_available,
- usbh_user_device_address_assigned,
- usbh_user_configuration_descavailable,
- usbh_user_manufacturer_string,
- usbh_user_product_string,
- usbh_user_serialnum_string,
- usbh_user_enumeration_finish,
- usbh_user_userinput,
- usbh_usr_msc_application,
- usbh_user_device_not_supported,
- usbh_user_unrecovered_error
-};
-
-#define USBH_USR_FS_INIT 0
-#define USBH_USR_FS_READLIST 1
-#define USBH_USR_FS_WRITEFILE 2
-#define USBH_USR_FS_DRAW 3
-#define USBH_USR_FS_DEMOEND 4
-
-static uint32_t usbh_usr_application_state = USBH_USR_FS_INIT;
-
-void usbh_user_init() {
- static uint32_t startup = 0U;
-
- if (0U == startup) {
- startup = 1U;
- puts("USB host library started.");
- }
-}
-
-void usbh_user_deinit() {
- usbh_usr_application_state = USBH_USR_FS_INIT;
-}
-
-void usbh_user_device_connected() {
- puts("> Device Attached.");
-}
-
-void usbh_user_unrecovered_error() {
- puts("> Unrecovered error state.");
-}
-
-void usbh_user_device_disconnected() {
- puts("> Device Disconnected.");
-}
-
-void usbh_user_device_reset() {
- puts("> Reset the USB device.");
-}
-
-void usbh_user_device_speed_detected(uint32_t device_speed) {
- if (PORT_SPEED_HIGH == device_speed) {
- puts("> High speed device detected.");
- } else if (PORT_SPEED_FULL == device_speed) {
- puts("> Full speed device detected.");
- } else if (PORT_SPEED_LOW == device_speed) {
- puts("> Low speed device detected.");
- } else {
- puts("> Device Fault.");
- }
-}
-
-void usbh_user_device_desc_available(void *device_desc) {
- auto *pDevStr = reinterpret_cast(device_desc);
-
- printf("VID: %04Xh\n", static_cast(pDevStr->idVendor));
- printf("PID: %04Xh\n", static_cast(pDevStr->idProduct));
-}
-
-void usbh_user_device_address_assigned() {
- puts("usbh_user_device_address_assigned");
-}
-
-void usbh_user_configuration_descavailable(usb_desc_config *cfg_desc, usb_desc_itf *itf_desc, usb_desc_ep *ep_desc) {
- auto *id = reinterpret_cast