V1.9
This commit is contained in:
@@ -149,7 +149,7 @@ void DMA_Tx_Init(DMA_Channel_TypeDef *DMA_CHx, u32 ppadr, u32 memadr, u16 bufsiz
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val) < 0)
|
||||
if((val + Calibrattion_Val) < 0 || val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -54,6 +54,7 @@ void ADC_Function_Init(void)
|
||||
ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
ADC_InjectedSequencerLengthConfig(ADC1, 1);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5);
|
||||
ADC_InjectedChannelConfig(ADC1, ADC_Channel_3, 1, ADC_SampleTime_239Cycles5);
|
||||
ADC_AutoInjectedConvCmd(ADC1, ENABLE);
|
||||
@@ -119,7 +120,7 @@ u16 Get_ADC_Val(u8 ch)
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val) < 0)
|
||||
if((val + Calibrattion_Val) < 0||val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -57,7 +57,7 @@ void ADC_Function_Init(void)
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigInjecConv_T1_CC4;
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfChannel = 3;
|
||||
ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
ADC_InjectedSequencerLengthConfig(ADC1, 3);
|
||||
@@ -133,7 +133,7 @@ void TIM1_PWM_In(u16 arr, u16 psc, u16 ccp)
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val) < 0)
|
||||
if((val + Calibrattion_Val) < 0||val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -151,7 +151,7 @@ void TIM2_PWM_In(u16 arr, u16 psc, u16 ccp)
|
||||
*/
|
||||
u16 Get_ConversionVal1(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val1) < 0)
|
||||
if((val + Calibrattion_Val1) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val1 + val) > 4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -166,7 +166,7 @@ void DMA_Tx_Init(DMA_Channel_TypeDef *DMA_CHx, u32 ppadr, u32 memadr, u16 bufsiz
|
||||
*/
|
||||
u16 Get_ConversionVal1(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val1) < 0)
|
||||
if((val + Calibrattion_Val1) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val1 + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -110,7 +110,7 @@ void ADC_Function_Init(void)
|
||||
*/
|
||||
u16 Get_ConversionVal1(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val1) < 0)
|
||||
if((val + Calibrattion_Val1) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val1 + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -101,9 +101,9 @@ void ADC_Function_Init(void)
|
||||
*/
|
||||
u16 Get_ConversionVal1(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val1) < 0)
|
||||
if((val + Calibrattion_Val1) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val1 + val) > 4095)
|
||||
if((Calibrattion_Val1 + val) > 4095|| val==4095)
|
||||
return 4095;
|
||||
return (val + Calibrattion_Val1);
|
||||
}
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*ADC1 channel 1 (PA1), ADC2 channel 3 (PA3)), and the rule group channel obtains
|
||||
*dual ADC conversion data through DMA interrupt.
|
||||
*
|
||||
*Note��only applied toCH32V203
|
||||
*Note:only applied toCH32V203
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
@@ -162,9 +162,9 @@ u16 Get_ConversionVal1(s16 val)
|
||||
*/
|
||||
u16 Get_ConversionVal2(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val2) < 0)
|
||||
if((val + Calibrattion_Val2) < 0||val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val2 + val) > 4095)
|
||||
if((Calibrattion_Val2 + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
return (val + Calibrattion_Val2);
|
||||
}
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -111,7 +111,7 @@ void ADC_Function_Init(void)
|
||||
*/
|
||||
u16 Get_ConversionVal1(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val1) < 0)
|
||||
if((val + Calibrattion_Val1) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val1 + val) > 4095 || val == 4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -116,7 +116,7 @@ void EXTI_Event_Init(void)
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val) < 0)
|
||||
if((val + Calibrattion_Val) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val + val) > 4095 || val==4095)
|
||||
return 4095;
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -161,9 +161,9 @@ u16 Get_ADC_Average(u8 ch, u8 times)
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val) < 0)
|
||||
if((val + Calibrattion_Val) < 0|| val==0)
|
||||
return 0;
|
||||
if((Calibrattion_Val + val) > 4095)
|
||||
if((Calibrattion_Val + val) > 4095|| val==4095)
|
||||
return 4095;
|
||||
return (val + Calibrattion_Val);
|
||||
}
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,143 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" moduleId="org.eclipse.cdt.core.settings" name="obj">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release">
|
||||
<folderInfo id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074." name="/" resourcePath="">
|
||||
<toolChain id="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release.231146001" name="RISC-V Cross GCC" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash.1311852988" name="Create flash image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting.1983282875" name="Create extended listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize.1000761142" name="Print size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.514997414" name="Optimization Level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.size" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength.1008570639" name="Message length (-fmessage-length=0)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar.467272439" name="'char' is signed (-fsigned-char)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections.2047756949" name="Function sections (-ffunction-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections.207613650" name="Data sections (-fdata-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.867779652" name="Debug format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format" useByScannerDiscovery="true"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base.1900297968" name="Architecture" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.arch.rv32i" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer.387605487" name="Integer ABI" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.integer.ilp32" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply.1509705449" name="Multiply extension (RVM)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed.1038505275" name="Compressed extension (RVC)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name.1218760634" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name" useByScannerDiscovery="false" value="GNU MCU RISC-V GCC" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix.103341323" name="Prefix" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix" useByScannerDiscovery="false" value="riscv-none-embed-" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c.487601824" name="C compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c" useByScannerDiscovery="false" value="gcc" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp.1062130429" name="C++ compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp" useByScannerDiscovery="false" value="g++" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar.1194282993" name="Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar" useByScannerDiscovery="false" value="ar" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy.1529355265" name="Hex/Bin converter" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy" useByScannerDiscovery="false" value="objcopy" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump.1053750745" name="Listing generator" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump" useByScannerDiscovery="false" value="objdump" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size.1441326233" name="Size command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size" useByScannerDiscovery="false" value="size" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make.550105535" name="Build command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make" useByScannerDiscovery="false" value="make" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm.719280496" name="Remove command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm" useByScannerDiscovery="false" value="rm" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id.226017994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id" useByScannerDiscovery="false" value="512258282" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic.1590833110" name="Atomic extension (RVA)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused.1961191588" name="Warn on various unused elements (-Wunused)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized.929829166" name="Warn on uninitialized variables (-Wuninitialized)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform.1944008784" isAbstract="false" osList="all" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform"/>
|
||||
<builder buildPath="${workspace_loc:/ADC_DMA}/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.1244756189" name="GNU RISC-V Cross Assembler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor.1692176068" name="Use preprocessor" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths.1034038285" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Startup}""/>
|
||||
</option>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input.126366858" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/User}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Peripheral/inc}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.1610882921" name="GNU RISC-V Cross C++ Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.1620074387" name="GNU RISC-V Cross C Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections.194760422" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths.2057340378" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths" useByScannerDiscovery="false" valueType="libPaths"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile.1390103472" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile" useByScannerDiscovery="false" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/ld/Link.ld}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1125808200" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat.82551320" name="Use wchprintfloat(-lprintfloat)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker.1947503520" name="GNU RISC-V Cross C++ Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections.1689063433" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths.1029177148" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value=""../LD""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile.1751226764" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value="Link.ld"/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart.642896175" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" value="true" valueType="boolean"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver.1292785366" name="GNU RISC-V Cross Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash.1801165667" name="GNU RISC-V Cross Create Flash Image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.1335632361" name="Output file format (-O)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.ihex" valueType="enumerated"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting.1356766765" name="GNU RISC-V Cross Create Listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source.2052761852" name="Display source (--source|-S)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders.439659821" name="Display all headers (--all-headers|-x)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle.67111865" name="Demangle names (--demangle|-C)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers.1549373929" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide.1298918921" name="Wide lines (--wide|-w)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble.1859590835" name="Disassemble (--disassemble|-d)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize.712424314" name="GNU RISC-V Cross Print Size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format.1404031980" name="Size format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format" useByScannerDiscovery="false"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="ld|Core|Peripheral|Debug|Startup" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Debug"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Peripheral"/>
|
||||
<entry excluding="startup_ch32v20x_D8W.S|startup_ch32v20x_D6.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="ld"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="999.ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf.275846018" name="Executable file" projectType="ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1375371130;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.1473381709">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
|
||||
</cproject>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<projectDescription>
|
||||
<name>I2C_OP_CH223</name>
|
||||
<comment/>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>Core</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Core</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Debug</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Debug</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Peripheral</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Peripheral</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Startup</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Startup</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>ld</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/SRC/Ld</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1595986042669</id>
|
||||
<name/>
|
||||
<type>22</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-*.wvproj</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,17 @@
|
||||
Mcu Type=CH32V20x
|
||||
Address=0x08000000
|
||||
Target Path=obj\I2C_OP_CH223.hex
|
||||
Erase All=true
|
||||
Program=true
|
||||
Verify=true
|
||||
Reset=true
|
||||
|
||||
Vendor=WCH
|
||||
Link=WCH-Link
|
||||
Toolchain=RISC-V
|
||||
Series=CH32V203
|
||||
Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.
|
||||
|
||||
PeripheralVersion=1.0
|
||||
MCU=CH32V203RBT6
|
||||
CLKSpeed=1
|
||||
@@ -0,0 +1,300 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : CH223.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2023/08/15
|
||||
* Description : CH223оƬ²Ù×÷Ïà¹ØÎļþ
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#include "debug.h"
|
||||
#include "CH223.h"
|
||||
#include "string.h"
|
||||
|
||||
u32 Buffer[7] = {0};//NDO raw data in SRCCAP
|
||||
u16 BufferV[SIZE] = {0};//Analyzing voltage data in SRCCAP
|
||||
u16 BufferI[SIZE] = {0};//Analyzing Current Data in SRCCAP
|
||||
u16 BufferVPPS[SIZE] = {0};//Parsing PPS data in SRCCAP
|
||||
|
||||
/*********************************************************************
|
||||
* @fn IIC_Init
|
||||
*
|
||||
* @brief Initializes the IIC peripheral.
|
||||
*
|
||||
* PB11------SDA
|
||||
* PB10------SCL
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void IIC_Init(u32 bound, u16 address)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure={0};
|
||||
I2C_InitTypeDef I2C_InitTSturcture={0};
|
||||
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE );
|
||||
// GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);
|
||||
RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C2, ENABLE );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init( GPIOB, &GPIO_InitStructure );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init( GPIOB, &GPIO_InitStructure );
|
||||
|
||||
I2C_InitTSturcture.I2C_ClockSpeed = bound;
|
||||
I2C_InitTSturcture.I2C_Mode = I2C_Mode_I2C;
|
||||
I2C_InitTSturcture.I2C_DutyCycle = I2C_DutyCycle_16_9;
|
||||
I2C_InitTSturcture.I2C_OwnAddress1 = address;
|
||||
I2C_InitTSturcture.I2C_Ack = I2C_Ack_Enable;
|
||||
I2C_InitTSturcture.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
||||
I2C_Init( I2C2, &I2C_InitTSturcture );
|
||||
|
||||
I2C_Cmd( I2C2, ENABLE );
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn CH223_Init
|
||||
*
|
||||
* @brief Initializes CH223.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void CH223_Init()
|
||||
{
|
||||
IIC_Init(100000, 0XA0);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn CH223_ReadOneByte
|
||||
*
|
||||
* @brief Read one data from CH223.
|
||||
*
|
||||
* @param ReadAddr - Read frist address.
|
||||
*
|
||||
* @return temp - Read data.
|
||||
*/
|
||||
u8 CH223_ReadOneByte(u16 ReadAddr)
|
||||
{
|
||||
u8 temp = 0;
|
||||
while( I2C_GetFlagStatus( I2C2, I2C_FLAG_BUSY ) != RESET )
|
||||
{
|
||||
|
||||
}
|
||||
I2C_GenerateSTART( I2C2, ENABLE );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_MODE_SELECT ) );
|
||||
|
||||
I2C_Send7bitAddress( I2C2, 0X44, I2C_Direction_Transmitter );
|
||||
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) );
|
||||
|
||||
#if (Address_Lenth == Address_8bit)
|
||||
I2C_SendData( I2C2, (u8)(ReadAddr&0x00FF) );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
|
||||
#elif (Address_Lenth == Address_16bit)
|
||||
I2C_SendData( I2C2, (u8)(ReadAddr>>8) );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
|
||||
I2C_SendData( I2C2, (u8)(ReadAddr&0x00FF) );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
|
||||
#endif
|
||||
|
||||
I2C_GenerateSTART( I2C2, ENABLE );
|
||||
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_MODE_SELECT ) );
|
||||
I2C_Send7bitAddress( I2C2, 0X45, I2C_Direction_Receiver );
|
||||
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ) );
|
||||
while( I2C_GetFlagStatus( I2C2, I2C_FLAG_RXNE ) == RESET )
|
||||
I2C_AcknowledgeConfig( I2C2, DISABLE );
|
||||
|
||||
temp = I2C_ReceiveData( I2C2 );
|
||||
I2C_GenerateSTOP( I2C2, ENABLE );
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn CH223_WriteOneByte
|
||||
*
|
||||
* @brief Write one data to CH223.
|
||||
*
|
||||
* @param WriteAddr - Write frist address.
|
||||
*
|
||||
* @return DataToWrite - Write data.
|
||||
*/
|
||||
void CH223_WriteOneByte(u16 WriteAddr, u8 DataToWrite)
|
||||
{
|
||||
while( I2C_GetFlagStatus( I2C2, I2C_FLAG_BUSY ) != RESET );
|
||||
I2C_GenerateSTART( I2C2, ENABLE );
|
||||
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_MODE_SELECT ) );
|
||||
I2C_Send7bitAddress( I2C2, 0X45, I2C_Direction_Transmitter );
|
||||
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) );
|
||||
|
||||
#if (Address_Lenth == Address_8bit)
|
||||
I2C_SendData( I2C2, (u8)(WriteAddr&0x00FF) );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
|
||||
#elif (Address_Lenth == Address_16bit)
|
||||
I2C_SendData( I2C2, (u8)(WriteAddr>>8) );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
|
||||
I2C_SendData( I2C2, (u8)(WriteAddr&0x00FF) );
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
|
||||
#endif
|
||||
|
||||
if( I2C_GetFlagStatus( I2C2, I2C_FLAG_TXE ) != RESET )
|
||||
{
|
||||
I2C_SendData( I2C2, DataToWrite );
|
||||
}
|
||||
|
||||
while( !I2C_CheckEvent( I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) );
|
||||
I2C_GenerateSTOP( I2C2, ENABLE );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn CH223_Read
|
||||
*
|
||||
* @brief Read multiple data from CH223.
|
||||
*
|
||||
* @param ReadAddr - Read frist address.
|
||||
* pBuffer - Read data.
|
||||
* NumToRead - Data number.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void CH223_Read(u16 ReadAddr, u32 *pBuffer, u16 NumToRead)
|
||||
{
|
||||
u8 t = 0;
|
||||
u32 temp[4] = {0};
|
||||
u32 temp1 = 0;
|
||||
|
||||
while(NumToRead)
|
||||
{
|
||||
temp[4] = 0;
|
||||
for (t = 0; t < 4; t++)
|
||||
{
|
||||
temp[t] = CH223_ReadOneByte(ReadAddr++);
|
||||
}
|
||||
temp1 = (temp[0] + (temp[1] << 8) + (temp[2] << 16) + (temp[3] << 24));
|
||||
*pBuffer++=temp1;
|
||||
NumToRead--;
|
||||
}
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn CH223_Write
|
||||
*
|
||||
* @brief Write multiple data to CH223.
|
||||
*
|
||||
* @param WriteAddr - Write frist address.
|
||||
* pBuffer - Write data.
|
||||
* NumToWrite - Data number.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void CH223_Write(u16 WriteAddr, u8 *pBuffer, u16 NumToWrite)
|
||||
{
|
||||
while(NumToWrite--)
|
||||
{
|
||||
CH223_WriteOneByte(WriteAddr, *pBuffer);
|
||||
WriteAddr++;
|
||||
pBuffer++;
|
||||
Delay_Ms(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Buffer_Change
|
||||
*
|
||||
* @brief Analysis of SRCCAP message
|
||||
*
|
||||
* @param buffer[] - NDO data.
|
||||
* n - NDO_Number.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void Buffer_Change(u32 buffer[], int n)
|
||||
{
|
||||
int i = 0;
|
||||
u32 tempV = 0, tempI = 0, tempVmax = 0;
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
tempV = buffer[i];
|
||||
tempI = buffer[i];
|
||||
if((tempV & 0xC0000000) == 0)
|
||||
{
|
||||
tempV >>= 10;
|
||||
tempV &= 0x03FF;
|
||||
BufferV[i] = tempV * 0.5;
|
||||
|
||||
tempI &= 0x03FF;
|
||||
BufferI[i] = tempI * 0.1;
|
||||
}
|
||||
else {
|
||||
tempV >>= 8;
|
||||
tempVmax = tempV >> 9;
|
||||
tempV &= 0x00FF;
|
||||
BufferV[i] = tempV * 1;
|
||||
tempVmax &= 0x00FF;
|
||||
BufferVPPS[i] = tempVmax * 1;
|
||||
|
||||
tempI &= 0x00FF;
|
||||
BufferI[i] = tempI * 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn Current_VI
|
||||
*
|
||||
* @brief Read and display the current output voltage value
|
||||
*
|
||||
* @param ndo_select - NDO_Select.
|
||||
*
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void Current_VI(u8 ndo_select)
|
||||
{
|
||||
u8 tempV = 0, tempI = 0;
|
||||
u8 current[2];
|
||||
tempV = BufferV[ndo_select] % 10;
|
||||
current[0] = BufferV[ndo_select] / 10;
|
||||
|
||||
tempI = BufferI[ndo_select] % 10;
|
||||
current[1] = BufferI[ndo_select] / 10;
|
||||
|
||||
printf("The current regulating voltage is£º%d.%dV,%d.%dA\t\r\n", current[0], tempV, current[1], tempI);
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn User_Set_VI
|
||||
*
|
||||
* @brief Set VBUS voltage
|
||||
*
|
||||
* @param TargetData - Target voltage value.
|
||||
* VBUS voltage=TargetData*200mv
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
|
||||
void User_Set_VI(u8 TargetData)
|
||||
{
|
||||
u8 ndo_select = 0, state_flag = 0;
|
||||
CH223_WriteOneByte(0xB6, TargetData);
|
||||
Delay_Ms(5000);
|
||||
state_flag = CH223_ReadOneByte(0xB5);
|
||||
ndo_select = (state_flag >> 3) & 0x07;
|
||||
printf("nod_select_user-->%d\r\n",ndo_select);
|
||||
Current_VI(ndo_select - 1);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : CH223.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2023/08/15
|
||||
* Description : header file for CH223.c
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#include"debug.h"
|
||||
|
||||
#define Address_8bit 0
|
||||
#define Address_16bit 1
|
||||
#define Address_Lenth Address_8bit
|
||||
#define SIZE sizeof(Buffer)
|
||||
|
||||
extern u32 Buffer[7] ;//NDO raw data in SRCCAP
|
||||
extern u16 BufferV[SIZE];//Analyzing voltage data in SRCCAP
|
||||
extern u16 BufferI[SIZE];//Analyzing Current Data in SRCCAP
|
||||
extern u16 BufferVPPS[SIZE];//Parsing PPS data in SRCCAP
|
||||
|
||||
void IIC_Init(u32 bound, u16 address);
|
||||
void CH223_Init();
|
||||
u8 CH223_ReadOneByte(u16 ReadAddr);
|
||||
void CH223_WriteOneByte(u16 WriteAddr, u8 DataToWrite);
|
||||
void CH223_Read(u16 ReadAddr, u32 *pBuffer, u16 NumToRead);
|
||||
void CH223_Write(u16 WriteAddr, u8 *pBuffer, u16 NumToWrite);
|
||||
void Buffer_Change(u32 buffer[], int n);
|
||||
void Current_VI(u8 ndo_select);
|
||||
void User_Set_VI(u8 TargetData);
|
||||
@@ -0,0 +1,392 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2023/06/06
|
||||
* Description : Main program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
*@Note
|
||||
CH223 chip application routine
|
||||
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include"CH223.h"
|
||||
|
||||
u8 ndo = 0;//Number of NDOs in SrcCap
|
||||
u8 IT_flag = 0;
|
||||
u8 rst_IT = 0, cc_IT = 0, srccap_IT = 0, ps_IT = 0;//Interrupt flag
|
||||
s16 Calibrattion_Val = 0;
|
||||
u16 TxBuf[1024];
|
||||
|
||||
/*********************************************************************
|
||||
* @fn ADC_Function_Init
|
||||
*
|
||||
* @brief Initializes ADC collection.
|
||||
* PB0-->ADC_IN
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void ADC_Function_Init(void)
|
||||
{
|
||||
ADC_InitTypeDef ADC_InitStructure = {0};
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
ADC_DeInit(ADC1);
|
||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
ADC_DMACmd(ADC1, ENABLE);
|
||||
ADC_Cmd(ADC1, ENABLE);
|
||||
|
||||
ADC_BufferCmd(ADC1, DISABLE); //disable buffer
|
||||
ADC_ResetCalibration(ADC1);
|
||||
while(ADC_GetResetCalibrationStatus(ADC1));
|
||||
ADC_StartCalibration(ADC1);
|
||||
while(ADC_GetCalibrationStatus(ADC1));
|
||||
Calibrattion_Val = Get_CalibrationValue(ADC1);
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ADC_Val
|
||||
*
|
||||
* @brief Returns ADCx conversion result data.
|
||||
*
|
||||
* @param ch - ADC channel.
|
||||
* ADC_Channel_0 - ADC Channel0 selected.
|
||||
* ADC_Channel_1 - ADC Channel1 selected.
|
||||
* ADC_Channel_2 - ADC Channel2 selected.
|
||||
* ADC_Channel_3 - ADC Channel3 selected.
|
||||
* ADC_Channel_4 - ADC Channel4 selected.
|
||||
* ADC_Channel_5 - ADC Channel5 selected.
|
||||
* ADC_Channel_6 - ADC Channel6 selected.
|
||||
* ADC_Channel_7 - ADC Channel7 selected.
|
||||
* ADC_Channel_8 - ADC Channel8 selected.
|
||||
* ADC_Channel_9 - ADC Channel9 selected.
|
||||
* ADC_Channel_10 - ADC Channel10 selected.
|
||||
* ADC_Channel_11 - ADC Channel11 selected.
|
||||
* ADC_Channel_12 - ADC Channel12 selected.
|
||||
* ADC_Channel_13 - ADC Channel13 selected.
|
||||
* ADC_Channel_14 - ADC Channel14 selected.
|
||||
* ADC_Channel_15 - ADC Channel15 selected.
|
||||
* ADC_Channel_16 - ADC Channel16 selected.
|
||||
* ADC_Channel_17 - ADC Channel17 selected.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
u16 Get_ADC_Val(u8 ch)
|
||||
{
|
||||
u16 val;
|
||||
|
||||
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5);
|
||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
||||
|
||||
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
|
||||
val = ADC_GetConversionValue(ADC1);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DMA_Tx_Init
|
||||
*
|
||||
* @brief Initializes the DMAy Channelx configuration.
|
||||
*
|
||||
* @param DMA_CHx - x can be 1 to 7.
|
||||
* ppadr - Peripheral base address.
|
||||
* memadr - Memory base address.
|
||||
* bufsize - DMA channel buffer size.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void DMA_Tx_Init(DMA_Channel_TypeDef *DMA_CHx, u32 ppadr, u32 memadr, u16 bufsize)
|
||||
{
|
||||
DMA_InitTypeDef DMA_InitStructure = {0};
|
||||
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
||||
|
||||
DMA_DeInit(DMA_CHx);
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = ppadr;
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = memadr;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
||||
DMA_InitStructure.DMA_BufferSize = bufsize;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
DMA_Init(DMA_CHx, &DMA_InitStructure);
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn Get_ConversionVal
|
||||
*
|
||||
* @brief Get Conversion Value.
|
||||
*
|
||||
* @param val - Sampling value
|
||||
*
|
||||
* @return val+Calibrattion_Val - Conversion Value.
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val + Calibrattion_Val) < 0)
|
||||
return 0;
|
||||
if((Calibrattion_Val + val) > 4095||val==4095)
|
||||
return 4095;
|
||||
return (val + Calibrattion_Val);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn EXTI0_INT_INIT
|
||||
*
|
||||
* @brief Initialize external trigger interrupt.
|
||||
*
|
||||
* PB13-->INT
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
/*********************************************************************
|
||||
* @fn EXTI0_INT_INIT
|
||||
*
|
||||
* @brief Initializes EXTI0 collection.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void EXTI0_INT_INIT(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
EXTI_InitTypeDef EXTI_InitStructure = {0};
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
/* GPIOB ----> EXTI_Line0 */
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource13);
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Adc_test
|
||||
*
|
||||
* @brief ADC measure VBUS output voltage.
|
||||
*
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void Adc_test(){
|
||||
u16 i = 0;
|
||||
float sum=0;
|
||||
DMA_Tx_Init(DMA1_Channel1, (u32)&ADC1->RDATAR, (u32)TxBuf, 1024);
|
||||
DMA_Cmd(DMA1_Channel1, ENABLE);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_239Cycles5);
|
||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
||||
Delay_Ms(50);
|
||||
ADC_SoftwareStartConvCmd(ADC1, DISABLE);
|
||||
for(i = 0; i < 1024; i++){
|
||||
sum+=Get_ConversionVal(TxBuf[i]);
|
||||
}
|
||||
printf("ADC_Value=%0.1fV\r\n",sum/1024/4095*3.3*6.1);
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief Main program.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
u16 n = 0;
|
||||
u8 tempV = 0, tempI = 0, tempV0 = 0, tempI0 = 0, tempVmax = 0;
|
||||
u8 res = 0, ndo_select = 0, STATE_flag = 0;
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
||||
Delay_Init();
|
||||
USART_Printf_Init( 115200 );
|
||||
CH223_Init();
|
||||
ADC_Function_Init();
|
||||
EXTI0_INT_INIT();
|
||||
printf("PD_CH223 Demo£¡\r\n");
|
||||
printf("\r\n");
|
||||
IT_flag = CH223_ReadOneByte(0xB4);
|
||||
if (IT_flag==0x0c)
|
||||
{
|
||||
printf("power-on reset£¡£¡£¡\r\n");
|
||||
printf("\r\n");
|
||||
Delay_Ms(10);
|
||||
printf("CC Connecting...\r\n");
|
||||
printf("\r\n");
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
Delay_Ms(1);
|
||||
while(ps_IT) //PS_RDY -->The power supply reaches the required working state
|
||||
{
|
||||
CH223_WriteOneByte(0xB6, 0x19); //The initial voltage is set to 9V£º0x2D
|
||||
res = CH223_ReadOneByte(0xB6);
|
||||
printf("The initial voltage is set to£º%dV\r\n",res*200/1000);
|
||||
printf("\r\n");
|
||||
Delay_Ms(300);
|
||||
if (rst_IT == 1)
|
||||
{
|
||||
printf("power-on reset£¡£¡£¡\r\n");
|
||||
printf("\r\n");
|
||||
}
|
||||
if (cc_IT == 1)
|
||||
{
|
||||
printf("CC Connecting...\r\n");
|
||||
printf("\r\n");
|
||||
}
|
||||
STATE_flag = CH223_ReadOneByte(0xB5); //Read IIC status register
|
||||
ndo = STATE_flag & 0x07; //NDO_Number
|
||||
printf("Number of NDOs in SRCCAP:%d\r\n", ndo);
|
||||
printf("\r\n");
|
||||
CH223_Read(0x84, Buffer, ndo); //SRCCAP message
|
||||
Buffer_Change(Buffer, ndo);
|
||||
if (srccap_IT == 1) //Display SRCCAP message
|
||||
{
|
||||
printf("Received SrcCap,NDO data is£º\n");
|
||||
printf("\r\n");
|
||||
for(n = 0; n < ndo; n++)
|
||||
{
|
||||
if((Buffer[n] & 0xC0000000) == 0)
|
||||
{
|
||||
tempV = BufferV[n] % 10;
|
||||
tempV0 = BufferV[n] / 10;
|
||||
tempI = BufferI[n] % 10;
|
||||
tempI0 = BufferI[n] / 10;
|
||||
printf("%d.%dV,%d.%dA\t", tempV0, tempV, tempI0, tempI);
|
||||
}
|
||||
else
|
||||
{
|
||||
tempV = BufferV[n] % 10;
|
||||
tempV0 = BufferV[n] / 10;
|
||||
tempVmax = BufferVPPS[n] % 10;
|
||||
BufferVPPS[n] /= 10;
|
||||
tempI = BufferI[n] % 10;
|
||||
tempI0 = BufferI[n] / 10;
|
||||
printf("%d.%dV/%d.%dV,%d.%dA\t", tempV0, tempV, BufferVPPS[n], tempVmax, tempI0, tempI);
|
||||
}
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
ndo_select = (STATE_flag >> 3) & 0x07;
|
||||
printf("ndo_select:%d\r\n", ndo_select);
|
||||
printf("Waiting PS_RDY...\r\n");
|
||||
Delay_Ms(500);
|
||||
if (ps_IT == 1)
|
||||
{
|
||||
printf("Received PS_RDY\r\n");
|
||||
Current_VI(ndo_select - 1);
|
||||
}
|
||||
//Set VBUS voltage
|
||||
printf("\r\n");
|
||||
Delay_Ms(10);
|
||||
printf("Set voltage output 5V-->0x19\r\n");
|
||||
User_Set_VI(0x19); //0x19---5V
|
||||
Adc_test();
|
||||
Delay_Ms(50);
|
||||
printf("\r\n");
|
||||
Delay_Ms(10);
|
||||
printf("Set voltage output 9V-->0x2d\r\n");
|
||||
User_Set_VI(0x2d); //0x2d---9V
|
||||
Adc_test();
|
||||
Delay_Ms(50);
|
||||
printf("\r\n");
|
||||
Delay_Ms(10);
|
||||
printf("Set voltage output 12V-->0x3c\r\n");
|
||||
User_Set_VI(0x3c); //0x3c---12V
|
||||
Adc_test();
|
||||
Delay_Ms(50);
|
||||
printf("\r\n");
|
||||
Delay_Ms(10);
|
||||
printf("Set voltage output 15V-->0x4b\r\n");
|
||||
User_Set_VI(0x4b); //0x4b---15V
|
||||
Adc_test();
|
||||
Delay_Ms(50);
|
||||
printf("\r\n");
|
||||
Delay_Ms(10);
|
||||
printf("Set voltage output 20V-->0x64\r\n");
|
||||
User_Set_VI(0x64); //0x64---20V
|
||||
Adc_test();
|
||||
Delay_Ms(50);
|
||||
ps_IT = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EXTI15_10_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
|
||||
{
|
||||
Delay_Us(500);
|
||||
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
|
||||
{
|
||||
IT_flag = CH223_ReadOneByte(0xB4);
|
||||
if ((IT_flag&0xF))
|
||||
{
|
||||
if (IT_flag&0x7)
|
||||
{
|
||||
if(IT_flag&0x3)
|
||||
{
|
||||
if (IT_flag&0x1)
|
||||
{
|
||||
ps_IT = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
srccap_IT = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rst_IT = 1;
|
||||
}
|
||||
}else
|
||||
{
|
||||
cc_IT = 1;
|
||||
}
|
||||
}
|
||||
EXTI_ClearITPendingBit(EXTI_Line13); /* Clear Flag */
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
@@ -0,0 +1,143 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" moduleId="org.eclipse.cdt.core.settings" name="obj">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release">
|
||||
<folderInfo id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074." name="/" resourcePath="">
|
||||
<toolChain id="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release.231146001" name="RISC-V Cross GCC" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash.1311852988" name="Create flash image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting.1983282875" name="Create extended listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize.1000761142" name="Print size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.514997414" name="Optimization Level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.size" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength.1008570639" name="Message length (-fmessage-length=0)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar.467272439" name="'char' is signed (-fsigned-char)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections.2047756949" name="Function sections (-ffunction-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections.207613650" name="Data sections (-fdata-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.867779652" name="Debug format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format" useByScannerDiscovery="true"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base.1900297968" name="Architecture" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.arch.rv32i" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer.387605487" name="Integer ABI" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.integer.ilp32" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply.1509705449" name="Multiply extension (RVM)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed.1038505275" name="Compressed extension (RVC)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name.1218760634" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name" useByScannerDiscovery="false" value="GNU MCU RISC-V GCC" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix.103341323" name="Prefix" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix" useByScannerDiscovery="false" value="riscv-none-embed-" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c.487601824" name="C compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c" useByScannerDiscovery="false" value="gcc" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp.1062130429" name="C++ compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp" useByScannerDiscovery="false" value="g++" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar.1194282993" name="Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar" useByScannerDiscovery="false" value="ar" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy.1529355265" name="Hex/Bin converter" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy" useByScannerDiscovery="false" value="objcopy" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump.1053750745" name="Listing generator" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump" useByScannerDiscovery="false" value="objdump" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size.1441326233" name="Size command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size" useByScannerDiscovery="false" value="size" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make.550105535" name="Build command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make" useByScannerDiscovery="false" value="make" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm.719280496" name="Remove command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm" useByScannerDiscovery="false" value="rm" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id.226017994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id" useByScannerDiscovery="false" value="512258282" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic.1590833110" name="Atomic extension (RVA)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused.1961191588" name="Warn on various unused elements (-Wunused)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized.929829166" name="Warn on uninitialized variables (-Wuninitialised)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon.1873467153" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw.2056253884" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore.1784944456" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform.1944008784" isAbstract="false" osList="all" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform"/>
|
||||
<builder buildPath="${workspace_loc:/I2C_7bit_Mode}/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.1244756189" name="GNU RISC-V Cross Assembler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor.1692176068" name="Use preprocessor" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths.1034038285" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Startup}""/>
|
||||
</option>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input.126366858" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/User}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Peripheral/inc}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.1610882921" name="GNU RISC-V Cross C++ Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.1620074387" name="GNU RISC-V Cross C Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections.194760422" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths.2057340378" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths" useByScannerDiscovery="false" valueType="libPaths"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile.1390103472" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile" useByScannerDiscovery="false" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Ld/Link.ld}""/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1125808200" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList"/>
|
||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker.1947503520" name="GNU RISC-V Cross C++ Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections.1689063433" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths.1029177148" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value=""../LD""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile.1751226764" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile" valueType="stringList">
|
||||
<listOptionValue builtIn="false" value="Link.ld"/>
|
||||
</option>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart.642896175" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" value="true" valueType="boolean"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver.1292785366" name="GNU RISC-V Cross Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash.1801165667" name="GNU RISC-V Cross Create Flash Image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting.1356766765" name="GNU RISC-V Cross Create Listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source.2052761852" name="Display source (--source|-S)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders.439659821" name="Display all headers (--all-headers|-x)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle.67111865" name="Demangle names (--demangle|-C)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers.1549373929" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide.1298918921" name="Wide lines (--wide|-w)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble.1859590835" name="Disassemble (--disassemble|-d)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize.712424314" name="GNU RISC-V Cross Print Size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format.1404031980" name="Size format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format" useByScannerDiscovery="false"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="Startup|Peripheral|Ld|Debug|Core" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Debug"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Ld"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Peripheral"/>
|
||||
<entry excluding="startup_ch32v20x_D8.S|startup_ch32v20x_D8W.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="999.ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf.275846018" name="Executable file" projectType="ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1375371130;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.1473381709">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
|
||||
</cproject>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<projectDescription>
|
||||
<name>OPA</name>
|
||||
<name>WS2812_LED</name>
|
||||
<comment/>
|
||||
<projects/>
|
||||
<buildSpec>
|
||||
@@ -35,27 +35,27 @@
|
||||
<link>
|
||||
<name>Core</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Core</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Core</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Debug</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Debug</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Debug</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Ld</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Ld</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Ld</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Peripheral</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Peripheral</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Peripheral</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Startup</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Startup</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Startup</location>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,17 @@
|
||||
Mcu Type=CH32V20x
|
||||
Address=0x08000000
|
||||
Target Path=obj\WS2812_LED.hex
|
||||
Erase All=true
|
||||
Program=true
|
||||
Verify=true
|
||||
Reset=true
|
||||
|
||||
Vendor=WCH
|
||||
Link=WCH-Link
|
||||
Toolchain=RISC-V
|
||||
Series=CH32V203
|
||||
Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.
|
||||
|
||||
PeripheralVersion=1.0
|
||||
MCU=CH32V203RBT6
|
||||
CLKSpeed=1
|
||||
@@ -0,0 +1,45 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : ch32v20x_it.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : Main Interrupt Service Routines.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
#include "ch32v20x_it.h"
|
||||
|
||||
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
/*********************************************************************
|
||||
* @fn NMI_Handler
|
||||
*
|
||||
* @brief This function handles NMI exception.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn HardFault_Handler
|
||||
*
|
||||
* @brief This function handles Hard Fault exception.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
printf("\nHardFault \n");
|
||||
printf("mepc %x \n",__get_MEPC());
|
||||
printf("mcause %x \n",__get_MCAUSE());
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,527 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : Main program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
*@Note
|
||||
* This example demonstrates control w2812 by using SPI or PWM.
|
||||
*
|
||||
* In spi mode
|
||||
* PA7 - w2812
|
||||
* In PWM mode
|
||||
* PA8 - w2812
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
/* Global define */
|
||||
|
||||
#define LED_SPI_MODE 1
|
||||
#define LED_PWM_MODE 2
|
||||
|
||||
#define LED_MODE LED_SPI_MODE
|
||||
//#define LED_MODE LED_PWM_MODE
|
||||
|
||||
#define Pixel_NUM (8)
|
||||
|
||||
#define LIST_SIZE(list) (sizeof(list)/sizeof(list[0]))
|
||||
#define hex2rgb(c) (((c)>>16)&0xff),(((c)>>8)&0xff),((c)&0xff)
|
||||
|
||||
/* Global Variable */
|
||||
|
||||
#if LED_MODE == LED_SPI_MODE
|
||||
|
||||
/** spi mode
|
||||
* When you using spi mode, you should make sure your spi work at 6M clock
|
||||
*/
|
||||
|
||||
#define Pixel_PRE_LEN (12u)
|
||||
#define Pixel_RESET_LEN (25u)
|
||||
#define COLOR_BUFFER_LEN (((Pixel_NUM)*Pixel_PRE_LEN)+Pixel_RESET_LEN)
|
||||
#define SPI1_DMA_TX_CH DMA1_Channel3
|
||||
|
||||
|
||||
uint8_t color_buf[COLOR_BUFFER_LEN] = {0};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn convToBit
|
||||
*
|
||||
* @brief Convert hex to spi bit
|
||||
*
|
||||
* @param res - the result
|
||||
* input - input data
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void convToBit(uint8_t *res, uint8_t input)
|
||||
{
|
||||
uint8_t mask = 0x80;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
uint8_t result = (input & mask) ? 0xE : 0x8;
|
||||
result <<= 4;
|
||||
mask >>= 1;
|
||||
result |= (input & mask) ? 0xE : 0x8;
|
||||
mask >>= 1;
|
||||
res[i] = result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn colorToBit
|
||||
*
|
||||
* @brief Convert color to spi bit
|
||||
*
|
||||
* @param buf - the result
|
||||
* r - red channel
|
||||
* g - green channel
|
||||
* b - blue channel
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void colorToBit(uint8_t *buf, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
uint8_t *res = buf;
|
||||
convToBit(res, g);
|
||||
convToBit(&(res[4]), r);
|
||||
convToBit(&(res[8]), b);
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn setPixelColor
|
||||
*
|
||||
* @brief Set the pixel color of an LED
|
||||
*
|
||||
* @param index - index of LED
|
||||
* r - red channel
|
||||
* g - green channel
|
||||
* b - blue channel
|
||||
*
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void setPixelColor(uint16_t index, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
uint8_t *buf = &(color_buf[index * Pixel_PRE_LEN]);
|
||||
colorToBit(buf,r,g,b);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SPI_1Lines_HalfDuplex_Init
|
||||
*
|
||||
* @brief Configuring the SPI for half-duplex communication.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void SPI_1Lines_HalfDuplex_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure= {0};
|
||||
SPI_InitTypeDef SPI_InitStructure= {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE );
|
||||
|
||||
|
||||
// the clock output
|
||||
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
||||
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
// GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||||
|
||||
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
|
||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
|
||||
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
|
||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
|
||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
|
||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
|
||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
|
||||
SPI_InitStructure.SPI_CRCPolynomial = 7;
|
||||
SPI_Init( SPI1, &SPI_InitStructure );
|
||||
|
||||
SPI_Cmd( SPI1, ENABLE );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SPI1_DMA_Init
|
||||
*
|
||||
* @brief Initialize DMA for SPI2
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void SPI1_DMA_Init()
|
||||
{
|
||||
DMA_InitTypeDef DMA_InitStructure = {0};
|
||||
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
||||
|
||||
DMA_DeInit(SPI1_DMA_TX_CH);
|
||||
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI1->DATAR;
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)color_buf;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
|
||||
DMA_InitStructure.DMA_BufferSize = COLOR_BUFFER_LEN;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
|
||||
DMA_Init(SPI1_DMA_TX_CH, &DMA_InitStructure);
|
||||
|
||||
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
|
||||
}
|
||||
#elif LED_MODE == LED_PWM_MODE
|
||||
|
||||
void DMA1_Channel5_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
#define CODE_0 (3)
|
||||
#define CODE_1 (7)
|
||||
#define RESET_LEN (60)
|
||||
#define TIM_DMA_CH1_CH DMA1_Channel5
|
||||
#define COLOR_BUFFER_LEN (((Pixel_NUM)*(3*8))+RESET_LEN)
|
||||
|
||||
uint16_t color_buf[COLOR_BUFFER_LEN] = {0};
|
||||
|
||||
/*********************************************************************
|
||||
* @fn TIM1_Init
|
||||
*
|
||||
* @brief Initialize TIM1
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void TIM1_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
TIM_OCInitTypeDef TIM_OCInitStructure = {0};
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_TIM1, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init( GPIOA, &GPIO_InitStructure);
|
||||
|
||||
TIM_TimeBaseInitStructure.TIM_Period = 10 - 1;
|
||||
TIM_TimeBaseInitStructure.TIM_Prescaler = SystemCoreClock / 8000000 - 1;
|
||||
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit( TIM1, &TIM_TimeBaseInitStructure);
|
||||
|
||||
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
|
||||
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
|
||||
TIM_OCInitStructure.TIM_Pulse = 0;
|
||||
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
|
||||
TIM_OC1Init( TIM1, &TIM_OCInitStructure);
|
||||
|
||||
TIM_OC1PreloadConfig( TIM1, TIM_OCPreload_Enable);
|
||||
TIM_ARRPreloadConfig( TIM1, ENABLE);
|
||||
TIM_CtrlPWMOutputs(TIM1, ENABLE);
|
||||
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
|
||||
TIM_Cmd( TIM1, ENABLE);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DMA1_Init
|
||||
*
|
||||
* @brief Initialize DMA for TIM1 ch1
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void DMA1_Init(void)
|
||||
{
|
||||
DMA_InitTypeDef DMA_InitStructure = {0};
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1, ENABLE);
|
||||
|
||||
DMA_DeInit( TIM_DMA_CH1_CH);
|
||||
DMA_Cmd( TIM_DMA_CH1_CH, DISABLE);
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &TIM1->CH1CVR;
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) color_buf;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
|
||||
DMA_InitStructure.DMA_BufferSize = COLOR_BUFFER_LEN;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
DMA_Init( TIM_DMA_CH1_CH, &DMA_InitStructure);
|
||||
|
||||
DMA_Cmd( TIM_DMA_CH1_CH, DISABLE);
|
||||
|
||||
DMA_ITConfig( DMA1_Channel5, DMA_IT_TC, ENABLE);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn setPixelColor
|
||||
*
|
||||
* @brief Set the pixel color of an LED
|
||||
*
|
||||
* @param id - index of LED
|
||||
* r - red channel
|
||||
* g - green channel
|
||||
* b - blue channel
|
||||
*
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void setPixelColor(uint16_t id, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
int i = 0, j = id * 24u;
|
||||
if (id >= Pixel_NUM) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (g & (0x80 >> i)) {
|
||||
color_buf[j] = CODE_1;
|
||||
} else {
|
||||
color_buf[j] = CODE_0;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (r & (0x80 >> i)) {
|
||||
color_buf[j] = CODE_1;
|
||||
} else {
|
||||
color_buf[j] = CODE_0;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (b & (0x80 >> i)) {
|
||||
color_buf[j] = CODE_1;
|
||||
} else {
|
||||
color_buf[j] = CODE_0;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* @fn w2812_sync
|
||||
*
|
||||
* @brief Write data to LEDs
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void w2812_sync()
|
||||
{
|
||||
#if LED_MODE == LED_SPI_MODE
|
||||
while(SPI1_DMA_TX_CH->CNTR!=0);
|
||||
DMA_ClearFlag(DMA1_FLAG_TC3);
|
||||
DMA_Cmd(SPI1_DMA_TX_CH, DISABLE);
|
||||
SPI1_DMA_TX_CH->CNTR = COLOR_BUFFER_LEN;
|
||||
DMA_Cmd(SPI1_DMA_TX_CH, ENABLE);
|
||||
#elif LED_MODE == LED_PWM_MODE
|
||||
while(DMA_GetCurrDataCounter(TIM_DMA_CH1_CH)!=0);
|
||||
DMA_SetCurrDataCounter( TIM_DMA_CH1_CH, COLOR_BUFFER_LEN);
|
||||
DMA_Cmd( TIM_DMA_CH1_CH, ENABLE);
|
||||
TIM_Cmd( TIM1, ENABLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define MAX_STEP (200)
|
||||
/*********************************************************************
|
||||
* @fn interpolateColors
|
||||
*
|
||||
* @brief Set the pixel color of an LED
|
||||
*
|
||||
* @param color1 - The color at the beginning
|
||||
* color2 - The color at the ending
|
||||
* step -
|
||||
*
|
||||
*
|
||||
* @return color
|
||||
*/
|
||||
uint32_t interpolateColors(uint32_t color1, uint32_t color2, uint8_t step)
|
||||
{
|
||||
uint8_t r1 = (color1 >> 16) & 0xFF;
|
||||
uint8_t g1 = (color1 >> 8) & 0xFF;
|
||||
uint8_t b1 = color1 & 0xFF;
|
||||
|
||||
uint8_t r2 = (color2 >> 16) & 0xFF;
|
||||
uint8_t g2 = (color2 >> 8) & 0xFF;
|
||||
uint8_t b2 = color2 & 0xFF;
|
||||
|
||||
float tmp1 = (r2 - r1) * (step / (float) MAX_STEP);
|
||||
float tmp2 = (g2 - g1) * (step / (float) MAX_STEP);
|
||||
float tmp3 = (b2 - b1) * (step / (float) MAX_STEP);
|
||||
|
||||
uint8_t r = (uint8_t) (r1 + tmp1);
|
||||
uint8_t g = (uint8_t) (g1 + tmp2);
|
||||
uint8_t b = (uint8_t) (b1 + tmp3);
|
||||
|
||||
return ((uint32_t) r << 16) | ((uint32_t) g << 8) | b;
|
||||
}
|
||||
|
||||
uint32_t color_list[] = {
|
||||
0xff0000,
|
||||
0x00ff00,
|
||||
0x0000ff,
|
||||
0xffff00,
|
||||
0xff00ff,
|
||||
0x00ffff,
|
||||
0xffffff,
|
||||
// 0x000000,
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* @fn led_example_0
|
||||
*
|
||||
* @brief In this example, all leds will gradually change from one color to another
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void led_example_0(void)
|
||||
{
|
||||
uint32_t i = 0, j = 0;
|
||||
uint32_t c = 0x0f0f00;
|
||||
while(1) {
|
||||
c = color_list[i];
|
||||
uint32_t next_color = color_list[i+1];
|
||||
i++;
|
||||
if((i+1)>=LIST_SIZE(color_list)) {
|
||||
i=0;
|
||||
}
|
||||
for(j = 0; j<MAX_STEP;j+=1) {
|
||||
uint32_t color = interpolateColors(c,next_color,j);
|
||||
for (int var = 0; var < Pixel_NUM; ++var) {
|
||||
setPixelColor(var,hex2rgb(color));
|
||||
|
||||
}
|
||||
w2812_sync();
|
||||
Delay_Ms(10);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn led_example_1
|
||||
*
|
||||
* @brief In this example, all leds will blink
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void led_example_1(void)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t c = 0x0f0f00;
|
||||
while(1) {
|
||||
c = color_list[i];
|
||||
printf("color[%d] %08x %08x \n",i,c,color_list[i]);
|
||||
i++;
|
||||
if(i>=LIST_SIZE(color_list)) {
|
||||
i=0;
|
||||
}
|
||||
for (int var = 0; var < Pixel_NUM; ++var) {
|
||||
setPixelColor(var,hex2rgb(c));
|
||||
}
|
||||
w2812_sync();
|
||||
Delay_Ms(100);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn led_example_2
|
||||
*
|
||||
* @brief In this example, the leds will blink one by one
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void led_example_2(void)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t c = 0x0f0f00;
|
||||
while(1) {
|
||||
c = color_list[i];
|
||||
printf("color[%d] %08x %08x \n",i,c,color_list[i]);
|
||||
i++;
|
||||
if(i>=LIST_SIZE(color_list)) {
|
||||
i=0;
|
||||
}
|
||||
|
||||
for (int var = 0; var < Pixel_NUM; var+=1) {
|
||||
setPixelColor(var, hex2rgb(c));
|
||||
w2812_sync();
|
||||
Delay_Ms(100);
|
||||
setPixelColor(var,0,0,0);
|
||||
w2812_sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*********************************************************************
|
||||
* @fn main
|
||||
*
|
||||
* @brief Main program.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
|
||||
Delay_Init();
|
||||
USART_Printf_Init(115200);
|
||||
printf("SystemClk:%d\r\n", SystemCoreClock);
|
||||
|
||||
// Turn off all LEDs
|
||||
for (i = 0; i < Pixel_NUM; i++) {
|
||||
setPixelColor(i, 0, 0, 0);
|
||||
}
|
||||
#if LED_MODE == LED_SPI_MODE
|
||||
SPI_1Lines_HalfDuplex_Init();
|
||||
SPI1_DMA_Init();
|
||||
DMA_Cmd(SPI1_DMA_TX_CH, ENABLE);
|
||||
#elif LED_MODE == LED_PWM_MODE
|
||||
TIM1_Init();
|
||||
DMA1_Init();
|
||||
DMA_Cmd( TIM_DMA_CH1_CH, ENABLE);
|
||||
#endif
|
||||
|
||||
led_example_0();
|
||||
// led_example_2();
|
||||
|
||||
}
|
||||
|
||||
#if LED_MODE == LED_PWM_MODE
|
||||
void DMA1_Channel5_IRQHandler(void)
|
||||
{
|
||||
if (DMA_GetFlagStatus( DMA1_FLAG_TC5)) {
|
||||
TIM_Cmd( TIM1, DISABLE);
|
||||
DMA_Cmd( TIM_DMA_CH1_CH, DISABLE);
|
||||
DMA_ClearFlag( DMA1_FLAG_TC5);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+1
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
@@ -45,11 +45,11 @@
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic.1590833110" name="Atomic extension (RVA)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused.1961191588" name="Warn on various unused elements (-Wunused)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized.929829166" name="Warn on uninitialized variables (-Wuninitialised)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw.932587520" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore.1091914013" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon.2027509349" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon.2003631682" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon" useByScannerDiscovery="true" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw.1819910041" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore.1179366128" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform.1944008784" isAbstract="false" osList="all" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform"/>
|
||||
<builder buildPath="${workspace_loc:/BKP}/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
|
||||
<builder buildPath="${workspace_loc:/GPIO_Toggle}/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.1244756189" name="GNU RISC-V Cross Assembler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler">
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor.1692176068" name="Use preprocessor" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths.1034038285" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
@@ -35,27 +35,27 @@
|
||||
<link>
|
||||
<name>Core</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Core</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Core</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Debug</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Debug</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Debug</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Ld</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Ld</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Ld</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Peripheral</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Peripheral</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Peripheral</location>
|
||||
</link>
|
||||
<link>
|
||||
<name>Startup</name>
|
||||
<type>2</type>
|
||||
<location>PARENT-1-PROJECT_LOC/SRC/Startup</location>
|
||||
<location>PARENT-2-PROJECT_LOC/SRC/Startup</location>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
||||
@@ -1,6 +1,6 @@
|
||||
Mcu Type=CH32V20x
|
||||
Address=0x08000000
|
||||
Target Path=obj/IWDG.hex
|
||||
Target Path=obj\BKP.hex
|
||||
Erase All=true
|
||||
Program=true
|
||||
Verify=true
|
||||
@@ -14,3 +14,4 @@ Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH
|
||||
|
||||
PeripheralVersion=1.0
|
||||
MCU=CH32V203RBT6
|
||||
CLKSpeed=1
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -56,11 +56,12 @@
|
||||
</tool>
|
||||
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/UART}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/APP/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SRC/Core}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SRC/Startup}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SRC/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SRC/Peripheral/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/APP/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Profile/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/HAL/include}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/LIB}""/>
|
||||
@@ -133,11 +134,11 @@
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="APP"/>
|
||||
<entry excluding="include/cdc.h|cdc.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="APP"/>
|
||||
<entry excluding="Profile" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="HAL"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="LIB"/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Profile"/>
|
||||
<entry excluding="Startup/startup_ch32v20x_D8.S|Startup/startup_ch32v20x_D6.S|Ld/" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="SRC"/>
|
||||
<entry excluding="Ld/|Startup/startup_ch32v20x_D6.S|Startup/startup_ch32v20x_D8.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="SRC"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
@@ -159,5 +160,5 @@
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
</cproject>
|
||||
|
||||
@@ -18,6 +18,18 @@
|
||||
#else
|
||||
#define SIMPLE_BUF_DBG(...)
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simple_buf_create
|
||||
*
|
||||
* @brief Create a simple_buf structure object.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
* buf_pool - a pointer to the buffer where data is stored.
|
||||
* pool_size - the size of the buffer.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
struct simple_buf *simple_buf_create(struct simple_buf *buf,
|
||||
uint8_t *buf_pool, uint16_t pool_size)
|
||||
{
|
||||
@@ -29,13 +41,24 @@ struct simple_buf *simple_buf_create(struct simple_buf *buf,
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simple_buf_add
|
||||
*
|
||||
* @brief Add data to the buf object.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
* len - length of the data to be added.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void *simple_buf_add(struct simple_buf *buf, size_t len)
|
||||
{
|
||||
uint8_t *tail = buf->data + buf->len;
|
||||
uint8_t *tail = buf->data + buf->len;
|
||||
|
||||
SIMPLE_BUF_DBG("buf %p add len %ld\n", buf, len);
|
||||
|
||||
if((buf->size - (buf->data - buf->__buf) - buf->len) < len) {
|
||||
if((buf->size - (buf->data - buf->__buf) - buf->len) < len)
|
||||
{
|
||||
SIMPLE_BUF_DBG("simple_buf_add: no memory\n");
|
||||
while(1);
|
||||
}
|
||||
@@ -45,39 +68,71 @@ void *simple_buf_add(struct simple_buf *buf, size_t len)
|
||||
return tail;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simple_buf_pull
|
||||
*
|
||||
* @brief pull data from the buf object.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
* len - The length of data to be retrieved.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void *simple_buf_pull(struct simple_buf *buf, size_t len)
|
||||
{
|
||||
void *data = buf->data;
|
||||
void *data = buf->data;
|
||||
|
||||
SIMPLE_BUF_DBG("buf %p pull len %ld\n", buf, len);
|
||||
|
||||
if(buf->len < len) {
|
||||
if(buf->len < len)
|
||||
{
|
||||
SIMPLE_BUF_DBG("simple_buf_pull: no data\n");
|
||||
while(1);
|
||||
}
|
||||
|
||||
buf->len -= len;
|
||||
buf->data += len;
|
||||
buf->len -= len;
|
||||
buf->data += len;
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simple_buf_add_mem
|
||||
*
|
||||
* @brief Add a segment of memory data to the buf object.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
* mem - a pointer to the memory data to be added.
|
||||
* len - the length of the data to be added.
|
||||
*
|
||||
* @return The function returns a pointer to the starting position of the added data.
|
||||
*/
|
||||
void *simple_buf_add_mem(struct simple_buf *buf, const void *mem,
|
||||
size_t len)
|
||||
size_t len)
|
||||
{
|
||||
SIMPLE_BUF_DBG("buf %p add len %ld\n", buf, len);
|
||||
|
||||
return memcpy(simple_buf_add(buf, len), mem, len);
|
||||
return memcpy(simple_buf_add(buf, len), mem, len);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simple_buf_add_u8
|
||||
*
|
||||
* @brief Add an 8-bit unsigned integer to the buf object.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
* val - the 8-bit unsigned integer to be added.
|
||||
*
|
||||
* @return The function returns a pointer to the starting position of the added data.
|
||||
*/
|
||||
uint8_t *simple_buf_add_u8(struct simple_buf *buf, uint8_t val)
|
||||
{
|
||||
uint8_t *u8;
|
||||
uint8_t *u8;
|
||||
|
||||
SIMPLE_BUF_DBG("buf %p add val 0x%02x\n", buf, val);
|
||||
|
||||
u8 = simple_buf_add(buf, 1);
|
||||
*u8 = val;
|
||||
u8 = simple_buf_add(buf, 1);
|
||||
*u8 = val;
|
||||
|
||||
return u8;
|
||||
return u8;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,796 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : ch32v20x_usbfs_device.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : This file provides all the USBOTG firmware functions.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ch32v20x_usbfs_device.h"
|
||||
#include "buf.h"
|
||||
#include "uart.h"
|
||||
/*******************************************************************************/
|
||||
/* Variable Definition */
|
||||
/* Global */
|
||||
const uint8_t *pUSBFS_Descr;
|
||||
|
||||
/* Setup Request */
|
||||
volatile uint8_t USBFS_SetupReqCode;
|
||||
volatile uint8_t USBFS_SetupReqType;
|
||||
volatile uint16_t USBFS_SetupReqValue;
|
||||
volatile uint16_t USBFS_SetupReqIndex;
|
||||
volatile uint16_t USBFS_SetupReqLen;
|
||||
|
||||
/* USB Device Status */
|
||||
volatile uint8_t USBFS_DevConfig;
|
||||
volatile uint8_t USBFS_DevAddr;
|
||||
volatile uint8_t USBFS_DevSleepStatus;
|
||||
volatile uint8_t USBFS_DevEnumStatus;
|
||||
|
||||
/* Endpoint Buffer */
|
||||
__attribute__ ((aligned(4))) uint8_t USBFS_EP0_Buf[ DEF_USBD_UEP0_SIZE ];
|
||||
__attribute__ ((aligned(4))) uint8_t USBFS_EP1_Buf[ DEF_USBD_ENDP1_SIZE ];
|
||||
__attribute__ ((aligned(4))) uint8_t USBFS_EP2_Buf[ DEF_USBD_ENDP2_SIZE ];
|
||||
__attribute__ ((aligned(4))) uint8_t USBFS_EP3_Buf[ DEF_USBD_ENDP3_SIZE ];
|
||||
|
||||
/* USB IN Endpoint Busy Flag */
|
||||
volatile uint8_t USBFS_Endp_Busy[ DEF_UEP_NUM ];
|
||||
|
||||
/******************************************************************************/
|
||||
/* Interrupt Service Routine Declaration*/
|
||||
void USBHD_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBFS_RCC_Init
|
||||
*
|
||||
* @brief Initializes the usbotg clock configuration.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBFS_RCC_Init( void )
|
||||
{
|
||||
if( SystemCoreClock == 144000000 )
|
||||
{
|
||||
RCC_USBCLKConfig( RCC_USBCLKSource_PLLCLK_Div3 );
|
||||
}
|
||||
else if( SystemCoreClock == 96000000 )
|
||||
{
|
||||
RCC_USBCLKConfig( RCC_USBCLKSource_PLLCLK_Div2 );
|
||||
}
|
||||
else if( SystemCoreClock == 48000000 )
|
||||
{
|
||||
RCC_USBCLKConfig( RCC_USBCLKSource_PLLCLK_Div1 );
|
||||
}
|
||||
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_OTG_FS, ENABLE );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBFS_Device_Endp_Init
|
||||
*
|
||||
* @brief Initializes USB device endpoints.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBFS_Device_Endp_Init( void )
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
USBOTG_FS->UEP4_1_MOD = USBFS_UEP1_TX_EN;
|
||||
USBOTG_FS->UEP2_3_MOD = USBFS_UEP2_RX_EN|USBFS_UEP3_TX_EN;
|
||||
|
||||
USBOTG_FS->UEP0_DMA = (uint32_t)USBFS_EP0_Buf;
|
||||
|
||||
USBOTG_FS->UEP1_DMA = (uint32_t)USBFS_EP1_Buf;
|
||||
USBOTG_FS->UEP2_DMA = (uint32_t)UART2_Tx_Buf;
|
||||
USBOTG_FS->UEP3_DMA = (uint32_t)USBFS_EP3_Buf;
|
||||
|
||||
USBOTG_FS->UEP0_RX_CTRL = USBFS_UEP_R_RES_ACK;
|
||||
USBOTG_FS->UEP2_RX_CTRL = USBFS_UEP_R_RES_ACK;
|
||||
|
||||
USBOTG_FS->UEP1_TX_LEN = 0;
|
||||
USBOTG_FS->UEP3_TX_LEN = 0;
|
||||
|
||||
USBOTG_FS->UEP0_TX_CTRL = USBFS_UEP_T_RES_NAK;
|
||||
USBOTG_FS->UEP1_TX_CTRL = USBFS_UEP_T_RES_NAK;
|
||||
USBOTG_FS->UEP3_TX_CTRL = USBFS_UEP_T_RES_NAK;
|
||||
|
||||
/* Clear End-points Busy Status */
|
||||
for( i=0; i<DEF_UEP_NUM; i++ )
|
||||
{
|
||||
USBFS_Endp_Busy[ i ] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBFS_Device_Init
|
||||
*
|
||||
* @brief Initializes USB device.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBFS_Device_Init( FunctionalState sta )
|
||||
{
|
||||
if( sta )
|
||||
{
|
||||
USBOTG_H_FS->BASE_CTRL = USBFS_UC_RESET_SIE | USBFS_UC_CLR_ALL;
|
||||
Delay_Us( 10 );
|
||||
USBOTG_H_FS->BASE_CTRL = 0x00;
|
||||
USBOTG_FS->INT_EN = USBFS_UIE_SUSPEND | USBFS_UIE_BUS_RST | USBFS_UIE_TRANSFER;
|
||||
USBOTG_FS->BASE_CTRL = USBFS_UC_DEV_PU_EN | USBFS_UC_INT_BUSY | USBFS_UC_DMA_EN;
|
||||
USBFS_Device_Endp_Init( );
|
||||
USBOTG_FS->UDEV_CTRL = USBFS_UD_PD_DIS | USBFS_UD_PORT_EN;
|
||||
NVIC_EnableIRQ( USBHD_IRQn );
|
||||
}
|
||||
else
|
||||
{
|
||||
USBOTG_H_FS->BASE_CTRL = USBFS_UC_RESET_SIE | USBFS_UC_CLR_ALL;
|
||||
Delay_Us( 10 );
|
||||
USBOTG_FS->BASE_CTRL = 0x00;
|
||||
NVIC_DisableIRQ( USBHD_IRQn );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DevEP2_OUT_Deal
|
||||
*
|
||||
* @brief 端点2数据处理
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void DevEP2_OUT_Deal( uint8_t l )
|
||||
{ /* 用户可自定义 */
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < l; i++)
|
||||
{
|
||||
simple_buf_add_u8(usb_buf, UART2_Tx_Buf[i]);
|
||||
}
|
||||
atomic_set(&usb_flag, USB_STATUS_RCV_END);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBSendData
|
||||
*
|
||||
* @brief 发送数据给主机
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t USBSendData(uint8_t *buf, uint16_t len)
|
||||
{
|
||||
|
||||
USBFS_Endp_DataUp(DEF_UEP3, buf, len, DEF_UEP_CPY_LOAD);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBFS_Endp_DataUp
|
||||
*
|
||||
* @brief USBFS device data upload
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t USBFS_Endp_DataUp(uint8_t endp, uint8_t *pbuf, uint16_t len, uint8_t mod)
|
||||
{
|
||||
uint8_t endp_mode;
|
||||
uint8_t buf_load_offset;
|
||||
|
||||
/* DMA config, endp_ctrl config, endp_len config */
|
||||
if( (endp>=DEF_UEP1) && (endp<=DEF_UEP7) )
|
||||
{
|
||||
if( USBFS_Endp_Busy[ endp ] == 0 )
|
||||
{
|
||||
if( (endp == DEF_UEP1) || (endp == DEF_UEP4) )
|
||||
{
|
||||
/* endp1/endp4 */
|
||||
endp_mode = USBFSD_UEP_MOD(0);
|
||||
if( endp == DEF_UEP1 )
|
||||
{
|
||||
endp_mode = (uint8_t)(endp_mode>>4);
|
||||
}
|
||||
}
|
||||
else if( (endp == DEF_UEP2) || (endp == DEF_UEP3) )
|
||||
{
|
||||
/* endp2/endp3 */
|
||||
endp_mode = USBFSD_UEP_MOD(1);
|
||||
if( endp == DEF_UEP3 )
|
||||
{
|
||||
endp_mode = (uint8_t)(endp_mode>>4);
|
||||
}
|
||||
}
|
||||
else if( (endp == DEF_UEP5) || (endp == DEF_UEP6) )
|
||||
{
|
||||
/* endp5/endp6 */
|
||||
endp_mode = USBFSD_UEP_MOD(2);
|
||||
if( endp == DEF_UEP6 )
|
||||
{
|
||||
endp_mode = (uint8_t)(endp_mode>>4);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* endp7 */
|
||||
endp_mode = USBFSD_UEP_MOD(3);
|
||||
}
|
||||
|
||||
if( endp_mode & USBFSD_UEP_TX_EN )
|
||||
{
|
||||
if( endp_mode & USBFSD_UEP_RX_EN )
|
||||
{
|
||||
buf_load_offset = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_load_offset = 0;
|
||||
}
|
||||
|
||||
if( buf_load_offset == 0 )
|
||||
{
|
||||
if( mod == DEF_UEP_DMA_LOAD )
|
||||
{
|
||||
/* DMA mode */
|
||||
USBFSD_UEP_DMA(endp) = (uint16_t)(uint32_t)pbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* copy mode */
|
||||
memcpy( USBFSD_UEP_BUF(endp), pbuf, len );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( USBFSD_UEP_BUF(endp)+buf_load_offset, pbuf, len );
|
||||
}
|
||||
/* Set end-point busy */
|
||||
USBFS_Endp_Busy[ endp ] = 0x01;
|
||||
/* tx length */
|
||||
USBFSD_UEP_TLEN(endp) = len;
|
||||
/* response ack */
|
||||
USBFSD_UEP_CTRL(endp) = (USBFSD_UEP_CTRL(endp) & ~USBFS_UEP_T_RES_MASK) | USBFS_UEP_T_RES_ACK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBHD_IRQHandler
|
||||
*
|
||||
* @brief This function handles HD-FS exception.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBHD_IRQHandler( void )
|
||||
{
|
||||
uint8_t intflag, intst, errflag;
|
||||
uint16_t len;
|
||||
uint32_t baudrate;
|
||||
|
||||
intflag = USBOTG_FS->INT_FG;
|
||||
intst = USBOTG_FS->INT_ST;
|
||||
|
||||
if( intflag & USBFS_UIF_TRANSFER )
|
||||
{
|
||||
switch (intst & USBFS_UIS_TOKEN_MASK)
|
||||
{
|
||||
/* data-in stage processing */
|
||||
case USBFS_UIS_TOKEN_IN:
|
||||
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) )
|
||||
{
|
||||
/* end-point 0 data in interrupt */
|
||||
case USBFS_UIS_TOKEN_IN | DEF_UEP0:
|
||||
if( USBFS_SetupReqLen == 0 )
|
||||
{
|
||||
USBOTG_FS->UEP0_RX_CTRL = USBFS_UEP_R_TOG | USBFS_UEP_R_RES_ACK;
|
||||
}
|
||||
if ( ( USBFS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD )
|
||||
{
|
||||
/* Non-standard request endpoint 0 Data upload */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Standard request endpoint 0 Data upload */
|
||||
switch( USBFS_SetupReqCode )
|
||||
{
|
||||
case USB_GET_DESCRIPTOR:
|
||||
len = USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||
memcpy( USBFS_EP0_Buf, pUSBFS_Descr, len );
|
||||
USBFS_SetupReqLen -= len;
|
||||
pUSBFS_Descr += len;
|
||||
USBOTG_FS->UEP0_TX_LEN = len;
|
||||
USBOTG_FS->UEP0_TX_CTRL ^= USBFS_UEP_T_TOG;
|
||||
break;
|
||||
|
||||
case USB_SET_ADDRESS:
|
||||
USBOTG_FS->DEV_ADDR = (USBOTG_FS->DEV_ADDR & USBFS_UDA_GP_BIT) | USBFS_DevAddr;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* end-point 1 data in interrupt */
|
||||
case ( USBFS_UIS_TOKEN_IN | DEF_UEP1 ):
|
||||
USBOTG_FS->UEP1_TX_CTRL ^= USBFS_UEP_T_TOG;
|
||||
USBOTG_FS->UEP1_TX_CTRL = (USBOTG_FS->UEP1_TX_CTRL & ~USBFS_UEP_T_RES_MASK) | USBFS_UEP_T_RES_NAK;
|
||||
USBFS_Endp_Busy[ DEF_UEP1 ] = 0;
|
||||
break;
|
||||
|
||||
/* end-point 3 data in interrupt */
|
||||
case ( USBFS_UIS_TOKEN_IN | DEF_UEP3 ):
|
||||
USBOTG_FS->UEP3_TX_CTRL ^= USBFS_UEP_T_TOG;
|
||||
USBOTG_FS->UEP3_TX_CTRL = (USBOTG_FS->UEP3_TX_CTRL & ~USBFS_UEP_T_RES_MASK) | USBFS_UEP_T_RES_NAK;
|
||||
USBFS_Endp_Busy[ DEF_UEP3 ] = 0;
|
||||
// Uart.USB_Up_IngFlag = 0x00;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* data-out stage processing */
|
||||
case USBFS_UIS_TOKEN_OUT:
|
||||
switch ( intst & ( USBFS_UIS_TOKEN_MASK | USBFS_UIS_ENDP_MASK ) )
|
||||
{
|
||||
/* end-point 0 data out interrupt */
|
||||
case USBFS_UIS_TOKEN_OUT | DEF_UEP0:
|
||||
len = USBOTG_FS->RX_LEN;
|
||||
if ( intst & USBFS_UIS_TOG_OK )
|
||||
{
|
||||
if ( ( USBFS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD )
|
||||
{
|
||||
/* Non-standard request end-point 0 Data download */
|
||||
USBFS_SetupReqLen = 0;
|
||||
/* Non-standard request end-point 0 Data download */
|
||||
if( USBFS_SetupReqCode == CDC_SET_LINE_CODING )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Standard request end-point 0 Data download */
|
||||
/* Add your code here */
|
||||
}
|
||||
if( USBFS_SetupReqLen == 0 )
|
||||
{
|
||||
USBOTG_FS->UEP0_TX_LEN = 0;
|
||||
USBOTG_FS->UEP0_TX_CTRL = USBFS_UEP_T_TOG | USBFS_UEP_T_RES_ACK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* end-point 1 data out interrupt */
|
||||
case USBFS_UIS_TOKEN_OUT | DEF_UEP2:
|
||||
USBOTG_FS->UEP2_RX_CTRL ^= USBFS_UEP_R_TOG;
|
||||
DevEP2_OUT_Deal(USBOTG_FS->RX_LEN);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Setup stage processing */
|
||||
case USBFS_UIS_TOKEN_SETUP:
|
||||
USBOTG_FS->UEP0_TX_CTRL = USBFS_UEP_T_TOG|USBFS_UEP_T_RES_NAK;
|
||||
USBOTG_FS->UEP0_RX_CTRL = USBFS_UEP_R_TOG|USBFS_UEP_R_RES_NAK;
|
||||
/* Store All Setup Values */
|
||||
USBFS_SetupReqType = pUSBFS_SetupReqPak->bRequestType;
|
||||
USBFS_SetupReqCode = pUSBFS_SetupReqPak->bRequest;
|
||||
USBFS_SetupReqLen = pUSBFS_SetupReqPak->wLength;
|
||||
USBFS_SetupReqValue = pUSBFS_SetupReqPak->wValue;
|
||||
USBFS_SetupReqIndex = pUSBFS_SetupReqPak->wIndex;
|
||||
len = 0;
|
||||
errflag = 0;
|
||||
if ( ( USBFS_SetupReqType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD )
|
||||
{
|
||||
/* usb non-standard request processing */
|
||||
if( USBFS_SetupReqType & USB_REQ_TYP_CLASS )
|
||||
{
|
||||
/* Class requests */
|
||||
switch( USBFS_SetupReqCode )
|
||||
{
|
||||
case CDC_GET_LINE_CODING:
|
||||
break;
|
||||
|
||||
case CDC_SET_LINE_CODING:
|
||||
break;
|
||||
|
||||
case CDC_SET_LINE_CTLSTE:
|
||||
break;
|
||||
|
||||
case CDC_SEND_BREAK:
|
||||
break;
|
||||
|
||||
default:
|
||||
errflag = 0xff;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( USBFS_SetupReqType & USB_REQ_TYP_VENDOR )
|
||||
{
|
||||
/* Manufacturer request */
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
|
||||
/* Copy Descriptors to Endp0 DMA buffer */
|
||||
len = (USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||
memcpy( USBFS_EP0_Buf, pUSBFS_Descr, len );
|
||||
pUSBFS_Descr += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* usb standard request processing */
|
||||
switch( USBFS_SetupReqCode )
|
||||
{
|
||||
/* get device/configuration/string/report/... descriptors */
|
||||
case USB_GET_DESCRIPTOR:
|
||||
switch( (uint8_t)( USBFS_SetupReqValue >> 8 ) )
|
||||
{
|
||||
/* get usb device descriptor */
|
||||
case USB_DESCR_TYP_DEVICE:
|
||||
pUSBFS_Descr = MyDevDescr;
|
||||
len = DEF_USBD_DEVICE_DESC_LEN;
|
||||
break;
|
||||
|
||||
/* get usb configuration descriptor */
|
||||
case USB_DESCR_TYP_CONFIG:
|
||||
pUSBFS_Descr = MyCfgDescr;
|
||||
len = DEF_USBD_CONFIG_DESC_LEN;
|
||||
break;
|
||||
|
||||
/* get usb string descriptor */
|
||||
case USB_DESCR_TYP_STRING:
|
||||
switch( (uint8_t)( USBFS_SetupReqValue & 0xFF ) )
|
||||
{
|
||||
/* Descriptor 0, Language descriptor */
|
||||
case DEF_STRING_DESC_LANG:
|
||||
pUSBFS_Descr = MyLangDescr;
|
||||
len = DEF_USBD_LANG_DESC_LEN;
|
||||
break;
|
||||
|
||||
/* Descriptor 1, Manufacturers String descriptor */
|
||||
case DEF_STRING_DESC_MANU:
|
||||
pUSBFS_Descr = MyManuInfo;
|
||||
len = DEF_USBD_MANU_DESC_LEN;
|
||||
break;
|
||||
|
||||
/* Descriptor 2, Product String descriptor */
|
||||
case DEF_STRING_DESC_PROD:
|
||||
pUSBFS_Descr = MyProdInfo;
|
||||
len = DEF_USBD_PROD_DESC_LEN;
|
||||
break;
|
||||
|
||||
/* Descriptor 3, Serial-number String descriptor */
|
||||
case DEF_STRING_DESC_SERN:
|
||||
pUSBFS_Descr = MySerNumInfo;
|
||||
len = DEF_USBD_SN_DESC_LEN;
|
||||
break;
|
||||
|
||||
default:
|
||||
errflag = 0xFF;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
errflag = 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy Descriptors to Endp0 DMA buffer */
|
||||
if( USBFS_SetupReqLen>len )
|
||||
{
|
||||
USBFS_SetupReqLen = len;
|
||||
}
|
||||
len = (USBFS_SetupReqLen >= DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||
memcpy( USBFS_EP0_Buf, pUSBFS_Descr, len );
|
||||
pUSBFS_Descr += len;
|
||||
break;
|
||||
|
||||
/* Set usb address */
|
||||
case USB_SET_ADDRESS:
|
||||
USBFS_DevAddr = (uint8_t)( USBFS_SetupReqValue & 0xFF );
|
||||
break;
|
||||
|
||||
/* Get usb configuration now set */
|
||||
case USB_GET_CONFIGURATION:
|
||||
USBFS_EP0_Buf[0] = USBFS_DevConfig;
|
||||
if ( USBFS_SetupReqLen > 1 )
|
||||
{
|
||||
USBFS_SetupReqLen = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Set usb configuration to use */
|
||||
case USB_SET_CONFIGURATION:
|
||||
USBFS_DevConfig = (uint8_t)( USBFS_SetupReqValue & 0xFF );
|
||||
USBFS_DevEnumStatus = 0x01;
|
||||
break;
|
||||
|
||||
/* Clear or disable one usb feature */
|
||||
case USB_CLEAR_FEATURE:
|
||||
if ( ( USBFS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_DEVICE )
|
||||
{
|
||||
/* clear one device feature */
|
||||
if( (uint8_t)( USBFS_SetupReqValue & 0xFF ) == USB_REQ_FEAT_REMOTE_WAKEUP )
|
||||
{
|
||||
/* clear usb sleep status, device not prepare to sleep */
|
||||
USBFS_DevSleepStatus &= ~0x01;
|
||||
}
|
||||
}
|
||||
else if( ( USBFS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP )
|
||||
{
|
||||
/* Clear End-point Feature */
|
||||
if( (uint8_t)( USBFS_SetupReqValue & 0xFF ) == USB_REQ_FEAT_ENDP_HALT )
|
||||
{
|
||||
switch( (uint8_t)( USBFS_SetupReqIndex & 0xFF ) )
|
||||
{
|
||||
case ( DEF_UEP_IN | DEF_UEP1 ):
|
||||
/* Set End-point 1 IN NAK */
|
||||
USBOTG_FS->UEP1_TX_CTRL = USBFS_UEP_T_RES_NAK;
|
||||
break;
|
||||
|
||||
case ( DEF_UEP_OUT | DEF_UEP2 ):
|
||||
/* Set End-point 2 OUT ACK */
|
||||
USBOTG_FS->UEP2_RX_CTRL = USBFS_UEP_R_RES_ACK;
|
||||
break;
|
||||
|
||||
case ( DEF_UEP_IN | DEF_UEP3 ):
|
||||
/* Set End-point 3 IN NAK */
|
||||
USBOTG_FS->UEP3_TX_CTRL = USBFS_UEP_T_RES_NAK;
|
||||
break;
|
||||
|
||||
default:
|
||||
errflag = 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
break;
|
||||
|
||||
/* set or enable one usb feature */
|
||||
case USB_SET_FEATURE:
|
||||
if( ( USBFS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_DEVICE )
|
||||
{
|
||||
/* Set Device Feature */
|
||||
if( (uint8_t)( USBFS_SetupReqValue & 0xFF ) == USB_REQ_FEAT_REMOTE_WAKEUP )
|
||||
{
|
||||
if( MyCfgDescr[ 7 ] & 0x20 )
|
||||
{
|
||||
/* Set Wake-up flag, device prepare to sleep */
|
||||
USBFS_DevSleepStatus |= 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
}
|
||||
else if( ( USBFS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP )
|
||||
{
|
||||
/* Set End-point Feature */
|
||||
if( (uint8_t)( USBFS_SetupReqValue & 0xFF ) == USB_REQ_FEAT_ENDP_HALT )
|
||||
{
|
||||
/* Set end-points status stall */
|
||||
switch( (uint8_t)( USBFS_SetupReqIndex & 0xFF ) )
|
||||
{
|
||||
case ( DEF_UEP_IN | DEF_UEP1 ):
|
||||
/* Set End-point 1 IN STALL */
|
||||
USBOTG_FS->UEP1_TX_CTRL = ( USBOTG_FS->UEP1_TX_CTRL & ~USBFS_UEP_T_RES_MASK ) | USBFS_UEP_T_RES_STALL;
|
||||
break;
|
||||
|
||||
case ( DEF_UEP_OUT | DEF_UEP2 ):
|
||||
/* Set End-point 2 OUT STALL */
|
||||
USBOTG_FS->UEP2_RX_CTRL = ( USBOTG_FS->UEP2_RX_CTRL & ~USBFS_UEP_R_RES_MASK ) | USBFS_UEP_R_RES_STALL;
|
||||
break;
|
||||
|
||||
case ( DEF_UEP_IN | DEF_UEP3 ):
|
||||
/* Set End-point 3 IN STALL */
|
||||
USBOTG_FS->UEP3_TX_CTRL = ( USBOTG_FS->UEP3_TX_CTRL & ~USBFS_UEP_T_RES_MASK ) | USBFS_UEP_T_RES_STALL;
|
||||
break;
|
||||
|
||||
default:
|
||||
errflag = 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
break;
|
||||
|
||||
/* This request allows the host to select another setting for the specified interface */
|
||||
case USB_GET_INTERFACE:
|
||||
USBFS_EP0_Buf[0] = 0x00;
|
||||
if ( USBFS_SetupReqLen > 1 )
|
||||
{
|
||||
USBFS_SetupReqLen = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_SET_INTERFACE:
|
||||
break;
|
||||
|
||||
/* host get status of specified device/interface/end-points */
|
||||
case USB_GET_STATUS:
|
||||
USBFS_EP0_Buf[ 0 ] = 0x00;
|
||||
USBFS_EP0_Buf[ 1 ] = 0x00;
|
||||
if ( ( USBFS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_DEVICE )
|
||||
{
|
||||
if( USBFS_DevSleepStatus & 0x01 )
|
||||
{
|
||||
USBFS_EP0_Buf[ 0 ] = 0x02;
|
||||
}
|
||||
}
|
||||
else if( ( USBFS_SetupReqType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP )
|
||||
{
|
||||
switch( (uint8_t)( USBFS_SetupReqIndex & 0xFF ) )
|
||||
{
|
||||
case ( DEF_UEP_IN | DEF_UEP1 ):
|
||||
if( ( (USBOTG_FS->UEP1_TX_CTRL) & USBFS_UEP_T_RES_MASK ) == USBFS_UEP_T_RES_STALL )
|
||||
{
|
||||
USBFS_EP0_Buf[ 0 ] = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case ( DEF_UEP_OUT | DEF_UEP2 ):
|
||||
if( ( (USBOTG_FS->UEP2_RX_CTRL) & USBFS_UEP_R_RES_MASK ) == USBFS_UEP_R_RES_STALL )
|
||||
{
|
||||
USBFS_EP0_Buf[ 0 ] = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case ( DEF_UEP_IN | DEF_UEP3 ):
|
||||
if( ( (USBOTG_FS->UEP3_TX_CTRL) & USBFS_UEP_T_RES_MASK ) == USBFS_UEP_T_RES_STALL )
|
||||
{
|
||||
USBFS_EP0_Buf[ 0 ] = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
errflag = 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errflag = 0xFF;
|
||||
}
|
||||
|
||||
if( USBFS_SetupReqLen > 2 )
|
||||
{
|
||||
USBFS_SetupReqLen = 2;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
errflag = 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* errflag = 0xFF means a request not support or some errors occurred, else correct */
|
||||
if( errflag == 0xff)
|
||||
{
|
||||
/* if one request not support, return stall */
|
||||
USBOTG_FS->UEP0_TX_CTRL = USBFS_UEP_T_TOG|USBFS_UEP_T_RES_STALL;
|
||||
USBOTG_FS->UEP0_RX_CTRL = USBFS_UEP_R_TOG|USBFS_UEP_R_RES_STALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* end-point 0 data Tx/Rx */
|
||||
if( USBFS_SetupReqType & DEF_UEP_IN )
|
||||
{
|
||||
/* tx */
|
||||
len = (USBFS_SetupReqLen>DEF_USBD_UEP0_SIZE) ? DEF_USBD_UEP0_SIZE : USBFS_SetupReqLen;
|
||||
USBFS_SetupReqLen -= len;
|
||||
USBOTG_FS->UEP0_TX_LEN = len;
|
||||
USBOTG_FS->UEP0_TX_CTRL = USBFS_UEP_T_TOG|USBFS_UEP_T_RES_ACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* rx */
|
||||
if( USBFS_SetupReqLen == 0 )
|
||||
{
|
||||
USBOTG_FS->UEP0_TX_LEN = 0;
|
||||
USBOTG_FS->UEP0_TX_CTRL = USBFS_UEP_T_TOG|USBFS_UEP_T_RES_ACK;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBOTG_FS->UEP0_RX_CTRL = USBFS_UEP_R_TOG|USBFS_UEP_R_RES_ACK;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Sof pack processing */
|
||||
case USBFS_UIS_TOKEN_SOF:
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
USBOTG_FS->INT_FG = USBFS_UIF_TRANSFER;
|
||||
}
|
||||
else if( intflag & USBFS_UIF_BUS_RST )
|
||||
{
|
||||
/* usb reset interrupt processing */
|
||||
USBOTG_FS->DEV_ADDR = 0;
|
||||
USBFS_Device_Endp_Init( );
|
||||
USBOTG_FS->INT_FG = USBFS_UIF_BUS_RST;
|
||||
}
|
||||
else if( intflag & USBFS_UIF_SUSPEND )
|
||||
{
|
||||
/* usb suspend interrupt processing */
|
||||
if ( USBOTG_FS->MIS_ST & USBFS_UMS_SUSPEND )
|
||||
{
|
||||
USBFS_DevSleepStatus |= 0x02;
|
||||
if( USBFS_DevSleepStatus == 0x03 )
|
||||
{
|
||||
/* Handling usb sleep here */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBFS_DevSleepStatus &= ~0x02;
|
||||
}
|
||||
USBOTG_FS->INT_FG = USBFS_UIF_SUSPEND;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* other interrupts */
|
||||
USBOTG_FS->INT_FG = intflag;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USBFS_Send_Resume
|
||||
*
|
||||
* @brief USBFS device sends wake-up signal to host
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USBFS_Send_Resume(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "hci_test.h"
|
||||
#include "config.h"
|
||||
#include "uart.h"
|
||||
|
||||
static uint16_t _opcode;
|
||||
static uint8_t hci_pool[100];
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
struct simple_buf {
|
||||
/** Pointer to the start of data in the buffer. */
|
||||
uint8_t *data;
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : ch32v20x_usbfs_device.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : This file contains all the functions prototypes for the
|
||||
* USBOTG firmware library.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __CH32V20X_USBFS_DEVICE_H_
|
||||
#define __CH32V20X_USBFS_DEVICE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "usb_desc.h"
|
||||
#include "ch32v20x_usb.h"
|
||||
#include <UART.h>
|
||||
|
||||
/******************************************************************************/
|
||||
/* Global Define */
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __attribute__((packed))
|
||||
#endif
|
||||
|
||||
/* end-point number */
|
||||
#define DEF_UEP_IN 0x80
|
||||
#define DEF_UEP_OUT 0x00
|
||||
#define DEF_UEP0 0x00
|
||||
#define DEF_UEP1 0x01
|
||||
#define DEF_UEP2 0x02
|
||||
#define DEF_UEP3 0x03
|
||||
#define DEF_UEP4 0x04
|
||||
#define DEF_UEP5 0x05
|
||||
#define DEF_UEP6 0x06
|
||||
#define DEF_UEP7 0x07
|
||||
#define DEF_UEP_NUM 8
|
||||
|
||||
#define USBFSD_UEP_MOD_BASE 0x5000000C
|
||||
#define USBFSD_UEP_DMA_BASE 0x50000010
|
||||
#define USBFSD_UEP_LEN_BASE 0x50000030
|
||||
#define USBFSD_UEP_CTL_BASE 0x50000032
|
||||
#define USBFSD_UEP_RX_EN 0x08
|
||||
#define USBFSD_UEP_TX_EN 0x04
|
||||
#define USBFSD_UEP_BUF_MOD 0x01
|
||||
#define DEF_UEP_DMA_LOAD 0 /* Direct the DMA address to the data to be processed */
|
||||
#define DEF_UEP_CPY_LOAD 1 /* Use memcpy to move data to a buffer */
|
||||
#define USBFSD_UEP_MOD(n) (*((volatile uint8_t *)(USBFSD_UEP_MOD_BASE+n)))
|
||||
#define USBFSD_UEP_CTRL(n) (*((volatile uint8_t *)(USBFSD_UEP_CTL_BASE+n*0x04)))
|
||||
#define USBFSD_UEP_DMA(n) (*((volatile uint32_t *)(USBFSD_UEP_DMA_BASE+n*0x04)))
|
||||
#define USBFSD_UEP_BUF(n) ((uint8_t *)(*((volatile uint32_t *)(USBFSD_UEP_DMA_BASE+n*0x04)))+0x20000000)
|
||||
#define USBFSD_UEP_TLEN(n) (*((volatile uint16_t *)(USBFSD_UEP_LEN_BASE+n*0x04)))
|
||||
|
||||
/* Setup Request Packets */
|
||||
#define pUSBFS_SetupReqPak ((PUSB_SETUP_REQ)USBFS_EP0_Buf)
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Variable Definition */
|
||||
/* Global */
|
||||
extern const uint8_t *pUSBFS_Descr;
|
||||
|
||||
/* Setup Request */
|
||||
extern volatile uint8_t USBFS_SetupReqCode;
|
||||
extern volatile uint8_t USBFS_SetupReqType;
|
||||
extern volatile uint16_t USBFS_SetupReqValue;
|
||||
extern volatile uint16_t USBFS_SetupReqIndex;
|
||||
extern volatile uint16_t USBFS_SetupReqLen;
|
||||
|
||||
/* USB Device Status */
|
||||
extern volatile uint8_t USBFS_DevConfig;
|
||||
extern volatile uint8_t USBFS_DevAddr;
|
||||
extern volatile uint8_t USBFS_DevSleepStatus;
|
||||
extern volatile uint8_t USBFS_DevEnumStatus;
|
||||
|
||||
/* Endpoint Buffer */
|
||||
extern __attribute__ ((aligned(4))) uint8_t USBFS_EP0_Buf[ ];
|
||||
extern __attribute__ ((aligned(4))) uint8_t USBFS_EP1_Buf[ ];
|
||||
extern __attribute__ ((aligned(4))) uint8_t USBFS_EP2_Buf[ ];
|
||||
extern __attribute__ ((aligned(4))) uint8_t USBFS_EP3_Buf[ ];
|
||||
/* USB IN Endpoint Busy Flag */
|
||||
extern volatile uint8_t USBFS_Endp_Busy[ ];
|
||||
|
||||
/******************************************************************************/
|
||||
/* external functions */
|
||||
extern void USBFS_Device_Init( FunctionalState sta );
|
||||
extern void USBFS_Device_Endp_Init(void);
|
||||
extern void USBFS_RCC_Init(void);
|
||||
extern void USBFS_Send_Resume(void);
|
||||
extern void USBFS_Sleep_Wakeup_Operate(void);
|
||||
extern uint8_t USBSendData(uint8_t *buf, uint16_t len);
|
||||
extern uint8_t USBFS_Endp_DataUp(uint8_t endp, uint8_t *pbuf, uint16_t len, uint8_t mod);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* USER_CH32V20X_USB_DEVICE_H_ */
|
||||
|
||||
@@ -15,20 +15,63 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "buf.h"
|
||||
#include "atomic.h"
|
||||
|
||||
#define UART_PROCESS_EVT 1
|
||||
#define USB_UartEnable 1
|
||||
#define DEF_UARTx_RX_BUF_LEN ( 4 * 512 ) /* Serial x receive buffer size */
|
||||
#define DEF_UARTx_TX_BUF_LEN ( 2 * 512 ) /* Serial x transmit buffer size */
|
||||
|
||||
/*process events*/
|
||||
#define UART_RECEIVE_POLL_EVT (1<<0)
|
||||
#define USB_RECEIVE_POLL_EVT (1<<1)
|
||||
|
||||
#define UART_PROCESS_EVT 1
|
||||
#define USB_PROCESS_EVT (1<<1)
|
||||
|
||||
enum uart_status
|
||||
{
|
||||
UART_STATUS_IDLE,
|
||||
UART_STATUS_RCVING,
|
||||
UART_STATUS_RCV_END,
|
||||
UART_STATUS_SENDING,
|
||||
|
||||
UART_STATUS_NUM,
|
||||
};
|
||||
|
||||
enum usb_status
|
||||
{
|
||||
USB_STATUS_IDLE,
|
||||
USB_STATUS_RCVING,
|
||||
USB_STATUS_RCV_END,
|
||||
USB_STATUS_SENDING,
|
||||
|
||||
USB_STATUS_NUM,
|
||||
};
|
||||
|
||||
struct uart_process_msg {
|
||||
tmos_event_hdr_t hdr;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
struct usb_process_msg {
|
||||
tmos_event_hdr_t hdr;
|
||||
uint8_t *data;
|
||||
};
|
||||
|
||||
extern struct simple_buf *usb_buf;
|
||||
extern atomic_t uart_flag;
|
||||
extern atomic_t usb_flag;
|
||||
extern uint8_t UART2_Tx_Buf[ DEF_UARTx_TX_BUF_LEN ];
|
||||
extern uint8_t UART2_Rx_Buf[ DEF_UARTx_RX_BUF_LEN ];
|
||||
|
||||
|
||||
int usb_send(struct simple_buf *buf);
|
||||
int uart_send(struct simple_buf *buf);
|
||||
int uart_start_receiving(void);
|
||||
int usb_start_receiving(void);
|
||||
void uart_task_init(void);
|
||||
void USB_Task_Init(void);
|
||||
|
||||
|
||||
|
||||
#endif /* BLE_DIRECTTEST_APP_INCLUDE_UART_H */
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_desc.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : header file of usb_desc.c
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef USER_USB_DESC_H_
|
||||
#define USER_USB_DESC_H_
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/* global define */
|
||||
/* file version */
|
||||
#define DEF_FILE_VERSION 0x01
|
||||
/* usb device info define */
|
||||
#define DEF_USB_VID 0x1A86
|
||||
#define DEF_USB_PID 0xFE0C
|
||||
/* USB device descriptor, device serial number(bcdDevice) */
|
||||
#define DEF_IC_PRG_VER DEF_FILE_VERSION
|
||||
|
||||
/******************************************************************************/
|
||||
/* usb device endpoint size define */
|
||||
#define DEF_USBD_UEP0_SIZE 64 /* usb hs/fs device end-point 0 size */
|
||||
/* FS */
|
||||
#define DEF_USBD_FS_PACK_SIZE 64 /* usb fs device max bluk/int pack size */
|
||||
#define DEF_USBD_FS_ISO_PACK_SIZE 1023 /* usb fs device max iso pack size */
|
||||
/* LS */
|
||||
#define DEF_USBD_LS_UEP0_SIZE 8 /* usb ls device end-point 0 size */
|
||||
#define DEF_USBD_LS_PACK_SIZE 64 /* usb ls device max int pack size */
|
||||
|
||||
/* Pack size */
|
||||
#define DEF_USBD_ENDP1_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
#define DEF_USBD_ENDP2_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
#define DEF_USBD_ENDP3_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
#define DEF_USBD_ENDP4_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
#define DEF_USBD_ENDP5_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
#define DEF_USBD_ENDP6_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
#define DEF_USBD_ENDP7_SIZE DEF_USBD_FS_PACK_SIZE
|
||||
|
||||
/******************************************************************************/
|
||||
/* usb device Descriptor length, length of usb descriptors, if one descriptor not
|
||||
* exists , set the length to 0 */
|
||||
#define DEF_USBD_DEVICE_DESC_LEN ((uint8_t)MyDevDescr[0])
|
||||
#define DEF_USBD_CONFIG_DESC_LEN ((uint16_t)MyCfgDescr[2] + (uint16_t)(MyCfgDescr[3] << 8))
|
||||
#define DEF_USBD_REPORT_DESC_LEN 0
|
||||
#define DEF_USBD_LANG_DESC_LEN ((uint16_t)MyLangDescr[0])
|
||||
#define DEF_USBD_MANU_DESC_LEN ((uint16_t)MyManuInfo[0])
|
||||
#define DEF_USBD_PROD_DESC_LEN ((uint16_t)MyProdInfo[0])
|
||||
#define DEF_USBD_SN_DESC_LEN ((uint16_t)MySerNumInfo[0])
|
||||
|
||||
/******************************************************************************/
|
||||
/* external variables */
|
||||
extern const uint8_t MyDevDescr[ ];
|
||||
extern const uint8_t MyCfgDescr[ ];
|
||||
extern const uint8_t MyLangDescr[ ];
|
||||
extern const uint8_t MyManuInfo[ ];
|
||||
extern const uint8_t MyProdInfo[ ];
|
||||
extern const uint8_t MySerNumInfo[ ];
|
||||
|
||||
#endif /* USER_USB_DESC_H_ */
|
||||
@@ -12,10 +12,12 @@
|
||||
|
||||
/******************************************************************************/
|
||||
/* Header file contains */
|
||||
#include "debug.h"
|
||||
#include "CONFIG.h"
|
||||
#include "HAL.h"
|
||||
#include "test_dtm.h"
|
||||
#include "uart.h"
|
||||
#include "ch32v20x_usbfs_device.h"
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL TYPEDEFS
|
||||
@@ -54,13 +56,19 @@ int main(void)
|
||||
{
|
||||
SystemCoreClockUpdate();
|
||||
Delay_Init();
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG // 默认Uart1打印 Uart2 Test
|
||||
USART_Printf_Init( 115200 );
|
||||
#endif
|
||||
PRINT("%s\n", VER_LIB);
|
||||
WCHBLE_Init();
|
||||
HAL_Init();
|
||||
uart_task_init();
|
||||
#if USB_UartEnable == 1 // 默认使能USB模拟串口
|
||||
/* Usb Init */
|
||||
USBFS_RCC_Init();
|
||||
USBFS_Device_Init( ENABLE );
|
||||
USB_Task_Init();
|
||||
#endif
|
||||
test_dtm_init();
|
||||
GAPRole_BroadcasterInit();
|
||||
Main_Circulation();
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "uart.h"
|
||||
#include "config.h"
|
||||
#include "test_dtm.h"
|
||||
#include "uart.h"
|
||||
|
||||
tmosTaskID test_taskid = INVALID_TASK_ID;
|
||||
|
||||
@@ -37,10 +37,23 @@ static void test_dtm_process_msg(tmos_event_hdr_t *pMsg) {
|
||||
if(evt)
|
||||
uart_send(evt);
|
||||
|
||||
uart_start_receiving();
|
||||
uart_start_receiving();
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_PROCESS_EVT:{
|
||||
struct simple_buf *evt = NULL;
|
||||
struct usb_process_msg *msg = \
|
||||
(struct usb_process_msg *)pMsg;
|
||||
|
||||
evt = hci_cmd_handle((struct simple_buf*)msg->data);
|
||||
|
||||
if(evt)
|
||||
usb_send(evt);
|
||||
|
||||
usb_start_receiving();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -10,74 +10,56 @@
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include "uart.h"
|
||||
#include "config.h"
|
||||
#include "atomic.h"
|
||||
#include "test_dtm.h"
|
||||
#include "ch32v20x_usbfs_device.h"
|
||||
|
||||
static tmosTaskID uart_taskid;
|
||||
static tmosTaskID usb_taskid;
|
||||
|
||||
__attribute__ ((aligned(4))) uint8_t UART2_Tx_Buf[ DEF_UARTx_TX_BUF_LEN ]; /* Serial port 2 transmit data buffer */
|
||||
__attribute__ ((aligned(4))) uint8_t UART2_Rx_Buf[ DEF_UARTx_RX_BUF_LEN ]; /* Serial port 2 receive data buffer */
|
||||
|
||||
static uint8_t rx_buf[100];
|
||||
static struct simple_buf *uart_buf = NULL;
|
||||
struct simple_buf *usb_buf = NULL;
|
||||
static struct simple_buf uart_buffer;
|
||||
|
||||
enum uart_status {
|
||||
UART_STATUS_IDLE,
|
||||
UART_STATUS_RCVING,
|
||||
UART_STATUS_RCV_END,
|
||||
UART_STATUS_SENDING,
|
||||
|
||||
UART_STATUS_NUM,
|
||||
};
|
||||
static uint8_t rx_ubuf[100];
|
||||
static struct simple_buf usb_buffer;
|
||||
|
||||
atomic_t uart_flag;
|
||||
atomic_t usb_flag;
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart_buffer_create
|
||||
*
|
||||
* @brief Create a file called uart_buffer simple buffer of the buffer
|
||||
* and assign its address to the variable pointed to by the buffer pointer.
|
||||
*
|
||||
* @param buf - a parameter buf pointing to a pointer.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void uart_buffer_create(struct simple_buf **buf)
|
||||
{
|
||||
*buf = simple_buf_create(&uart_buffer, rx_buf, sizeof(rx_buf));
|
||||
}
|
||||
|
||||
int uart_start_receiving(void)
|
||||
/*********************************************************************
|
||||
* @fn usb_buffer_create
|
||||
*
|
||||
* @brief Create a file called usb_buffer simple buffer of the buffer
|
||||
* and assign its address to the variable pointed to by the buffer pointer.
|
||||
*
|
||||
* @param buf - a parameter buf pointing to a pointer.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void usb_buffer_create(struct simple_buf **buf)
|
||||
{
|
||||
PRINT("uart2 reeciving\n");
|
||||
atomic_set(&uart_flag, UART_STATUS_RCVING);
|
||||
uart_buffer_create(&uart_buf);
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uart2_send_data(uint8_t *data, uint16_t len)
|
||||
{
|
||||
for(int i = 0; i < len; i++) {
|
||||
USART_SendData(USART2, data[i]);
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET) {
|
||||
/* waiting for sending finish */
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int uart_send(struct simple_buf *buf)
|
||||
{
|
||||
atomic_set(&uart_flag, UART_STATUS_SENDING);
|
||||
|
||||
uint8_t *send_data;
|
||||
uint16_t send_len;
|
||||
|
||||
send_len = buf->len;
|
||||
send_data = simple_buf_pull(buf, buf->len);
|
||||
uart2_send_data(send_data, send_len);
|
||||
atomic_set(&uart_flag, UART_STATUS_IDLE);
|
||||
|
||||
PRINT("uart2 send %d bytes [", send_len);
|
||||
for(int i = 0; i < send_len; i++){
|
||||
if(i) PRINT(" ");
|
||||
PRINT("%#x", send_data[i]);
|
||||
}
|
||||
PRINT("]\n");
|
||||
|
||||
return 0;
|
||||
*buf = simple_buf_create(&usb_buffer, rx_ubuf, sizeof(rx_ubuf));
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
@@ -108,7 +90,7 @@ tmosEvents uart_processevent(tmosTaskID task_id, tmosEvents events)
|
||||
|
||||
if(events & UART_RECEIVE_POLL_EVT) {
|
||||
if(atomic_get(&uart_flag) == UART_STATUS_RCV_END) {
|
||||
PRINT("uart2 recevied %d bytes [", uart_buf->len);
|
||||
PRINT("uart recevied %d bytes [", uart_buf->len);
|
||||
for(int i = 0; i < uart_buf->len; i++) {
|
||||
if(i) PRINT(" ");
|
||||
PRINT("%#x", uart_buf->data[i]);
|
||||
@@ -130,11 +112,119 @@ tmosEvents uart_processevent(tmosTaskID task_id, tmosEvents events)
|
||||
|
||||
return (events ^ UART_RECEIVE_POLL_EVT);
|
||||
}
|
||||
if(events & USB_RECEIVE_POLL_EVT)
|
||||
{
|
||||
if(atomic_get(&usb_flag) == USB_STATUS_RCV_END)
|
||||
{
|
||||
PRINT("usb recevied %d bytes [", usb_buf->len);
|
||||
for(int i = 0; i < usb_buf->len; i++)
|
||||
{
|
||||
if(i)
|
||||
PRINT(" ");
|
||||
PRINT("%#x", usb_buf->data[i]);
|
||||
}
|
||||
PRINT("]\n");
|
||||
|
||||
struct usb_process_msg *usb_msg;
|
||||
|
||||
usb_msg = (struct usb_process_msg *) \
|
||||
tmos_msg_allocate(sizeof(struct usb_process_msg));
|
||||
|
||||
if(usb_msg)
|
||||
{
|
||||
usb_msg->hdr.event = USB_PROCESS_EVT;
|
||||
usb_msg->hdr.status = true;
|
||||
usb_msg->data = (uint8_t *)usb_buf;
|
||||
tmos_msg_send(test_taskid, (uint8_t *)usb_msg );
|
||||
}
|
||||
}
|
||||
|
||||
return (events ^ USB_RECEIVE_POLL_EVT);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if(DEBUG == DEBUG_UART1)
|
||||
/*********************************************************************
|
||||
* @fn uart_start_receiving
|
||||
*
|
||||
* @brief Serial port starts receiving.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int uart_start_receiving(void)
|
||||
{
|
||||
PRINT("uart2 receiving\n");
|
||||
atomic_set(&uart_flag, UART_STATUS_RCVING);
|
||||
uart_buffer_create(&uart_buf);
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart2_send_data
|
||||
*
|
||||
* @brief Serial port 2 sends data.
|
||||
*
|
||||
* @param data - Data to be sent.
|
||||
* len - The length of data.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void uart2_send_data(uint8_t *data, uint16_t len)
|
||||
{
|
||||
for(int i = 0; i < len; i++) {
|
||||
USART_SendData(USART2, data[i]);
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET) {
|
||||
/* waiting for sending finish */
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart_send
|
||||
*
|
||||
* @brief Serial port starts Sending.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int uart_send(struct simple_buf *buf)
|
||||
{
|
||||
atomic_set(&uart_flag, UART_STATUS_SENDING);
|
||||
|
||||
uint8_t *send_data;
|
||||
uint16_t send_len;
|
||||
|
||||
send_len = buf->len;
|
||||
send_data = simple_buf_pull(buf, buf->len);
|
||||
uart2_send_data(send_data, send_len);
|
||||
atomic_set(&uart_flag, UART_STATUS_IDLE);
|
||||
|
||||
PRINT("uart2 send %d bytes [", send_len);
|
||||
for(int i = 0; i < send_len; i++){
|
||||
if(i) PRINT(" ");
|
||||
PRINT("%#x", send_data[i]);
|
||||
}
|
||||
PRINT("]\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart_task_init
|
||||
*
|
||||
* @brief Serial port initialization and task initialization.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void uart_task_init(void)
|
||||
{
|
||||
uart_taskid = TMOS_ProcessEventRegister(uart_processevent);
|
||||
@@ -172,12 +262,210 @@ void uart_task_init(void)
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
tmos_start_reload_task(uart_taskid, UART_RECEIVE_POLL_EVT,
|
||||
tmos_start_reload_task(uart_taskid, UART_RECEIVE_POLL_EVT,
|
||||
MS1_TO_SYSTEM_TIME(100));
|
||||
|
||||
atomic_set(&uart_flag, UART_STATUS_IDLE);
|
||||
uart_start_receiving();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if(DEBUG == DEBUG_UART2)
|
||||
/*********************************************************************
|
||||
* @fn uart_start_receiving
|
||||
*
|
||||
* @brief Serial port starts receiving.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int uart_start_receiving(void)
|
||||
{
|
||||
PRINT("uart1 receiving\n");
|
||||
atomic_set(&uart_flag, UART_STATUS_RCVING);
|
||||
uart_buffer_create(&uart_buf);
|
||||
USART_Cmd(USART1, ENABLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart1_send_data
|
||||
*
|
||||
* @brief Serial port 1 sends data.
|
||||
*
|
||||
* @param data - Data to be sent.
|
||||
* len - The length of data.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void uart1_send_data(uint8_t *data, uint16_t len)
|
||||
{
|
||||
for(int i = 0; i < len; i++) {
|
||||
USART_SendData(USART1, data[i]);
|
||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) {
|
||||
/* waiting for sending finish */
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart_send
|
||||
*
|
||||
* @brief Serial port starts Sending.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int uart_send(struct simple_buf *buf)
|
||||
{
|
||||
atomic_set(&uart_flag, UART_STATUS_SENDING);
|
||||
|
||||
uint8_t *send_data;
|
||||
uint16_t send_len;
|
||||
|
||||
send_len = buf->len;
|
||||
send_data = simple_buf_pull(buf, buf->len);
|
||||
uart1_send_data(send_data, send_len);
|
||||
atomic_set(&uart_flag, UART_STATUS_IDLE);
|
||||
|
||||
PRINT("uart1 send %d bytes [", send_len);
|
||||
for(int i = 0; i < send_len; i++){
|
||||
if(i) PRINT(" ");
|
||||
PRINT("%#x", send_data[i]);
|
||||
}
|
||||
PRINT("]\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn uart_task_init
|
||||
*
|
||||
* @brief Serial port initialization and task initialization.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void uart_task_init(void)
|
||||
{
|
||||
uart_taskid = TMOS_ProcessEventRegister(uart_processevent);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
/* USART1 TX-->A.9 RX-->A.10 */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = 115200;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
|
||||
USART_Init(USART1, &USART_InitStructure);
|
||||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
tmos_start_reload_task(uart_taskid, UART_RECEIVE_POLL_EVT,
|
||||
MS1_TO_SYSTEM_TIME(100));
|
||||
|
||||
atomic_set(&uart_flag, UART_STATUS_IDLE);
|
||||
uart_start_receiving();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USB_Task_Init
|
||||
*
|
||||
* @brief USB initialization and task initialization.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void USB_Task_Init(void)
|
||||
{
|
||||
usb_taskid = TMOS_ProcessEventRegister(uart_processevent);
|
||||
|
||||
tmos_start_reload_task(usb_taskid, USB_RECEIVE_POLL_EVT,
|
||||
MS1_TO_SYSTEM_TIME(100));
|
||||
|
||||
atomic_set(&usb_flag, USB_STATUS_IDLE);
|
||||
usb_start_receiving();
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn usb_start_receiving
|
||||
*
|
||||
* @brief Usb starts receiving.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int usb_start_receiving(void)
|
||||
{
|
||||
PRINT("usb receiving\n");
|
||||
atomic_set(&usb_flag, USB_STATUS_RCVING);
|
||||
usb_buffer_create(&usb_buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn usb_send
|
||||
*
|
||||
* @brief Usb starts Sending.
|
||||
*
|
||||
* @param buf - defined simple_buf structural object.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
int usb_send(struct simple_buf *buf)
|
||||
{
|
||||
atomic_set(&usb_flag, USB_STATUS_SENDING);
|
||||
|
||||
uint8_t *send_data;
|
||||
uint16_t send_len;
|
||||
|
||||
send_len = buf->len;
|
||||
send_data = simple_buf_pull(buf, buf->len);
|
||||
|
||||
USBSendData(send_data, send_len); //ÐÞ¸ÄΪUSBSend
|
||||
atomic_set(&usb_flag, UART_STATUS_IDLE);
|
||||
|
||||
PRINT("usb send %d bytes [", send_len);
|
||||
for(int i = 0; i < send_len; i++)
|
||||
{
|
||||
if(i) PRINT(" ");
|
||||
PRINT("%#x", send_data[i]);
|
||||
}
|
||||
PRINT("]\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART2_IRQHandler
|
||||
@@ -203,3 +491,26 @@ void USART2_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART1_IRQHandler
|
||||
*
|
||||
* @brief This function handles USART1 global interrupt request.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
__attribute__((interrupt("WCH-Interrupt-fast")))
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
|
||||
{
|
||||
simple_buf_add_u8(uart_buf, USART_ReceiveData(USART1));
|
||||
}
|
||||
|
||||
if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)
|
||||
{
|
||||
atomic_set(&uart_flag, UART_STATUS_RCV_END);
|
||||
|
||||
/* clear IDLE flag */
|
||||
(void)USART_ReceiveData(USART1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : usb_desc.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2022/08/20
|
||||
* Description : usb device descriptor,configuration descriptor,
|
||||
* string descriptors and other descriptors.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "usb_desc.h"
|
||||
|
||||
/* Device Descriptor */
|
||||
const uint8_t MyDevDescr[] =
|
||||
{
|
||||
0x12, // bLength
|
||||
0x01, // bDescriptorType (Device)
|
||||
0x10, 0x01, // bcdUSB 1.10
|
||||
0x02, // bDeviceClass
|
||||
0x00, // bDeviceSubClass
|
||||
0x00, // bDeviceProtocol
|
||||
DEF_USBD_UEP0_SIZE, // bMaxPacketSize0 64
|
||||
(uint8_t)DEF_USB_VID, (uint8_t)(DEF_USB_VID >> 8), // idVendor 0x1A86
|
||||
(uint8_t)DEF_USB_PID, (uint8_t)(DEF_USB_PID >> 8), // idProduct 0x5537
|
||||
DEF_IC_PRG_VER, 0x00, // bcdDevice 0.01
|
||||
0x01, // iManufacturer (String Index)
|
||||
0x02, // iProduct (String Index)
|
||||
0x00, // iSerialNumber (String Index)
|
||||
0x01, // bNumConfigurations 1
|
||||
};
|
||||
|
||||
/* Configuration Descriptor */
|
||||
const uint8_t MyCfgDescr[] =
|
||||
{
|
||||
/* Configure descriptor */
|
||||
0x09, 0x02, 0x43, 0x00, 0x02, 0x01, 0x00, 0x80, 0x32,
|
||||
|
||||
/* Interface 0 (CDC) descriptor */
|
||||
0x09, 0x04, 0x00, 0x00, 0x01, 0x02, 0x02, 0x01, 0x00,
|
||||
|
||||
/* Functional Descriptors */
|
||||
0x05, 0x24, 0x00, 0x10, 0x01,
|
||||
|
||||
/* Length/management descriptor (data class interface 1) */
|
||||
0x05, 0x24, 0x01, 0x00, 0x01,
|
||||
0x04, 0x24, 0x02, 0x02,
|
||||
0x05, 0x24, 0x06, 0x00, 0x01,
|
||||
|
||||
/* Interrupt upload endpoint descriptor */
|
||||
0x07, 0x05, 0x81, 0x03, (uint8_t)DEF_USBD_ENDP1_SIZE, (uint8_t)( DEF_USBD_ENDP1_SIZE >> 8 ), 0x01,
|
||||
|
||||
/* Interface 1 (data interface) descriptor */
|
||||
0x09, 0x04, 0x01, 0x00, 0x02, 0x0A, 0x00, 0x00, 0x00,
|
||||
|
||||
/* Endpoint descriptor */
|
||||
0x07, 0x05, 0x02, 0x02, (uint8_t)DEF_USBD_ENDP2_SIZE, (uint8_t)( DEF_USBD_ENDP2_SIZE >> 8 ), 0x00,
|
||||
|
||||
/* Endpoint descriptor */
|
||||
0x07, 0x05, 0x83, 0x02, (uint8_t)DEF_USBD_ENDP3_SIZE, (uint8_t)( DEF_USBD_ENDP3_SIZE >> 8 ), 0x00,
|
||||
};
|
||||
|
||||
/* Language Descriptor */
|
||||
const uint8_t MyLangDescr[] =
|
||||
{
|
||||
0x04, 0x03, 0x09, 0x04
|
||||
};
|
||||
|
||||
/* Manufacturer Descriptor */
|
||||
const uint8_t MyManuInfo[] =
|
||||
{
|
||||
0x0E, 0x03, 'w', 0, 'c', 0, 'h', 0, '.', 0, 'c', 0, 'n', 0
|
||||
};
|
||||
|
||||
/* Product Information */
|
||||
const uint8_t MyProdInfo[] =
|
||||
{
|
||||
0x16, 0x03, 'U', 0x00, 'S', 0x00, 'B', 0x00, ' ', 0x00, 'S', 0x00, 'e', 0x00,
|
||||
'r', 0x00, 'i', 0x00, 'a', 0x00, 'l', 0x00
|
||||
};
|
||||
|
||||
/* Serial Number Information */
|
||||
const uint8_t MySerNumInfo[] =
|
||||
{
|
||||
0x16, 0x03, '0', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0
|
||||
, '6', 0, '7', 0, '8', 0, '9', 0
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ void HAL_TimeInit(void)
|
||||
{
|
||||
uint16_t temp=0;
|
||||
uint8_t state=0;
|
||||
bleClockConfig_t conf;
|
||||
bleClockConfig_t conf={0};
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_BKP, ENABLE);
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
Binary file not shown.
+11836
-11812
File diff suppressed because it is too large
Load Diff
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -159,5 +159,5 @@
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
|
||||
</cproject>
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
@@ -205,6 +205,7 @@ void SystemCoreClockUpdate (void)
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
//GPIO_IPD_Unused();
|
||||
#ifdef SYSCLK_FREQ_HSE
|
||||
SetSysClockToHSE();
|
||||
#elif defined SYSCLK_FREQ_48MHz_HSE
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user