Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Bug in usb_dev.c

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4

    Bug in usb_dev.c

    There is a fencepost error in usb_dev.c related to NUM_ENDPOINTS. This bit me because I'm setting NUM_ENDPOINTS to 1, and I was getting STALL errors when trying to talk to endpoint 1; this was because usb_dev.c was never setting up the endpoint. After applying the patch, bulk transfers to endpoint 1 are working as expected.

    Here is the patch:

    Code:
    --- usb_dev.c~	2012-11-13 06:16:06.304414405 -0800
    +++ usb_dev.c	2012-11-29 22:11:52.757192844 -0800
    @@ -113,14 +113,14 @@
     		reg = &USB0_ENDPT1;
     		cfg = usb_endpoint_config_table;
     		// clear all BDT entries, free any allocated memory...
    -		for (i=4; i < NUM_ENDPOINTS*4; i++) {
    +		for (i=4; i <= NUM_ENDPOINTS*4; i++) {
     			if (table[i].desc & BDT_OWN) {
     				usb_free((usb_packet_t *)((uint8_t *)(table[i].addr) - 8));
     				table[i].desc = 0;
     			}
     		}
     		usb_rx_memory_needed = 0;
    -		for (i=1; i < NUM_ENDPOINTS; i++) {
    +		for (i=1; i <= NUM_ENDPOINTS; i++) {
     			epconf = *cfg++;
     			*reg = epconf;
     			reg += 4;

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,973
    Thanks. I'll fix this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •