Hi all,
I'm experimenting with USB on the STM32F103C8 as I've mentionned in this thread:
https://www.eevblog.com/forum/microcontrollers/weird-stm32f103-usb-module!!/
With your help (thanks ataradov, pcprogrammer, ... and others) I can now control a LED via control transfer or send/receive data via simple bulk transfer.
The only problem however, is when the size of the config descriptor is EVEN, the device can't be enumerated!! I've to add an extra dummy byte in order to get things working. No problem with other descriptors if they are even.
Now I'm struggling with double buffered IN endpoint. Only one buffer can be sent to the host.
Here's how I do it:
1- EP1 descriptor:
0x07, // bLength
0x05, // bDescriptorType: Endpoint
0x81, // bEndpointAddress: (1IN)
0x02, // bmAttributes: Bulk
0x08, // wMaxPacketSize: 8 bytes
0x00,
0x00, // bInterval:
2- EP1 initialization:
...............
Addr += 64;
BTable[1].TX_ADDR = Addr; // TX0_ADDR
BTable[1].TX_COUNT = 0; // TX0_COUNT
Addr += 64; //
BTable[1].RX_ADDR = Addr; // TX1_ADDR
BTable[1].RX_COUNT = 0; // TX1_COUNT
// at startup the Application owns TX1BUF
USB->EPR[1] = EP_DTOG_RX | EP_KIND | EP_TX_VALID | 1;
fill(tx0buf, BTable[1].TX_ADDR); // copy tx0buf[] to TX0_ADDR in PMA
fill(tx1buf, BTable[1].RX_ADDR); // copy tx1buf[] to TX1_ADDR in PMA
BTable[1].TX_COUNT = 8; // TX0_COUNT
BTable[1].RX_COUNT = 8; // TX1_COUNT
3- EP1 transfer complete interrupt handler:
to toggle the DTOG_RX bit I declared a pointer to it in the bitband region:
#define BITBAND_PERIPH(address, bit) ((uint32_t *)(0x42000000 + (((uint32_t)address) - 0x40000000) * 32 + (bit) * 4))
volatile uint32_t* bb_DTOGRX = BITBAND_PERIPH(&(USB->EPR[1]), 14);
and the handler:
if(EP == 1){
if(USB->EPR[1] & EP_CTR_TX){
USB->EPR[1] = EP_BULK | EP_KIND | 1; //Reset the CTR TX bit
*bb_DTOGRX = 1; //toggle DTOG_RX by bitbanding
}
}
4- The host application:
a 10 times for() loop doing usb_bulk_read() from the device.
I expected to see tx0buf[] then tx1buf[] then tx0buf[] ...etc, but I get only the contents of tx0buf[] once then the device stops responding.