Skip to content

Commit 5002ce8

Browse files
authored
Merge pull request #2382 from YixingShen/master
fixed device/video_capture/src/images.h,main.c CFG_EXAMPLE_VIDEO_DISA…
2 parents 7db9119 + ab7538d commit 5002ce8

File tree

8 files changed

+124
-18
lines changed

8 files changed

+124
-18
lines changed

examples/device/video_capture/src/images.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
1+
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
22
static const unsigned char frame_buffer[128 * (96 + 1) * 2] = {
33
/* 0 */
44
0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80,

examples/device/video_capture/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static unsigned interval_ms = 1000 / FRAME_RATE;
115115
#ifdef CFG_EXAMPLE_VIDEO_READONLY
116116
#include "images.h"
117117

118-
# if !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
118+
# if !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
119119
static struct {
120120
uint32_t size;
121121
uint8_t const *buffer;
@@ -187,7 +187,7 @@ void video_task(void)
187187
already_sent = 1;
188188
start_ms = board_millis();
189189
#ifdef CFG_EXAMPLE_VIDEO_READONLY
190-
# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
190+
# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
191191
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
192192
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
193193
# else
@@ -205,7 +205,7 @@ void video_task(void)
205205
start_ms += interval_ms;
206206

207207
#ifdef CFG_EXAMPLE_VIDEO_READONLY
208-
# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPG)
208+
# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
209209
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
210210
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
211211
# else

examples/device/video_capture/src/usb_descriptors.c

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@
3737
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
3838
_PID_MAP(MIDI, 3) | _PID_MAP(AUDIO, 4) | _PID_MAP(VIDEO, 5) | _PID_MAP(VENDOR, 6) )
3939

40+
#define USB_VID 0xCafe
41+
#define USB_BCD 0x0200
42+
4043
//--------------------------------------------------------------------+
4144
// Device Descriptors
4245
//--------------------------------------------------------------------+
4346
tusb_desc_device_t const desc_device =
4447
{
4548
.bLength = sizeof(tusb_desc_device_t),
4649
.bDescriptorType = TUSB_DESC_DEVICE,
47-
.bcdUSB = 0x0200,
50+
.bcdUSB = USB_BCD,
4851

4952
// Use Interface Association Descriptor (IAD) for Video
5053
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
@@ -54,7 +57,7 @@ tusb_desc_device_t const desc_device =
5457

5558
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
5659

57-
.idVendor = 0xCafe,
60+
.idVendor = USB_VID,
5861
.idProduct = USB_PID,
5962
.bcdDevice = 0x0100,
6063

@@ -137,14 +140,89 @@ uint8_t const desc_fs_configuration[] =
137140
#endif
138141
};
139142

143+
#if TUD_OPT_HIGH_SPEED
144+
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
145+
146+
uint8_t const desc_hs_configuration[] =
147+
{
148+
// Config number, interface count, string index, total length, attribute, power in mA
149+
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 500),
150+
151+
// IAD for Video Control
152+
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
153+
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
154+
TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(4, EPNUM_VIDEO_IN,
155+
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
156+
512)
157+
# else
158+
TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN,
159+
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
160+
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
161+
# endif
162+
#else
163+
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
164+
TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK(4, EPNUM_VIDEO_IN,
165+
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
166+
512)
167+
# else
168+
TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(4, EPNUM_VIDEO_IN,
169+
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
170+
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
171+
# endif
172+
#endif
173+
};
174+
175+
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
176+
tusb_desc_device_qualifier_t const desc_device_qualifier =
177+
{
178+
.bLength = sizeof(tusb_desc_device_t),
179+
.bDescriptorType = TUSB_DESC_DEVICE,
180+
.bcdUSB = USB_BCD,
181+
182+
.bDeviceClass = TUSB_CLASS_MISC,
183+
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
184+
.bDeviceProtocol = MISC_PROTOCOL_IAD,
185+
186+
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
187+
.bNumConfigurations = 0x01,
188+
.bReserved = 0x00
189+
};
190+
191+
// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
192+
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
193+
// device_qualifier descriptor describes information about a high-speed capable device that would
194+
// change if the device were operating at the other speed. If not highspeed capable stall this request.
195+
uint8_t const* tud_descriptor_device_qualifier_cb(void)
196+
{
197+
return (uint8_t const*) &desc_device_qualifier;
198+
}
199+
200+
// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
201+
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
202+
// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
203+
uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
204+
{
205+
(void) index; // for multiple configurations
206+
207+
// if link speed is high return fullspeed config, and vice versa
208+
return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_fs_configuration : desc_hs_configuration;
209+
}
210+
211+
#endif // highspeed
212+
140213
// Invoked when received GET CONFIGURATION DESCRIPTOR
141214
// Application return pointer to descriptor
142215
// Descriptor contents must exist long enough for transfer to complete
143216
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
144217
{
145218
(void) index; // for multiple configurations
146219

220+
#if TUD_OPT_HIGH_SPEED
221+
// Although we are highspeed, host may be fullspeed.
222+
return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
223+
#else
147224
return desc_fs_configuration;
225+
#endif
148226
}
149227

150228
//--------------------------------------------------------------------+

hw/bsp/stm32f1/boards/stm32f103_bluepill/board.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
#define BUTTON_STATE_ACTIVE 1
4343

4444
// UART
45-
//#define UART_DEV USART1
46-
//#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
47-
//#define UART_GPIO_PORT GPIOA
45+
#define UART_DEV USART1
46+
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
47+
#define UART_GPIO_PORT GPIOA
4848
//#define UART_GPIO_AF GPIO_AF1_USART1
49-
//#define UART_TX_PIN GPIO_PIN_9
50-
//#define UART_RX_PIN GPIO_PIN_10
49+
#define UART_TX_PIN GPIO_PIN_9
50+
#define UART_RX_PIN GPIO_PIN_10
5151

5252
//--------------------------------------------------------------------+
5353
// RCC Clock

hw/bsp/stm32f1/family.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void USBWakeUp_IRQHandler(void) {
4646
//--------------------------------------------------------------------+
4747
// MACRO TYPEDEF CONSTANT ENUM
4848
//--------------------------------------------------------------------+
49+
UART_HandleTypeDef UartHandle;
4950

5051
void board_init(void) {
5152
board_stm32f1_clock_init();
@@ -82,6 +83,30 @@ void board_init(void) {
8283
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
8384
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
8485

86+
#ifdef UART_DEV
87+
// UART
88+
UART_CLK_EN();
89+
90+
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
91+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
92+
GPIO_InitStruct.Pull = GPIO_PULLUP;
93+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
94+
//GPIO_InitStruct.Alternate = UART_GPIO_AF;
95+
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
96+
97+
UartHandle = (UART_HandleTypeDef) {
98+
.Instance = UART_DEV,
99+
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
100+
.Init.WordLength = UART_WORDLENGTH_8B,
101+
.Init.StopBits = UART_STOPBITS_1,
102+
.Init.Parity = UART_PARITY_NONE,
103+
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
104+
.Init.Mode = UART_MODE_TX_RX,
105+
.Init.OverSampling = UART_OVERSAMPLING_16
106+
};
107+
HAL_UART_Init(&UartHandle);
108+
#endif
109+
85110
// USB Pins
86111
// Configure USB DM and DP pins.
87112
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
@@ -127,9 +152,8 @@ int board_uart_read(uint8_t *buf, int len) {
127152
}
128153

129154
int board_uart_write(void const *buf, int len) {
130-
(void) buf;
131-
(void) len;
132-
return 0;
155+
HAL_UART_Transmit(&UartHandle, (uint8_t *) (uintptr_t) buf, len, 0xffff);
156+
return len;
133157
}
134158

135159
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/stm32f1/family.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ CFLAGS_GCC += \
1818
-flto \
1919
-nostdlib -nostartfiles \
2020

21+
# mcu driver cause following warnings
22+
CFLAGS_GCC += -Wno-error=cast-align
23+
2124
LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs
2225

2326
# ------------------------
@@ -30,7 +33,8 @@ SRC_C += \
3033
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \
3134
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
3235
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
33-
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c
36+
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
37+
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c
3438

3539
INC += \
3640
$(TOP)/$(BOARD_PATH) \

hw/bsp/stm32f1/stm32f1xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/* #define HAL_ADC_MODULE_ENABLED */
3939
/* #define HAL_CAN_MODULE_ENABLED */
4040
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */
41-
#define HAL_CORTEX_MODULE_ENABLED */
41+
#define HAL_CORTEX_MODULE_ENABLED
4242
/* #define HAL_CRC_MODULE_ENABLED */
4343
/* #define HAL_DAC_MODULE_ENABLED */
4444
#define HAL_DMA_MODULE_ENABLED

src/common/tusb_verify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
#define _MESS_FAILED() do {} while (0)
7676
#endif
7777

78-
// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7, M33
79-
#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)
78+
// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7, M33. M55
79+
#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8_1M_MAIN__)
8080
#define TU_BREAKPOINT() do \
8181
{ \
8282
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \

0 commit comments

Comments
 (0)