2021-07-08 10:07 AM
Hi there,
Recently if done a project regarding custom hid on a STM32F411RE Nucleo prototype board, this was successful. I have created my own pcb design but unfortunatly due the lack of availability of the STM32F411RE i was forced to go with the STM32F411CE QFN48. Adapted my board design and after populating my newly received boards i run into a snag. I adapted my original code to the 411CE alas its not popping up in my windows device list as a custom HID device. But it does show in DFU mode , i can upload my code through ST LINK. Debugger in CUBEIDE works fine. Just to keep it simple i made a bare project which only use the custom HID options out of CUBE IDE. Does behave exactly as described, but not showing up as Custom HID Device.
Might be a bit short sighted but i think it is not my PCB design,cause of the above behavior.
Maybe someone in here has some experience with the F411CE and can put me on the right track.
Thanks in advance.
2021-07-13 12:59 PM
TDK, I meant LSE.
I use a abm3b-8.000mhz-10-1-u-t oscillator
And I will recheck my capacitors
Thanks for the error handler sugestion I'll give it a try tomorrow.
2021-07-14 12:59 PM
I swapped the capacitors to 10pF.
The F411 mco1 pin allows HSE,HSI,LSE and LSI measurement only, there is no mco2(pc9) pin on this qfn48 package so i cant measure the sysclk other package have this ability.
I can confirm 8 Mhz clock on mco1, so the crystall seems to be running, is there another way to measure the sysclock just to confirm it is working?
Just noticed the following,
If line 14 is commented my while loop is running i can measure my HSE, but my device is not showing up as Custom HID device.
If line 14 is uncommented my while loop does not run and i can measure my HSE but my device DOES shows up as Custom HID device.
So my tought is in the first option is the 48MHz clock is not getting started.
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
//RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 72;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 3;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
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_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1);
}
Are there more parameters to check?
2021-07-14 01:23 PM
If you specify OscillatorType = RCC_OSCILLATORTYPE_HSI, you need to specify a value for HSIState. And if it's currently used for the PLL, it can't be off. Same for HSE. You can't just comment those out. Use CubeMX to generate clock settings or read documentation in the function headers.
2021-07-17 03:20 AM
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 = 4;
RCC_OscInitStruct.PLL.PLLN = 72;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 3;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
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_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1);
}
After some more measuring i know my HSE is running at 8MHz.
The device shows up in the Device list so i am getting a 48MHz clock on my USB perpherial.
Just my main while wont start i and have now clue why, is this related to clock as well ?
2021-07-18 06:09 PM
> Just my main while wont start i and have now clue why
Debug it, hit pause, see where the code is stuck.
Ensure Error_Handler has something inside of it so you know when calls fail.
2021-07-22 12:08 PM
Looks my ADC1 was hanging my MCU.
I added a counter to my while loop and after just a few counts the counter stopped.
By commenting out functions one by one and run the debugger i noticed the program just run fine with the ADC initialization commented out.
It seems like my
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2
was to fast and changed it into
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8
But why did this happen i couldn't find a exploitation for, yeah it runs but i just need to know why and learn from it.
While loop is running now , just to need program my code again step by step and see if there are more bugs.
Is there a simple guide somewhere on how to do proper debugging?