-Subproject commit 5617ed466444790b787b6df8d7f21d1611905fd1
+Subproject commit ad5ec6af085dc8cbe695872f98c2d07eb325fcf6
Q := @
endif
-OPT_FLAGS ?= -O2
+OPT_FLAGS ?= -Os
CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts\
$(OPT_FLAGS) -std=gnu99 -g3 -MD \
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 \
/* Include the common ld script from libopenstm32. */
INCLUDE stm32/f1/stm32f103x8.ld
-INCLUDE cortex-m-generic.ld
/* 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');
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);
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)
#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
* @note starting with index 1
*/
static const char *usb_strings[] = {
- "BarBillards v1",
+ "CuVoodoo",
"CDC-ACM",
"STM32F1",
};
* @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;
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;
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
/* 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;