]> git.sommitrealweird.co.uk Git - barbilliards.git/commitdiff
Fixes to usb stack so that it works master
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sat, 3 Oct 2020 16:43:21 +0000 (17:43 +0100)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sat, 3 Oct 2020 16:43:21 +0000 (17:43 +0100)
libopencm3
src/Makefile
src/bluepill.ld
src/timer.c
src/usb_cdcacm.c

index 5617ed466444790b787b6df8d7f21d1611905fd1..ad5ec6af085dc8cbe695872f98c2d07eb325fcf6 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 5617ed466444790b787b6df8d7f21d1611905fd1
+Subproject commit ad5ec6af085dc8cbe695872f98c2d07eb325fcf6
index 8cc64711cf4cf20a501441fcff30edee6095c413..0f5e574dcfeb4989d7d7cd3e4abe884b7514e1f1 100644 (file)
@@ -3,7 +3,7 @@ MAKEFLAGS += --no-print-dir
 Q := @
 endif
 
 Q := @
 endif
 
-OPT_FLAGS ?= -O2
+OPT_FLAGS ?= -Os
 
 CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts\
        $(OPT_FLAGS) -std=gnu99 -g3 -MD \
 
 CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts\
        $(OPT_FLAGS) -std=gnu99 -g3 -MD \
@@ -20,7 +20,8 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
 
 OPT_FLAGS = -Os
 CFLAGS += -mcpu=cortex-m3 -mthumb \
 
 OPT_FLAGS = -Os
 CFLAGS += -mcpu=cortex-m3 -mthumb \
-       -DSTM32F1 -DDISCOVERY_STLINK -I../libopencm3/include \
+       -DSTM32F1 -DDISCOVERY_STLINK \
+       -I../libopencm3/include \
        -I .
 LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs \
        -lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
        -I .
 LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs \
        -lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
index ffa24a83f91317eff2c28e177c5e1e1895481adb..3398f9e2fcc2349e066a291d5c30119e42d68354 100644 (file)
@@ -19,4 +19,3 @@
 
 /* Include the common ld script from libopenstm32. */
 INCLUDE stm32/f1/stm32f103x8.ld
 
 /* Include the common ld script from libopenstm32. */
 INCLUDE stm32/f1/stm32f103x8.ld
-INCLUDE cortex-m-generic.ld
index db8b8bb1db7ef4ee48af6c2cc74e6774673368b2..73283f467aace85480d393f01b4796da77b34958 100644 (file)
@@ -47,10 +47,13 @@ void sys_tick_handler(void) {
     /* calculate remaining seconds to print out on the serial port, only do this every
        1000 millis or so */
     if (n_millis_loops >= 4) {
     /* calculate remaining seconds to print out on the serial port, only do this every
        1000 millis or so */
     if (n_millis_loops >= 4) {
-        char seconds_remaining[5];
-        sprintf(seconds_remaining, "%d", (int)((game_time - n_millis_total) / 1000));
-        for (int i = 0; i < 4; i++) {
-            cdcacm_putchar(seconds_remaining[i]);
+        char time_remaining[6];
+        uint32_t seconds_remaining = (uint32_t)((game_time - n_millis_total) / 1000);
+        int minutes = (int)(seconds_remaining / 60);
+        int seconds = (int)(seconds_remaining % 60);
+        sprintf(time_remaining, "%02d:%02d", minutes, seconds);
+        for (int i = 0; i < 5; i++) {
+            cdcacm_putchar(time_remaining[i]);
         }
         cdcacm_putchar('\r');
         cdcacm_putchar('\n');
         }
         cdcacm_putchar('\r');
         cdcacm_putchar('\n');
@@ -71,6 +74,9 @@ static void clock_setup(void) {
     rcc_clock_setup_in_hse_8mhz_out_72mhz();
     rcc_periph_clock_enable(RCC_GPIOA);
     rcc_periph_clock_enable(RCC_GPIOC);
     rcc_clock_setup_in_hse_8mhz_out_72mhz();
     rcc_periph_clock_enable(RCC_GPIOA);
     rcc_periph_clock_enable(RCC_GPIOC);
+    rcc_periph_clock_enable(RCC_AFIO);
+
+    AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
 
     /* 72MHz / 8 => 9000000 counts per second */
     systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
 
     /* 72MHz / 8 => 9000000 counts per second */
     systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
@@ -87,11 +93,6 @@ static void gpio_setup(void) {
     gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
         GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
     gpio_set(GPIOC, GPIO13);
     gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
         GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
     gpio_set(GPIOC, GPIO13);
-
-    // Pull up the USB D+ line for reset
-    gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
-      GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12);
-    gpio_clear(GPIOA, GPIO12);
 }
 
 int main(void)
 }
 
 int main(void)
index 311727370e80539def8f7b7057bd8a19b5496e29..2dd1bc62a832fd54e23292333d0bd94878771c31 100644 (file)
@@ -33,7 +33,7 @@
 #include <libopencm3/usb/cdc.h> // USB CDC library
 #include <libopencm3/cm3/sync.h> // synchronisation utilities
 
 #include <libopencm3/usb/cdc.h> // USB CDC library
 #include <libopencm3/cm3/sync.h> // synchronisation utilities
 
-#include "global.h"
+#include "global.h" // global utilities
 #include "usb_cdcacm.h" // USB CDC ACM header and definitions
 
 /** USB CDC ACM device descriptor
 #include "usb_cdcacm.h" // USB CDC ACM header and definitions
 
 /** USB CDC ACM device descriptor
@@ -189,7 +189,7 @@ static const struct usb_config_descriptor config = {
  *  @note starting with index 1
  */
 static const char *usb_strings[] = {
  *  @note starting with index 1
  */
 static const char *usb_strings[] = {
-       "BarBillards v1",
+       "CuVoodoo",
        "CDC-ACM",
        "STM32F1",
 };
        "CDC-ACM",
        "STM32F1",
 };
@@ -242,7 +242,7 @@ static void usb_disconnect(void)
  *  @return 0 if succeeded, error else
  *  @note resets device when configured with 5 bits
  */
  *  @return 0 if succeeded, error else
  *  @note resets device when configured with 5 bits
  */
-static enum usbd_request_return_codes cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
+static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
 {
        (void)complete;
        (void)buf;
 {
        (void)complete;
        (void)buf;
@@ -268,12 +268,11 @@ static enum usbd_request_return_codes cdcacm_control_request(usbd_device *usbd_d
                        reply[8] = req->wValue & 3;
                        reply[9] = 0;
                        usbd_ep_write_packet(usbd_dev, 0x83, reply, LENGTH(reply));
                        reply[8] = req->wValue & 3;
                        reply[9] = 0;
                        usbd_ep_write_packet(usbd_dev, 0x83, reply, LENGTH(reply));
-            return USBD_REQ_HANDLED;
                        break;
                case USB_CDC_REQ_SET_LINE_CODING:
                        // ignore if length is wrong
                        if (*len < sizeof(struct usb_cdc_line_coding)) {
                        break;
                case USB_CDC_REQ_SET_LINE_CODING:
                        // ignore if length is wrong
                        if (*len < sizeof(struct usb_cdc_line_coding)) {
-                               return USBD_REQ_NOTSUPP;
+                               return 0;
                        }
                        // get the line coding
                        struct usb_cdc_line_coding *coding = (struct usb_cdc_line_coding *)*buf;
                        }
                        // get the line coding
                        struct usb_cdc_line_coding *coding = (struct usb_cdc_line_coding *)*buf;
@@ -286,12 +285,11 @@ static enum usbd_request_return_codes cdcacm_control_request(usbd_device *usbd_d
                                scb_reset_system(); // reset device
                                while (true); // wait for the reset to happen
                        }
                                scb_reset_system(); // reset device
                                while (true); // wait for the reset to happen
                        }
-            return USBD_REQ_HANDLED;
                        break;
                default:
                        break;
                default:
-                       return USBD_REQ_HANDLED;
+                       return 0;
        }
        }
-       return USBD_REQ_NOTSUPP;
+       return 1;
 }
 
 /** USB CDC ACM data received callback
 }
 
 /** USB CDC ACM data received callback
@@ -367,7 +365,7 @@ void cdcacm_setup(void)
 
        /* enable interrupts (to not have to poll all the time) */
        nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); // without this USB isn't detected by the host
 
        /* enable interrupts (to not have to poll all the time) */
        nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); // without this USB isn't detected by the host
-
+    
     /* reset buffer states */
        rx_i = 0;
        rx_used = 0;
     /* reset buffer states */
        rx_i = 0;
        rx_used = 0;