AnsweredAssumed Answered

CubeMx problems with USER CODE SECTIONs

Question asked by illescas.Eduardo on Feb 26, 2017
Latest reply on Feb 28, 2017 by Sirma Siang

HI

I am using Cube32MX for the implementation of a USB Host + Fatfs to work with a pendrive connected to a stm32f407, generate code for SW4STM32 but in the usb_host.c file generated by Cube32MX the following appears.

 

#include "usb_host.h"
#include "usbh_core.h"
#include "usbh_msc.h"

/* USB Host Core handle declaration */
USBH_HandleTypeDef hUsbHostFS;
ApplicationTypeDef Appli_state = APPLICATION_IDLE;

/**
* -- Insert your variables declaration here --
*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/*
* user callbak declaration
*/
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id);

/**
* -- Insert your external function declaration here --
*/
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* init function */
void MX_USB_HOST_Init(void)
{
/* Init Host Library,Add Supported Class and Start the library*/
USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);

USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS);

USBH_Start(&hUsbHostFS);
}

/*
* Background task
*/
void MX_USB_HOST_Process(void)
{
/* USB Host Background task */
USBH_Process(&hUsbHostFS);
}
/*
* user callbak definition
*/
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
}

 

As you can see in the USBH_UserProcess function, the user section number is repeated as well as at the beginning of the code in the dedicated section for the prototype of an external function. I write a prototype and re-generate the code with Cube32MX prototype is copied inside the USBH_UserProcess function. Now if I write code inside the user zone in the function USBH_UserProcess when regenerating code with Cube32Mx this erases the written code. I think the fault is because the user zone number is repeated to one, I think it should be two but that is automatically generated by the Cube32Mx and I can not change it and I lose the code that I write inside that function when I have to re-generating coded from Cube32Mx.

What would be the solution to the problem?

The Cube32Mx version is 4.19.0 STM32Cube v1.0

Thank you.

Outcomes