cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103c8 classB

jihoon
Associate II

hello,

 

I am applying the safety library provided by st company to stm32f103c8.
In the example provided, the capture function of TIM5 is connected to the LSI oscillator, but the MCU (stm32f103c8) I use does not seem to be able to connect to the LSI oscillator.
I need your advice.

1 ACCEPTED SOLUTION

Accepted Solutions

>>Can you check my code why TIM4_IRQHandler is not working?

You can't just invent connectivity to TIM4_CH4 and expect it to work. Or randomly cut-n-paste code from entirely different parts with different functionality and plumbing.

To get to the RTC / LSI clock you'd need to push it out the TAMPER pin and loop it back to a TIM pin you can actually monitor.

You could also watch the RTC count, or generate interrupts on a periodic basis.

How is it that those who know the least about coding and the MCU get tasked with "safety" ?

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

View solution in original post

9 REPLIES 9
TDK
Guru

The STM32F103C8 doesn't have a TIM5, only TIM1-4.

If you feel a post has answered your question, please click "Accept as Solution".
jihoon
Associate II

hi, Guru.

Thank you for your quick response.

You're right.

Stm32f103C8 has TIM1-TIM4, but any TIMx can't connect LSI oscillator.
if The TIM1-TIM4 of stm32f103c8 can't connect LSI oscillator, The Clock start-up self(and run) test of Functional Safety can't checked.

I'm not sure what your code is supposed to do, but it is correct that none of the timers can be clocked from LSI. However, RTC can be clocked from LSI and presumably can give you the same type of error checking functionality.

If you feel a post has answered your question, please click "Accept as Solution".
STTwo-32
ST Employee

Hello @jihoon and welcome to the ST Community :smiling_face_with_smiling_eyes:.

As said @TDK WE don't know exactly what you want to do. So, i suggest you give us more informations about your needs.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

jihoon
Associate II

 

Can you check my code why TIM4_IRQHandler is not working?
 
There is an example using RTC in the stm32f373 safety library, so I referred to it..
stm32f373 use TIM16 Channel1, and stm32f103 useTIM4 Channel 4
 
ErrorStatus STL_InitClock_Xcross_Measurement(void)
{
  ErrorStatus result = SUCCESS;
  TIM_HandleTypeDef  tim_capture_handle;
  TIM_IC_InitTypeDef tim_input_config;
  RCC_OscInitTypeDef        RCC_OscInitStruct;
  RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;
  
  __PWR_CLK_ENABLE();
  HAL_PWR_EnableBkUpAccess();
 
  /* Configue LSI as RTC clock soucre */
  RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  { 
    result = ERROR;
  }
 
  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  {
    result = ERROR;
  }
  /* Enable RTC Clock */
  __HAL_RCC_RTC_ENABLE();
  
  /*## Enable peripherals and GPIO Clocks ####################################*/
  /* TIMx Peripheral clock enable */
__TIM4_CLK_ENABLE();
  
  /*## Configure the NVIC for TIMx ###########################################*/
  HAL_NVIC_SetPriority(TIM4_IRQn, 4u, 0u);
  
  /* Enable the TIM4 global Interrupt */
  HAL_NVIC_EnableIRQ(TIM4_IRQn);
  
  /* TIM4 configuration: Input Capture mode ---------------------
  The LSI oscillator is connected to TIM4 CH4.
  The Rising edge is used as active edge, ICC input divided by 8
  The TIM4 CCR4 is used to compute the frequency value. 
  ------------------------------------------------------------ */
  tim_capture_handle.Instance = TIM4;
  tim_capture_handle.Init.Prescaler         = 0u; 
  tim_capture_handle.Init.CounterMode       = TIM_COUNTERMODE_UP;  
  tim_capture_handle.Init.Period            = 0xFFFFFFFFul; 
  tim_capture_handle.Init.ClockDivision     = 0u;     
  tim_capture_handle.Init.RepetitionCounter = 0u;
  /* define internal HAL driver status here as handle structure is defined locally */
  __HAL_RESET_HANDLE_STATE(&tim_capture_handle);
  if(HAL_TIM_IC_Init(&tim_capture_handle) != HAL_OK)
  {
    /* Initialization Error */
    result = ERROR;
  }
/* Connect internally the TIM16_CH1 Input Capture to the LSI clock output */
//HAL_TIMEx_RemapConfig(&tim_capture_handle, TIM_TIM16_RTC, TIM_TIM16_NONE);

/* Configure the TIM16 Input Capture of channel 1 */
  tim_input_config.ICPolarity  = TIM_ICPOLARITY_RISING;
  tim_input_config.ICSelection = TIM_ICSELECTION_DIRECTTI;
  tim_input_config.ICPrescaler = TIM_ICPSC_DIV8;
  tim_input_config.ICFilter    = 0u;
  if(HAL_TIM_IC_ConfigChannel(&tim_capture_handle, &tim_input_config, TIM_CHANNEL_4) != HAL_OK)
  {
    /* Initialization Error */
    result = ERROR;
  }
  
  /* Reset the flags */
  tim_capture_handle.Instance->SR = 0u;
  LSIPeriodFlag = 0u;
 
  /* Start the TIM Input Capture measurement in interrupt mode */
  if(HAL_TIM_IC_Start_IT(&tim_capture_handle, TIM_CHANNEL_4) != HAL_OK)
  {
    /* Initialization Error */
    result = ERROR;
  }
 
  return(result);
}

Thank you for your interest.

 

/* Internally connect the TIM16_CH1 input capture to the LSI clock output */
//HAL_TIMEx_RemapConfig(&TIM_capture_handle, TIM_TIM16_RTC, TIM_TIM16_NONE);

How can stm32f103c8 connect Timer to LSI clock output as above example?

 

 

>>Can you check my code why TIM4_IRQHandler is not working?

You can't just invent connectivity to TIM4_CH4 and expect it to work. Or randomly cut-n-paste code from entirely different parts with different functionality and plumbing.

To get to the RTC / LSI clock you'd need to push it out the TAMPER pin and loop it back to a TIM pin you can actually monitor.

You could also watch the RTC count, or generate interrupts on a periodic basis.

How is it that those who know the least about coding and the MCU get tasked with "safety" ?

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

Thank you for your interest

/* Internally connect the TIM16_CH1 input capture to the LSI clock output */
//HAL_TIMEx_RemapConfig(&TIM_capture_handle, TIM_TIM16_RTC, TIM_TIM16_NONE);

How can stm32f103c8 connect Timer to LSI clock output as above example?

If I can't connect, can't stm32f103c8 implement clock of safety function?

Dear Tesla DeLorean

You're right.
I'm not good enough, and I tried to solve it only within the example code.
However, using the timer and rtc counter values as your advice, it will be possible to check the validity of the cpu clock of safety.
I hope to receive your help in the future.
I respect you.

Thank you so much.