AnsweredAssumed Answered

CubeMx, Suggestion

Question asked by JulienD on Dec 2, 2015
Latest reply on Feb 25, 2016 by JulienD
Hi,


I'm writing an app which will embed its own DFU.
In CubeMx gui, I checked usb as a DFU class.

Here's what I get in the main function:

int main(void) {
 
    /* USER CODE BEGIN 1 */
 
    /* USER CODE END 1 */
 
    /* MCU Configuration----------------------------------------------------------*/
 
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
 
    /* Configure the system clock */
    SystemClock_Config();
 
    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_ADC_Init();
    MX_CRC_Init();
    MX_I2C2_Init();
    MX_IWDG_Init();
    MX_RTC_Init();
    MX_SPI1_Init();
    MX_SPI2_Init();
    MX_TIM2_Init();
    MX_TIM3_Init();
    MX_TIM4_Init();
    MX_TIM5_Init();
    MX_TIM11_Init();
    MX_UART4_Init();
    MX_UART5_Init();
    MX_USART1_UART_Init();
    MX_USART2_UART_Init();
    MX_USART3_UART_Init();
    MX_USB_DEVICE_Init();
 
    /* USER CODE BEGIN 2 */
    /* USER CODE END 2 */
 
    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
 
    while (1) {
 
        /* USER CODE END WHILE */
 
        /* USER CODE BEGIN 3 */
 
    }
    /* USER CODE END 3 */
 
}

The point is: I did not find any elegant way to initialize or not the usb port
depending on the user action (typically press a button at boot).

Suggestion : put the MX_USB_DEVICE_Init() at the end of the initialization
process (as it seems to be) and add a user code section before and after it, in which
we will be able to check the custom user action.

Of course, if you have a cool way to do it with the current generated code, I'll
be pleased to use it !   ;)

Best regards
Julien

Outcomes