Sysprogs forums › Forums › VisualGDB › STM32F042K6 USB CDC Locking Up MCU
Tagged: USB CDC STM32F042K6
- This topic has 1 reply, 2 voices, and was last updated 8 years, 8 months ago by support.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
April 9, 2016 at 07:47 #7923atomicParticipant
Hello, I am using the STM32F042K6
- Latest BSP updated and installed from STM
- Using the example tutorial from: http://visualgdb.com/tutorials/arm/stm32/usb/
- Using internal oscillator
- USB works in STM DFU Boot0 mode correctly
- Should also add that I use ST-Link and i’m unable to debug because i get an error about a memory address not being writable – so cannot step through code to find out where it’s locking up the MCU within the USBD_Init call-tree
The MCU locks up in the USBD_Init(&USBD_Device, &VCP_Desc, 0);
#ifdef __cplusplus extern "C" { #endif #include <usbd_core.h> #include <usbd_cdc.h> #include "usbd_cdc_if.h" #include <usbd_desc.h> USBD_HandleTypeDef USBD_Device; void SysTick_Handler(void); void OTG_FS_IRQHandler(void); void OTG_HS_IRQHandler(void); extern PCD_HandleTypeDef hpcd; int VCP_read(void *pBuffer, int size); int VCP_write(const void *pBuffer, int size); extern char g_VCPInitialized; #ifdef __cplusplus } #endif void flashled() { __GPIOB_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.Pin = GPIO_PIN_5; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; GPIO_InitStructure.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); for (;;) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET); HAL_Delay(500); } } static void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; /* Enable HSI48 Oscillator to be used as system clock source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48; RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI48; RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2; HAL_RCC_OscConfig(&RCC_OscInitStruct); /* Select HSI48 as system clock source and configure the HCLK and PCLK1 clock dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1); /* Select HSI48 as USB clock source */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB; PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); __SYSCFG_CLK_ENABLE(); /*Configure the clock recovery system (CRS)**********************************/ static RCC_CRSInitTypeDef RCC_CRSInitStruct; /* Default Synchro Signal division factor (not divided) */ RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; /* Set the SYNCSRC[1:0] bits according to CRS_Source value */ RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; /* HSI48 is synchronized with USB SOF at 1KHz rate */ RCC_CRSInitStruct.ReloadValue = RCC_CRS_RELOADVALUE_DEFAULT; // __HAL_RCC_CRS_CALCULATE_RELOADVALUE(48000000, 1000); RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT; /* Set the TRIM[5:0] to the default value*/ RCC_CRSInitStruct.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT; // 0x20; /* Start automatic synchronization */ HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); /*Enable CRS Clock*/ __CRS_CLK_ENABLE(); } void SysTick_Handler(void) { HAL_IncTick(); HAL_SYSTICK_IRQHandler(); } void OTG_FS_IRQHandler(void) { HAL_PCD_IRQHandler(&hpcd); } int main(void) { HAL_Init(); SystemClock_Config(); // flashled(); // this works USBD_Init(&USBD_Device, &VCP_Desc, 0); flashled(); // never gets to here USBD_RegisterClass(&USBD_Device, &USBD_CDC); USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_USBEZB_fops); USBD_Start(&USBD_Device); char byte; for (;;) { if (VCP_read(&byte, 1) != 1) continue; VCP_write("\r\nYou typed ", 12); VCP_write(&byte, 1); VCP_write("\r\n", 2); } }
April 11, 2016 at 03:24 #7933supportKeymasterHi,
It’s hard to say what could be wrong without seeing the hardware. Have you copied SystemClock_Config() from a proper example for your board? This function varies slightly between different boards.
If yes, we would need to first get debugging to work before we could give any further advice. Could you attach the full gdb log and the OpenOCD output so that we could see why the debugging is impossible?
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.