cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX - USB Virtual COM Port sends only first word

sincoon
Associate II
Posted on April 03, 2015 at 16:50

What happens? I've created project in CubeMX, there - CDC virtual com port. So, this is function CDC_Transmit_FS() in usbd_cdc_if.c

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */ 
USBD_CDC_SetTxBuffer(hUsbDevice_0, Buf, Len); 
result = USBD_CDC_TransmitPacket(hUsbDevice_0);
/* USER CODE END 7 */ 
return result;
}

So, I have button interrupt in main.c

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
CDC_Transmit_FS(''Hello'',5);
for (int i = 0 ; i <1000000; i++);
CDC_Transmit_FS(''World'',5);
}

What happened when I press on button:

Serial port COM22 opened
Hello

Second word does not send! Why? Board STM32F4discovery, CubeMX 4.7, Firmware package 1.5.0 - the latest for today. #cdc #stm32 #stm32f4 #usb #vc
6 REPLIES 6
petr239955
Associate III
Posted on April 04, 2015 at 15:24

for (int i = 0 ; i <1000000; i++);

How

your compiler

interprets the

data type

int

as

16 bits or

32 bits

?
sincoon
Associate II
Posted on April 04, 2015 at 23:10

Hello patr.k! I use IAR, and actually did not think about this - I've used this delay in blinking LED, so this leds to delay about 0.5 sec(and cannot check now, because I'm not at work((( . Even if there is overflow... Do you think this is a problem?

sincoon
Associate II
Posted on April 23, 2015 at 17:08

So, no suggestions?

markb
Associate II
Posted on April 23, 2015 at 18:22

Well, you are trying to send from what looks like an IRQ handler so it's surely possible that, depending on the relative IRQ priorities, the USB code is not completing. Anyway, putting a 1/2 second delay in an IRQ handler is probably asking for trouble.

sincoon
Associate II
Posted on April 24, 2015 at 11:56

Really! I've changed NVIC priority to 15 and this fixed this problem! Thank you!

vladsol2009
Associate II
Posted on August 10, 2017 at 09:10

So, calling CDC_Transmit_FS() from ISR is not recommended?

From CDC_Receive_FS(), on example?