Strange optimization problem TIM4

Sysprogs forums Forums VisualGDB Strange optimization problem TIM4

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12194
    jiris97
    Participant

    Hi,

    I am trying to write a simple application in C++ and HAL on STM32F405, but I am experiencing strange problem when I turn on optimization (from “None” to “Optimize for GDB”):

    The timer which I initialize for PWM control of RGB LED strip (using channel 1,2 and 3) has CCMR register set for channel to work as input instead of output as shown in the attached screenshot from VS.

    I also can not write to registers of output compare (CCR1,2,3) even with Hardware Registers view.

    The code looks as follows:

    main.cpp

    #include <stm32f4xx_hal.h>
    #include “LedStrip.h”

    int main() {
    HAL_Init();
    LedStrip::Init();
    LedStrip::SetColor(0xAA55AA); //here I set breakpoint and observe registers or manually try to set CCRx
    while (1);
    }

    The LedStrip class is attached as source files with the mentioned screenshot below.

    I am using VisualGDB 5.2R9 Embedded edition on Windows 10 x64, STM32F405, NewLib Nano or Standard library (same problem)

    Could anyone please know what I am doing wrong / where is the problem?

    Thanks in advance, Jiri

     

    //EDIT

    Can not upload .cpp file, here it is: https://1drv.ms/f/s!ApINDtgYn4CiiLpMIdDdP77qS-va7g

     

    • This topic was modified 6 years, 8 months ago by jiris97. Reason: File missing
    Attachments:
    You must be logged in to view attached files.
    #12199
    support
    Keymaster

    Hi,

    This could be caused by a bug somewhere in the code (e.g. uninitialized variable or missing ‘volatile’ keyword) that only takes effect when the code is optimized. We would advise locating the code responsible for setting the hardware registers and stepping through it in disassembly mode to understand what is going on.

    #12212
    jiris97
    Participant

    Thank you, you are right, everything works well now.

    The problem was I did not set all needed members of TIM_OC_InitTypeDef:

    TIM_OC_InitTypeDef ocChannel;
    ocChannel.OCMode = TIM_OCMODE_PWM1;
    ocChannel.OCPolarity = TIM_OCPOLARITY_HIGH;
    ocChannel.OCFastMode = TIM_OCFAST_DISABLE; //this one was missing
    ocChannel.Pulse = 0;

     

    As I found, it is masked to the CCMR register which had wrong value before: htim->Instance->CCMR1 |= sConfig->OCFastMode;

     

    Thank you again for your help and time, Jiri

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.