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 --- boot/bootloader.c | 79 ++++++++++++------------------------------------------- boot/dfu.c | 30 ++++++++++----------- boot/project.h | 6 +++-- boot/prototypes.h | 2 +- 4 files changed, 37 insertions(+), 80 deletions(-) (limited to 'boot') diff --git a/boot/bootloader.c b/boot/bootloader.c index a5932f0..3bc7344 100644 --- a/boot/bootloader.c +++ b/boot/bootloader.c @@ -25,69 +25,23 @@ static const clock_scale_t hsi_16mhz_3v3_48 = { - /* 48MHz */ - .pllm = 16, - .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, + .pllm = 16, + .plln = 96, + .pllp = 2, + .pllq = 2, + .pllr = 0, + .pll_source = RCC_CFGR_PLLSRC_HSI_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_3WS, + .ahb_frequency = 48000000, + .apb1_frequency = 12000000, + .apb2_frequency = 24000000, }; -static void rcc_clock_setup_hsi_3v3 (const clock_scale_t *clock) -{ - - /* Enable internal high-speed oscillator. */ - rcc_osc_on (HSI); - rcc_wait_for_osc_ready (HSI); - - /* Select HSI as SYSCLK source. */ - rcc_set_sysclk_source (RCC_CFGR_SW_HSI); - rcc_wait_for_sysclk_status (HSI); - - rcc_osc_off (PLL); - - while (RCC_CR & RCC_CR_PLLRDY); - - pwr_set_vos_scale (SCALE1); - - /* - * Set prescalers for AHB, ADC, ABP1, ABP2. - * Do this before touching the PLL (TODO: why?). - */ - rcc_set_hpre (clock->hpre); - rcc_set_ppre1 (clock->ppre1); - rcc_set_ppre2 (clock->ppre2); - - rcc_set_main_pll_hsi (clock->pllm, clock->plln, - clock->pllp, clock->pllq); - - /* Enable PLL oscillator and wait for it to stabilize. */ - rcc_osc_on (PLL); - rcc_wait_for_osc_ready (PLL); - - /* Configure flash settings. */ - flash_set_ws (clock->flash_config); - - /* Select PLL as SYSCLK source. */ - rcc_set_sysclk_source (RCC_CFGR_SW_PLL); - - /* Wait for PLL clock to be selected. */ - rcc_wait_for_sysclk_status (PLL); - - /* Set the peripheral clock frequencies used. */ - rcc_apb1_frequency = clock->apb1_frequency; - rcc_apb2_frequency = clock->apb2_frequency; - -} - - int main (void) { @@ -126,7 +80,8 @@ int main (void) rcc_periph_clock_enable (RCC_SYSCFG); - rcc_clock_setup_hsi_3v3 (&hsi_16mhz_3v3_48); + + rcc_clock_setup_pll (&hsi_16mhz_3v3_48); RCC_AHB1RSTR |= RCC_AHB1RSTR_ETHMACRST; RCC_AHB2RSTR |= RCC_AHB2RSTR_OTGFSRST; diff --git a/boot/dfu.c b/boot/dfu.c index 4054520..138c6f8 100644 --- a/boot/dfu.c +++ b/boot/dfu.c @@ -80,7 +80,7 @@ static uint8_t usbdfu_getstatus (usbd_device *usbd_dev, uint32_t *bwPollTimeout) } } -static int usbdfu_getstatus_complete (usbd_device *usbd_dev, struct usb_setup_data *req) +static void usbdfu_getstatus_complete (usbd_device *usbd_dev, struct usb_setup_data *req) { unsigned i; (void)req; @@ -123,37 +123,37 @@ static int usbdfu_getstatus_complete (usbd_device *usbd_dev, struct usb_setup_da /* Jump straight to dfuDNLOAD-IDLE, skipping dfuDNLOAD-SYNC. */ usbdfu_state = STATE_DFU_DNLOAD_IDLE; - return 0; + return ; case STATE_DFU_MANIFEST: /* USB device must detach, we just reset... */ scb_reset_system(); - return 0; /* Will never return. */ + return ; /* Will never return. */ default: - return 0; + ; } } -int usbdfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, - uint16_t *len, int (**complete) (usbd_device *usbd_dev, struct usb_setup_data *req)) +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) { if ((req->bmRequestType & 0x7F) != 0x21) - return 0; /* Only accept class request. */ + return USBD_REQ_NEXT_CALLBACK; /* Only accept class request. */ switch (req->bRequest) { case DFU_DNLOAD: if ((len == NULL) || (*len == 0)) { usbdfu_state = STATE_DFU_MANIFEST_SYNC; - return 1; + return USBD_REQ_HANDLED; } else { /* Copy download data for use on GET_STATUS. */ prog.blocknum = req->wValue; prog.len = *len; memcpy (prog.buf, *buf, *len); usbdfu_state = STATE_DFU_DNLOAD_SYNC; - return 1; + return USBD_REQ_HANDLED; } case DFU_CLRSTATUS: @@ -162,16 +162,16 @@ int usbdfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, u if (usbdfu_state == STATE_DFU_ERROR) usbdfu_state = STATE_DFU_IDLE; - return 1; + return USBD_REQ_HANDLED; case DFU_ABORT: /* Abort returns to dfuIDLE state. */ usbdfu_state = STATE_DFU_IDLE; - return 1; + return USBD_REQ_HANDLED; case DFU_UPLOAD: /* Upload not supported for now. */ - return 0; + return USBD_REQ_NOTSUPP; case DFU_GETSTATUS: { uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */ @@ -183,17 +183,17 @@ int usbdfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, u (*buf)[5] = 0; /* iString not used here */ *len = 6; *complete = usbdfu_getstatus_complete; - return 1; + return USBD_REQ_HANDLED; } case DFU_GETSTATE: /* Return state with no state transision. */ *buf[0] = usbdfu_state; *len = 1; - return 1; + return USBD_REQ_HANDLED; } - return 0; + return USBD_REQ_NEXT_CALLBACK; } diff --git a/boot/project.h b/boot/project.h index 5699389..4c3a92c 100644 --- a/boot/project.h +++ b/boot/project.h @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -27,3 +27,5 @@ extern uint32_t dfu_flag; #define APP_ADDRESS 0x08004000 + +typedef struct rcc_clock_scale clock_scale_t; diff --git a/boot/prototypes.h b/boot/prototypes.h index 74f6b60..40ae6c5 100644 --- a/boot/prototypes.h +++ b/boot/prototypes.h @@ -10,7 +10,7 @@ extern void usb(void); /* dfu.c */ extern const struct usb_dfu_descriptor dfu_function; extern const struct usb_interface_descriptor dfu_iface; -extern int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)); +extern enum usbd_request_return_codes usbdfu_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)); /* delay.c */ extern void sys_tick_handler(void); extern void ticker_on(void); -- cgit v1.2.3