From 03486e52a2dde8ade759f36fea8b403b6524451c Mon Sep 17 00:00:00 2001 From: root Date: Sat, 6 Mar 2021 18:19:33 +0000 Subject: pull a new libopencm3 in the hope it fixes tim's usb problems --- app/adc.c | 4 +- app/cdcacm.c | 23 ++++---- app/dfu.c | 24 ++++---- app/gdbfl.script | 2 + app/main.c | 176 +++++++------------------------------------------------ app/project.h | 6 +- app/prototypes.h | 6 +- app/sysclk.c | 2 +- app/ticker.c | 2 +- app/usb.c | 25 +++++--- 10 files changed, 74 insertions(+), 196 deletions(-) create mode 100644 app/gdbfl.script (limited to 'app') diff --git a/app/adc.c b/app/adc.c index 821bac9..8825c71 100644 --- a/app/adc.c +++ b/app/adc.c @@ -69,7 +69,7 @@ void adc_dispatch (void) ago = now - adc_stamp; if (ago > ADC_TIMEOUT) { - adc_off (ADC1); + adc_power_off (ADC1); adc_power_on (ADC1); state = WAIT_VREF; start_conversion (VREF_CHANNEL); @@ -116,7 +116,7 @@ void adc_init (void) MAP_ANALOG_INPUT (POT); - adc_off (ADC1); + adc_power_off (ADC1); adc_disable_scan_mode (ADC1); adc_enable_temperature_sensor(); diff --git a/app/cdcacm.c b/app/cdcacm.c index af45ac6..5327c0a 100644 --- a/app/cdcacm.c +++ b/app/cdcacm.c @@ -122,35 +122,36 @@ const struct usb_iface_assoc_descriptor cdc_iface_assoc = { -int cdcacm_control_request (usbd_device *usbd_dev, - struct usb_setup_data *req, - uint8_t **buf, - uint16_t *len, - usbd_control_complete_callback *complete) -{ +enum usbd_request_return_codes +cdcacm_control_request (usbd_device *usbd_dev, + struct usb_setup_data *req, + uint8_t **buf, + uint16_t *len, + usbd_control_complete_callback *complete) { (void) complete; (void) buf; (void) usbd_dev; - switch (req->bRequest) { + switch (req->bRequest) + { case USB_CDC_REQ_SET_CONTROL_LINE_STATE: { /* * This Linux cdc_acm driver requires this to be implemented * even though it's optional in the CDC spec, and we don't * advertise it in the ACM functional descriptor. */ - return 1; + return USBD_REQ_HANDLED; } case USB_CDC_REQ_SET_LINE_CODING: if (*len < sizeof (struct usb_cdc_line_coding)) - return 0; + return USBD_REQ_NOTSUPP; - return 1; + return USBD_REQ_HANDLED; } - return 0; + return USBD_REQ_NEXT_CALLBACK; } diff --git a/app/dfu.c b/app/dfu.c index 08e3bf9..8e72e3f 100644 --- a/app/dfu.c +++ b/app/dfu.c @@ -36,7 +36,7 @@ const struct usb_iface_assoc_descriptor dfu_iface_assoc = { }; -static int +static void dfu_detach_complete (usbd_device *usbd_dev, struct usb_setup_data *req) { (void) req; @@ -48,23 +48,21 @@ dfu_detach_complete (usbd_device *usbd_dev, struct usb_setup_data *req) //SCB_AIRCR= SCB_AIRCR_SYSRESETREQ; scb_reset_core(); - return 1; } -int +enum usbd_request_return_codes dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, - usbd_control_complete_callback *complete) -{ + usbd_control_complete_callback *complete) { (void) buf; (void) len; (void) usbd_dev; - if ((req->bmRequestType & 0x7F) != 0x21) { - return 0; /* Only accept class request. */ - } + if ((req->bmRequestType & 0x7F) != 0x21) + return USBD_REQ_NEXT_CALLBACK; - switch (req->bRequest) { + switch (req->bRequest) + { case DFU_GETSTATUS: { (*buf) [0] = DFU_STATUS_OK; (*buf) [1] = 0; @@ -73,20 +71,20 @@ dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, (*buf) [4] = STATE_APP_IDLE; (*buf) [5] = 0; /* iString not used here */ *len = 6; - return 1; + return USBD_REQ_HANDLED; } case DFU_GETSTATE: /* Return state with no state transision. */ *buf[0] = STATE_APP_IDLE; *len = 1; - return 1; + return USBD_REQ_HANDLED; case DFU_DETACH: *complete = dfu_detach_complete; - return 1; + return USBD_REQ_HANDLED; } - return 0; + return USBD_REQ_NEXT_CALLBACK; } diff --git a/app/gdbfl.script b/app/gdbfl.script new file mode 100644 index 0000000..11f7bc5 --- /dev/null +++ b/app/gdbfl.script @@ -0,0 +1,2 @@ +target remote tick:3333 +cont diff --git a/app/main.c b/app/main.c index da5ffb8..18baed1 100644 --- a/app/main.c +++ b/app/main.c @@ -84,160 +84,25 @@ static void cmd_dispatch (void) } -#if 0 -static void pd_port (uint32_t p) -{ - unsigned c; - - for (c = 0; c < 32; ++c) { - - if ((p == GPIOA) && ((c == 13) || (c == 14))) continue; - - gpio_mode_setup (p, GPIO_MODE_INPUT, GPIO_PUPD_NONE, 1UL << c); - } -} - - -static void pd_clear (uint32_t g, uint32_t b) -{ - gpio_mode_setup (g, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, b); - gpio_set_output_options (g, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, b); - gpio_clear (g, b); -} - - -static void pd_set (uint32_t g, uint32_t b) -{ - gpio_mode_setup (g, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, b); - gpio_set_output_options (g, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, b); - gpio_set (g, b); -} - - -static void pd (void) -{ - pd_port (GPIOA); - pd_port (GPIOB); - pd_port (GPIOC); - pd_port (GPIOD); - pd_port (GPIOE); - pd_port (GPIOF); - pd_port (GPIOG); - - - pd_set (GPIOB, GPIO10); - - pd_set (GPIOG, GPIO4); - pd_set (GPIOD, GPIO10); - - pd_set (GPIOD, GPIO1); - pd_set (GPIOB, GPIO13); - - pd_set (GPIOE, GPIO3); - pd_set (GPIOE, GPIO4); - - - rcc_periph_clock_disable (RCC_ETHMACPTP); - rcc_periph_clock_disable (RCC_ETHMACRX); - rcc_periph_clock_disable (RCC_ETHMACTX); - rcc_periph_clock_disable (RCC_ETHMAC); - rcc_periph_clock_disable (RCC_USART2); - rcc_periph_clock_disable (RCC_USART1); - rcc_periph_clock_disable (RCC_GPIOG); - rcc_periph_clock_disable (RCC_GPIOF); - rcc_periph_clock_disable (RCC_GPIOE); - rcc_periph_clock_disable (RCC_GPIOD); - rcc_periph_clock_disable (RCC_GPIOC); - rcc_periph_clock_disable (RCC_GPIOB); - rcc_periph_clock_disable (RCC_GPIOA); - rcc_periph_clock_disable (RCC_SYSCFG); - - - - for (;;); -} -#endif - - -static const clock_scale_t hse_10mhz_3v3_168 = { - /* 168MHz */ +const struct rcc_clock_scale hse_10mhz_3v3_168 = { .pllm = 10, .plln = 336, .pllp = 2, .pllq = 7, - .hpre = RCC_CFGR_HPRE_DIV_NONE, - .ppre1 = RCC_CFGR_PPRE_DIV_4, - .ppre2 = RCC_CFGR_PPRE_DIV_2, - .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE | + .pllr = 0, + .pll_source = RCC_CFGR_PLLSRC_HSE_CLK, + .hpre = RCC_CFGR_HPRE_NODIV, + .ppre1 = RCC_CFGR_PPRE_DIV4, + .ppre2 = RCC_CFGR_PPRE_DIV2, + .voltage_scale = PWR_SCALE1, + .flash_config = FLASH_ACR_DCEN | FLASH_ACR_ICEN | FLASH_ACR_LATENCY_5WS, + .ahb_frequency = 168000000, .apb1_frequency = 42000000, .apb2_frequency = 84000000, }; -#if 0 -static const clock_scale_t hse_10mhz_3v3_120 = { - /* 120 */ - .pllm = 10, - .plln = 240, - .pllp = 2, - .pllq = 5, - .hpre = RCC_CFGR_HPRE_DIV_NONE, - .ppre1 = RCC_CFGR_PPRE_DIV_4, - .ppre2 = RCC_CFGR_PPRE_DIV_2, - .power_save = 1, - .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE | - FLASH_ACR_LATENCY_3WS, - .apb1_frequency = 30000000, - .apb2_frequency = 60000000, -}; - -static const clock_scale_t hse_10mhz_3v3_84 = { - .pllm = 10, - .plln = 336, - .pllp = 4, - .pllq = 7, - .hpre = RCC_CFGR_HPRE_DIV_NONE, - .ppre1 = RCC_CFGR_PPRE_DIV_2, - .ppre2 = RCC_CFGR_PPRE_DIV_NONE, - .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE | - FLASH_ACR_LATENCY_2WS, - .apb1_frequency = 42000000, - .apb2_frequency = 84000000, -}; - - -static const clock_scale_t hse_10mhz_3v3_48 = { - .pllm = 10, - .plln = 96, - .pllp = 2, - .pllq = 2, - .hpre = RCC_CFGR_HPRE_DIV_NONE, - .ppre1 = RCC_CFGR_PPRE_DIV_4, - .ppre2 = RCC_CFGR_PPRE_DIV_2, - .power_save = 1, - .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE | - FLASH_ACR_LATENCY_3WS, - .apb1_frequency = 12000000, - .apb2_frequency = 24000000, -}; - -static const clock_scale_t hse_10mhz_3v3_10 = { - /* 10 */ - .pllm = 10, - .plln = 336, - .pllp = 2, - .pllq = 7, - .hpre = RCC_CFGR_HPRE_DIV_NONE, - .ppre1 = RCC_CFGR_PPRE_DIV_NONE, - .ppre2 = RCC_CFGR_PPRE_DIV_NONE, - .flash_config = FLASH_ACR_ICE | FLASH_ACR_DCE | FLASH_ACR_LATENCY_0WS, - // .ahb_frequency = 10000000, - .apb1_frequency = 10000000, - .apb2_frequency = 10000000, -}; - -#endif static void ptp_clock_start (void) { @@ -268,23 +133,23 @@ static void clock_setup (void) */ /*Get us up and running on the 16MHz RC clock */ - rcc_osc_on (HSI); - rcc_wait_for_osc_ready (HSI); + rcc_osc_on (RCC_HSI); + rcc_wait_for_osc_ready (RCC_HSI); /* Select HSI as SYSCLK source. */ rcc_set_sysclk_source (RCC_CFGR_SW_HSI); /* confiure HSE as input not oscillator */ - rcc_osc_bypass_enable (HSE); - rcc_osc_on (HSE); + rcc_osc_bypass_enable (RCC_HSE); + rcc_osc_on (RCC_HSE); while ((RCC_CR & RCC_CR_HSERDY) == 0) { if (fail++ == 4000000) { /*No external clock, try seeing if we have a crystal */ - rcc_osc_off (HSE); - rcc_osc_bypass_disable (HSE); - rcc_osc_on (HSE); + rcc_osc_off (RCC_HSE); + rcc_osc_bypass_disable (RCC_HSE); + rcc_osc_on (RCC_HSE); } } @@ -299,8 +164,7 @@ static void clock_setup (void) RCC_CFGR &= ~ (RCC_CFGR_MCOPRE_DIV_5 << RCC_CFGR_MCO1PRE_SHIFT); RCC_CFGR |= RCC_CFGR_MCOPRE_DIV_NONE << RCC_CFGR_MCO1PRE_SHIFT; - rcc_clock_setup_hse_3v3 (&hse_10mhz_3v3_168); - /* rcc_clock_setup_hse_3v3_no_pll (&hse_10mhz_3v3_10); */ + rcc_clock_setup_pll (&hse_10mhz_3v3_168); } @@ -340,7 +204,7 @@ static void timer_setup (void) */ - timer_reset (TIM1); + rcc_periph_reset_pulse (RST_TIM1); timer_set_mode (TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); /* meh */ timer_slave_set_filter (TIM1, TIM_SMCR_ETF_OFF); /* No filter */ timer_slave_set_prescaler (TIM1, TIM_SMCR_ETPS_OFF); /* no prescaler */ @@ -349,7 +213,7 @@ static void timer_setup (void) timer_set_master_mode (TIM1, TIM_CR2_MMS_RESET); /* output reset on TRGO */ timer_enable_counter (TIM1); /* go */ - timer_reset (TIM2); + rcc_periph_reset_pulse (RST_TIM2); timer_set_mode (TIM2, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); /* count up with clock*/ timer_slave_set_filter (TIM2, TIM_SMCR_ETF_OFF); /*no filter*/ timer_slave_set_prescaler (TIM2, TIM_SMCR_ETPS_OFF); /*no prescaler */ @@ -367,7 +231,7 @@ static void timer_setup (void) MAP_AF (REFCLK_IN, GPIO_AF1); - timer_reset (TIM2); + rcc_periph_reset_pulse (RST_TIM2); timer_set_mode (TIM2, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); /* count up with clock*/ timer_slave_set_filter (TIM2, TIM_SMCR_ETF_OFF); /*no filter*/ timer_slave_set_prescaler (TIM2, TIM_SMCR_ETPS_OFF); /*no prescaler */ diff --git a/app/project.h b/app/project.h index fcf16ce..cfa58a4 100644 --- a/app/project.h +++ b/app/project.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include /* SoC */ @@ -23,10 +24,11 @@ #include #include #include +#include #include #include -#include -#include +#include +#include #include /* Drivers */ #include diff --git a/app/prototypes.h b/app/prototypes.h index e6b631b..d6ce3ad 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -68,6 +68,7 @@ extern void pll_dispatch(uint64_t happy, uint64_t edge, uint64_t ptp_edge, const extern void pll_check(void); /* main.c */ extern int time_known; +extern const struct rcc_clock_scale hse_10mhz_3v3_168; extern int main(void); /* time_fn.c */ extern UTC time_epoch_to_utc(EPOCH epoch); @@ -130,7 +131,7 @@ extern ring_t cdcacm_tx_ring; extern const struct usb_interface_descriptor comm_iface; extern const struct usb_interface_descriptor data_iface; extern const struct usb_iface_assoc_descriptor cdc_iface_assoc; -extern int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete); +extern enum usbd_request_return_codes cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete); extern void cdcacm_tick(void); extern int cdcacm_write(char *ptr, int len, int blocking); extern void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue); @@ -139,12 +140,13 @@ extern void cdcacm_rings_init(void); extern uint8_t usbd_control_buffer[128]; extern usbd_device *usb_device; extern void otg_fs_isr(void); +extern enum usbd_request_return_codes usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete); extern void usb_init(void); /* dfu.c */ extern const struct usb_dfu_descriptor dfu_function; extern const struct usb_interface_descriptor dfu_iface; extern const struct usb_iface_assoc_descriptor dfu_iface_assoc; -extern int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete); +extern enum usbd_request_return_codes dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete); /* adc.c */ extern uint8_t pot_brightness; extern void adc_dispatch(void); diff --git a/app/sysclk.c b/app/sysclk.c index 98b5ed8..d61ab22 100644 --- a/app/sysclk.c +++ b/app/sysclk.c @@ -7,7 +7,7 @@ static Event_ring sysclk_ring; void sysclk_event (void) { uint32_t refclk_now = HW_CLOCK_REG; - uint32_t sysclk_now = SCS_DWT_CYCCNT; + uint32_t sysclk_now = DWT_CYCCNT; sysclk_ring.events[sysclk_ring.tx_ptr].when = refclk_now; diff --git a/app/ticker.c b/app/ticker.c index 791839e..4df9806 100644 --- a/app/ticker.c +++ b/app/ticker.c @@ -80,6 +80,6 @@ ticker_init (void) } while (w); SCS_DEMCR |= SCS_DEMCR_TRCENA; - SCS_DWT_CTRL |= SCS_DWT_CTRL_CYCCNTENA; + DWT_CTRL |= DWT_CTRL_CYCCNTENA; } diff --git a/app/usb.c b/app/usb.c index fc9e6ea..d1fb625 100644 --- a/app/usb.c +++ b/app/usb.c @@ -77,16 +77,25 @@ void otg_fs_isr (void) } -static int control_request (usbd_device *usbd_dev, - struct usb_setup_data *req, - uint8_t **buf, - uint16_t *len, - usbd_control_complete_callback *complete) +static enum usbd_request_return_codes control_request (usbd_device *usbd_dev, + struct usb_setup_data *req, + uint8_t **buf, + uint16_t *len, + usbd_control_complete_callback *complete) { - if (dfu_control_request (usbd_dev, req, buf, len, complete)) - return 1; + enum usbd_request_return_codes ret; - return cdcacm_control_request (usbd_dev, req, buf, len, complete); + ret = dfu_control_request (usbd_dev, req, buf, len, complete); + + if (ret != USBD_REQ_NEXT_CALLBACK) + return ret; + + ret = cdcacm_control_request (usbd_dev, req, buf, len, complete); + + if (ret != USBD_REQ_NEXT_CALLBACK) + return ret; + + return USBD_REQ_NOTSUPP; } static void set_config (usbd_device *usbd_dev, uint16_t wValue) -- cgit v1.2.3