diff --git a/F3:F303/NitrogenFlooding/adc.c b/F3:F303/NitrogenFlooding/adc.c index 9247386..1f84b63 100644 --- a/F3:F303/NitrogenFlooding/adc.c +++ b/F3:F303/NitrogenFlooding/adc.c @@ -114,7 +114,7 @@ uint16_t getADCval(int nch){ int addr = nch, adval = NUMBER_OF_ADC1_CHANNELS; if(nch >= NUMBER_OF_ADC1_CHANNELS){ adval = NUMBER_OF_ADC2_CHANNELS; - addr += ADC2START; + addr += ADC2START - NUMBER_OF_ADC1_CHANNELS; } for(int i = 0; i < 9; ++i, addr += adval) // first we should prepare array for optmed p[i] = ADC_array[addr]; diff --git a/F3:F303/NitrogenFlooding/hardware.c b/F3:F303/NitrogenFlooding/hardware.c index 8bf160c..f644ce2 100644 --- a/F3:F303/NitrogenFlooding/hardware.c +++ b/F3:F303/NitrogenFlooding/hardware.c @@ -73,8 +73,8 @@ TRUE_INLINE void gpio_setup(){ // PORT E //GPIOE->ODR = 0; - GPIOE->AFR[0] = 0; - GPIOE->AFR[1] = AFRf(2, 2) | AFRf(2, 3) | AFRf(2, 4) | AFRf(2, 5); + GPIOE->AFR[0] = AFRf(2, 2) | AFRf(2, 3) | AFRf(2, 4) | AFRf(2, 5); + GPIOE->AFR[1] = 0; GPIOE->MODER = MODER_AF(2) | MODER_AF(3) | MODER_AF(4) | MODER_AF(5) | MODER_O(8) | MODER_O(9) | MODER_O(10) | MODER_O(11); GPIOE->OSPEEDR = 0; GPIOE->OTYPER = 0; @@ -92,12 +92,15 @@ TRUE_INLINE void gpio_setup(){ TRUE_INLINE void pwm_setup(){ TIM3->CR1 = TIM_CR1_ARPE; - TIM3->PSC = 1999; // 48M/2000 = 24kHz + TIM3->PSC = 7199; // 72M/7200 = 10kHz; PWMfreq=10k/100=100Hz // PWM mode 1 (active -> inactive) TIM3->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1; TIM3->CCMR2 = TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1; TIM3->CCR1 = 0; - TIM3->ARR = 255; // 8bit PWM + TIM3->CCR2 = 0; + TIM3->CCR3 = 0; + TIM3->CCR4 = 0; + TIM3->ARR = PWM_CCR_MAX-1; // 8bit PWM TIM3->BDTR |= TIM_BDTR_MOE; // enable main output TIM3->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E; TIM3->CR1 |= TIM_CR1_CEN; @@ -138,7 +141,7 @@ void hw_setup(){ #endif } -void setPWM(int nch, uint8_t val){ +void setPWM(int nch, uint16_t val){ switch(nch){ case 0: TIM3->CCR1 = val; diff --git a/F3:F303/NitrogenFlooding/hardware.h b/F3:F303/NitrogenFlooding/hardware.h index 53792e9..986a517 100644 --- a/F3:F303/NitrogenFlooding/hardware.h +++ b/F3:F303/NitrogenFlooding/hardware.h @@ -26,6 +26,9 @@ #define PCLK (72000000) #endif +// Max PWM CCR1 value (->1) +#define PWM_CCR_MAX (100) + // USB pullup: PC9 #define USBPU_port GPIOC #define USBPU_pin (1<<9) @@ -77,5 +80,5 @@ extern int LEDsON; uint8_t MSB(uint16_t val); void hw_setup(); -void setPWM(int nch, uint8_t val); +void setPWM(int nch, uint16_t val); uint8_t getPWM(int nch); diff --git a/F3:F303/NitrogenFlooding/nitrogen.bin b/F3:F303/NitrogenFlooding/nitrogen.bin index 05e6931..26b440d 100755 Binary files a/F3:F303/NitrogenFlooding/nitrogen.bin and b/F3:F303/NitrogenFlooding/nitrogen.bin differ diff --git a/F3:F303/NitrogenFlooding/openocd.cfg b/F3:F303/NitrogenFlooding/openocd.cfg index 0210594..ad3c59d 100644 --- a/F3:F303/NitrogenFlooding/openocd.cfg +++ b/F3:F303/NitrogenFlooding/openocd.cfg @@ -1,4 +1,4 @@ set FLASH_SIZE 0x20000 -source [find interface/stlink-v2-1.cfg] +source [find interface/stlink.cfg] source [find target/stm32f3x.cfg] diff --git a/F3:F303/NitrogenFlooding/proto.c b/F3:F303/NitrogenFlooding/proto.c index 5f702f5..e9c86e9 100644 --- a/F3:F303/NitrogenFlooding/proto.c +++ b/F3:F303/NitrogenFlooding/proto.c @@ -29,7 +29,11 @@ static uint8_t I2Caddress = 0; // parno - number of parameter (or -1); cargs - string with arguments (after '=') (==NULL for getter), iarg - integer argument -static int goodstub(const char _U_ *cmd, int _U_ parno, const char _U_ *carg, int32_t _U_ iarg){ +static int goodstub(const char *cmd, int parno, const char *carg, int32_t iarg){ + USB_sendstr("cmd="); USB_sendstr(cmd); + USB_sendstr(", parno="); USB_sendstr(i2str(parno)); + USB_sendstr(", args="); USB_sendstr(carg); + USB_sendstr(", intarg="); USB_sendstr(i2str(iarg)); newline(); return RET_GOOD; } @@ -130,8 +134,11 @@ static int tms(const char _U_ *cmd, int _U_ parno, const char _U_ *c, int32_t _U static int pwm(const char *cmd, int parno, const char *c, int32_t i){ if(parno < 0 || parno > 3) return RET_WRONGPARNO; - if(c) setPWM(parno, (uint8_t)i); - sendkeyu(cmd, -1, getPWM(parno)); + if(c){ + if(i < 0 || i > PWM_CCR_MAX) return RET_WRONGARG; + setPWM(parno, (uint16_t)i); + } + sendkeyu(cmd, parno, getPWM(parno)); return RET_GOOD; } @@ -146,7 +153,7 @@ commands cmdlist[] = { {NULL, "Different commands", NULL}, {buzzer, "buzzer", "get/set (0 - off, 1 - on) buzzer"}, {leds, "LED", "LEDx=y; where x=0..3 to work with single LED (then y=1-set, 0-reset, 2-toggle), absent to work with all (y=0 - disable, 1-enable)"}, - {pwm, "pwm", "set/get x channel (0..3) pwm value (0..255)"}, + {pwm, "pwm", "set/get x channel (0..3) pwm value (0..100)"}, {reset, "reset", "reset MCU"}, {tms, "tms", "print Tms"}, {NULL, "I2C commands", NULL}, diff --git a/F3:F303/NitrogenFlooding/usbhw.c b/F3:F303/NitrogenFlooding/usbhw.c index 8d2a880..f98d0ef 100644 --- a/F3:F303/NitrogenFlooding/usbhw.c +++ b/F3:F303/NitrogenFlooding/usbhw.c @@ -50,10 +50,10 @@ static uint16_t lastaddr = LASTADDR_DEFAULT; int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ if(number >= STM32ENDPOINTS) return 4; // out of configured amount if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large - if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE) return 2; // out of btable + if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; - if(rxsz & 1 || rxsz > 512) return 3; // wrong rx buffer size + if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size uint16_t countrx = 0; if(rxsz < 64) countrx = rxsz / 2; else{ diff --git a/F3:F303/NitrogenFlooding/version.inc b/F3:F303/NitrogenFlooding/version.inc index 379d92d..1d5ece6 100644 --- a/F3:F303/NitrogenFlooding/version.inc +++ b/F3:F303/NitrogenFlooding/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "52" -#define BUILD_DATE "2023-04-10" +#define BUILD_NUMBER "56" +#define BUILD_DATE "2023-05-03"