diff --git a/ch32v/ch32v003fun b/ch32v/ch32v003fun index 627ddd3..119924c 160000 --- a/ch32v/ch32v003fun +++ b/ch32v/ch32v003fun @@ -1 +1 @@ -Subproject commit 627ddd3a6b1beed8902f06078ee5e8f834e7b7a9 +Subproject commit 119924c0d9ee02b8c069254d37d2a89921820689 diff --git a/ch32v/ch32v203-adcrx/adcrx.c b/ch32v/ch32v203-adcrx/adcrx.c index 16ef816..e2230eb 100644 --- a/ch32v/ch32v203-adcrx/adcrx.c +++ b/ch32v/ch32v203-adcrx/adcrx.c @@ -81,6 +81,7 @@ volatile uint16_t adc_buffer[ADC_BUFFSIZE]; void SetupADC() { // XXX TODO -look into PGA + // XXX TODO - look into BUFEN and TKITUNE // XXX TODO - Look into tag-teaming the ADCs // PDA is analog input chl 7 diff --git a/ch32v/ch32v203-goertzel/adcgoertzel.c b/ch32v/ch32v203-goertzel/adcgoertzel.c index ec1575e..6f252a1 100644 --- a/ch32v/ch32v203-goertzel/adcgoertzel.c +++ b/ch32v/ch32v203-goertzel/adcgoertzel.c @@ -193,7 +193,10 @@ void SetupADC() while(ADC1->CTLR2 & ADC_CAL); // ADC_SCAN: Allow scanning. - ADC1->CTLR1 = ADC_Pga_64 | ADC_SCAN; + ADC1->CTLR1 = + //ADC_SCAN; + ADC_Pga_16 | ADC_SCAN; + //ADC_Pga_64 | ADC_SCAN; // Turn on DMA diff --git a/ch32v/ch32v203-goertzel/ttest/demo_run.ods b/ch32v/ch32v203-goertzel/ttest/demo_run.ods index d998af2..38834bf 100644 Binary files a/ch32v/ch32v203-goertzel/ttest/demo_run.ods and b/ch32v/ch32v203-goertzel/ttest/demo_run.ods differ diff --git a/ch32v/ch32v203tx/Makefile b/ch32v/ch32v203tx/Makefile new file mode 100644 index 0000000..201a38b --- /dev/null +++ b/ch32v/ch32v203tx/Makefile @@ -0,0 +1,13 @@ +all : flash + +TARGET:=ch32v203tx +TARGET_MCU:=CH32V203 +CH32V003FUN:=../ch32v003fun/ch32v003fun + +EXTRA_CFLAGS:=-Wno-unused-function -I../../lib + +include $(CH32V003FUN)/ch32v003fun.mk + +flash : cv_flash +clean : cv_clean + diff --git a/ch32v/ch32v203tx/ch32v203tx.c b/ch32v/ch32v203tx/ch32v203tx.c new file mode 100644 index 0000000..b04f542 --- /dev/null +++ b/ch32v/ch32v203tx/ch32v203tx.c @@ -0,0 +1,93 @@ +/** + +MIT-like-non-ai-license + +Copyright (c) 2024 Charles Lohr "CNLohr" + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the two following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +In addition the following restrictions apply: + +1. The Software and any modifications made to it may not be used for the +purpose of training or improving machine learning algorithms, including but not +limited to artificial intelligence, natural language processing, or data +mining. This condition applies to any derivatives, modifications, or updates +based on the Software code. Any usage of the Software in an AI-training dataset +is considered a breach of this License. + +2. The Software may not be included in any dataset used for training or +improving machine learning algorithms, including but not limited to artificial +intelligence, natural language processing, or data mining. + + +3. Any person or organization found to be in violation of these restrictions +will be subject to legal action and may be held liable for any damages +resulting from such use. + +If any term is unenforcable, other terms remain in-force. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +**/ + +#include "ch32v003fun.h" +#include + +#define LEDPIN PD6 + +int main() +{ + SystemInit(); + + Delay_Ms( 100 ); + + + funGpioInitAll(); + RCC->APB1PCENR |= RCC_APB1Periph_TIM2; + // PD4 = T2C1 on 003, PA0 on the 203. + funPinMode( PA0, GPIO_CFGLR_OUT_50Mhz_AF_PP ); + funPinMode( PA1, GPIO_CFGLR_OUT_50Mhz_AF_PP ); + funPinMode( LEDPIN, GPIO_CFGLR_OUT_50Mhz_PP ); + + // Reset TIM2 to init all regs + RCC->APB1PRSTR |= RCC_APB1Periph_TIM2; + RCC->APB1PRSTR &= ~RCC_APB1Periph_TIM2; + + TIM2->PSC = 0x0000; // Prescalar + TIM2->ATRLR = 4; // Max + TIM2->CHCTLR1 = TIM_OC1M_2 | TIM_OC1M_1 | TIM_OC1PE | TIM_OC1FE; + TIM2->CTLR1 = TIM_ARPE; + TIM2->CCER = TIM_CC1E | TIM_CC1P | TIM_CC1NE; + TIM2->SWEVGR = TIM_UG; + + // Enable TIM2 + TIM2->CTLR1 |= TIM_CEN; + TIM2->CH1CVR = TIM2->ATRLR/2+1; + + printf( "Setup\n" ); + while(1) + { + TIM2->CH1CVR = 2; + TIM2->CCER = TIM_CC1E | TIM_CC1P; + funDigitalWrite( LEDPIN, 1 ); + Delay_Us( 2000 ); + TIM2->CCER = TIM_CC1E; + TIM2->CH1CVR = 2; + funDigitalWrite( LEDPIN, 0 ); + Delay_Us( 2000 ); + } +} diff --git a/ch32v/ch32v203tx/funconfig.h b/ch32v/ch32v203tx/funconfig.h new file mode 100644 index 0000000..046451f --- /dev/null +++ b/ch32v/ch32v203tx/funconfig.h @@ -0,0 +1,9 @@ +#ifndef _FUNCONFIG_H +#define _FUNCONFIG_H + +#define FUNCONF_USE_DEBUGPRINTF 1 +#define FUNCONF_USE_UARTPRINTF 0 +#define FUNCONF_USE_HSE 1 + +#endif +