Commit ecc84c98 authored by 2088234910's avatar 2088234910

实验3参数还需细调

parent 016ba01c
setup()
{
__message "----- setup hardware for Flashloader -----\n";
/*Wait*/
__delay(5);
__emulatorSpeed(0);
/*Vectors at RAM*/
__writeMemory32(0x20000000, 0xE000ED08, "Memory");
}
execUserPreload()
{
__message "----- execUserPreload -----\n";
setup();
}
execUserFlashInit() // Called by debugger before loading flash loader in RAM.
{
__message "----- execUserFlashInit -----\n";
setup();
}
<?xml version="1.0" encoding="UTF-8"?>
<flash_board>
<pass>
<loader>$TOOLKIT_DIR$\config\flashloader\CW\FlashLoader_CW32F030x6.flash</loader>
<range>CODE 0x0 0x7fff</range>
</pass>
</flash_board>
<?xml version="1.0" encoding="iso-8859-1"?>
<flash_device>
<exe>$TOOLKIT_DIR$\config\flashloader\CW\FlashCW32F030_RAM6K.out</exe>
<page>1</page>
<block>64 0x200</block>
<flash_base>0x00000000</flash_base>
<macro>$TOOLKIT_DIR$\config\flashloader\CW\FlashLoader_CW030.mac</macro>
<aggregate>0</aggregate>
</flash_device>
<?xml version="1.0" encoding="UTF-8"?>
<flash_board>
<pass>
<loader>$TOOLKIT_DIR$\config\flashloader\CW\FlashLoader_CW32F030x8.flash</loader>
<range>CODE 0x0 0xffff</range>
</pass>
</flash_board>
<?xml version="1.0" encoding="iso-8859-1"?>
<flash_device>
<exe>$TOOLKIT_DIR$\config\flashloader\CW\FlashCW32F030_RAM8K.out</exe>
<page>1</page>
<block>128 0x200</block>
<flash_base>0x00000000</flash_base>
<macro>$TOOLKIT_DIR$\config\flashloader\CW\FlashLoader_CW030.mac</macro>
<aggregate>0</aggregate>
</flash_device>
/*###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
用于EWARM工具的单片机Flash烧写配置文件,请将该文件下的arm文件加拷贝到EWARM的安装目录下。
1. 拷贝arm文件到EWARM的安装路径:
如EWARM安装路径为D:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2
则将arm文件夹拷贝到D:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\目录下,覆盖同名的arm文件夹。
2. 使用:
1) EWARM界面->"Project"->"Options..."->"Linker"->"Config"->在显示的标签栏中选择“Override default",点击"..."在弹出的对话框中选择"CW32F030.icf"->点击"打开"
2)EWARM界面->"Project"->"Options..."->"Debugger"->"Download"->在显示的标签栏中选择“Override default .board file",点击"..."在弹出的对话框中选择"CW"文件夹下的"FlashLoader_CW030.board"->点击"打开"
用于MDK工具的单片机Flash烧写配置文件,请将该文件拷贝到Keil的安装目录下。
1. 拷贝文件到Keil的安装路径:
如Keil安装路径为C:\Program Files (x86)\Keil_v5
则将FlashCW32F030.FLM拷贝到C:\Program Files (x86)\Keil_v5\ARM\Flash\文件中。
2. 使用:
Keil界面->"Options for Target"->"Debug"->"Setting"->"Flash Download"->"Add"->在弹出的对话框中选择"CW32F030"->点击"Add","确定"
;/*****************************************************************************/
;/* Startup for ARM */
;/* Version V1.0 */
;/* Date 2021-03-12 */
;/* Target-mcu {MCU_PN_H} */
;/*****************************************************************************/
; Stack Configuration
; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
Stack_Size EQU 0x00000200
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; Heap Configuration
; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors
DCD __initial_sp ; Top of Stack
DCD Reset_Handler ;< -15 Reset Vector, invoked on Power up and warm reset
DCD NMI_Handler ;< -14 Non maskable Interrupt, cannot be stopped or preempted
DCD HardFault_Handler ;< -13 Hard Fault, all classes of Fault
DCD 0 ;< -12 Reserved
DCD 0 ;< -11 Reserved
DCD 0 ;< -10 Reserved
DCD 0 ;< -9 Reserved
DCD 0 ;< -8 Reserved
DCD 0 ;< -7 Reserved
DCD 0 ;< -6 Reserved
DCD SVC_Handler ;< -5 System Service Call via SVC instruction
DCD 0 ;< -4 Reserved
DCD 0 ;< -3 Reserved
DCD PendSV_Handler ;< -2 Pendable request for system service
DCD SysTick_Handler ;< -1 System Tick Timer
DCD WDT_IRQHandler ;< 0 Watch Dog Timer Interrupt Handler
DCD LVD_IRQHandler ;< 1 Low Voltage Detect Interrupt Handler
DCD RTC_IRQHandler ;< 2 Real Time Clock Interrupt Handler
DCD FLASHRAM_IRQHandler ;< 3 Flash/RAM Interrupt Handler
DCD RCC_IRQHandler ;< 4 RCC Interupt Handler
DCD GPIOA_IRQHandler ;< 5 GPIOA Interrupt Handler
DCD GPIOB_IRQHandler ;< 6 GPIOB Interrupt Handler
DCD GPIOC_IRQHandler ;< 7 GPIOC Interrupt Handler
DCD GPIOF_IRQHandler ;< 8 GPIOF Interrupt Handler
DCD DMACH1_IRQHandler ;< 9 DMA Channel 1 Interrupt Handler
DCD DMACH23_IRQHandler ;< 10 DMA Channel 2/3 Interrupt Handler
DCD DMACH45_IRQHandler ;< 11 DMA Channel 4/5 Interrupt Handler
DCD ADC_IRQHandler ;< 12 ADC Interrupt Handler
DCD ATIM_IRQHandler ;< 13 Advanced Timer Interrupt Handler
DCD VC1_IRQHandler ;< 14 Voltage Comparator 1 Interrupt Handler
DCD VC2_IRQHandler ;< 15 Voltage Comparator 2 Interrupt Handler
DCD GTIM1_IRQHandler ;< 16 General Timer1 Interrupt Handler
DCD GTIM2_IRQHandler ;< 17 General Timer2 Interrupt Handler
DCD GTIM3_IRQHandler ;< 18 General Timer3 Interrupt Handler
DCD GTIM4_IRQHandler ;< 19 General Timer4 Interrupt Handler
DCD BTIM1_IRQHandler ;< 20 Base Timer1 Interrupt Handler
DCD BTIM2_IRQHandler ;< 21 Base Timer2 Interrupt Handler
DCD BTIM3_IRQHandler ;< 22 Base Timer3 Interrupt Handler
DCD I2C1_IRQHandler ;< 23 I2C1 Interrupt Handler
DCD I2C2_IRQHandler ;< 24 I2C2 Interrupt Handler
DCD SPI1_IRQHandler ;< 25 SPI1 Interrupt Handler
DCD SPI2_IRQHandler ;< 26 SPI2 Interrupt Handler
DCD UART1_IRQHandler ;< 27 UART1 Interrupt Handler
DCD UART2_IRQHandler ;< 28 UART2 Interrupt Handler
DCD UART3_IRQHandler ;< 29 UART3 Interrupt Handler
DCD AWT_IRQHandler ;< 30 Auto Wakeup Timer Handler
DCD FAULT_IRQHandler ;< 31 FAULT Interrupt Handler
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset Handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
;reset NVIC if in rom debug
LDR R0, =0x20000000
LDR R2, =0x0
MOVS R1, #0 ; for warning,
ADD R1, PC,#0 ; for A1609W,
CMP R1, R0
BLS RAMCODE
; ram code base address.
ADD R2, R0,R2
RAMCODE
; reset Vector table address.
LDR R0, =0xE000ED08
STR R2, [R0]
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WDT_IRQHandler [WEAK]
EXPORT LVD_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASHRAM_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT GPIOA_IRQHandler [WEAK]
EXPORT GPIOB_IRQHandler [WEAK]
EXPORT GPIOC_IRQHandler [WEAK]
EXPORT GPIOF_IRQHandler [WEAK]
EXPORT DMACH1_IRQHandler [WEAK]
EXPORT DMACH23_IRQHandler [WEAK]
EXPORT DMACH45_IRQHandler [WEAK]
EXPORT ADC_IRQHandler [WEAK]
EXPORT ATIM_IRQHandler [WEAK]
EXPORT VC1_IRQHandler [WEAK]
EXPORT VC2_IRQHandler [WEAK]
EXPORT GTIM1_IRQHandler [WEAK]
EXPORT GTIM2_IRQHandler [WEAK]
EXPORT GTIM3_IRQHandler [WEAK]
EXPORT GTIM4_IRQHandler [WEAK]
EXPORT BTIM1_IRQHandler [WEAK]
EXPORT BTIM2_IRQHandler [WEAK]
EXPORT BTIM3_IRQHandler [WEAK]
EXPORT I2C1_IRQHandler [WEAK]
EXPORT I2C2_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT UART1_IRQHandler [WEAK]
EXPORT UART2_IRQHandler [WEAK]
EXPORT UART3_IRQHandler [WEAK]
EXPORT AWT_IRQHandler [WEAK]
EXPORT FAULT_IRQHandler [WEAK]
WDT_IRQHandler
LVD_IRQHandler
RTC_IRQHandler
FLASHRAM_IRQHandler
RCC_IRQHandler
GPIOA_IRQHandler
GPIOB_IRQHandler
GPIOC_IRQHandler
GPIOF_IRQHandler
DMACH1_IRQHandler
DMACH23_IRQHandler
DMACH45_IRQHandler
ADC_IRQHandler
ATIM_IRQHandler
VC1_IRQHandler
VC2_IRQHandler
GTIM1_IRQHandler
GTIM2_IRQHandler
GTIM3_IRQHandler
GTIM4_IRQHandler
BTIM1_IRQHandler
BTIM2_IRQHandler
BTIM3_IRQHandler
I2C1_IRQHandler
I2C2_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
UART1_IRQHandler
UART2_IRQHandler
UART3_IRQHandler
AWT_IRQHandler
FAULT_IRQHandler
B .
ENDP
ALIGN
; User Initial Stack & Heap
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
#ifndef __BASE_TYPES_H
#define __BASE_TYPES_H
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
#ifndef TRUE
/** Value is true (boolean_t type) */
#define TRUE ((boolean_t) 1u)
#endif
#ifndef FALSE
/** Value is false (boolean_t type) */
#define FALSE ((boolean_t) 0u)
#endif
/** Returns the minimum value out of two values */
#define MINIMUM( X, Y ) ((X) < (Y) ? (X) : (Y))
/** Returns the maximum value out of two values */
#define MAXIMUM( X, Y ) ((X) > (Y) ? (X) : (Y))
/** Returns the dimension of an array */
#define ARRAY_SZ( X ) (sizeof(X) / sizeof((X)[0]))
#ifdef __DEBUG_ASSERT
#define ASSERT(x) do{ assert((x)> 0u) ; }while(0);
#else
#define ASSERT(x) {}
#endif
/******************************************************************************
* Global type definitions
******************************************************************************/
/** logical datatype (only values are TRUE and FALSE) */
typedef uint8_t boolean_t;
/** single precision floating point number (4 byte) */
typedef float float32_t;
/** double precision floating point number (8 byte) */
typedef double float64_t;
/** ASCII character for string generation (8 bit) */
typedef char char_t;
/** function pointer type to void/void function */
typedef void (*func_ptr_t)(void);
/** function pointer type to void/uint8_t function */
typedef void (*func_ptr_arg1_t)(uint8_t u8Param);
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/
#define bv(n) ((uint32_t)1u << (n))
#define bv0 (((uint32_t)1u) << 0)
#define bv1 (((uint32_t)1u) << 1)
#define bv2 (((uint32_t)1u) << 2)
#define bv3 (((uint32_t)1u) << 3)
#define bv4 (((uint32_t)1u) << 4)
#define bv5 (((uint32_t)1u) << 5)
#define bv6 (((uint32_t)1u) << 6)
#define bv7 (((uint32_t)1u) << 7)
#define bv8 (((uint32_t)1u) << 8)
#define bv9 (((uint32_t)1u) << 9)
#define bv10 (((uint32_t)1u) << 10)
#define bv11 (((uint32_t)1u) << 11)
#define bv12 (((uint32_t)1u) << 12)
#define bv13 (((uint32_t)1u) << 13)
#define bv14 (((uint32_t)1u) << 14)
#define bv15 (((uint32_t)1u) << 15)
#define bv16 (((uint32_t)1u) << 16)
#define bv17 (((uint32_t)1u) << 17)
#define bv18 (((uint32_t)1u) << 18)
#define bv19 (((uint32_t)1u) << 19)
#define bv20 (((uint32_t)1u) << 20)
#define bv21 (((uint32_t)1u) << 21)
#define bv22 (((uint32_t)1u) << 22)
#define bv23 (((uint32_t)1u) << 23)
#define bv24 (((uint32_t)1u) << 24)
#define bv25 (((uint32_t)1u) << 25)
#define bv26 (((uint32_t)1u) << 26)
#define bv27 (((uint32_t)1u) << 27)
#define bv28 (((uint32_t)1u) << 28)
#define bv29 (((uint32_t)1u) << 29)
#define bv30 (((uint32_t)1u) << 30)
#define bv31 (((uint32_t)1u) << 31)
#define REGBITS_SET( Reg , Mask ) ( (Reg) |= (Mask) )
#define REGBITS_CLR( Reg , Mask ) ( (Reg) &= (~((uint32_t)(Mask))) )
#define REGBITS_GET( Reg , Mask ) ( (Reg) & (Mask) )
#define REGBITS_MODIFY( Reg , Mask , Value ) ( (Reg) = ((Reg) & (~(uint32_t)(Mask))) | (Value) )
/* Exported macro ------------------------------------------------------------*/
// #define USE_FULL_ASSERT
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
#endif /* __BASE_TYPES_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
/**
* @file cw32f030_awt.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-05-18
*
* @copyright Copyright (c) 2021
*
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CW32F030_AWT_H
#define __CW32F030_AWT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "cw32f030.h"
typedef struct
{
uint32_t AWT_ClkSource; /* 时钟源选择,设置值0 - 4 */
uint32_t AWT_Prescaler; /* 预分配系数,设置值1 - 15,对应取值范围2的n次幂,n=1,2…15 */
uint32_t AWT_Period; /* 计数重载周期,低16位有效,取值范围0x0000 到 0xFFFF. */
uint32_t AWT_Mode; /* AWT工作模式,固定为11 */
} AWT_TimeCntInitTypeDef;
#define AWT_CLKSOURCE_HSIOSC ( uint32_t )(0x00UL << 8)
#define AWT_CLKSOURCE_LSI ( uint32_t )(0x01UL << 8)
#define AWT_CLKSOURCE_HSE ( uint32_t )(0x02UL << 8)
#define AWT_CLKSOURCE_LSE ( uint32_t )(0x03UL << 8)
#define AWT_CLKSOURCE_ETR ( uint32_t )(0x04UL << 8)
#define IS_AWT_CLKSOURCE(SOURCE) (((SOURCE) == AWT_CLKSOURCE_HSIOSC) || \
((SOURCE) == AWT_CLKSOURCE_LSI) || \
((SOURCE) == AWT_CLKSOURCE_HSE) || \
((SOURCE) == AWT_CLKSOURCE_LSE) || \
((SOURCE) == AWT_CLKSOURCE_ETR))
#define AWT_PRS_DIV2 ( uint32_t )(0x01UL << 4)
#define AWT_PRS_DIV4 ( uint32_t )(0x02UL << 4)
#define AWT_PRS_DIV8 ( uint32_t )(0x03UL << 4)
#define AWT_PRS_DIV16 ( uint32_t )(0x04UL << 4)
#define AWT_PRS_DIV32 ( uint32_t )(0x05UL << 4)
#define AWT_PRS_DIV64 ( uint32_t )(0x06UL << 4)
#define AWT_PRS_DIV128 ( uint32_t )(0x07UL << 4)
#define AWT_PRS_DIV256 ( uint32_t )(0x08UL << 4)
#define AWT_PRS_DIV512 ( uint32_t )(0x09UL << 4)
#define AWT_PRS_DIV1024 ( uint32_t )(0x0AUL << 4)
#define AWT_PRS_DIV2048 ( uint32_t )(0x0BUL << 4)
#define AWT_PRS_DIV4096 ( uint32_t )(0x0CUL << 4)
#define AWT_PRS_DIV8192 ( uint32_t )(0x0DUL << 4)
#define AWT_PRS_DIV16384 ( uint32_t )(0x0EUL << 4)
#define AWT_PRS_DIV32768 ( uint32_t )(0x0FUL << 4)
#define IS_AWT_PRS_DIV(DIV) (((DIV) == AWT_PRS_DIV2) || \
((DIV) == AWT_PRS_DIV4) || \
((DIV) == AWT_PRS_DIV8) || \
((DIV) == AWT_PRS_DIV16) || \
((DIV) == AWT_PRS_DIV32) || \
((DIV) == AWT_PRS_DIV64) || \
((DIV) == AWT_PRS_DIV128) || \
((DIV) == AWT_PRS_DIV256) || \
((DIV) == AWT_PRS_DIV512) || \
((DIV) == AWT_PRS_DIV1024) || \
((DIV) == AWT_PRS_DIV2048) || \
((DIV) == AWT_PRS_DIV4096) || \
((DIV) == AWT_PRS_DIV8192) || \
((DIV) == AWT_PRS_DIV16384) || \
((DIV) == AWT_PRS_DIV32768))
#define AWT_MODE_TIMECNT ( uint32_t )(0x03UL << 1)
#define IS_AWT_MODE(MODE) ((MODE) == AWT_MODE_TIMECNT)
#define AWT_CR_EN bv0
#define IS_AWT_ARR(ARR) ((ARR) <= 65535)
#define AWT_IT_UD ((uint32_t)0x08)
#define IS_AWT_IT(IT) ((((IT) & (uint32_t)0xFFFFFFF7) == 0x0000) && ((IT) != 0x0000))
#define IS_AWT_GET_IT(IT) (((IT) == AWT_IT_UD)
void AWT_DeInit(void);
void AWT_TimeCntInit(AWT_TimeCntInitTypeDef* AWT_TimeCntInitStruct);
void AWT_TimeCntStructInit(AWT_TimeCntInitTypeDef* AWT_TimeCntInitStruct);
void AWT_Cmd(FunctionalState NewState);
void AWT_ITConfig(uint32_t AWT_IT, FunctionalState NewState);
ITStatus AWT_GetITStatus(uint32_t AWT_IT);
void AWT_ClearITPendingBit(uint32_t AWT_IT);
void AWT_ClkSourceConfig(uint32_t AWT_ClkSource);
void AWT_PrescalerConfig(uint32_t AWT_Prescaler);
uint16_t AWT_GetCounter(void);
uint16_t AWT_GetAutoreload(void);
uint32_t AWT_GetClkSource(void);
uint32_t AWT_GetPrescaler(void);
#ifdef __cplusplus
}
#endif
#endif
/**
* @file cw32f030_crc.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_CRC_H__
#define __CW32F03x_CRC_H__
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "base_types.h"
#include "cw32f030.h"
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
//============================================================
uint16_t CRC16_Calc_8bit( uint8_t CrcMode , uint8_t *pByteBuf , uint16_t ByteCnt );
uint16_t CRC16_Calc_16bit( uint8_t CrcMode , uint16_t *pHWBuf , uint16_t HalfWordCnt );
uint16_t CRC16_Calc_32bit( uint8_t CrcMode , uint32_t *pWBuf , uint16_t WordCnt );
uint32_t CRC32_Calc_8bit( uint8_t CrcMode , uint8_t *pByteBuf , uint16_t ByteCnt );
uint32_t CRC32_Calc_16bit( uint8_t CrcMode , uint16_t *pHWBuf , uint16_t HalfWordCnt );
uint32_t CRC32_Calc_32bit( uint8_t CrcMode , uint32_t *pWBuf , uint16_t WordCnt );
//============================================================
#define CRC16_IBM 0x00UL
#define CRC16_MAXIM 0x01UL
#define CRC16_USB 0x02UL
#define CRC16_MODBUS 0x03UL
#define CRC16_CCITT 0x04UL
#define CRC16_CCITTFALSE 0x05UL
#define CRC16_X25 0x06UL
#define CRC16_XMODEM 0x07UL
#define CRC32_DEFAULT 0x08UL
#define CRC32_MPEG2 0x09UL
#define IS_CRC_CRC16_MODE(MODE) (((MODE) == CRC16_IBM) || \
((MODE) == CRC16_MAXIM) || \
((MODE) == CRC16_USB) || \
((MODE) == CRC16_MODBUS) || \
((MODE) == CRC16_CCITT) || \
((MODE) == CRC16_CCITTFALSE) || \
((MODE) == CRC16_X25) || \
((MODE) == CRC16_XMODEM))
#define IS_CRC_CRC32_MODE(MODE) (((MODE) == CRC32_DEFAULT) || \
((MODE) == CRC32_MPEG2))
//============================================================
#ifdef __cplusplus
}
#endif
#endif
/**
* @file cw32f030_debug.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_DEBUG_H__
#define __CW32F03x_DEBUG_H__
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "base_types.h"
#include "cw32f030.h"
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
//============================================================
void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState);
#define DBGMCU_ATIM_STOP ((uint32_t)0x00000001)
#define DBGMCU_GTIM1_STOP ((uint32_t)0x00000002)
#define DBGMCU_GTIM2_STOP ((uint32_t)0x00000004)
#define DBGMCU_GTIM3_STOP ((uint32_t)0x00000008)
#define DBGMCU_GTIM4_STOP ((uint32_t)0x00000010)
#define DBGMCU_BTIM123_STOP ((uint32_t)0x00000020)
#define DBGMCU_AWT_STOP ((uint32_t)0x00000040)
#define DBGMCU_RTC_STOP ((uint32_t)0x00000100)
#define DBGMCU_IWDT_STOP ((uint32_t)0x00000200)
#define DBGMCU_WWDT_STOP ((uint32_t)0x00000400)
#define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFF880) == 0x00) && ((PERIPH) != 0x00))
//============================================================
#ifdef __cplusplus
}
#endif
#endif
/**
* @file cw32f030_digitalsign.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-05-14
*
* @copyright Copyright (c) 2021
*
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CW32F03x_DIGITALSIGN_H__
#define __CW32F03x_DIGITALSIGN_H__
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "base_types.h"
#include "cw32f030.h"
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
//============================================================
#define DIGITALSIGN_BASE 0x00012610UL
#define CHIP_TYPE_BASE 0x00012610UL
#define PIN_COUNT_BASE 0x00012626UL
#define FLASH_SIZE_BASE 0x00012628UL
#define RAM_SIZE_BASE 0x0001262CUL
#define CHIP_UID_BASE 0x00012660UL
#define CHIP_TYPE_LENGTH 22
#define CHIP_UID_LENGTH 10
//============================================================
//获取芯片型号//
void DIGITALSIGN_GetChipType(uint8_t *pChipType);
//获取管脚数量//
uint16_t DIGITALSIGN_GetPinCount(void);
//获取FLASH容量//
uint32_t DIGITALSIGN_GetFlashSize(void);
//获取RAM容量//
uint32_t DIGITALSIGN_GetRamSize(void);
//获取芯片UID//
void DIGITALSIGN_GetChipUid(uint8_t *pChipUid);
//============================================================
#ifdef __cplusplus
}
#endif
#endif
/**
* @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 cw32f030_i2c.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2021-04-27
*
* @copyright Copyright (c) 2021
* x
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CW32F03x_I2C_H
#define __CW32F03x_I2C_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "cw32f030.h"
#include "base_types.h"
#include "cw32f030_rcc.h"
//I2C从设备地址,按照8 BIT设置,最低位0或者1均可。
#define I2C_SLAVEADDRESS 0xA0 //读EEPROM时设置为0XA0,主从通信时设置为0x60
//主从通信时从机地址设置(在从程序中设置)
#define OwnSlaveAddress0 0x60 //按照8位设置,最低位设置为0或者1,写入寄存器之前会自动右移一位,再写入寄存器高7位
#define OwnSlaveAddress1 0xb0 //按照8位设置,最低位设置为0或者1,写入寄存器之前会自动右移一位,再写入寄存器高7位
#define OwnSlaveAddress2 0xfe //按照8位设置,最低位设置为0或者1,写入寄存器之前会自动右移一位,再写入寄存器高7位
/**
* @brief I2C通道选择
*
*/
typedef enum en_i2c_channel
{
I2C1 = 0,///<通道1
I2C2 = 1,///<通道2
}en_i2c_channel_t;
/**
******************************************************************************
** \brief I2C初始化配置结构
*****************************************************************************/
typedef struct
{
FunctionalState I2C_BaudEn; ///<波特率计数器使能
uint8_t I2C_Baud; ///<波特率计数器配置
uint8_t I2C_OwnSlaveAddr0; ///<从机地址0
FunctionalState I2C_OwnGc; ///<广播响应使能
uint8_t I2C_OwnSlaveAddr1; ///<从机地址1
uint8_t I2C_OwnSlaveAddr2; ///<从机地址2
FunctionalState I2C_FLT; ///<FLT配置
FunctionalState I2C_AA; ///<ACK配置
}I2C_InitTypeDef;
/** @defgroup I2C_Exported_Constants
* @{
*/
#define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == CW_I2C1) || \
((PERIPH) == CW_I2C2))
#define IS_I2C_OWN_ADDRESS0(ADDRESS0) ((ADDRESS0) <= 0x7F)
#define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x7F)
#define IS_I2C_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= 0x7F)
#define I2C_Baud_BRR_1 ((uint8_t)0x01)
#define I2C_Baud_BRR_2 ((uint8_t)0x02)
#define I2C_Baud_BRR_3 ((uint8_t)0x03)
#define I2C_Baud_BRR_4 ((uint8_t)0x04)
#define I2C_Baud_BRR_5 ((uint8_t)0x05)
#define I2C_Baud_BRR_6 ((uint8_t)0x06)
#define I2C_Baud_BRR_7 ((uint8_t)0x07)
#define IS_I2C_Baud_BRR(PARA) (((PARA) == I2C_Baud_BRR_1) || \
((PARA) == I2C_Baud_BRR_2) ||\
((PARA) == I2C_Baud_BRR_3) ||\
((PARA) == I2C_Baud_BRR_4) ||\
((PARA) == I2C_Baud_BRR_5) ||\
((PARA) == I2C_Baud_BRR_6) ||\
((PARA) == I2C_Baud_BRR_7))
/** @defgroup I2C_transfer_direction
* @{
*/
#define I2C_Direction_Transmitter ((uint8_t)0x00)
#define I2C_Direction_Receiver ((uint8_t)0x01)
#define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \
((DIRECTION) == I2C_Direction_Receiver))
//波特率生成器启停设置
void I2C_BaudGeneratorEnable(I2C_TypeDef* I2Cx, FunctionalState NewState);
//设置波特率配置寄存器
void I2C_SetBaud(I2C_TypeDef *I2Cx, uint8_t u8TBaud);
//发送START信号
void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
//发送STOP信号
void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
//Ack信号配置
void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
//Filter配置
void I2C_FilterConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
//做从机时的从机地址0配置
void I2C_SetOwnSlaveAddress0(I2C_TypeDef* I2Cx, uint8_t I2CSlaveAddr);
//做从机时的从机地址1配置
void I2C_SetOwnSlaveAddress1(I2C_TypeDef* I2Cx, uint8_t I2CSlaveAddr);
//做从机时的从机地址2配置
void I2C_SetOwnSlaveAddress2(I2C_TypeDef* I2Cx, uint8_t I2CSlaveAddr);
//做从机时广播响应配置
void I2C_GcConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
//I2C模块使能
void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
//获取SI中断标志
ITStatus I2C_GetIrq(I2C_TypeDef *I2Cx);
//清除SI中断标志
void I2C_ClearIrq(I2C_TypeDef *I2Cx);
//获取状态寄存器
uint8_t I2C_GetState(I2C_TypeDef *I2Cx);
//I2C MASTER初始化
void I2C_Master_Init(I2C_TypeDef *I2Cx,I2C_InitTypeDef *I2C_InitStruct);
//I2C SLAVE初始化
void I2C_Slave_Init(I2C_TypeDef *I2Cx,I2C_InitTypeDef *I2C_InitStruct);
//I2C1关闭初始化
void I2C1_DeInit(void);
//I2C2关闭初始化
void I2C2_DeInit(void);
//发送1字节数据
void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
//接收1字节数据
uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx);
//发送地址字节
void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction);
//软复位I2C1模块
void I2C1_SoftwareResetCmd(FunctionalState NewState);
//软复位I2C2模块
void I2C2_SoftwareResetCmd(FunctionalState NewState);
//主写EEPROM函数
void I2C_MasterWriteEepromData(I2C_TypeDef *I2Cx,uint8_t u8Addr,uint8_t *pu8Data,uint32_t u32Len);
//主读EEPROM函数
void I2C_MasterReadEepomData(I2C_TypeDef *I2Cx,uint8_t u8Addr,uint8_t *pu8Data,uint32_t u32Len);
//主发送数据
void I2C_MasterSendDataToSlave(I2C_TypeDef *I2Cx,uint8_t *pu8Data,uint32_t u32Len);
//主接收数据
void I2C_MasterRecDataFromSlave(I2C_TypeDef *I2Cx,uint8_t *pu8Data,uint32_t u32Len);
//从发送数据
void I2C_SlaveSendDataToMaster(I2C_TypeDef* I2Cx,uint8_t *pu8Data,uint32_t *u32Len);
//从接收数据
void I2C_SlaveRecDataFromMaster(I2C_TypeDef* I2Cx,uint8_t *pu8Data,uint32_t *pu32Len);
//从机状态检测
uint8_t I2C_MasterCheckSlaveBusy( I2C_TypeDef* I2Cx );
#ifdef __cplusplus
}
#endif
#endif /*__CW32F030_I2C_H */
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CW32F030_IWDT_H
#define __CW32F030_IWDT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "cw32f030.h"
/******************************************************************************
* type definitions ('typedef')
******************************************************************************/
typedef struct
{
uint32_t IWDT_Prescaler; /* 预分配系数,取值范围2的n次幂,n=2,3..9 */
uint32_t IWDT_OverFlowAction; /* 溢出后的动作 */
FunctionalState IWDT_ITState; /* 看门狗中断状态,取值范围ENABLE或DISABLE */
uint32_t IWDT_Pause; /* Deepsleep模式下IWDT暂停控制 */
uint32_t IWDT_ReloadValue; /* 看门狗重载值,取值范围小于等于0x0FFF */
uint32_t IWDT_WindowValue; /* 窗口比较器比较值,取值范围小于等于0x0FFF */
} IWDT_InitTypeDef;
/******************************************************************************
* pre-processor symbols/macros ('#define')
******************************************************************************/
#define IWDT_FREQ 10000UL
#define IWDT_Prescaler_DIV4 ((uint32_t)0x00000000)
#define IWDT_Prescaler_DIV8 ((uint32_t)0x00000001)
#define IWDT_Prescaler_DIV16 ((uint32_t)0x00000002)
#define IWDT_Prescaler_DIV32 ((uint32_t)0x00000003)
#define IWDT_Prescaler_DIV64 ((uint32_t)0x00000004)
#define IWDT_Prescaler_DIV128 ((uint32_t)0x00000005)
#define IWDT_Prescaler_DIV256 ((uint32_t)0x00000006)
#define IWDT_Prescaler_DIV512 ((uint32_t)0x00000007)
#define IS_IWDT_PRESCALER(PRESCALER) (((PRESCALER) == IWDT_Prescaler_DIV4) ||\
((PRESCALER) == IWDT_Prescaler_DIV8) ||\
((PRESCALER) == IWDT_Prescaler_DIV16) ||\
((PRESCALER) == IWDT_Prescaler_DIV32) ||\
((PRESCALER) == IWDT_Prescaler_DIV64) ||\
((PRESCALER) == IWDT_Prescaler_DIV128) ||\
((PRESCALER) == IWDT_Prescaler_DIV512))
#define IS_IWDT_WINDOW_VALUE(VALUE) ((VALUE) <= 0xFFF)
#define IS_IWDT_RELOAD(COUNTER) ((COUNTER) <= 0xFFF)
#define IWDT_UNLOCK_KEY 0x5555
#define IWDT_LOCK_KEY 0x6666
#define IWDT_RUN_KEY 0xCCCC
#define IWDT_REFRESH_KEY 0xAAAA
#define IWDT_STOP_KEY1 0x5A5A
#define IWDT_STOP_KEY2 0xA5A5
#define IWDT_OVERFLOW_ACTION_RESET 0
#define IWDT_OVERFLOW_ACTION_INT IWDT_CR_ACTION_Msk
#define IS_IWDT_ACTION(ACTION) ((ACTION) == IWDT_OVERFLOW_ACTION_RESET || \
(ACTION) == IWDT_OVERFLOW_ACTION_INT)
#define IWDT_SLEEP_PAUSE IWDT_CR_PAUSE_Msk
#define IWDT_SLEEP_CONTINUE 0
#define IS_IWDT_SLEEP_MODE(MODE) ((MODE) == IWDT_SLEEP_PAUSE || \
(MODE) == IWDT_SLEEP_CONTINUE)
#define __IWDT_RUN() (CW_IWDT->KR = IWDT_RUN_KEY)
#define __IWDT_REFRESH() (CW_IWDT->KR = IWDT_REFRESH_KEY)
#define __IWDT_STOP() do{ \
CW_IWDT->KR = IWDT_STOP_KEY1;\
CW_IWDT->KR = IWDT_STOP_KEY2;\
} while(0)
#define __IWDT_UNLOCK() (CW_IWDT->KR = IWDT_UNLOCK_KEY)
#define __IWDT_LOCK() (CW_IWDT->KR = IWDT_LOCK_KEY)
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes
******************************************************************************/
void IWDT_DeInit(void);
void IWDT_Init(IWDT_InitTypeDef *IWDT_InitStruct);
void IWDT_Cmd(void);
void IWDT_Refresh(void);
void IWDT_Unlock(void);
void IWDT_Lock(void);
void IWDT_Stop(void);
void IWDT_SetPrescaler(uint32_t WWDT_Prescaler);
void IWDT_SetWindowValue(uint32_t WindowValue);
void IWDT_SetReloadValue(uint32_t ReloadValue);
void IWDT_ITConfig(FunctionalState NewState);
FlagStatus IWDT_GetFlagStatus(uint32_t StatusBit);
void IWDT_ClearOVFlag(void);
uint32_t IWDT_GetCounterValue(void);
#ifdef __cplusplus
}
#endif
#endif /*__CW32F030_IWDT_H */
/**
* @}
*/
/**
* @file cw32f030_pwr.h
* @author P&S (you@domain.com)
* @brief
* @version 0.1
* @date 2021-06-21
*
* @copyright Copyright (c) 2021
*
*/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
#ifndef __CW32F030_PWR_H
#define __CW32F030_PWR_H
/*****************************************************************************
* Include files
*****************************************************************************/
#include "base_types.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup LpmGroup Low Power Management (LPM)
**
**
******************************************************************************/
//@{
/******************************************************************************
** Global pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/** @defgroup PWR_Sevonpend
* @{
*/
#define PWR_Sevonpend_Disable ((uint32_t)0x00000000)
#define PWR_Sevonpend_Enable ((uint32_t)0x00000010)
#define IS_PWR_SEVONPEND(SEVONPEND) (((SEVONPEND) == PWR_Sevonpend_Disable) || \
((SEVONPEND) == PWR_Sevonpend_Enable))
/** @defgroup PWR_SleepDeep
* @{
*/
#define PWR_SleepDeep_Disable ((uint32_t)0x00000000)
#define PWR_SleepDeep_Enable ((uint32_t)0x00000004)
#define IS_PWR_SLEEPDEEP(SLEEPDEEP) (((SLEEPDEEP) == PWR_SleepDeep_Disable) || \
((SLEEPDEEP) == PWR_SleepDeep_Enable))
/** @defgroup PWR_SleepOnExit
* @{
*/
#define PWR_SleepOnExit_Disable ((uint32_t)0x00000000)
#define PWR_SleepOnExit_Enable ((uint32_t)0x00000002)
#define IS_PWR_SLEEPONEXIT(SLEEPONEXIT) (((SLEEPONEXIT) == PWR_SleepOnExit_Disable) || \
((SLEEPONEXIT) == PWR_SleepOnExit_Enable))
/**
******************************************************************************
** @brief Low Power Mode 配置结构体定义
*****************************************************************************/
typedef struct
{
uint32_t PWR_Sevonpend; // 使能:每次新中断会产生一个事件,如果使用WFE休眠,则可用于唤醒处理器.
uint32_t PWR_SleepDeep; // 使能:执行WFI进入深度休眠;不使能:执行WFI进入休眠.
uint32_t PWR_SleepOnExit; // 使能:退出异常处理并返回时,处理器自动进入休眠模式;不使能:该特性禁止.
}PWR_InitTypeDef;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//功能配置及操作函数
//低功耗模式配置
void PWR_Config(PWR_InitTypeDef* PWR_InitStruct);
//进入低功耗模式
void PWR_GotoLpmMode(void);
//@} // PWRGroup
#ifdef __cplusplus
}
#endif
#endif /* __CW32F030_PWR_H */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/
/*******************************************************************************
*
* 代码许可和免责信息
* 武汉力源半导体有限公司授予您使用所有编程代码示例的非专属的版权许可,您可以由此
* 生成根据您的特定需要而定制的相似功能。根据不能被排除的任何法定保证,武汉力源半
* 导体有限公司及其程序开发商和供应商对程序或技术支持(如果有)不提供任何明示或暗
* 含的保证或条件,包括但不限于暗含的有关适销性、适用于某种特定用途和非侵权的保证
* 或条件。
* 无论何种情形,武汉力源半导体有限公司及其程序开发商或供应商均不对下列各项负责,
* 即使被告知其发生的可能性时,也是如此:数据的丢失或损坏;直接的、特别的、附带的
* 或间接的损害,或任何后果性经济损害;或利润、业务、收入、商誉或预期可节省金额的
* 损失。
* 某些司法辖区不允许对直接的、附带的或后果性的损害有任何的排除或限制,因此某些或
* 全部上述排除或限制可能并不适用于您。
*
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CW32F030C8T6_STARTKIT_H
#define __CW32F030C8T6_STARTKIT_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
#include "cw32f030.h"
/* type definitions ('typedef') ----------------------------------------------*/
typedef struct
{
GPIO_TypeDef *LED_Port;
uint32_t LED_Pin;
void (*LED_On)(void *LED);
void (*LED_Off)(void *LED);
void (*LED_Toggle)(void *LED);
} LED_InitTypeDef;
/* pre-processor symbols/macros ('#define') ----------------------------------*/
/* Global variable definitions (declared in header file with 'extern') ------*/
/* Global function prototypes -----------------------------------------------*/
void LED_Init(void *LED);
#ifdef __cplusplus
}
#endif
#endif
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