From: Brett Parker Date: Sat, 3 Oct 2020 16:43:21 +0000 (+0100) Subject: Fixes to usb stack so that it works X-Git-Url: https://git.sommitrealweird.co.uk/barbilliards.git/commitdiff_plain?ds=inline Fixes to usb stack so that it works --- diff --git a/libopencm3 b/libopencm3 index 5617ed4..ad5ec6a 160000 --- a/libopencm3 +++ b/libopencm3 @@ -1 +1 @@ -Subproject commit 5617ed466444790b787b6df8d7f21d1611905fd1 +Subproject commit ad5ec6af085dc8cbe695872f98c2d07eb325fcf6 diff --git a/src/Makefile b/src/Makefile index 8cc6471..0f5e574 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ MAKEFLAGS += --no-print-dir Q := @ endif -OPT_FLAGS ?= -O2 +OPT_FLAGS ?= -Os 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 \ - -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 \ diff --git a/src/bluepill.ld b/src/bluepill.ld index ffa24a8..3398f9e 100644 --- a/src/bluepill.ld +++ b/src/bluepill.ld @@ -19,4 +19,3 @@ /* Include the common ld script from libopenstm32. */ INCLUDE stm32/f1/stm32f103x8.ld -INCLUDE cortex-m-generic.ld diff --git a/src/timer.c b/src/timer.c index db8b8bb..73283f4 100644 --- a/src/timer.c +++ b/src/timer.c @@ -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) { - 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'); @@ -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_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); @@ -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); - - // 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) diff --git a/src/usb_cdcacm.c b/src/usb_cdcacm.c index 3117273..2dd1bc6 100644 --- a/src/usb_cdcacm.c +++ b/src/usb_cdcacm.c @@ -33,7 +33,7 @@ #include // USB CDC library #include // 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 @@ -189,7 +189,7 @@ static const struct usb_config_descriptor config = { * @note starting with index 1 */ static const char *usb_strings[] = { - "BarBillards v1", + "CuVoodoo", "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 */ -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; @@ -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)); - 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)) { - return USBD_REQ_NOTSUPP; + return 0; } // 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 } - return USBD_REQ_HANDLED; break; default: - return USBD_REQ_HANDLED; + return 0; } - return USBD_REQ_NOTSUPP; + return 1; } /** 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 - + /* reset buffer states */ rx_i = 0; rx_used = 0;