mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-01 04:45:09 +03:00
some fixes, now speed is big enough
This commit is contained in:
parent
ea05df117b
commit
fd05ff73e6
@ -38,6 +38,7 @@ int main(void){
|
||||
SysTick_Config(72000);
|
||||
#ifdef EBUG
|
||||
usart_setup();
|
||||
DBG("Start");
|
||||
uint32_t tt = 0;
|
||||
#endif
|
||||
USB_setup();
|
||||
|
||||
Binary file not shown.
@ -198,8 +198,14 @@ void get_descriptor(config_pack_t *pack){
|
||||
break;
|
||||
case STRING_DESCRIPTOR:
|
||||
DBG("STRING_DESCRIPTOR");
|
||||
if(descridx < iDESCR_AMOUNT) wr0((const uint8_t *)StringDescriptor[descridx], *((uint8_t*)StringDescriptor[descridx]), pack->wLength);
|
||||
else EP_WriteIRQ(0, NULL, 0);
|
||||
if(descridx < iDESCR_AMOUNT){
|
||||
wr0((const uint8_t *)StringDescriptor[descridx], *((uint8_t*)StringDescriptor[descridx]), pack->wLength);
|
||||
DBGs(StringDescriptor[descridx]);
|
||||
}else{
|
||||
EP_WriteIRQ(0, NULL, 0);
|
||||
DBG("Wrong index");
|
||||
DBGs(uhex2str(descridx));
|
||||
}
|
||||
break;
|
||||
case DEVICE_QUALIFIER_DESCRIPTOR:
|
||||
DBG("DEVICE_QUALIFIER_DESCRIPTOR");
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
#include "usb_lib.h"
|
||||
|
||||
// definition of parts common for USB_DeviceDescriptor & USB_DeviceQualifierDescriptor
|
||||
// bcdUSB: 2.00
|
||||
#define bcdUSB 0x0200
|
||||
// bcdUSB: 1.10
|
||||
#define bcdUSB 0x0110
|
||||
// Class - Misc (EF), subclass - common (2), protocol - interface association descr (1)
|
||||
#define bDeviceSubClass 0x02
|
||||
#define bDeviceProtocol 0x01
|
||||
|
||||
@ -101,6 +101,7 @@ static void rxtx_handler(){
|
||||
}
|
||||
rcvbuflen = EP_Read(1, (uint8_t*)rcvbuf);
|
||||
USB->EPnR[1] = epstatus & ~(USB_EPnR_CTR_RX | USB_EPnR_STAT_RX | USB_EPnR_STAT_TX); // keep RX in STALL state until read data
|
||||
chkin(); // try to write current data into RXbuf if it's not busy
|
||||
}else{ // tx successfull
|
||||
DBG("Tx OK");
|
||||
USB->EPnR[1] = (epstatus & ~(USB_EPnR_CTR_TX | USB_EPnR_STAT_TX)) ^ USB_EPnR_STAT_RX;
|
||||
@ -124,6 +125,7 @@ void WEAK clstate_handler(uint16_t val){
|
||||
|
||||
// SEND_BREAK
|
||||
void WEAK break_handler(){
|
||||
CDCready = 0;
|
||||
DBG("break_handler()");
|
||||
}
|
||||
|
||||
@ -159,7 +161,6 @@ void usb_class_request(config_pack_t *req, uint8_t *data, uint16_t datalen){
|
||||
break;
|
||||
case SEND_BREAK:
|
||||
DBG("SEND_BREAK");
|
||||
CDCready = 0;
|
||||
break_handler();
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -21,12 +21,12 @@
|
||||
#include "usb_descr.h"
|
||||
#include "usb_dev.h"
|
||||
|
||||
/*
|
||||
|
||||
#undef DBG
|
||||
#define DBG(x)
|
||||
#undef DBGs
|
||||
#define DBGs(x)
|
||||
*/
|
||||
|
||||
|
||||
static ep_t endpoints[STM32ENDPOINTS];
|
||||
|
||||
@ -54,6 +54,7 @@ static inline void std_d2h_req(){
|
||||
default:
|
||||
DBG("Wrong");
|
||||
DBGs(uhex2str(setup_packet->bRequest));
|
||||
EP_WriteIRQ(0, NULL, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -90,19 +91,17 @@ void WEAK usb_standard_request(){
|
||||
std_d2h_req();
|
||||
}else{
|
||||
std_h2d_req();
|
||||
//EP_WriteIRQ(0, NULL, 0);
|
||||
}
|
||||
break;
|
||||
case REQ_RECIPIENT_INTERFACE:
|
||||
DBG("REQ_RECIPIENT_INTERFACE");
|
||||
if(dev2host && setup_packet->bRequest == GET_DESCRIPTOR){
|
||||
get_descriptor(setup_packet);
|
||||
}//else EP_WriteIRQ(0, NULL, 0);
|
||||
}
|
||||
break;
|
||||
case REQ_RECIPIENT_ENDPOINT:
|
||||
DBG("REQ_RECIPIENT_ENDPOINT");
|
||||
if(setup_packet->bRequest == CLEAR_FEATURE){
|
||||
//EP_WriteIRQ(0, NULL, 0);
|
||||
}else{
|
||||
DBG("Wrong");
|
||||
}
|
||||
|
||||
@ -17,9 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "hardware.h"
|
||||
#ifdef EBUG
|
||||
#include "usart.h"
|
||||
#endif
|
||||
#include "usb_dev.h"
|
||||
|
||||
volatile uint32_t Tms = 0;
|
||||
@ -33,7 +31,7 @@ void sys_tick_handler(void){
|
||||
|
||||
int main(void){
|
||||
char inbuff[RBINSZ];
|
||||
uint32_t lastT = 0;
|
||||
uint32_t lastT = 0, lastS = 0;
|
||||
StartHSE();
|
||||
hw_setup();
|
||||
USBPU_OFF();
|
||||
@ -61,6 +59,16 @@ int main(void){
|
||||
__enable_irq();
|
||||
}
|
||||
#endif
|
||||
if(Tms - lastS > 9999){
|
||||
int n = 0;
|
||||
USND(uhex2str(Tms));
|
||||
do{
|
||||
if(USB_send((uint8_t*)"112345678921234567893123456789412345678951234567896123456789712345678981234567899123456789a123456789\n", 101)) ++n;
|
||||
}while(n < 40 && CDCready);
|
||||
while(CDCready && !USB_sendstr(uhex2str(Tms)));
|
||||
newline();
|
||||
lastS = Tms;
|
||||
}
|
||||
int l = USB_receivestr(inbuff, RBINSZ);
|
||||
if(l < 0) USB_sendstr("ERROR: USB buffer overflow or string was too long\n");
|
||||
else if(l){
|
||||
|
||||
Binary file not shown.
@ -47,7 +47,7 @@ static uint8_t volatile rcvbuflen = 0;
|
||||
// line coding
|
||||
usb_LineCoding WEAK lineCoding = {115200, 0, 0, 8};
|
||||
// CDC configured and ready to use
|
||||
static volatile uint8_t CDCready = 0;
|
||||
volatile uint8_t CDCready = 0;
|
||||
|
||||
// ring buffers for incoming and outgoing data
|
||||
static uint8_t obuf[RBOUTSZ], ibuf[RBINSZ];
|
||||
@ -87,8 +87,6 @@ static void send_next(){
|
||||
return;
|
||||
}else if(buflen < 0){
|
||||
lastdsz = 0;
|
||||
// Uncomment next line if you want 4Mbit/s instead of 6Mbit/s
|
||||
//EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now
|
||||
return;
|
||||
}
|
||||
EP_Write(3, (uint8_t*)usbbuff, buflen);
|
||||
@ -111,6 +109,7 @@ static void receive_Handler(){ // EP2OUT
|
||||
rcvbuflen = 0;
|
||||
}
|
||||
rcvbuflen = EP_Read(2, (uint8_t*)rcvbuf);
|
||||
chkin();
|
||||
USB->EPnR[2] = status & ~USB_EPnR_CTR_RX;
|
||||
}
|
||||
|
||||
@ -119,16 +118,19 @@ static void receive_Handler(){ // EP2OUT
|
||||
void WEAK linecoding_handler(usb_LineCoding *lc){
|
||||
lineCoding = *lc;
|
||||
DBG("linecoding_handler");
|
||||
CDCready = 1;
|
||||
}
|
||||
|
||||
// SET_CONTROL_LINE_STATE
|
||||
void WEAK clstate_handler(uint16_t _U_ val){
|
||||
void WEAK clstate_handler(uint16_t val){
|
||||
DBG("clstate_handler");
|
||||
CDCready = val;
|
||||
}
|
||||
|
||||
// SEND_BREAK
|
||||
void WEAK break_handler(){
|
||||
DBG("break_handler()");
|
||||
CDCready = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -155,7 +157,6 @@ void usb_class_request(config_pack_t *req, uint8_t *data, uint16_t datalen){
|
||||
if(!data || !datalen) break; // wait for data
|
||||
if(datalen == sizeof(usb_LineCoding))
|
||||
linecoding_handler((usb_LineCoding*)data);
|
||||
CDCready = 1;
|
||||
break;
|
||||
case 0x33: // -//-
|
||||
case GET_LINE_CODING:
|
||||
@ -164,12 +165,10 @@ void usb_class_request(config_pack_t *req, uint8_t *data, uint16_t datalen){
|
||||
break;
|
||||
case SET_CONTROL_LINE_STATE:
|
||||
DBG("SET_CONTROL_LINE_STATE");
|
||||
CDCready = 1;
|
||||
clstate_handler(req->wValue);
|
||||
break;
|
||||
case SEND_BREAK:
|
||||
DBG("SEND_BREAK");
|
||||
CDCready = 0;
|
||||
break_handler();
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -34,6 +34,7 @@ typedef struct {
|
||||
} __attribute__ ((packed)) usb_LineCoding;
|
||||
|
||||
extern usb_LineCoding lineCoding;
|
||||
extern volatile uint8_t CDCready;
|
||||
|
||||
void break_handler();
|
||||
void clstate_handler(uint16_t val);
|
||||
@ -41,8 +42,8 @@ void linecoding_handler(usb_LineCoding *lc);
|
||||
|
||||
|
||||
// sizes of ringbuffers for outgoing and incoming data
|
||||
#define RBOUTSZ (256)
|
||||
#define RBINSZ (256)
|
||||
#define RBOUTSZ (1024)
|
||||
#define RBINSZ (1024)
|
||||
|
||||
#define newline() USB_putbyte('\n')
|
||||
#define USND(s) do{USB_sendstr(s); USB_putbyte('\n');}while(0)
|
||||
|
||||
@ -21,12 +21,12 @@
|
||||
#include "usb_descr.h"
|
||||
#include "usb_dev.h"
|
||||
|
||||
/*
|
||||
|
||||
#undef DBG
|
||||
#define DBG(x)
|
||||
#undef DBGs
|
||||
#define DBGs(x)
|
||||
*/
|
||||
|
||||
|
||||
static ep_t endpoints[STM32ENDPOINTS];
|
||||
|
||||
@ -54,6 +54,7 @@ static inline void std_d2h_req(){
|
||||
default:
|
||||
DBG("Wrong");
|
||||
DBGs(uhex2str(setup_packet->bRequest));
|
||||
EP_WriteIRQ(0, NULL, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -90,19 +91,17 @@ void WEAK usb_standard_request(){
|
||||
std_d2h_req();
|
||||
}else{
|
||||
std_h2d_req();
|
||||
//EP_WriteIRQ(0, NULL, 0);
|
||||
}
|
||||
break;
|
||||
case REQ_RECIPIENT_INTERFACE:
|
||||
DBG("REQ_RECIPIENT_INTERFACE");
|
||||
if(dev2host && setup_packet->bRequest == GET_DESCRIPTOR){
|
||||
get_descriptor(setup_packet);
|
||||
}//else EP_WriteIRQ(0, NULL, 0);
|
||||
}
|
||||
break;
|
||||
case REQ_RECIPIENT_ENDPOINT:
|
||||
DBG("REQ_RECIPIENT_ENDPOINT");
|
||||
if(setup_packet->bRequest == CLEAR_FEATURE){
|
||||
//EP_WriteIRQ(0, NULL, 0);
|
||||
}else{
|
||||
DBG("Wrong");
|
||||
}
|
||||
@ -159,11 +158,11 @@ static void EP0_Handler(){
|
||||
// check direction
|
||||
if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit)
|
||||
if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack
|
||||
//DBG("USB_EPnR_SETUP");
|
||||
DBG("USB_EPnR_SETUP");
|
||||
EP_Read(0, setupdatabuf);
|
||||
// interrupt handler will be called later
|
||||
}else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf
|
||||
//if(endpoints[0].rx_cnt){ DBG("data");}
|
||||
if(endpoints[0].rx_cnt){ DBG("data"); DBGs(uhex2str(endpoints[0].rx_cnt));}
|
||||
ep0dbuflen = EP_Read(0, ep0databuf);
|
||||
}
|
||||
}
|
||||
@ -243,8 +242,8 @@ void EP_WriteIRQ(uint8_t number, const uint8_t *buf, uint16_t size){
|
||||
void EP_Write(uint8_t number, const uint8_t *buf, uint16_t size){
|
||||
EP_WriteIRQ(number, buf, size);
|
||||
uint16_t epstatus = KEEP_DTOG(USB->EPnR[number]);
|
||||
// keep DTOGs, clear CTR_TX & set TX VALID to start transmission
|
||||
USB->EPnR[number] = (epstatus & ~(USB_EPnR_CTR_TX)) ^ USB_EPnR_STAT_TX;
|
||||
// keep DTOGs and RX stat, clear CTR_TX & set TX VALID to start transmission
|
||||
USB->EPnR[number] = (epstatus & ~(USB_EPnR_CTR_TX | USB_EPnR_STAT_RX)) ^ USB_EPnR_STAT_TX;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -172,6 +172,7 @@ typedef struct{
|
||||
#define USB_CLASS_MASS_STORAGE 8
|
||||
#define USB_CLASS_HUB 9
|
||||
#define USB_CLASS_DATA 10
|
||||
#define USB_CLASS_MISC 0xef
|
||||
#define USB_CLASS_VENDOR_SPEC 0xff
|
||||
|
||||
/*
|
||||
@ -187,6 +188,7 @@ typedef struct{
|
||||
#define USB_DT_HID 0x21
|
||||
#define USB_DT_REPORT 0x22
|
||||
#define USB_DT_PHYSICAL 0x23
|
||||
#define USB_DT_CS_INTERFACE 0x24
|
||||
#define USB_DT_HUB 0x29
|
||||
|
||||
/*
|
||||
@ -198,6 +200,7 @@ typedef struct{
|
||||
#define USB_DT_HID_SIZE 9
|
||||
#define USB_DT_ENDPOINT_SIZE 7
|
||||
#define USB_DT_QUALIFIER_SIZE 10
|
||||
#define USB_DT_CS_INTERFACE_SIZE 5
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user