AnsweredAssumed Answered

CubeMx, Suggestion

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

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. */
    /* Configure the system clock */
    /* Initialize all configured peripherals */
    /* USER CODE BEGIN 2 */
    /* USER CODE END 2 */
    /* Infinite loop */
    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