cancel
Showing results for 
Search instead for 
Did you mean: 

Migrating usbd_cdc_if.c to updated HAL, STM32 Cube MX

a2temp
Associate
Posted on October 06, 2015 at 10:14

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 */

}

#solved #bug #stm32cube #migration
1 REPLY 1
a2temp
Associate
Posted on October 07, 2015 at 08:20

The cause includes number mismatch between the old and the new library.

If the syntax were

'/* USER CODE BEGIN' <identifier>|<number> '*/'

the migration tool can be useful for any source, securing <indentifier> could be derived from the migrated function's name. The <number> should be kept for backwards compatibility.