Skip to content

Discovery L072CZ USB Serial #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evandavey opened this issue Mar 25, 2019 · 11 comments · Fixed by #481
Closed

Discovery L072CZ USB Serial #479

evandavey opened this issue Mar 25, 2019 · 11 comments · Fixed by #481

Comments

@evandavey
Copy link

Describe the bug
I get an Unknown USB Device (Device Descriptor Request Failed) when trying to use CDC Serial on a Discovery L072CZ-LWRAN1. I know the USB works as I've successfully used it with this core https://github.com/GrumpyOldPizza/ArduinoCore-stm32l0.

To Reproduce
Load blink example, selecting USB CDC support from the submenu.

fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Mar 25, 2019
@fpistm
Copy link
Member

fpistm commented Mar 25, 2019

Hi @evandavey
Right, this does not work as the USB CLK is not enabled by default in the SystemClock_Config()

You can add this to your sketch as it is a weak function, this will enable the USB clock:

extern "C" void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;

  __HAL_RCC_PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
    Error_Handler();
  }

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | 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_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
    Error_Handler();
  }

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

@evandavey
Copy link
Author

OK, thanks. I will give this a go tomorrow and close the thread if successful.

@evandavey evandavey reopened this Mar 25, 2019
@fpistm
Copy link
Member

fpistm commented Mar 25, 2019

@evandavey I've tested and it works. I've also push a PR to enable USB clock by default even if by default USB could not work as SB15/16 are not fitted (Don't ask me why, I don't know 🤣 )

@evandavey
Copy link
Author

OK great! I am actually on a custom board using the CMWX1ZZABZ-078 module and using this board variant as a starting point. Do you know if arduino-lmic works?

fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Mar 25, 2019
@evandavey
Copy link
Author

So this works if I use a simple example like blink. However, I tried adding it to the LMIC TTN-OTAA example and it compiles and uploads but I then get the same device not recognized error.

@fpistm
Copy link
Member

fpistm commented Mar 26, 2019

@evandavey
which library you used ?
And could you be more precise about the board you really used ?

@evandavey
Copy link
Author

evandavey commented Mar 26, 2019 via email

@fpistm
Copy link
Member

fpistm commented Mar 26, 2019

@fpistm
Copy link
Member

fpistm commented Mar 26, 2019

Well, reproduce your issue with this lib.
Adding while(!Serial); allow to have a proper enumeration.
In fact, os_init(); seems to disable irq before USB ended to configure.
Anyway, I think some update will be required to be used with this core.

fpistm added a commit that referenced this issue Mar 26, 2019
@evandavey
Copy link
Author

OK, this is what I was using https://github.com/matthijskooijman/arduino-lmic.git. Will try some other libraries and see if anything works. In the meantime, I will probably switch over to MBED.

@fpistm
Copy link
Member

fpistm commented Mar 26, 2019

No worries. This issue was closed automatically after merge of the #481, which fix original issue.
Arduino-lmic is an other request.

benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this issue Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants