cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L053 USB with SYSCLK HSI16DIV

antonello
Associate
Posted on March 25, 2015 at 09:15

Greetings,

I'm developing an application using STM32L053 micro. I use usb device (composite hid, msc). When I  configure the system clock with HSI16, NO PLL  all DIVS to 1 everything works fine. Now I need to change this to run with HSI16DIV. (I simply change the HSI16DIVEN bit). Now the pc does not recognize the usb device any more.

I do not see why since my understanding was that HSI48 clock feeding usb shold be independent;

I post here the two configurations, the difference is in red:

This works:

 

RCC_OscInitTypeDef RCC_OscInitStruct;

   RCC_ClkInitTypeDef RCC_ClkInitStruct;

   RCC_PeriphCLKInitTypeDef PeriphClkInit;

   

   __PWR_CLK_ENABLE();

   

   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

   

   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI

      |RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_HSI48;

   RCC_OscInitStruct.LSEState = RCC_LSE_ON;

   RCC_OscInitStruct.HSIState = RCC_HSI_ON;

   RCC_OscInitStruct.HSICalibrationValue = 16;

   RCC_OscInitStruct.LSIState = RCC_LSI_OFF;

   RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_3;

   RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;

   HAL_RCC_OscConfig(&RCC_OscInitStruct);

   

   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;//RCC_SYSCLKSOURCE_PLLCLK;//RCC_SYSCLKSOURCE_PLLCLK;

   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);

   

   PeriphClkInit.PeriphClockSelection = /*RCC_PERIPHCLK_LPUART1|RCC_PERIPHCLK_I2C1

      |*/RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB;

   PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;

   PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;

   PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;

   PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;

   HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

This does not:

RCC_OscInitTypeDef RCC_OscInitStruct;

   RCC_ClkInitTypeDef RCC_ClkInitStruct;

   RCC_PeriphCLKInitTypeDef PeriphClkInit;

   

   __PWR_CLK_ENABLE();

   

   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

   

   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI

      |RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_HSI48;

   RCC_OscInitStruct.LSEState = RCC_LSE_ON;

   RCC_OscInitStruct.HSIState =

RCC_HSI_DIV4

;

   RCC_OscInitStruct.HSICalibrationValue = 16;

   RCC_OscInitStruct.LSIState = RCC_LSI_OFF;

   RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_3;

   RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;

   HAL_RCC_OscConfig(&RCC_OscInitStruct);

   

   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;//RCC_SYSCLKSOURCE_PLLCLK;//RCC_SYSCLKSOURCE_PLLCLK;

   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);

   

   PeriphClkInit.PeriphClockSelection = /*RCC_PERIPHCLK_LPUART1|RCC_PERIPHCLK_I2C1

      |*/RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB;

   PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;

   PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;

   PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;

   PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;

   HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

  

  

#stm32-stm32l0-usb-clock-hsi16div
0 REPLIES 0