AnsweredAssumed Answered

Migrating usbd_cdc_if.c to updated HAL, STM32 Cube MX

Question asked by sett.radek on Oct 6, 2015
Latest reply on Oct 7, 2015 by sett.radek
When modifying existing project.ioc I may either download older libraries or migrate to those currently maintained. Migrating tool duplicates parts of user code and then shifts body from each function to following one until the sourcefile ends.

Below is part of the file 'usb_cdc_if.c' affected by the bug.
This could be caused by an unexpected formatting of the code.
How to embrace the user code to be migration-proof?

Part of /* USER CODE */ is repeated when migrating existing project.ioc

_Before:_

/** @defgroup USBD_CDC_Private_Variables
  * @{
  */
  /* USER CODE BEGIN 3 */
_single occurence_
/* Create buffer for reception and transmission           */
/* It's up to user to redefine and/or remove those define */
/* Received Data over USB are stored in this buffer       */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
 
/* Send Data over USB CDC are stored in this buffer       */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
extern uint8_t data_request_flag;
extern uint8_t config_change_flag;
extern struct _config_struct temp_config;
extern struct _config_struct config;
/* USER CODE END 3 */
 
/* USB handler declaration */
/* Handle for USB Full Speed IP */
USBD_HandleTypeDef  *hUsbDevice_0;

_After:_
/** @defgroup USBD_CDC_Private_Variables
  * @{
  */
_occurence 1_
/* Create buffer for reception and transmission           */
/* It's up to user to redefine and/or remove those define */
/* Received Data over USB are stored in this buffer       */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];

/* Send Data over USB CDC are stored in this buffer       */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];

/* USB handler declaration */
/* Handle for USB Full Speed IP */
USBD_HandleTypeDef  *hUsbDevice_0;
...
static int8_t CDC_Init_FS(void)
{
  hUsbDevice_0 = &hUsbDeviceFS;
  /* USER CODE BEGIN 3 */
_occurence 2_
/* Create buffer for reception and transmission           */
/* It's up to user to redefine and/or remove those define */
/* Received Data over USB are stored in this buffer       */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];

/* Send Data over USB CDC are stored in this buffer       */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
extern uint8_t data_request_flag;
extern uint8_t config_change_flag;
extern struct _config_struct temp_config;
extern struct _config_struct config;
  /* USER CODE END 3 */
}

Outcomes