STM32 F446RE: Error in activating timer

Hello everyone,

I am working on a code base. I want to use timer 10 with frequency of 100 MHz.

WHAT I DID:
I initialized the timer by the initialization function from STM32 CubeMX. I configured the clock rate in the file system_clock.c to the rate I want.
I declared the timer, started the time, and retrieve the clock counter by __HAL_TIM_GET_COUNTER.

WHAT I RECEIVED:
What I got from __HAL_TIM_GET_COUNTER is 0.

ASSUMPTION:
Maybe I either configured the clock incorrectly or I missed some step.

Below is the attached file of the main.c

#include "radio.h"

#if defined(SX128x_H)
    #define BW_KHZ              200
    #define SPREADING_FACTOR    7
    #define CF_HZ               2487000000
    #define TX_DBM              6
#else
    #if defined(SX126x_H)
        #define TX_DBM              (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14)
    #else
        #define TX_DBM              20
    #endif
    #define BW_KHZ              125
    #define SPREADING_FACTOR    7
    #define CF_HZ               915000000
#endif

/**********************************************************************/
EventQueue queue(4 * EVENTS_EVENT_SIZE);

TIM_HandleTypeDef htim10;
static void MX_TIM10_Init(void)
{

  /* USER CODE BEGIN TIM10_Init 0 */

  /* USER CODE END TIM10_Init 0 */

  /* USER CODE BEGIN TIM10_Init 1 */

  /* USER CODE END TIM10_Init 1 */
  htim10.Instance = TIM10;
  htim10.Init.Prescaler = 0;
  htim10.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim10.Init.Period = 65535;
  htim10.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  //htim10.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim10) != HAL_OK)
  {
    printf("Error Error\r\n");
  }
  /* USER CODE BEGIN TIM10_Init 2 */

  /* USER CODE END TIM10_Init 2 */

}


void tx_test()
{
    static uint8_t seq = 0;

    uint16_t timer_val = __HAL_TIM_GET_COUNTER(&htim10);
    Radio::radio.tx_buf[0] = seq++;  /* set payload */
    Radio::Send(1, 0, 0, 0);   /* begin transmission */
    printf("sent\r\n");
    printf("timer value = %d\r\n", timer_val);

/*    {
        mbed_stats_cpu_t stats;
        mbed_stats_cpu_get(&stats);
        printf("canDeep:%u ", sleep_manager_can_deep_sleep());
        printf("Uptime: %llu ", stats.uptime / 1000);
        printf("Sleep time: %llu ", stats.sleep_time / 1000);
        printf("Deep Sleep: %llu\r\n", stats.deep_sleep_time / 1000);
    }*/
}

void txDoneCB()
{
    printf("got-tx-done\r\n");
    queue.call_in(500, tx_test);
}

void rxDoneCB(uint8_t size, float rssi, float snr)
{
}


void radio_irq_callback()
{
    queue.call(Radio::service);
}


const RadioEvents_t rev = {
    /* DioPin_top_half */   radio_irq_callback,
    /* TxDone_topHalf */    NULL,
    /* TxDone_botHalf */    txDoneCB,
    /* TxTimeout  */        NULL,
    /* RxDone  */           rxDoneCB,
    /* RxTimeout  */        NULL,
    /* RxError  */          NULL,
    /* FhssChangeChannel  */NULL,
    /* CadDone  */          NULL
};

int main()
{
    printf("\r\nreset-tx ");

    Radio::Init(&rev);

    Radio::Standby();
    Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1);
    Radio::SetChannel(CF_HZ);

    Radio::set_tx_dbm(TX_DBM);

               // preambleLen, fixLen, crcOn, invIQ
    Radio::LoRaPacketConfig(8, false, true, false);
    MX_TIM10_Init();
    HAL_TIM_Base_Start_IT(&htim10);

    queue.call_in(500, tx_test);

    queue.dispatch();
}

Do you have any instruction on using timer like my case?

Best regards, Huy Nguyen.

I used both HAL_TIM_Base_Start_IT and HAL_TIM_Base_Start but nothing worked.

Update: I check the state of the timer 10 by htim10.state and it is in ready state.

Is it possible that clock to the timer hasn’t been enabled?

Thank you for your response.

Timer 10 takes the clock from APB2 whose source is from PLLCLK. I did a quick search about “how to enable clock in mbed os” or “enable pllclk clock mbed os” but I could not find anything.

Would you mind suggesting some places where I can find?

@MultipleMonomials I already found it. Indeed, I haven’t enabled the clock for timer 10. that’s why the counter did not start. The function to enable is __HAL_RCC_TIM10_CLK_ENABLE().

Thank you very much for suggesting me.