This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to get USB working properly on STM32F469IIT

Hello

I have a working example of USB CDC for STM32F429 (based on Keil example)
We have changed the CPU to STM32F469IIT and the usage of USB from HS to FS mode.
I have been able to successfully run STMCube example of the CDC on hte device in FS mode.
Yet when I have changed the Keil based example from STM32F429 to teh STM32F469, and work without VBUS in FS mode I am not able to even correctly initialize USB (I am not getting USBRST interrupt that should arrive at the initialization).
The drivers version is 6.8.0 (MDK)
I have change clocks initialization as defined in Cube:

/* System Clock Configuration */
void SystemClock_Config(void) {
#if 0 RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;

/* Enable Power Control clock */ __PWR_CLK_ENABLE();

/* The voltage scaling allows optimizing the power consumption when the device is clocked below the maximum system frequency (see datasheet). */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = 2; RCC_OscInitStruct.PLL.PLLQ = 7; RCC_OscInitStruct.PLL.PLLR = 7; HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
#endif RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

/* Enable Power Control clock */ __HAL_RCC_PWR_CLK_ENABLE();

/* The voltage scaling allows optimizing the power consumption when the device is clocked below the maximum system frequency, to update the voltage scaling value regarding system frequency refer to product datasheet. */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 360; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; RCC_OscInitStruct.PLL.PLLR = 2; HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Activate the OverDrive to reach the 180 MHz Frequency */ HAL_PWREx_EnableOverDrive();

/* Select PLLSAI output as USB clock source */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CK48; PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP; PeriphClkInitStruct.PLLSAI.PLLSAIN = 384; PeriphClkInitStruct.PLLSAI.PLLSAIQ = 7; PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}

And it is still not working (i.e. USBRST and USB suspend interrupts at init are not coming)
Do you have any idea what a problem can be?
We are working without VBNUS and without overcurrent detection

Otherwise can i use Keil environment using existing SPI,I2C drivers from Keil while USB from STM Cube and the protocol stack of USB from Cube?

Thanks

  • Check the Cube repository for STM32F469 USB examples:

    C:\Users\<user name>\STM32Cube\Repository\STM32Cube_FW_F4_V1.13.0\Projects\STM32469I_EVAL\Applications

    They have several MDK-ARM projects. Use target drop-down list for USB FS / USB HS selection. Compare one of these projects to the current project to check for any differences in USB setup.

  • Thanks

    I know that and already tried to compare. The point is that they are using STM Cube drivers while we in our project, are trying to use Keil configuration and drivers (Keil middleware) so this is not really comparable.
    I can say that the settings are definitely different since most of registers are different between the 2 projects after initialization.

    Or am i missing something?

    Thanks
    Igor

  • Hello Igor,

    OK, I am sorry, I misread. You are using the Keil USB middleware. The last question had me bark up the wrong tree.

    Yes, a choice must be made between using the Keil USB middleware or the USB middleware from the Cube. There are different example projects for using both, in the F4 device family.
    The choice can depend on a number of factors, including software portability, the number of available examples, and how much of the USB specification is implemented in both.

    To give Keil USB middleware a fair test,
    Have you tried creating a CubeMX project for 469IIT device that enables USB peripheral, but does not use CubeMX's USB middleware, then export to MDK, and then try enabling Keil's USB component?

    Thanks,
    Zack

  • Hello Zack

    We are not testing - rather already using Keil Middleware, since we are relying on RTX.

    "Have you tried creating a CubeMX project for 469IIT device that enables USB peripheral, but does not use CubeMX's USB middleware" - if the project is Cube MX but Does not uses Cube MX middleware than which middleware it uses?I am lost a bit...Can u please explain?

    On top of that theoretically i think that it will be possible to get the USB code from CubeMX and run it under Keil, while eliminating USB stack for Keil? (This will be simply "user" code from Keil perspective)...Am i right?
    This is not preferred option of course but at least sounds like an option ...Do u think so?

    Thanks
    Igor

  • Hello Igor,

    You asked:
    "if the project is Cube MX but Does not uses Cube MX middleware than which middleware it uses?"

    You can choose, which middleware to use, later on. This problem looks like it is just about enabling the USB peripheral. Enable USB under Configuration tab => Peripherals => USB. (You don't want to enable the USB under "MiddleWares", because this action adds CubeMX USB middleware.)

    Make sure MDK-ARMv5 is selected under Project => Settings = > Project tab => Toolchain/IDE.
    Then export project to MDK, under Project => "Generate Code".

    Then open MDK project, and enable Keil USB middleware inside MDK as a software component in Manage RTE window. Then project includes basic USB peripheral initialization code. To call Keil's USB middleware layer, include '#include "rl_usb.h"' in the C source file, and copy this layer of code from the F4 CDC example.

    I'm sure some of the initialization code will overlap, between HAL layer's USB initialization and CMSIS driver's USB initialization. But then issue is more about what duplicate code to remove, rather than what code is missing.

    The software layers for F4's require some modification to be compatible. A few necessary changes for CubeMX-exported projects to work OK inside MDK and with our RTOS, are listed here:
    www.keil.com/.../_troubleshooting.html

    Thanks,
    Zack