cancel
Showing results for 
Search instead for 
Did you mean: 

AN4776 Timer Example not running on STM32F303 Nucleo board

David Pekin
Senior

Hello,

I'm trying to run the frequency meter example of App Note 4776 on a STM32F303 Nucleo board.

I've built the code specifying the new target. It builds without errors but hangs waiting for the DMA transfer to complete. I'm using the default version of the code where it uses the internal 8 MHz clock. to drive the timer. Does the STM32F303 Nucleo board have that clock available to the timer?

Any suggestions appreciated.

Dave

3 REPLIES 3

The F3 starts from the internal 8 MHz HSI. The NUCLEO's ST-LINK provides an 8 MHz HSE clock.

You can choose sources and PLL settings from there.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
David Pekin
Senior

Thanks Clive. I figured it was a clock source issue. Would it be fair to say that if I got the system clock issues figured out that the timer sample should work? Here's a SystemClock_Config that works correctly with an application running on the F303:

void SystemClock_Config(void)

{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* HSI Oscillator already ON after system reset, activate PLL with HSI as source */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;  //dfp was 2

  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;

  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)

  {

    /* Initialization Error */

    while(1);

  }

  /* 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_DIV2;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2)!= HAL_OK)

  {

    /* Initialization Error */

    while(1);

  }

}

And here's the sysclock_config that is in the Timer example.

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct;

 RCC_ClkInitTypeDef RCC_ClkInitStruct;

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = 16;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 HAL_RCC_OscConfig(&RCC_OscInitStruct);

  

  

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

 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_0);

 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

 /* SysTick_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

They are certainly significantly different. Swapping the first clock config into the timer example doesn't help. It still hangs waiting for the DMA complete. So I suspect I'll need to really learn the clock/timer/DMA interactions to get it working on the F303. Thanks for any pointers Clive!

Dave

So, when you say the F3 starts from the internal 8 MHz HSI, I would think that the SystemClock_config from the timer example would be OK.

It uses RCC_OSCILLATORTYPE_HSI and

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

To get from the original example targeting the STM32F302 I

  1. Changed the target in the compiler to STM32F303RE.
  2. Changed the startup file to startup_stm32F303xes.
  3. Rebuilt all

Then I input a 1KHz square wave (0-4.5V) into PA1 (and PA0 for mode 2). Running the example hangs at

 /* wait until the transfer complete*/

 while ((DMA1->ISR & DMA_ISR_TCIF7) == RESET) 

 {

 }

I haven't yet jumped into the details of the differences between the 302 and the 303RE and was hoping not to have to.

You mentioned that I "can choose sources and PLL settings from there" I'm not sure what I would need to change to get the example code working. Doesn't the F302 have the same clocks as the F303?

Thanks,