Commit aa44e42a authored by FineL's avatar FineL 😛

胜利一步之遥!

parent 8ff48311
/**
* @file cw32f030_dma.c
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-05-17
*
* @copyright Copyright (c) 2021
*
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "cw32f030_dma.h"
/* Private_TypesDefinitions --------------------------------------------------*/
/* Private_Defines -----------------------------------------------------------*/
/* Private_Variables ---------------------------------------------------------*/
/* Private_FunctionPrototypes ------------------------------------------------*/
/* Private_Functions ---------------------------------------------------------*/
/* Public_Functions ----------------------------------------------------------*/
void DMA_DeInit(DMACHANNEL_TypeDef* DMA_Channelx)
{
/* Check the parameters */
assert_param(IS_DMA_ALL_PERIPH(DMA_Channelx));
/* Disable the selected DMAy Channelx */
DMA_Channelx->CSR &= (~DMA_CHANNEL_EN); ///disable DMA Channel
DMA_Channelx->CSR = 0x00UL; ///reset CSR register
DMA_Channelx->TRIG = 0x00UL; ///reset the trig register
DMA_Channelx->CNT = 0x00010000UL; ///reset the CNT register
DMA_Channelx->SRCADDR = 0x00UL; ///reset srcaddr register
DMA_Channelx->DSTADDR = 0x00UL; ///reset dstaddr register
}
/**
* @brief DMA通道初始化
*
* @param DMA_Channelx
* @param DMA_InitStruct
*/
void DMA_Init(DMACHANNEL_TypeDef* DMA_Channelx, DMA_InitTypeDef* DMA_InitStruct)
{
/* Check the parameters */
assert_param(IS_DMA_ALL_PERIPH(DMA_Channelx));
assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
assert_param(IS_DMA_TRANSFER_WIDTH(DMA_InitStruct->DMA_TransferWidth));
assert_param(IS_DMA_SRCADDRESS_INC(DMA_InitStruct->DMA_SrcInc));
assert_param(IS_DMA_DSTADDRESS_INC(DMA_InitStruct->DMA_DstInc));
assert_param(IS_DMA_TRIG(DMA_InitStruct->TrigMode));
assert_param(IS_DMA_HARD_TRIGSRC(DMA_InitStruct->HardTrigSource));
assert_param(IS_DMA_TRANSFERCNT(DMA_InitStruct->DMA_TransferCnt));
DMA_Channelx->CSR = ( (DMA_Channelx->CSR & CSR_CLEAR_Mask) | \
DMA_InitStruct->DMA_Mode | DMA_InitStruct->DMA_TransferWidth | \
DMA_InitStruct->DMA_SrcInc | DMA_InitStruct->DMA_DstInc );
DMA_Channelx->TRIG = ( (DMA_Channelx->TRIG & TRIG_CLEAR_Mask) | DMA_InitStruct->TrigMode | \
DMA_InitStruct->HardTrigSource ) ;
DMA_Channelx->CNT= bv16 | DMA_InitStruct->DMA_TransferCnt ;
DMA_Channelx->SRCADDR = DMA_InitStruct->DMA_SrcAddress ;
DMA_Channelx->DSTADDR = DMA_InitStruct->DMA_DstAddress ;
}
/**
* @brief DMA结构初始化
*
* @param DMA_InitStruct
*/
void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
{
/*-------------- Reset DMA init structure parameters values ------------------*/
/* Initialize the DMA_Mode */
DMA_InitStruct->DMA_Mode = DMA_MODE_BLOCK;
/* Initialize the DMA_TransferWidth */
DMA_InitStruct->DMA_TransferWidth = DMA_TRANSFER_WIDTH_8BIT;
/* Initialize the DMA_SrcInc */
DMA_InitStruct->DMA_SrcInc = DMA_SrcAddress_Fix;
/* Initialize the DMA_DstInc */
DMA_InitStruct->DMA_DstInc = DMA_DstAddress_Fix;
/* Initialize the TrigMode */
DMA_InitStruct->TrigMode = DMA_SWTrig;
/* Initialize the HardTrigSource, if we use softtrig ,we can not config it*/
DMA_InitStruct->HardTrigSource = DMA_HardTrig_UART1_RXBufferNE;
/* Initialize the DMA_TransferCnt */
DMA_InitStruct->DMA_TransferCnt = 0x00;
/* Initialize the DMA_SrcAddress */
DMA_InitStruct->DMA_SrcAddress = 0x00;
/* Initialize the DMA_DstAddress */
DMA_InitStruct->DMA_DstAddress = 0x00;
}
/**
* @brief 使能DMAy_Channelx 进行DMA传输
*
* @param DMA_Channelx
* @param NewState
*/
void DMA_Cmd(DMACHANNEL_TypeDef* DMA_Channelx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_DMA_ALL_PERIPH(DMA_Channelx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the selected DMAy Channelx */
DMA_Channelx->CSR |= DMA_CHANNEL_EN;
}
else
{
/* Disable the selected DMAy Channelx */
DMA_Channelx->CSR &= ~DMA_CHANNEL_EN;
}
}
/**
* @brief 通过软件置1,立即触发该通道启动传输
*
* @param DMA_Channelx
*/
void DMA_SWTrigCmd(DMACHANNEL_TypeDef* DMA_Channelx)
{
/* Check the parameters */
assert_param(IS_DMA_ALL_PERIPH(DMA_Channelx));
DMA_Channelx->TRIG |= DMA_SOFTTRIG_EN;
}
/**
* @brief 配置DMA_Channelx 指定中断使能
*
* @param DMA_Channelx :CW_DMACHANNEL1/2/3/4/5
* @param DMA_IT :DMA_IT_TC DMA_IT_TE
* @param NewState :ENABLE DISABLE
*/
void DMA_ITConfig(DMACHANNEL_TypeDef* DMA_Channelx, uint32_t DMA_IT, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_DMA_ALL_PERIPH(DMA_Channelx));
assert_param(IS_DMA_CONFIG_IT(DMA_IT));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the selected DMA interrupts */
DMA_Channelx->CSR |= DMA_IT;
}
else
{
/* Disable the selected DMA interrupts */
DMA_Channelx->CSR &= ~DMA_IT;
}
}
/**
* @brief 获取DMA_Channelx's 指定中断标志。
* @param DMAy_IT: specifies the DMAy interrupt source to check.
* This parameter can be one of the following values:
* @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
* @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
* @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
* @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
* @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
* @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
* @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
* @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
* @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
* @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
* @retval The new state of DMAy_IT (SET or RESET).
*/
ITStatus DMA_GetITStatus(uint32_t DMA_IT)
{
/* Check the parameters */
assert_param(IS_DMA_GET_IT(DMA_IT));
return (CW_DMA->ISR & DMA_IT) ? SET : RESET;
}
/**
* @brief 清除DMA_Channelx's 指定中断标志。
* @param DMAy_IT: specifies the DMAy interrupt pending bit to clear.
* This parameter can be any combination (for the same DMA) of the following values:
* @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
* @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
* @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
* @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
* @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
* @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
* @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
* @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
* @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
* @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
* @retval None
*/
void DMA_ClearITPendingBit(uint32_t DMA_IT)
{
/* Check the parameters */
assert_param(IS_DMA_CLEAR_IT(DMA_IT));
CW_DMA->ICR &= (~DMA_IT);
}
/**
* @brief 获取DMAy Channelx传输状态
*
* @param DMA_Channelx :CW_DMACHANNEL1/2/3/4/5
* @return uint8_t : DMA_CHANNEL_STATUS_INIT DMA_CHANNEL_STATUS_ADDRESSOUTRANGE
* DMA_CHANNEL_STATUS_STOPREQ DMA_CHANNEL_STATUS_SRCADDERR
* DMA_CHANNEL_STATUS_DSTADDERR DMA_CHANNEL_STATUS_TRANSCOMPLETE
*/
uint8_t DMA_GetFlagStatus(DMACHANNEL_TypeDef* DMA_Channelx)
{
/* Check the parameters */
assert_param(IS_DMA_ALL_PERIPH(DMA_Channelx));
return ( (uint8_t)(DMA_Channelx->CSR >> 8) );
}
/**
* @file cw32f030_flash.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-05-13
*
* @copyright Copyright (c) 2021
*
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CW32F03x_FLASH_H__
#define __CW32F03x_FLASH_H__
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "base_types.h"
#include "cw32f030.h"
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
//============================================================
/** @defgroup FLASH状态
* @{
*/
#define FLASH_FLAG_OK (0UL)
#define FLASH_FLAG_BSY (bv5) /*!< FLASH Busy flag */
#define FLASH_FLAG_PGERR (bv4) /*!< FLASH Program error flag */
#define FLASH_FLAG_WRPRTERR (bv1) /*!< FLASH Write protected error flag */
#define FLASH_FLAG_PCERR (bv0) /*!< FLASH PC error flag */
#define FLASH_ERROR_ADDR 0x80
/** @defgroup 读访问周期延时
* @{
*/
#define FLASH_Latency_1 ((uint32_t)0x00000000) /*!< FLASH One Latency cycle */
#define FLASH_Latency_2 ((uint32_t)0x00000001) /*!< FLASH Two Latency cycles */
#define FLASH_Latency_3 ((uint32_t)0x00000002) /*!< FLASH THREE Latency cycles */
#define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_1) || \
((LATENCY) == FLASH_Latency_2) || \
((LATENCY) == FLASH_Latency_3))
/** @defgroup FETCH开关
* @{
*/
#define FLASH_Prefetch_Enable ((uint32_t)0x00000008) /*!< FLASH Prefetch Enable */
#define FLASH_Prefetch_Disable ((uint32_t)0x00000000) /*!< FLASH Prefetch Disable */
#define IS_FLASH_PREFETCH_STATE(STATE) (((STATE) == FLASH_Prefetch_Enable) || \
((STATE) == FLASH_Prefetch_Disable))
/** @defgroup CACHE开关
* @{
*/
#define FLASH_Cache_Enable ((uint32_t)0x00000010) /*!< FLASH Buffer Enable */
#define FLASH_Cache_Disable ((uint32_t)0x00000000) /*!< FLASH Buffer Disable */
#define IS_FLASH_CACHE_STATE(STATE) (((STATE) == FLASH_Cache_Enable) || \
((STATE) == FLASH_Cache_Disable))
/** @defgroup 读保护等级
* @{
*/
#define FLASH_RDLEVEL0 ((uint16_t)0x00)
#define FLASH_RDLEVEL1 ((uint16_t)0x01)
#define FLASH_RDLEVEL2 ((uint16_t)0x02)
#define FLASH_RDLEVEL3 ((uint16_t)0x03)
#define IS_FLASH_RDLEVEL(LEVEL) (((LEVEL) == FLASH_RDLEVEL0) || \
((LEVEL) == FLASH_RDLEVEL1) || \
((LEVEL) == FLASH_RDLEVEL2) || \
((LEVEL) == FLASH_RDLEVEL3))
/** @defgroup 中断标志位
* @{
*/
#define FLASH_IT_PROG (bv4)
#define FLASH_IT_PAGELOCK (bv1)
#define FLASH_IT_PC (bv0)
#define IS_FLASH_IT(IT) (((IT) & 0xFFFFFFEC == 0x0UL) && ((IT) != 0x0UL))
#define IS_FLASH_GET_IT(IT) (((IT) == FLASH_IT_PROG) || \
((IT) == FLASH_IT_PAGELOCK) || \
((IT) == FLASH_IT_PC))
/** @defgroup FLASH页
* @{
*/
#define FLASH_WRProt_AllPages ((uint32_t)0x0000FFFF) /*!< Write protection of all Pages */
#define IS_FLASH_PAGE_Number(PAGENUMBER) (((PAGENUMBER) >= 0) && ((PAGENUMBER) <= 127))
#define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x00000000) && ((ADDRESS) < 0x00010000))
//============================================================
//设置FLASH读访问周期
void FLASH_SetLatency( uint32_t FLASH_Latency );
//设置预取使能
void FLASH_PrefetchCmd(uint32_t FLASH_Prefetch);
//设置BUFFER使能
void FLASH_CacheCmd(uint32_t FLASH_Buffer);
//获取FLASH的Fetch状态
FlagStatus FLASH_GetPrefetchStatus(void);
//获取FLASH的Cache状态
FlagStatus FLASH_GetCacheStatus(void);
//获取FLASH的读保护等级
uint8_t FLASH_GetReadOutLevel( void );
//设置FLASH的读保护等级
void FLASH_SetReadOutLevel( uint16_t RdLevel );
//解锁FLASH所有页面
void FLASH_UnlockAllPages(void);
//锁定FLASH所有页面
void FLASH_LockAllPages( void );
//解锁FLASH指定页面:按照页面号解锁,0~127
uint8_t FLASH_UnlockPage( uint8_t Page_Number );
//解锁FLASH指定页面:按照起始和终止地址解锁
uint8_t FLASH_UnlockPages( uint32_t StartAddr , uint32_t EndAddr );
//擦除FLASH指定页面:按照页面号擦除,0~127
uint8_t FLASH_ErasePage( uint8_t Page_Number );
//擦除FLASH指定页面:按照起始和终止地址擦除
uint8_t FLASH_ErasePages( uint32_t StartAddr , uint32_t EndAddr );
//指定地址开始写一定长度的数据,按照字节写
uint8_t FLASH_WirteBytes( uint32_t WriteAddr, uint8_t *pWrBuf , uint16_t WrByteCnt );
//锁定FLASH指定页面:按照页面号锁定,0~127
uint8_t FLASH_LockPage( uint8_t Page_Number );
//锁定FLASH指定页面:按照起始和终止地址锁定
uint8_t FLASH_LockPages( uint32_t StartAddr , uint32_t EndAddr );
//FLASH指定中断使能配置
void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
//获取指定FLASH中断标志位
ITStatus FLASH_GetITStatus(uint32_t FLASH_IT);
//清除指定FLASH中断标志位
void FLASH_ClearITPendingBit(uint32_t FLASH_IT);
//获取FLASH模块当前状态//
uint32_t FLASH_GetStatus(void);
//============================================================
#ifdef __cplusplus
}
#endif
#endif
/**
******************************************************************************
* @file CW030xx_gpio.c
* @author
* @version
* @date 2021-03-16
* @brief GPIO HAL module driver.
* This file provides firmware functions to manage the following
* functionalities of the General Purpose Input/Output (GPIO) peripheral:
* + Initialization and de-initialization functions
* + IO operation functions
*
***/
/* Includes ------------------------------------------------------------------*/
#include "cw32f030_gpio.h"
//=============================================================================
//GPIO 初始化,多个引脚
/**
* @brief GPIO 初始化,可同时设置多个引脚或单个引脚
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
* @param GPIO_Init 参见GPIO_InitTypeDef的定义
*/
void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
{
if( GPIO_Init->Mode == GPIO_MODE_ANALOG ) //模拟功能
{
REGBITS_SET( GPIOx->ANALOG , GPIO_Init->Pins );
}
else
{
REGBITS_CLR( GPIOx->ANALOG , GPIO_Init->Pins ); //数字功能
if( (GPIO_Init->Mode & GPIO_MODE_INPUT) == GPIO_MODE_INPUT ) //输入模式
{
REGBITS_SET( GPIOx->DIR , GPIO_Init->Pins );
if( GPIO_Init->Mode == GPIO_MODE_INPUT_PULLUP )
{
REGBITS_SET( GPIOx->PUR , GPIO_Init->Pins );
REGBITS_CLR( GPIOx->PDR , GPIO_Init->Pins );
}
if( GPIO_Init->Mode == GPIO_MODE_INPUT_PULLDOWN )
{
REGBITS_SET( GPIOx->PDR , GPIO_Init->Pins );
REGBITS_CLR( GPIOx->PUR , GPIO_Init->Pins );
}
REGBITS_CLR( GPIOx->RISEIE , GPIO_Init->Pins );
REGBITS_CLR( GPIOx->FALLIE , GPIO_Init->Pins );
REGBITS_CLR( GPIOx->HIGHIE , GPIO_Init->Pins );
REGBITS_CLR( GPIOx->LOWIE , GPIO_Init->Pins );
if( ( GPIO_Init->IT & GPIO_IT_RISING ) == GPIO_IT_RISING )
{
REGBITS_SET( GPIOx->RISEIE , GPIO_Init->Pins );
}
if( ( GPIO_Init->IT & GPIO_IT_FALLING ) == GPIO_IT_FALLING )
{
REGBITS_SET( GPIOx->FALLIE , GPIO_Init->Pins );
}
if( ( GPIO_Init->IT & GPIO_IT_HIGH ) == GPIO_IT_HIGH )
{
REGBITS_SET( GPIOx->HIGHIE , GPIO_Init->Pins );
}
if( ( GPIO_Init->IT & GPIO_IT_LOW ) == GPIO_IT_LOW )
{
REGBITS_SET( GPIOx->LOWIE , GPIO_Init->Pins );
}
}
else //输出模式
{
REGBITS_CLR( GPIOx->DIR , GPIO_Init->Pins );
if( GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP )
{
REGBITS_CLR( GPIOx->OPENDRAIN , GPIO_Init->Pins );
}
else
{
REGBITS_SET( GPIOx->OPENDRAIN , GPIO_Init->Pins );
}
if( GPIO_Init->Speed == GPIO_SPEED_HIGH )
{
REGBITS_SET( GPIOx->SPEED , GPIO_Init->Pins );
}
else
{
REGBITS_CLR( GPIOx->SPEED , GPIO_Init->Pins );
}
}
}
}
//=============================================================================
//GPIO 反初始化, 多个引脚
/**
* @brief GPIO 去初始化,可同时设置多个引脚或单个引脚
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
*
* @param GPIO_Pins 参数取值如下
* @arg GPIO_PIN_0/1/2.../15/ALL 可通过与运算同时操作多个引脚
*/
void GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pins)
{
REGBITS_SET( GPIOx->ANALOG , GPIO_Pins );
REGBITS_SET( GPIOx->DIR , GPIO_Pins );
REGBITS_CLR( GPIOx->PUR , GPIO_Pins );
REGBITS_CLR( GPIOx->PDR , GPIO_Pins );
REGBITS_CLR( GPIOx->RISEIE , GPIO_Pins );
REGBITS_CLR( GPIOx->FALLIE , GPIO_Pins );
REGBITS_CLR( GPIOx->HIGHIE , GPIO_Pins );
REGBITS_CLR( GPIOx->LOWIE , GPIO_Pins );
REGBITS_CLR( GPIOx->OPENDRAIN , GPIO_Pins );
}
//=============================================================================
//获取指定引脚电平,一个引脚
//注意:建议采用宏函数来获取引脚电平,例PA00_GETVALUE()
/**
* @brief 获取一个引脚的电平
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
* @param GPIO_Pin 参数取值如下
* @arg GPIO_PIN_0/1/2.../15
* @return GPIO_PinState 取值如下:
* @arg GPIO_Pin_SET
* @arg GPIO_Pin_RESET
*/
GPIO_PinState GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
if( GPIOx->IDR & GPIO_Pin )
{
return( GPIO_Pin_SET );
}
return( GPIO_Pin_RESET );
}
//=============================================================================
//设置指定引脚电平,多个引脚
//注意:如只操作一只引脚,建议采用宏函数,例PA00_SETHIGH(), PA00_SETLOW()
/**
* @brief 设置指定引脚电平,可同时设置多个引脚
*
* @param GPIOx GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
* @param GPIO_Pins 参数取值如下
* @arg GPIO_PIN_0/1/2.../15/ALL;
* @param PinState 取值如下:
* @arg GPIO_Pin_SET
* @arg GPIO_Pin_RESET
*/
void GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pins, GPIO_PinState PinState)
{
if( PinState == GPIO_Pin_SET )
{
GPIOx->BSRR = GPIO_Pins;
}
else
{
GPIOx->BRR = GPIO_Pins;
}
}
//=============================================================================
//设置端口低字节(B0-B7)引脚电平
/**
* @brief 设置端口低字节(B0-B7)引脚电平
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOF
* @param Value 取值范围:0x00~0xFF
*/
void GPIO_LowByte_Write(GPIO_TypeDef* GPIOx, uint8_t Value )
{
GPIOx->ODRLOWBYTE = Value;
}
//=============================================================================
//设置端口高字节(B8-B15)引脚电平
/**
* @brief 设置端口高字节(B8-B15)引脚电平
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC
* @param Value 取值范围:0x00~0xFF
*/
void GPIO_HighByte_Write(GPIO_TypeDef* GPIOx, uint8_t Value )
{
GPIOx->ODRHIGHBYTE = Value;
}
//=============================================================================
//翻转指定引脚电平,多个引脚
//注意:如只操作一只引脚,建议采用宏函数,例PA00_TOG()
/**
* @brief 翻转指定引脚电平,可同时设置多个引脚
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
* @param GPIO_Pins
*/
void GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pins)
{
GPIOx->TOG = GPIO_Pins;
}
//=============================================================================
//锁定指定引脚配置项,多个引脚
/**
* @brief 锁定指定引脚配置项,可同时设置多个引脚
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
* @param GPIO_Pins
*/
void GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pins)
{
REGBITS_SET( GPIOx->LOCK , GPIO_Pins );
}
//=============================================================================
//将PA13/PA14设置成GPIO
/**
* @brief 将PA13/PA14设置成GPIO
*
*/
void GPIO_SWD2GPIO( void )
{
CW_SYSCTRL->CR2 = CW_SYSCTRL->CR2 | ( 0x5A5A0000 | bv1 );
}
//=============================================================================
//将PA13/PA14设置成SWD
/**
* @brief 将PA13/PA14设置成SWD,PA13/SWDIO PA14/SWCLK
*
*/
void GPIO_GPIO2SWD( void )
{
CW_SYSCTRL->CR2 = 0x5A5A0000 | ( CW_SYSCTRL->CR2 & (~(bv1)) );
}
//=============================================================================
//配置端口滤波
// FltClk 只能是宏定义中定义的参数
/**
* @brief 配置端口滤波
*
* @param GPIOx 参数为下列参数之一:
* @arg CW_GPIOA CW_GPIOB CW_GPIOC CW_GPIOF
* @param GPIO_Pins
* @param FltClk 只能是宏定义中定义的参数 GPIO_FLTCLK_xxx
*/
void GPIO_ConfigFilter( GPIO_TypeDef* GPIOx, uint16_t GPIO_Pins, uint32_t FltClk )
{
GPIOx->FILTER = FltClk | GPIO_Pins;
}
//=============================================================================
//配置端口辅助功能
//请使用CW32f030_gpio.h中的宏定义来配置每个端口的辅助功能
/**
* @file cw32f030_systick.c
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-05-13
*
* @copyright Copyright (c) 2021
*
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "cw32f030_systick.h"
/* Private_TypesDefinitions --------------------------------------------------*/
/* Private_Defines -----------------------------------------------------------*/
/* Private_Variables ---------------------------------------------------------*/
__IO uint32_t uwTick;
uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
TickFreqTypeDef uwTickFreq = TICK_FREQ_DEFAULT; /* 1KHz */
/* Private_FunctionPrototypes ------------------------------------------------*/
/* Private_Functions ---------------------------------------------------------*/
/* Public_Functions ----------------------------------------------------------*/
/**
* @brief This function configures the source of the time base.
* The time source is configured to have 1ms time base with a dedicated
* Tick interrupt priority.
* @note This function is called automatically at the beginning of program after
* reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
* @note In the default implementation, SysTick timer is the source of time base.
* It is used to generate interrupts at regular time intervals.
* Care must be taken if HAL_Delay() is called from a peripheral ISR process,
* The SysTick interrupt must have higher priority (numerically lower)
* than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
* The function is declared as __Weak to be overwritten in case of other
* implementation in user file.
* @param system hclk freq.
* @retval HAL status
*/
__weak void InitTick(uint32_t HclkFreq)
{
/*Configure the SysTick to have interrupt in 1ms time basis*/
if (SysTick_Config(HclkFreq / (1000U / uwTickFreq)) > 0U)
{
return ;
}
/* Configure the SysTick IRQ priority */
if (TICK_INT_PRIORITY < (1UL << __NVIC_PRIO_BITS))
{
NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY);
uwTickPrio = TICK_INT_PRIORITY;
}
else
{
return ;
}
}
/**
* @brief Provides a tick value in millisecond.
* @note This function is declared as __weak to be overwritten in case of other
* implementations in user file.
* @retval tick value
*/
__weak uint32_t GetTick(void)
{
return uwTick;
}
/**
* @brief This function provides accurate delay (in milliseconds) based
* on variable incremented.
* @note In the default implementation , SysTick timer is the source of time base.
* It is used to generate interrupts at regular time intervals where uwTick
* is incremented.
* @note ThiS function is declared as __weak to be overwritten in case of other
* implementations in user file.
* @param Delay specifies the delay time length, in milliseconds.
* @retval None
*/
__weak void SysTickDelay(uint32_t Delay)
{
uint32_t tickstart = GetTick();
uint32_t wait = Delay;
/* Add a freq to guarantee minimum wait */
if (wait < MAX_SYSTICK_DELAY)
{
wait += (uint32_t)(uwTickFreq);
}
while((GetTick() - tickstart) < wait)
{
}
}
/**
* @brief Suspend Tick increment.
* @note In the default implementation , SysTick timer is the source of time base. It is
* used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
* is called, the the SysTick interrupt will be disabled and so Tick increment
* is suspended.
* @note This function is declared as __weak to be overwritten in case of other
* implementations in user file.
* @retval None
*/
__weak void SuspendTick(void)
{
/* Disable SysTick Interrupt */
REGBITS_CLR(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
}
/**
* @brief Resume Tick increment.
* @note In the default implementation , SysTick timer is the source of time base. It is
* used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
* is called, the the SysTick interrupt will be enabled and so Tick increment
* is resumed.
* @note This function is declared as __weak to be overwritten in case of other
* implementations in user file.
* @retval None
*/
__weak void ResumeTick(void)
{
/* Enable SysTick Interrupt */
REGBITS_SET(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn */
uwTick += uwTickFreq;
/* USER CODE END SysTick_IRQn */
}
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x0;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0000FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x200;
define symbol __ICFEDIT_size_heap__ = 0x200;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite, block CSTACK, block HEAP };
\ No newline at end of file
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<batchBuild/>
</workspace>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment