Hal Timer not accurate (off by 4 seconds) stm32 f10x

Sysprogs forums Forums VisualGDB Hal Timer not accurate (off by 4 seconds) stm32 f10x

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9961
    Sir.Kovek
    Participant

    I’m using the the stm32f103c8 (t6) and debugging using the St link v2.

    Running on the standard nano-lib:

    Led should blink on and off every 500ms, blinking roughly every 4.5 seconds

    Open cd output:

    Open On-Chip Debugger 0.9.0 (2016-10-14) [https://github.com/sysprogs/openocd]
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    Info : auto-selecting first available session transport “hla_swd”. To override use ‘transport s
    elect <transport>’.
    Info : The selected transport took over low-level target control. The results might differ comp
    ared to plain JTAG/SWD
    adapter speed: 1000 kHz
    adapter_nsrst_delay: 100
    none separate
    Info : Unable to match requested speed 1000 kHz, using 950 kHz
    Info : Unable to match requested speed 1000 kHz, using 950 kHz
    Info : clock speed 950 kHz
    Info : STLINK v2 JTAG v27 API v2 SWIM v6 VID 0x0483 PID 0x3748
    Info : using stlink api v2
    Info : Target voltage: 3.246224
    Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
    stm32f1x.cpu: target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x0800038c msp: 0x20005000
    VisualGDB_OpenOCD_Ready
    Info : accepting ‘gdb’ connection on tcp/21776
    Info : device id = 0x20036410
    Info : flash size = 64kbytes
    stm32f1x.cpu: target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x0800038c msp: 0x20005000
    stm32f1x.cpu: target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x0800038c msp: 0x20005000
    stm32f1x.cpu: target state: halted
    target halted due to breakpoint, current mode: Thread
    xPSR: 0x61000000 pc: 0x2000003a msp: 0x20005000
    stm32f1x.cpu: target state: halted
    target halted due to debug-request, current mode: Thread
    xPSR: 0x01000000 pc: 0x0800038c msp: 0x20005000

     

    I’m very new to the embedded world but have significant experience in C/C++ and other language such as C#(irrelevant). I got myself the board since i want to create my own quad copter controller as a challenge to myself, i also picked up a discovery book for the stm32 f10x which walks your through the standard lib and more (I’m hoping to be able to easily translate what he’s doing in to the HAL on VisualGDB). I’ve set the on board LED to blink every 500 ms but it isn’t, it way off blinking at 4.5 seconds(roughly).

    Does anyone know what’s going on? The board is getting plenty of power, even plugged it into an external battery, so i can exclude that, plus it’s not resetting randomly. JTAG is blink away (red and green) when debugging if thats of any help.

    #9963
    support
    Keymaster

    Hi,

    Most likely the HSE_VALUE macro defined in your project configuration does not match the speed of the clock oscillator on your board. Please double-check your project configuration and the board schematics.

    #9972
    Sir.Kovek
    Participant

    The clock is the same as the external oscillator running at 8mhz, Even after re-creating the project i’m still getting the same result, Here an image of the settings

     

    https://s29.postimg.org/aromgek6v/Screenshot_2017_01_07_21_41_34.png

    #9973
    Sir.Kovek
    Participant

    The board runs at 70mhz with PLL

    #9980
    support
    Keymaster

    Hi,

    Thanks for clarifying this. Looks like in the latest STM32 BSP there is a small bug that prevents the oscillator speed from the wizard from being set in the project configuration.

    Please locate the stm32xxx_hal_conf.h file in your project and then double-check the HSE_VALUE defined there:

    #if !defined  (HSE_VALUE) 
      #define HSE_VALUE    ((uint32_t)25000000U) /*!< Value of the External oscillator in Hz */
    #endif /* HSE_VALUE */

    Also the default LEDBlink project does not automatically configure the PLL. To do that you can generate the configuration code using the STM32Cube software, or copy it from one of other examples for your board. The typical clock configuration function looks like this:

    static void SystemClock_Config(void)
    {
      RCC_ClkInitTypeDef RCC_ClkInitStruct;
      RCC_OscInitTypeDef RCC_OscInitStruct;
      
      /* Enable HSE Oscillator and Activate PLL with HSE as source */
      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
      RCC_OscInitStruct.HSEState = RCC_HSE_ON;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
      RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
      RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
      RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
      if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
      {
        Error_Handler(); 
      }
    
      /* Select PLL as system clock source and configure the HCLK, PCLK1 clocks dividers */
      RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
      if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1)!= HAL_OK)
      {
        Error_Handler(); 
      }
    }

     

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