kopia lustrzana https://github.com/skuep/AIOC
Added DFU runtime implementation to reboot into on-board DFU bootloader, thus new software can be flashed without the BOOT0 jumper over USB.
rodzic
7e7c8af252
commit
18e4ad7a13
|
@ -98,6 +98,7 @@
|
|||
#define CFG_TUD_AUDIO 1
|
||||
#define CFG_TUD_CDC 1
|
||||
#define CFG_TUD_HID 1
|
||||
#define CFG_TUD_DFU_RUNTIME 1
|
||||
|
||||
// CDC FIFO size of TX and RX
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 128
|
||||
|
|
|
@ -112,7 +112,8 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf)
|
|||
TUD_CONFIG_DESC_LEN + \
|
||||
AIOC_AUDIO_DESC_LEN + \
|
||||
AIOC_HID_DESC_LEN + \
|
||||
AIOC_CDC_DESC_LEN \
|
||||
AIOC_CDC_DESC_LEN + \
|
||||
AIOC_DFU_RT_DESC_LEN \
|
||||
)
|
||||
|
||||
uint8_t const desc_fs_configuration[] = {
|
||||
|
@ -155,6 +156,16 @@ uint8_t const desc_fs_configuration[] = {
|
|||
/* _epout */ EPNUM_CDC_0_OUT,
|
||||
/* _epin */ EPNUM_CDC_0_IN,
|
||||
/* _epsize */ CFG_TUD_CDC_EP_BUFSIZE
|
||||
),
|
||||
|
||||
AIOC_DFU_RT_DESCRIPTOR(
|
||||
/* _itfnum */ ITF_NUM_DFU_RT,
|
||||
/* _stridx */ STR_IDX_DFU_RT,
|
||||
/* _attr */ DFU_ATTR_WILL_DETACH | \
|
||||
DFU_ATTR_CAN_UPLOAD | \
|
||||
DFU_ATTR_CAN_DOWNLOAD,
|
||||
/* _timeout */ 255, /* not used if WILL_DETACH */
|
||||
/* _xfer_size */ 2048 /* max size for stm32 dfu bootloader */
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -280,6 +291,10 @@ const uint16_t * tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|||
len = ascii_to_utf16(ptr, len, USB_STRING_HIDITF);
|
||||
break;
|
||||
|
||||
case STR_IDX_DFU_RT:
|
||||
len = ascii_to_utf16(ptr, len, USB_STRING_DFU_RT);
|
||||
break;
|
||||
|
||||
default:
|
||||
TU_ASSERT(0, NULL);
|
||||
break;
|
||||
|
|
|
@ -9,6 +9,7 @@ enum USB_DESCRIPTORS_ITF {
|
|||
ITF_NUM_HID, /* For CM108 compatibility make this interface #3 */
|
||||
ITF_NUM_CDC_0,
|
||||
ITF_NUM_CDC_0_DATA,
|
||||
ITF_NUM_DFU_RT,
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
|
||||
|
@ -26,7 +27,8 @@ enum USB_STRING_IDX {
|
|||
STR_IDX_AUDIOINCHAN,
|
||||
STR_IDX_AUDIOOUTCHAN,
|
||||
STR_IDX_HIDITF,
|
||||
STR_IDX_CDCITF
|
||||
STR_IDX_CDCITF,
|
||||
STR_IDX_DFU_RT
|
||||
};
|
||||
|
||||
#define USB_VID 0x1209
|
||||
|
@ -44,6 +46,7 @@ enum USB_STRING_IDX {
|
|||
#define USB_STRING_AUDIOOUTCHAN "AIOC Audio Out Channel"
|
||||
#define USB_STRING_CDCITF "AIOC CDC"
|
||||
#define USB_STRING_HIDITF "AIOC HID"
|
||||
#define USB_STRING_DFU_RT "AIOC DFU Runtime"
|
||||
|
||||
/* Endpoints */
|
||||
#define EPNUM_AUDIO_IN 0x81
|
||||
|
@ -55,7 +58,6 @@ enum USB_STRING_IDX {
|
|||
#define EPNUM_CDC_0_IN 0x84
|
||||
#define EPNUM_CDC_0_NOTIF 0x85
|
||||
|
||||
|
||||
/* Custom Audio Descriptor.
|
||||
* Courtesy of https://github.com/hathach/tinyusb/issues/1249#issuecomment-1148727765 */
|
||||
#define AUDIO_CTRL_ID_SPK_INPUT_STREAM 0x01
|
||||
|
@ -168,4 +170,8 @@ enum USB_STRING_IDX {
|
|||
|
||||
#define AIOC_CDC_DESCRIPTOR TUD_CDC_DESCRIPTOR
|
||||
|
||||
#define AIOC_DFU_RT_DESC_LEN TUD_DFU_RT_DESC_LEN
|
||||
|
||||
#define AIOC_DFU_RT_DESCRIPTOR TUD_DFU_RT_DESCRIPTOR
|
||||
|
||||
#endif /* USB_DESCRIPTORS_H_ */
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include "usb_dfu.h"
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "tusb.h"
|
||||
#include "usb.h"
|
||||
|
||||
// Invoked on DFU_DETACH request to reboot to the bootloader
|
||||
void tud_dfu_runtime_reboot_to_dfu_cb(void)
|
||||
{
|
||||
/* Reset USB and force reset via watchdog timer. */
|
||||
USB_Reset();
|
||||
|
||||
IWDG_HandleTypeDef IWDGHandle = {
|
||||
.Instance = IWDG,
|
||||
.Init = {
|
||||
.Prescaler = IWDG_PRESCALER_4,
|
||||
.Reload = 128,
|
||||
.Window = 0x0FFF
|
||||
}
|
||||
};
|
||||
|
||||
HAL_IWDG_Init(&IWDGHandle);
|
||||
|
||||
while(1) {
|
||||
/* Wait for Reset */
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef USB_DFU_H_
|
||||
#define USB_DFU_H_
|
||||
|
||||
#endif /* USB_DFU_H_ */
|
Ładowanie…
Reference in New Issue