diff --git a/F1:F103/BISS_C_encoders/TODO b/F1:F103/BISS_C_encoders/TODO new file mode 100644 index 0000000..6fbf0ad --- /dev/null +++ b/F1:F103/BISS_C_encoders/TODO @@ -0,0 +1 @@ +fix error in USB_send (RB_write returns 0 in case of overflow!) diff --git a/F3:F303/InterfaceBoard/Makefile b/F3:F303/InterfaceBoard/Makefile index aa55d66..6659b99 100644 --- a/F3:F303/InterfaceBoard/Makefile +++ b/F3:F303/InterfaceBoard/Makefile @@ -2,7 +2,7 @@ BINARY := multiiface # MCU code MCU := F303xc # change this linking script depending on particular MCU model, -LDSCRIPT := stm32f303xC.ld +LDSCRIPT := stm32f303xB.ld DEFINES := -DUSB1_16 include ../makefile.f3 diff --git a/F3:F303/InterfaceBoard/main.c b/F3:F303/InterfaceBoard/main.c index 5810040..7f1ed6b 100644 --- a/F3:F303/InterfaceBoard/main.c +++ b/F3:F303/InterfaceBoard/main.c @@ -42,20 +42,26 @@ int main(void){ USB_setup(); //uint32_t ctr = Tms; USBPU_ON(); + int maxno = (Config_mode) ? ICFG : InterfacesAmount; while(1){ // Put here code working WITOUT USB connected if(!usbON) continue; - for(int i = 0; i < 6; ++i){ // just echo for first time + for(int i = 0; i < maxno; ++i){ // just echo for first time + if(!CDCready[i]) continue; int l = USB_receive(i, (uint8_t*)inbuff, MAXSTRLEN); if(l) USB_send(i, (uint8_t*)inbuff, l); } // and here is code what should run when USB connected - if(Config_mode){ + if(Config_mode && CDCready[ICFG]){ + /*if(Tms - ctr > 999){ + ctr = Tms; + CFGWR("I'm alive\n"); + }*/ int l = USB_receivestr(ICFG, inbuff, MAXSTRLEN); if(l < 0) CFGWR("ERROR: USB buffer overflow or string was too long\n"); else if(l){ const char *ans = parse_cmd(inbuff); - if(ans) CFGWR(ans); + if(ans) CFGWRn(ans); } } } diff --git a/F3:F303/InterfaceBoard/multiiface.bin b/F3:F303/InterfaceBoard/multiiface.bin index 80ef1e4..2972aef 100755 Binary files a/F3:F303/InterfaceBoard/multiiface.bin and b/F3:F303/InterfaceBoard/multiiface.bin differ diff --git a/F3:F303/InterfaceBoard/multiiface.config b/F3:F303/InterfaceBoard/multiiface.config index 1cf1964..1aff3d9 100644 --- a/F3:F303/InterfaceBoard/multiiface.config +++ b/F3:F303/InterfaceBoard/multiiface.config @@ -5,3 +5,4 @@ #define STM32F303xb #define __thumb2__ 1 #define __ARM_ARCH_7M__ +#define USB1_16 diff --git a/F3:F303/InterfaceBoard/multiiface.creator.user b/F3:F303/InterfaceBoard/multiiface.creator.user index 393c9cc..f8feebc 100644 --- a/F3:F303/InterfaceBoard/multiiface.creator.user +++ b/F3:F303/InterfaceBoard/multiiface.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/F3:F303/InterfaceBoard/usb_descr.h b/F3:F303/InterfaceBoard/usb_descr.h index 2390859..90bc928 100644 --- a/F3:F303/InterfaceBoard/usb_descr.h +++ b/F3:F303/InterfaceBoard/usb_descr.h @@ -57,15 +57,17 @@ // buffer sizes // for USB FS EP0 buffers are from 8 to 64 bytes long -#define USB_EP0BUFSZ 64 +#define USB_EP0BUFSZ 16 // virtual #define USB_EP1BUFSZ 10 // Rx/Tx EPs (USB_BTABLE_SIZE-64-2*USB_EP0BUFSZ)/(2*InterfacesAmount) rounded to 8 -// 534 / 112 -> 4 -#define _RTBUFSZ8 (((USB_BTABLE_SIZE) - 64 - (2 * (USB_EP0BUFSZ)))/(16 * (InterfacesAmount))) +// ([btable size] - [registers] - [EP0 buffers])/([interfaces buffers (Rx/Tx)])/8 (for rounding by 8 later) +#define _RTBUFSZ8 (((USB_BTABLE_SIZE)/(ACCESSZ) - (LASTADDR_DEFAULT) - (2 * (USB_EP0BUFSZ)))/(16 * (InterfacesAmount))) // 32 bytes; so we have free 86 bytes which can't be used #define USB_RXBUFSZ (8 * (_RTBUFSZ8)) #define USB_TXBUFSZ (8 * (_RTBUFSZ8)) +//#define USB_RXBUFSZ 8 +//#define USB_TXBUFSZ 8 // string descriptors enum{ diff --git a/F3:F303/InterfaceBoard/usb_dev.c b/F3:F303/InterfaceBoard/usb_dev.c index 81fa994..0c90964 100644 --- a/F3:F303/InterfaceBoard/usb_dev.c +++ b/F3:F303/InterfaceBoard/usb_dev.c @@ -95,21 +95,21 @@ static void send_next(uint8_t ifno){ // data IN/OUT handler static void rxtx_handler(){ - uint8_t ifno = (USB->ISTR & USB_ISTR_EPID) - 1; + uint8_t epno = (USB->ISTR & USB_ISTR_EPID), ifno = epno - 1; if(ifno > InterfacesAmount-1){ return; } - uint16_t epstatus = KEEP_DTOG(USB->EPnR[1+ifno]); + uint16_t epstatus = KEEP_DTOG(USB->EPnR[epno]); if(RX_FLAG(epstatus)){ // receive data if(rcvbuflen[ifno]){ bufovrfl[ifno] = 1; // lost last data rcvbuflen[ifno] = 0; } - rcvbuflen[ifno] = EP_Read(1+ifno, (uint8_t*)rcvbuf[ifno]); - USB->EPnR[1+ifno] = epstatus & ~(USB_EPnR_CTR_RX | USB_EPnR_STAT_RX | USB_EPnR_STAT_TX); // keep RX in STALL state until read data + rcvbuflen[ifno] = EP_Read(epno, (uint8_t*)rcvbuf[ifno]); + USB->EPnR[epno] = epstatus & ~(USB_EPnR_CTR_RX | USB_EPnR_STAT_RX | USB_EPnR_STAT_TX); // keep RX in STALL state until read data chkin(ifno); // try to write current data into RXbuf if it's not busy }else{ // tx successfull - USB->EPnR[1+ifno] = (epstatus & ~(USB_EPnR_CTR_TX | USB_EPnR_STAT_TX)) ^ USB_EPnR_STAT_RX; + USB->EPnR[epno] = (epstatus & ~(USB_EPnR_CTR_TX | USB_EPnR_STAT_TX)) ^ USB_EPnR_STAT_RX; send_next(ifno); } } @@ -200,7 +200,7 @@ int USB_sendall(uint8_t ifno){ uint32_t T0 = Tms; while(lastdsz[ifno] > 0){ if(Tms - T0 > DISCONN_TMOUT){ - break_handler(ifno); + //break_handler(ifno); return FALSE; } if(!CDCready[ifno]) return FALSE; @@ -215,12 +215,20 @@ int USB_send(uint8_t ifno, const uint8_t *buf, int len){ uint32_t T0 = Tms; while(len){ if(Tms - T0 > DISCONN_TMOUT){ - break_handler(ifno); + //break_handler(ifno); return FALSE; } if(!CDCready[ifno]) return FALSE; IWDG->KR = IWDG_REFRESH; - int a = RB_write((ringbuffer*)&rbout[ifno], buf, len); + int l = RB_datalen((ringbuffer*)&rbout[ifno]); + if(l < 0) continue; + int portion = rbout[ifno].length - 1 - l; + if(portion < 1){ + if(lastdsz[ifno] < 0) send_next(ifno); + continue; + } + if(portion > len) portion = len; + int a = RB_write((ringbuffer*)&rbout[ifno], buf, portion); if(a > 0){ len -= a; buf += a; @@ -238,7 +246,7 @@ int USB_putbyte(uint8_t ifno, uint8_t byte){ uint32_t T0 = Tms; while((l = RB_write((ringbuffer*)&rbout[ifno], &byte, 1)) != 1){ if(Tms - T0 > DISCONN_TMOUT){ - break_handler(ifno); + //break_handler(ifno); return FALSE; } if(!CDCready[ifno]) return FALSE; diff --git a/F3:F303/InterfaceBoard/usb_dev.h b/F3:F303/InterfaceBoard/usb_dev.h index 07b1efb..0f9c458 100644 --- a/F3:F303/InterfaceBoard/usb_dev.h +++ b/F3:F303/InterfaceBoard/usb_dev.h @@ -41,8 +41,8 @@ void break_handler(uint8_t ifno); void clstate_handler(uint8_t ifno, uint16_t val); void linecoding_handler(uint8_t ifno, usb_LineCoding *lc); -// as ugly CDC have no BREAK after disconnected client in non-canonical mode, we should use timeout - more than 2ms -#define DISCONN_TMOUT (2) +// as ugly CDC have no BREAK after disconnected client in non-canonical mode, we should use timeout - near 2s +#define DISCONN_TMOUT (2000) // sizes of ringbuffers for outgoing and incoming data #define RBOUTSZ (256) diff --git a/F3:F303/InterfaceBoard/usb_lib.c b/F3:F303/InterfaceBoard/usb_lib.c index f5dbd5f..3fb650b 100644 --- a/F3:F303/InterfaceBoard/usb_lib.c +++ b/F3:F303/InterfaceBoard/usb_lib.c @@ -80,7 +80,7 @@ void WEAK usb_standard_request(){ } break; case REQ_RECIPIENT_ENDPOINT: - if(setup_packet->bRequest == CLEAR_FEATURE){ + if(setup_packet->bRequest == CLEAR_FEATURE){ /* what to do here? */ }else{ /* wrong */ } break; default: @@ -138,7 +138,7 @@ static void EP0_Handler(){ case REQ_TYPE_STANDARD: if(SETUP_FLAG(epstatus)){ usb_standard_request(); - }else{ } + }else{ /* ??? */ } break; case REQ_TYPE_CLASS: usb_class_request(setup_packet, ep0databuf, ep0dbuflen); diff --git a/F3:F303/InterfaceBoard/usb_lib.h b/F3:F303/InterfaceBoard/usb_lib.h index d55c83f..9b1004f 100644 --- a/F3:F303/InterfaceBoard/usb_lib.h +++ b/F3:F303/InterfaceBoard/usb_lib.h @@ -63,7 +63,7 @@ #if defined STM32F0 #define USB_BTABLE_SIZE 1024 #elif defined STM32F3 -#define USB_BTABLE_SIZE 726 +#define USB_BTABLE_SIZE 1024 //#warning "Please, check real buffer size due to docs" #else #error "define STM32F0 or STM32F3" @@ -72,7 +72,8 @@ #if defined STM32F0 #define USB_BTABLE_SIZE 768 #elif defined STM32F3 -#define USB_BTABLE_SIZE 726 +// 1024 bytes for USB and 256 from them are for CAN (on lower F303 with half-addr ACCESSZ=2 !!!) +#define USB_BTABLE_SIZE 768 //#warning "Please, check real buffer size due to docs" #else // STM32F103: 1024 bytes but with 32-bit addressing #define USB_BTABLE_SIZE 1024 diff --git a/F3:F303/InterfaceBoard/version.inc b/F3:F303/InterfaceBoard/version.inc index c0afe52..39367ae 100644 --- a/F3:F303/InterfaceBoard/version.inc +++ b/F3:F303/InterfaceBoard/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "20" -#define BUILD_DATE "2026-02-11" +#define BUILD_NUMBER "41" +#define BUILD_DATE "2026-02-12" diff --git a/F3:F303/inc/ld/stm32f303xC.ld b/F3:F303/inc/ld/stm32f303xC.ld new file mode 100644 index 0000000..f294f8a --- /dev/null +++ b/F3:F303/inc/ld/stm32f303xC.ld @@ -0,0 +1,11 @@ +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 256K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 40K + ccmram (rwx) : ORIGIN = 0x10000000, LENGTH = 8K +} + +PROVIDE(_BLOCKSIZE = 2048); + +/* Include the common ld script. */ +INCLUDE stm32f3.ld