Skip to main content
Fede Rico
Associate III
September 27, 2016
Question

TIM1 remap cause debug crash

  • September 27, 2016
  • 4 replies
  • 898 views
Posted on September 27, 2016 at 12:26

Hi there,

I build a Keil project for my STM32F103 MCU with STM32CubeMx.

My goal is use the TIM1 channel 2 for control a Buzzer.

I want to generate a PWM at 4KHz through TIM1 channel 2.

I configured, with STM32CubeMx, the TIM1_Channel2 as ''PWM Generator CH2''.

The problem regards the debug session. In particular, when I start the debug session and when the MCU executes the macro ''__HAL_AFIO_REMAP_TIM1_ENABLE()'' the debug session crash.

Anyone have the same issue?

Thanks!
    This topic has been closed for replies.

    4 replies

    Walid FTITI_O
    Visitor II
    September 27, 2016
    Posted on September 27, 2016 at 13:37

    Hi fede.rico,

    You should set the DBG_TIM1_STOP bit to debug a timer code.

    -Hannibal-
    Fede Rico
    Fede RicoAuthor
    Associate III
    September 27, 2016
    Posted on September 27, 2016 at 14:01

    I don't need to debug the timer code.

    My problem regard the pin remap macro. 

    At start up, the firmware initialise the the peripheral (auto-generated code) and when the code ''__HAL_AFIO_REMAP_TIM1_ENABLE()  MODIFY_REG(AFIO->MAPR, AFIO_MAPR_TIM1_REMAP, AFIO_MAPR_TIM1_REMAP_FULLREMAP)'' in executed, the debug session crash.

    This is the problem.

    Walid FTITI_O
    Visitor II
    September 28, 2016
    Posted on September 28, 2016 at 16:46

    Hi fede.rico, 

    You would share the code ( part that contains the remapping) and .ioc file.

    -Hannibal-

    Fede Rico
    Fede RicoAuthor
    Associate III
    September 30, 2016
    Posted on September 30, 2016 at 12:03

    Hi,

    I'm sorry but I can't share the code, I can add some pieces of code. This is the code for timer initialisation (generated by CubeMx):

    void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
    {
    GPIO_InitTypeDef GPIO_InitStruct;
    if(htim->Instance==TIM1)
    {
    /* USER CODE BEGIN TIM1_MspPostInit 0 */
    /* USER CODE END TIM1_MspPostInit 0 */
    /**TIM1 GPIO Configuration 
    PE11 ------> TIM1_CH2 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_11;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
    __HAL_AFIO_REMAP_TIM1_ENABLE();
    /* USER CODE BEGIN TIM1_MspPostInit 1 */
    /* USER CODE END TIM1_MspPostInit 1 */
    }
    }

    In particular, the debug session stuck on ''

    __HAL_AFIO_REMAP_TIM1_ENABLE();''

    This is the macro code:

    /**
    * @brief Enable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, external trigger (ETR) and Break input (BKIN)
    * @note ENABLE: Full remap (ETR/PE7, CH1/PE9, CH2/PE11, CH3/PE13, CH4/PE14, BKIN/PE15, CH1N/PE8, CH2N/PE10, CH3N/PE12)
    * @retval None
    */
    #define __HAL_AFIO_REMAP_TIM1_ENABLE() MODIFY_REG(AFIO->MAPR, AFIO_MAPR_TIM1_REMAP, AFIO_MAPR_TIM1_REMAP_FULLREMAP)

    I think that the problem is related to TIM1 pin remap. Thanks.