mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 10:45:11 +03:00
All OK, now I need to make proper protocol
This commit is contained in:
parent
7fa84cb0ef
commit
72ef5c9cc6
@ -53,6 +53,7 @@ int main(void){
|
|||||||
if(Tms - ctr > 499){
|
if(Tms - ctr > 499){
|
||||||
ctr = Tms;
|
ctr = Tms;
|
||||||
pin_toggle(GPIOB, 1 << 1 | 1 << 0); // toggle LED @ PB0
|
pin_toggle(GPIOB, 1 << 1 | 1 << 0); // toggle LED @ PB0
|
||||||
|
USB_sendstr(CMD_IDX, "1");
|
||||||
//DBGmesg(u2str(Tms));
|
//DBGmesg(u2str(Tms));
|
||||||
//DBGnl();
|
//DBGnl();
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@ -87,7 +87,7 @@ void usart_config(uint8_t ifNo, usb_LineCoding *lc){
|
|||||||
|
|
||||||
void usart1_exti25_isr(){
|
void usart1_exti25_isr(){
|
||||||
if(USART1->ISR & USART_ISR_RXNE){ // RX not emty - receive next char
|
if(USART1->ISR & USART_ISR_RXNE){ // RX not emty - receive next char
|
||||||
DBG("got\n");
|
//DBG("got\n");
|
||||||
// read RDR clears flag
|
// read RDR clears flag
|
||||||
uint8_t rb = USART1->RDR;
|
uint8_t rb = USART1->RDR;
|
||||||
USB_putbyte(USART1_IDX, rb);
|
USB_putbyte(USART1_IDX, rb);
|
||||||
@ -96,7 +96,7 @@ void usart1_exti25_isr(){
|
|||||||
|
|
||||||
void usart2_exti26_isr(){
|
void usart2_exti26_isr(){
|
||||||
if(USART2->ISR & USART_ISR_RXNE){
|
if(USART2->ISR & USART_ISR_RXNE){
|
||||||
DBG("got\n");
|
//DBG("got\n");
|
||||||
uint8_t rb = USART2->RDR;
|
uint8_t rb = USART2->RDR;
|
||||||
USB_putbyte(USART2_IDX, rb);
|
USB_putbyte(USART2_IDX, rb);
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ void usart2_exti26_isr(){
|
|||||||
|
|
||||||
void usart3_exti28_isr(){
|
void usart3_exti28_isr(){
|
||||||
if(USART3->ISR & USART_ISR_RXNE){
|
if(USART3->ISR & USART_ISR_RXNE){
|
||||||
DBG("got\n");
|
//DBG("got\n");
|
||||||
uint8_t rb = USART3->RDR;
|
uint8_t rb = USART3->RDR;
|
||||||
USB_putbyte(USART3_IDX, rb);
|
USB_putbyte(USART3_IDX, rb);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,24 +22,24 @@
|
|||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "usb_lib.h"
|
#include "usb_lib.h"
|
||||||
|
|
||||||
static volatile uint8_t usbbuff[USB_TRBUFSZ]; // temporary buffer for sending data
|
static volatile uint8_t usbbuff[USB_TXBUFSZ]; // temporary buffer for sending data
|
||||||
// ring buffers for incoming and outgoing data
|
// ring buffers for incoming and outgoing data
|
||||||
static uint8_t obuf[WORK_EPs][RBOUTSZ], ibuf[WORK_EPs][RBINSZ];
|
static uint8_t obuf[MAX_IDX][RBOUTSZ], ibuf[MAX_IDX][RBINSZ];
|
||||||
#define OBUF(N) {.data = obuf[N], .length = RBOUTSZ, .head = 0, .tail = 0}
|
#define OBUF(N) {.data = obuf[N], .length = RBOUTSZ, .head = 0, .tail = 0}
|
||||||
volatile ringbuffer rbout[WORK_EPs] = {OBUF(0), OBUF(1), OBUF(2), OBUF(3), OBUF(4), OBUF(5), OBUF(6)};
|
volatile ringbuffer rbout[MAX_IDX] = {OBUF(0), OBUF(1), OBUF(2), OBUF(3), OBUF(4), OBUF(5), OBUF(6)};
|
||||||
#define IBUF(N) {.data = ibuf[N], .length = RBINSZ, .head = 0, .tail = 0}
|
#define IBUF(N) {.data = ibuf[N], .length = RBINSZ, .head = 0, .tail = 0}
|
||||||
volatile ringbuffer rbin[WORK_EPs] = {IBUF(0), IBUF(1), IBUF(2), IBUF(3), IBUF(4), IBUF(5), IBUF(6)};
|
volatile ringbuffer rbin[MAX_IDX] = {IBUF(0), IBUF(1), IBUF(2), IBUF(3), IBUF(4), IBUF(5), IBUF(6)};
|
||||||
// transmission is succesfull
|
// transmission is succesfull
|
||||||
volatile uint8_t bufisempty[WORK_EPs] = {1,1,1,1,1,1,1};
|
volatile uint8_t bufisempty[MAX_IDX] = {1,1,1,1,1,1,1};
|
||||||
volatile uint8_t bufovrfl[WORK_EPs] = {0};
|
volatile uint8_t bufovrfl[MAX_IDX] = {0};
|
||||||
|
|
||||||
// here and later: ifNo is index of buffers, i.e. ifNo = epno-1 !!!
|
// here and later: ifNo is index of buffers, i.e. ifNo = epno-1 !!!
|
||||||
void send_next(int ifNo){
|
void send_next(int ifNo){
|
||||||
if(bufisempty[ifNo]) return;
|
if(bufisempty[ifNo]) return;
|
||||||
static uint8_t lastdsz[WORK_EPs] = {0};
|
static uint8_t lastdsz[MAX_EPNO] = {0};
|
||||||
int buflen = RB_read((ringbuffer*)&rbout[ifNo], (uint8_t*)usbbuff, USB_TRBUFSZ);
|
int buflen = RB_read((ringbuffer*)&rbout[ifNo], (uint8_t*)usbbuff, USB_TXBUFSZ);
|
||||||
if(!buflen){
|
if(!buflen){
|
||||||
if(lastdsz[ifNo] == USB_TRBUFSZ) EP_Write(ifNo+1, NULL, 0); // send ZLP after 64 bits packet when nothing more to send
|
if(lastdsz[ifNo] == USB_TXBUFSZ) EP_Write(ifNo+1, NULL, 0); // send ZLP after 64 bits packet when nothing more to send
|
||||||
lastdsz[ifNo] = 0;
|
lastdsz[ifNo] = 0;
|
||||||
bufisempty[ifNo] = 1;
|
bufisempty[ifNo] = 1;
|
||||||
return;
|
return;
|
||||||
@ -104,13 +104,12 @@ int USB_sendstr(int ifNo, const char *string){
|
|||||||
* @return amount of received bytes (negative, if overfull happened)
|
* @return amount of received bytes (negative, if overfull happened)
|
||||||
*/
|
*/
|
||||||
int USB_receive(int ifNo, uint8_t *buf, int len){
|
int USB_receive(int ifNo, uint8_t *buf, int len){
|
||||||
int sz = RB_read((ringbuffer*)&rbin[ifNo], buf, len);
|
|
||||||
if(bufovrfl[ifNo]){
|
if(bufovrfl[ifNo]){
|
||||||
RB_clearbuf((ringbuffer*)&rbin[ifNo]);
|
RB_clearbuf((ringbuffer*)&rbin[ifNo]);
|
||||||
if(!sz) sz = -1;
|
|
||||||
else sz = -sz;
|
|
||||||
bufovrfl[ifNo] = 0;
|
bufovrfl[ifNo] = 0;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
int sz = RB_read((ringbuffer*)&rbin[ifNo], buf, len);
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,14 +120,13 @@ int USB_receive(int ifNo, uint8_t *buf, int len){
|
|||||||
* @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared)
|
* @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared)
|
||||||
*/
|
*/
|
||||||
int USB_receivestr(int ifNo, char *buf, int len){
|
int USB_receivestr(int ifNo, char *buf, int len){
|
||||||
int l = RB_readto((ringbuffer*)&rbin[ifNo], '\n', (uint8_t*)buf, len);
|
|
||||||
if(l == 0) return 0;
|
|
||||||
if(--l < 0 || bufovrfl[ifNo]) RB_clearbuf((ringbuffer*)&rbin[ifNo]);
|
|
||||||
else buf[l] = 0; // replace '\n' with strend
|
|
||||||
if(bufovrfl[ifNo]){
|
if(bufovrfl[ifNo]){
|
||||||
if(l > 0) l = -l;
|
RB_clearbuf((ringbuffer*)&rbin[ifNo]);
|
||||||
else l = -1;
|
|
||||||
bufovrfl[ifNo] = 0;
|
bufovrfl[ifNo] = 0;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
int l = RB_readto((ringbuffer*)&rbin[ifNo], '\n', (uint8_t*)buf, len);
|
||||||
|
if(l < 1) return 0;
|
||||||
|
buf[--l] = 0; // replace '\n' with strend
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,8 +31,6 @@
|
|||||||
#define STR_HELPER(s) #s
|
#define STR_HELPER(s) #s
|
||||||
#define STR(s) STR_HELPER(s)
|
#define STR(s) STR_HELPER(s)
|
||||||
|
|
||||||
// total amount of working EPs
|
|
||||||
#define WORK_EPs 7
|
|
||||||
// functional EPs
|
// functional EPs
|
||||||
#define CMD_EPNO 1
|
#define CMD_EPNO 1
|
||||||
#define DBG_EPNO 2
|
#define DBG_EPNO 2
|
||||||
@ -41,6 +39,7 @@
|
|||||||
#define USART3_EPNO 5
|
#define USART3_EPNO 5
|
||||||
#define USART4_EPNO 6
|
#define USART4_EPNO 6
|
||||||
#define CAN_EPNO 7
|
#define CAN_EPNO 7
|
||||||
|
// total amount of working EPs
|
||||||
#define MAX_EPNO 7
|
#define MAX_EPNO 7
|
||||||
|
|
||||||
#define USARTMAX_EPNO USART3_EPNO
|
#define USARTMAX_EPNO USART3_EPNO
|
||||||
@ -52,7 +51,7 @@
|
|||||||
#define USART2_IDX (USART2_EPNO-1)
|
#define USART2_IDX (USART2_EPNO-1)
|
||||||
#define USART3_IDX (USART3_EPNO-1)
|
#define USART3_IDX (USART3_EPNO-1)
|
||||||
#define USART4_IDX (USART4_EPNO-1)
|
#define USART4_IDX (USART4_EPNO-1)
|
||||||
#define MAX_IDX 7
|
#define MAX_IDX (MAX_EPNO)
|
||||||
|
|
||||||
extern volatile ringbuffer rbout[], rbin[];
|
extern volatile ringbuffer rbout[], rbin[];
|
||||||
extern volatile uint8_t bufisempty[], bufovrfl[];
|
extern volatile uint8_t bufisempty[], bufovrfl[];
|
||||||
|
|||||||
@ -153,16 +153,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
0x81, /* bEndpointAddress IN1 */
|
0x81, /* bEndpointAddress IN1 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor*/
|
/*Endpoint OUT Descriptor*/
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
0x01, /* bEndpointAddress OUT1 */
|
0x01, /* bEndpointAddress OUT1 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -234,16 +234,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x82, /* bEndpointAddress IN2 */
|
/**/0x82, /* bEndpointAddress IN2 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor */
|
/*Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x02, /* bEndpointAddress OUT2 */
|
/**/0x02, /* bEndpointAddress OUT2 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -315,16 +315,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x83, /* bEndpointAddress IN3 */
|
/**/0x83, /* bEndpointAddress IN3 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor */
|
/*Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x03, /* bEndpointAddress OUT3 */
|
/**/0x03, /* bEndpointAddress OUT3 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -396,16 +396,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x84, /* bEndpointAddress IN4 */
|
/**/0x84, /* bEndpointAddress IN4 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor */
|
/*Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x04, /* bEndpointAddress OUT4 */
|
/**/0x04, /* bEndpointAddress OUT4 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -477,16 +477,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x85, /* bEndpointAddress IN5 */
|
/**/0x85, /* bEndpointAddress IN5 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor */
|
/*Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x05, /* bEndpointAddress OUT5 */
|
/**/0x05, /* bEndpointAddress OUT5 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -558,16 +558,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x86, /* bEndpointAddress IN6 */
|
/**/0x86, /* bEndpointAddress IN6 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor */
|
/*Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x06, /* bEndpointAddress OUT6 */
|
/**/0x06, /* bEndpointAddress OUT6 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -639,16 +639,16 @@ static const uint8_t USB_ConfigDescriptor[] = {
|
|||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x87, /* bEndpointAddress IN7 */
|
/**/0x87, /* bEndpointAddress IN7 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_TXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint OUT Descriptor */
|
/*Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
0x05, /* bDescriptorType: Endpoint */
|
0x05, /* bDescriptorType: Endpoint */
|
||||||
/**/0x07, /* bEndpointAddress OUT7 */
|
/**/0x07, /* bEndpointAddress OUT7 */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
(USB_TRBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
(USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */
|
||||||
(USB_TRBUFSZ >> 8),
|
(USB_RXBUFSZ >> 8),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
};
|
};
|
||||||
@ -749,18 +749,18 @@ static inline void std_d2h_req(){
|
|||||||
|
|
||||||
// Rx and Tx handlers for EP1..EP7
|
// Rx and Tx handlers for EP1..EP7
|
||||||
static void rxtx_Handler(uint8_t epno){
|
static void rxtx_Handler(uint8_t epno){
|
||||||
uint8_t buf[USB_TRBUFSZ];
|
uint8_t buf[USB_RXBUFSZ];
|
||||||
int idx = epno - 1;
|
int idx = epno - 1;
|
||||||
uint16_t epstatus = KEEP_DTOG(USB->EPnR[epno]);
|
uint16_t epstatus = KEEP_DTOG(USB->EPnR[epno]);
|
||||||
//uint16_t epstatus = USB->EPnR[epno];
|
|
||||||
if(RX_FLAG(epstatus)){
|
if(RX_FLAG(epstatus)){
|
||||||
epstatus = (epstatus & ~(USB_EPnR_STAT_TX|USB_EPnR_CTR_RX)) ^ USB_EPnR_STAT_RX; // keep stat Tx & set valid RX, clear CTR Rx
|
epstatus = (epstatus & ~(USB_EPnR_STAT_TX|USB_EPnR_CTR_RX)) ^ USB_EPnR_STAT_RX; // keep stat Tx & set valid RX, clear CTR Rx
|
||||||
USB->EPnR[epno] = epstatus;
|
USB->EPnR[epno] = epstatus;
|
||||||
//USB->EPnR[epno] = (KEEP_DTOG(epstatus) & ~USB_EPnR_CTR_RX) ^ USB_EPnR_STAT_RX;
|
|
||||||
uint8_t sz = EP_Read(epno, (uint8_t*)buf);
|
uint8_t sz = EP_Read(epno, (uint8_t*)buf);
|
||||||
|
/*
|
||||||
DBG("epno");
|
DBG("epno");
|
||||||
DBGmesg(u2str(epno)); DBGmesg(" ("); DBGmesg(u2str(sz));
|
DBGmesg(u2str(epno)); DBGmesg(" ("); DBGmesg(u2str(sz));
|
||||||
DBGmesg(") > "); hexdump(DBG_IDX, buf, sz); DBGnl();
|
DBGmesg(") > "); hexdump(DBG_IDX, buf, sz); DBGnl();
|
||||||
|
*/
|
||||||
if(sz){
|
if(sz){
|
||||||
switch(epno){
|
switch(epno){
|
||||||
case USART1_EPNO:
|
case USART1_EPNO:
|
||||||
@ -779,14 +779,10 @@ static void rxtx_Handler(uint8_t epno){
|
|||||||
if(RB_write((ringbuffer*)&rbin[idx], buf, sz) != sz) bufovrfl[idx] = 1;
|
if(RB_write((ringbuffer*)&rbin[idx], buf, sz) != sz) bufovrfl[idx] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*if(epno != DBG_EPNO){
|
|
||||||
MSG();
|
|
||||||
}*/
|
|
||||||
// set ACK Rx
|
// set ACK Rx
|
||||||
USB->EPnR[epno] = (KEEP_DTOG(USB->EPnR[epno]) & ~(USB_EPnR_STAT_TX)) ^ USB_EPnR_STAT_RX;
|
USB->EPnR[epno] = (KEEP_DTOG(USB->EPnR[epno]) & ~(USB_EPnR_STAT_TX)) ^ USB_EPnR_STAT_RX;
|
||||||
}else{
|
}else{
|
||||||
USB->EPnR[epno] = (epstatus & ~(USB_EPnR_STAT_TX|USB_EPnR_CTR_TX)) ^ USB_EPnR_STAT_RX; // clear TX ctr
|
USB->EPnR[epno] = (epstatus & ~(USB_EPnR_STAT_TX|USB_EPnR_CTR_TX)) ^ USB_EPnR_STAT_RX; // clear TX ctr
|
||||||
//USB->EPnR[epno] = (KEEP_DTOG_STAT(epstatus) & ~(USB_EPnR_CTR_TX)); // clear TX ctr
|
|
||||||
send_next(idx);
|
send_next(idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -800,8 +796,8 @@ static inline void std_h2d_req(){
|
|||||||
case SET_CONFIGURATION:
|
case SET_CONFIGURATION:
|
||||||
// Now device configured
|
// Now device configured
|
||||||
configuration = setup_packet->wValue;
|
configuration = setup_packet->wValue;
|
||||||
for(uint8_t i = 1; i <= WORK_EPs; ++i){
|
for(uint8_t i = 1; i <= MAX_EPNO; ++i){
|
||||||
EP_Init(i, EP_TYPE_BULK, USB_TRBUFSZ, USB_TRBUFSZ, rxtx_Handler);
|
EP_Init(i, EP_TYPE_BULK, USB_TXBUFSZ, USB_RXBUFSZ, rxtx_Handler);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -30,9 +30,10 @@
|
|||||||
//#define USB_EP0_BASEADDR 64
|
//#define USB_EP0_BASEADDR 64
|
||||||
// for USB FS EP0 buffers are from 8 to 64 bytes long
|
// for USB FS EP0 buffers are from 8 to 64 bytes long
|
||||||
// For STM32F303CBT6 ACCESSZ=2, so real available buffers size for all EPs = only 192 bytes (128 - EP0)
|
// For STM32F303CBT6 ACCESSZ=2, so real available buffers size for all EPs = only 192 bytes (128 - EP0)
|
||||||
#define USB_EP0_BUFSZ 64
|
#define USB_EP0_BUFSZ 16
|
||||||
// USB transmit/receive buffer size
|
// USB transmit/receive buffer size; RXBUFSZ>=8 !!!
|
||||||
#define USB_TRBUFSZ 4
|
#define USB_RXBUFSZ 14
|
||||||
|
#define USB_TXBUFSZ 8
|
||||||
// EP1 - interrupt - buffer size
|
// EP1 - interrupt - buffer size
|
||||||
#define USB_EP1BUFSZ 8
|
#define USB_EP1BUFSZ 8
|
||||||
|
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
#define BUILD_NUMBER "102"
|
#define BUILD_NUMBER "122"
|
||||||
#define BUILD_DATE "2023-04-29"
|
#define BUILD_DATE "2023-04-29"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user