mirror of
https://github.com/andreili/katapult.git
synced 2025-08-23 19:34:06 +02:00
usb_cdc: Resync USB code with upstream code from Klipper
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
b19cc2a9ad
commit
6a233ff4f5
@ -78,6 +78,7 @@ config CANBUS_FILTER
|
|||||||
bool
|
bool
|
||||||
default y if CANSERIAL
|
default y if CANSERIAL
|
||||||
|
|
||||||
|
# Support setting gpio state at startup
|
||||||
config INITIAL_PINS
|
config INITIAL_PINS
|
||||||
string "GPIO pins to set on bootloader entry"
|
string "GPIO pins to set on bootloader entry"
|
||||||
depends on LOW_LEVEL_OPTIONS
|
depends on LOW_LEVEL_OPTIONS
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#include <string.h> // memcmp
|
#include <string.h> // memcmp
|
||||||
#include "autoconf.h" // CONFIG_BLOCK_SIZE
|
#include "autoconf.h" // CONFIG_BLOCK_SIZE
|
||||||
|
#include "board/armcm_reset.h" // try_request_canboot
|
||||||
#include "board/flash.h" // flash_write_block
|
#include "board/flash.h" // flash_write_block
|
||||||
#include "board/io.h" // readb
|
#include "board/io.h" // readb
|
||||||
#include "board/misc.h" // try_request_canboot
|
|
||||||
#include "deployer.h" // deployer_is_active
|
#include "deployer.h" // deployer_is_active
|
||||||
#include "sched.h" // sched_check_periodic
|
#include "sched.h" // sched_check_periodic
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "autoconf.h" // CONFIG_FLASH_BOOT_ADDRESS
|
#include "autoconf.h" // CONFIG_FLASH_BOOT_ADDRESS
|
||||||
|
#include "armcm_reset.h" // try_request_canboot
|
||||||
#include "board/internal.h" // NVIC_SystemReset
|
#include "board/internal.h" // NVIC_SystemReset
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/irq.h" // irq_disable
|
||||||
#include "board/misc.h" // try_request_canboot
|
#include "board/misc.h" // try_request_canboot
|
||||||
|
6
src/generic/armcm_reset.h
Normal file
6
src/generic/armcm_reset.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __GENERIC_ARMCM_RESET_H
|
||||||
|
#define __GENERIC_ARMCM_RESET_H
|
||||||
|
|
||||||
|
void try_request_canboot(void);
|
||||||
|
|
||||||
|
#endif // armcm_reset.h
|
8
src/generic/armcm_timer.h
Normal file
8
src/generic/armcm_timer.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef __GENERIC_ARMCM_TIMER_H
|
||||||
|
#define __GENERIC_ARMCM_TIMER_H
|
||||||
|
|
||||||
|
#include <stdint.h> // uint32_t
|
||||||
|
|
||||||
|
void udelay(uint32_t usecs);
|
||||||
|
|
||||||
|
#endif // armcm_timer.h
|
@ -18,8 +18,6 @@ void application_read_flash(uint32_t address, uint32_t *dest);
|
|||||||
int application_check_valid(void);
|
int application_check_valid(void);
|
||||||
void application_jump(void);
|
void application_jump(void);
|
||||||
|
|
||||||
void try_request_canboot(void);
|
|
||||||
|
|
||||||
void timer_setup(void);
|
void timer_setup(void);
|
||||||
|
|
||||||
uint32_t timer_from_us(uint32_t us);
|
uint32_t timer_from_us(uint32_t us);
|
||||||
@ -32,4 +30,6 @@ void *dynmem_end(void);
|
|||||||
|
|
||||||
uint16_t crc16_ccitt(uint8_t *buf, uint_fast8_t len);
|
uint16_t crc16_ccitt(uint8_t *buf, uint_fast8_t len);
|
||||||
|
|
||||||
|
void bootloader_request(void);
|
||||||
|
|
||||||
#endif // misc.h
|
#endif // misc.h
|
||||||
|
@ -21,7 +21,6 @@ int_fast8_t usb_send_ep0_progmem(const void *data, uint_fast8_t len);
|
|||||||
void usb_stall_ep0(void);
|
void usb_stall_ep0(void);
|
||||||
void usb_set_address(uint_fast8_t addr);
|
void usb_set_address(uint_fast8_t addr);
|
||||||
void usb_set_configure(void);
|
void usb_set_configure(void);
|
||||||
void usb_request_bootloader(void);
|
|
||||||
struct usb_string_descriptor *usbserial_get_serialid(void);
|
struct usb_string_descriptor *usbserial_get_serialid(void);
|
||||||
|
|
||||||
// usb_cdc.c
|
// usb_cdc.c
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
// Default USB endpoint ids
|
// Default USB endpoint ids
|
||||||
enum {
|
enum {
|
||||||
USB_CDC_EP_ACM = 1,
|
USB_CDC_EP_BULK_IN = 1,
|
||||||
USB_CDC_EP_BULK_OUT = 2,
|
USB_CDC_EP_BULK_OUT = 2,
|
||||||
USB_CDC_EP_BULK_IN = 3,
|
USB_CDC_EP_ACM = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // usb_cdc_ep.h
|
#endif // usb_cdc_ep.h
|
||||||
|
@ -8,6 +8,12 @@
|
|||||||
#define USB_DIR_OUT 0 /* to device */
|
#define USB_DIR_OUT 0 /* to device */
|
||||||
#define USB_DIR_IN 0x80 /* to host */
|
#define USB_DIR_IN 0x80 /* to host */
|
||||||
|
|
||||||
|
#define USB_TYPE_MASK (0x03 << 5)
|
||||||
|
#define USB_TYPE_STANDARD (0x00 << 5)
|
||||||
|
#define USB_TYPE_CLASS (0x01 << 5)
|
||||||
|
#define USB_TYPE_VENDOR (0x02 << 5)
|
||||||
|
#define USB_TYPE_RESERVED (0x03 << 5)
|
||||||
|
|
||||||
#define USB_REQ_GET_STATUS 0x00
|
#define USB_REQ_GET_STATUS 0x00
|
||||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||||
#define USB_REQ_SET_FEATURE 0x03
|
#define USB_REQ_SET_FEATURE 0x03
|
||||||
|
@ -23,5 +23,6 @@ int is_enabled_pclock(uint32_t pclk);
|
|||||||
void enable_pclock(uint32_t pclk);
|
void enable_pclock(uint32_t pclk);
|
||||||
uint32_t get_pclock_frequency(uint32_t pclk);
|
uint32_t get_pclock_frequency(uint32_t pclk);
|
||||||
void gpio_peripheral(uint32_t gpio, int func, int pullup);
|
void gpio_peripheral(uint32_t gpio, int func, int pullup);
|
||||||
|
void usb_disconnect(void);
|
||||||
|
|
||||||
#endif // internal.h
|
#endif // internal.h
|
||||||
|
@ -5,13 +5,12 @@
|
|||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include <string.h> // memcpy
|
#include <string.h> // memcpy
|
||||||
#include "autoconf.h" // CONFIG_SMOOTHIEWARE_BOOTLOADER
|
|
||||||
#include "board/armcm_boot.h" // armcm_enable_irq
|
#include "board/armcm_boot.h" // armcm_enable_irq
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/armcm_timer.h" // udelay
|
||||||
#include "board/misc.h" // timer_read_time
|
#include "board/misc.h" // timer_read_time
|
||||||
#include "generic/usb_cdc.h" // usb_notify_ep0
|
|
||||||
#include "byteorder.h" // cpu_to_le32
|
#include "byteorder.h" // cpu_to_le32
|
||||||
#include "command.h" // DECL_CONSTANT_STR
|
#include "command.h" // DECL_CONSTANT_STR
|
||||||
|
#include "generic/usb_cdc.h" // usb_notify_ep0
|
||||||
#include "internal.h" // gpio_peripheral
|
#include "internal.h" // gpio_peripheral
|
||||||
#include "sched.h" // DECL_INIT
|
#include "sched.h" // DECL_INIT
|
||||||
#include "usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
|
#include "usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
|
||||||
@ -244,6 +243,15 @@ usb_set_configure(void)
|
|||||||
usb_irq_enable();
|
usb_irq_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Force a USB disconnect (used during reboot into bootloader)
|
||||||
|
void
|
||||||
|
usb_disconnect(void)
|
||||||
|
{
|
||||||
|
sie_cmd_write(SIE_CMD_SET_DEVICE_STATUS, 0);
|
||||||
|
udelay(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Setup and interrupts
|
* Setup and interrupts
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <string.h> // NULL
|
#include <string.h> // NULL
|
||||||
#include "board/armcm_boot.h" // armcm_enable_irq
|
#include "board/armcm_boot.h" // armcm_enable_irq
|
||||||
|
#include "board/armcm_timer.h" // udelay
|
||||||
#include "board/gpio.h" // gpio_out_setup
|
#include "board/gpio.h" // gpio_out_setup
|
||||||
#include "board/io.h" // writeb
|
#include "board/io.h" // writeb
|
||||||
#include "board/usb_cdc.h" // usb_notify_ep0
|
#include "board/usb_cdc.h" // usb_notify_ep0
|
||||||
@ -14,12 +15,12 @@
|
|||||||
#include "internal.h" // GPIO
|
#include "internal.h" // GPIO
|
||||||
#include "sched.h" // DECL_INIT
|
#include "sched.h" // DECL_INIT
|
||||||
|
|
||||||
#if CONFIG_MACH_STM32F103
|
#if CONFIG_MACH_STM32F103 || CONFIG_MACH_STM32G4
|
||||||
// Transfer memory is accessed with 32bits, but contains only 16bits of data
|
// Transfer memory is accessed with 32bits, but contains only 16bits of data
|
||||||
typedef volatile uint32_t epmword_t;
|
typedef volatile uint32_t epmword_t;
|
||||||
#define WSIZE 2
|
#define WSIZE 2
|
||||||
#define USBx_IRQn USB_LP_IRQn
|
#define USBx_IRQn USB_LP_IRQn
|
||||||
#elif CONFIG_MACH_STM32F0
|
#elif CONFIG_MACH_STM32F0 || CONFIG_MACH_STM32L4
|
||||||
// Transfer memory is accessed with 16bits and contains 16bits of data
|
// Transfer memory is accessed with 16bits and contains 16bits of data
|
||||||
typedef volatile uint16_t epmword_t;
|
typedef volatile uint16_t epmword_t;
|
||||||
#define WSIZE 2
|
#define WSIZE 2
|
||||||
@ -28,9 +29,14 @@
|
|||||||
// Transfer memory is accessed with 32bits and contains 32bits of data
|
// Transfer memory is accessed with 32bits and contains 32bits of data
|
||||||
typedef volatile uint32_t epmword_t;
|
typedef volatile uint32_t epmword_t;
|
||||||
#define WSIZE 4
|
#define WSIZE 4
|
||||||
#define USBx_IRQn USB_UCPD1_2_IRQn
|
#define USBx_IRQn USB_IRQn
|
||||||
|
#endif
|
||||||
|
|
||||||
// The stm32g0 has slightly different register names
|
// The stm32g0 has slightly different register names
|
||||||
|
#if CONFIG_MACH_STM32G0
|
||||||
|
#if CONFIG_MACH_STM32G0B1
|
||||||
|
#define USB_IRQn USB_UCPD1_2_IRQn
|
||||||
|
#endif
|
||||||
#define USB USB_DRD_FS
|
#define USB USB_DRD_FS
|
||||||
#define USB_PMAADDR USB_DRD_PMAADDR
|
#define USB_PMAADDR USB_DRD_PMAADDR
|
||||||
#define USB_EPADDR_FIELD USB_CHEP_ADDR
|
#define USB_EPADDR_FIELD USB_CHEP_ADDR
|
||||||
|
@ -15,21 +15,31 @@
|
|||||||
#include "sched.h" // DECL_INIT
|
#include "sched.h" // DECL_INIT
|
||||||
|
|
||||||
#if CONFIG_STM32_USB_PB14_PB15
|
#if CONFIG_STM32_USB_PB14_PB15
|
||||||
#define USB_PERIPH_BASE USB_OTG_HS_PERIPH_BASE
|
#define IS_OTG_HS 1
|
||||||
#define OTG_IRQn OTG_HS_IRQn
|
#define GPIO_D_NEG GPIO('B', 14)
|
||||||
#define USBOTGEN RCC_AHB1ENR_USB1OTGHSEN
|
#define GPIO_D_POS GPIO('B', 15)
|
||||||
#define GPIO_D_NEG GPIO('B', 14)
|
#define GPIO_FUNC GPIO_FUNCTION(12)
|
||||||
#define GPIO_D_POS GPIO('B', 15)
|
DECL_CONSTANT_STR("RESERVE_PINS_USB1", "PB14,PB15");
|
||||||
#define GPIO_FUNC GPIO_FUNCTION(12)
|
|
||||||
DECL_CONSTANT_STR("RESERVE_PINS_USB1", "PB14,PB15");
|
|
||||||
#else
|
#else
|
||||||
#define USB_PERIPH_BASE USB_OTG_FS_PERIPH_BASE
|
#if CONFIG_MACH_STM32H723
|
||||||
#define OTG_IRQn OTG_FS_IRQn
|
#define IS_OTG_HS 1
|
||||||
#define USBOTGEN RCC_AHB1ENR_USB2OTGHSEN
|
#else
|
||||||
#define GPIO_D_NEG GPIO('A', 11)
|
#define IS_OTG_HS 0
|
||||||
#define GPIO_D_POS GPIO('A', 12)
|
#endif
|
||||||
#define GPIO_FUNC GPIO_FUNCTION(10)
|
#define GPIO_D_NEG GPIO('A', 11)
|
||||||
DECL_CONSTANT_STR("RESERVE_PINS_USB", "PA11,PA12");
|
#define GPIO_D_POS GPIO('A', 12)
|
||||||
|
#define GPIO_FUNC GPIO_FUNCTION(10)
|
||||||
|
DECL_CONSTANT_STR("RESERVE_PINS_USB", "PA11,PA12");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if IS_OTG_HS
|
||||||
|
#define USB_PERIPH_BASE USB_OTG_HS_PERIPH_BASE
|
||||||
|
#define OTG_IRQn OTG_HS_IRQn
|
||||||
|
#define USBOTGEN RCC_AHB1ENR_USB1OTGHSEN
|
||||||
|
#else
|
||||||
|
#define USB_PERIPH_BASE USB_OTG_FS_PERIPH_BASE
|
||||||
|
#define OTG_IRQn OTG_FS_IRQn
|
||||||
|
#define USBOTGEN RCC_AHB1ENR_USB2OTGHSEN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user