Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit de05463

Browse files
cparatafpistm
authored andcommitted
Fix for USB serial issue
Signed-off-by: Carlo.Parata <carlo.parata@st.com>
1 parent b623a62 commit de05463

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

cores/arduino/stm32/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ void TimerHandleInit(stimer_t *obj, uint16_t period, uint16_t prescaler)
409409
*/
410410
void TimerHandleDeinit(stimer_t *obj)
411411
{
412-
HAL_TIM_Base_DeInit(&(obj->handle));
413412
HAL_TIM_Base_Stop_IT(&(obj->handle));
413+
HAL_TIM_Base_DeInit(&(obj->handle));
414414
}
415415

416416
/**

cores/arduino/stm32/usbd_cdc_if.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ uint8_t lineSetup[] = {0x00, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x08};
109109

110110
#define CDC_POLLING_INTERVAL 1 /* in ms. The max is 65 and the min is 1 */
111111

112-
TIM_HandleTypeDef TimHandle;
112+
stimer_t TimHandle;
113113

114114
volatile uint8_t dfu_request = 0;
115115
/* For a bug in some Linux 64 bit PC we need to delay the reset of the CPU of 500ms seconds */
@@ -162,12 +162,9 @@ USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
162162
*/
163163
static int8_t CDC_Init_FS(void)
164164
{
165-
/*##-3- Configure the TIM Base generation #################################*/
165+
/*##-3- Configure and start the TIM Base generation #################################*/
166166
TIM_Config();
167167

168-
/*##-4- Start the TIM Base generation in interrupt mode ####################*/
169-
/* Start Channel1 */
170-
HAL_TIM_Base_Start_IT(&TimHandle);
171168
/* Set Application Buffers */
172169
USBD_CDC_SetTxBuffer(&hUSBD_Device_CDC, UserTxBufferFS, 1);
173170
USBD_CDC_SetRxBuffer(&hUSBD_Device_CDC, StackRxBufferFS);
@@ -360,25 +357,21 @@ void CDC_enable_TIM_Interrupt(void)
360357
static void TIM_Config(void)
361358
{
362359
/* Set TIMx instance */
363-
TimHandle.Instance = TIM6;
364-
360+
TimHandle.timer = TIM6;
365361
/* Initialize TIM6 peripheral as follow:
366362
+ Period = 10000 - 1
367363
+ Prescaler = ((SystemCoreClock/2)/10000) - 1
368364
+ ClockDivision = 0
369365
+ Counter direction = Up
370366
*/
371-
TimHandle.Init.Period = (CDC_POLLING_INTERVAL*1000) - 1;
372-
TimHandle.Init.Prescaler = 84-1;
373-
TimHandle.Init.ClockDivision = 0;
374-
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
367+
TimerHandleInit(&TimHandle, (uint16_t)((CDC_POLLING_INTERVAL*1000) - 1), (84 - 1)); //CDC_POLLING_INTERVAL
375368

376-
timer_attach_interrupt_handle(&TimHandle, HAL_TIM6_PeriodElapsedCallback);
377-
HAL_TIM_Base_Init(&TimHandle);
378369
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 6, 0);
370+
371+
timer_attach_interrupt_handle(&TimHandle.handle, TIM6_PeriodElapsedCallback);
379372
}
380373

381-
void HAL_TIM6_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
374+
void TIM6_PeriodElapsedCallback(stimer_t *htim)
382375
{
383376
uint8_t status;
384377

cores/arduino/stm32/usbd_cdc_if.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#endif
4242
/* Includes ------------------------------------------------------------------*/
4343
#include "usbd_cdc.h"
44+
#include "timer.h"
4445

4546
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
4647
* @{
@@ -94,7 +95,7 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len);
9495
void CDC_flush(void);
9596
void CDC_disable_TIM_Interrupt(void);
9697
void CDC_enable_TIM_Interrupt(void);
97-
void HAL_TIM6_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
98+
void TIM6_PeriodElapsedCallback(stimer_t *htim);
9899

99100
/**
100101
* @}

0 commit comments

Comments
 (0)