cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F101 with StdPeriph_Lib

Rami Rosenbaum (old)
Associate II
Posted on February 16, 2017 at 08:12

Hi,

I'm working on a new project, 2 boards: STM32F101CBT6 and STM32F101T6U6ATR.

I've generated a project/code via Cube (which has many advantages), but, similar to other posts - the HAL layer is, simply, lot's of code which make things complex, but not HAL-able.

The old StdPeriph_Lib was not bad, I've used it a few times successfully.

I downloaded stm32F10x_StdPeriph_Lib_V3.5.0, but it's from 2011 - is there anything more up-to-date?

I adapted the project to my STM32F101T6U6ATR (32K flash, 6K RAM, 36Mhz), and added minimal code for a 1ms SisTick and a GPIO, which toggles every second (a simple test I do, reading with an analyzer, to test the clock) - but my 1 second is about 9 seconds!!!

What am I missing?

Thanks

#stm32-stdperiph_lib #stm32f101
8 REPLIES 8
Amel NASRI
ST Employee
Posted on February 16, 2017 at 08:45

Hi

Rosenbaum.Rami

‌,

The last STM32F1 SPL library version is the one available on the web (

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32html

).

The maintenance priority is given for the Cube package.

But asyou are not convinced to use it (I am curious to know if you faced any particular issue using the Cube package), I recommend you review the clock settings of your application.

There are 2 examples in the SPL that you may take as reference:

  1. STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\SysTick\TimeBase: '

    This example shows how to configure the SysTick to generate a time base equal to1 ms. The system clock is set to 24 MHz on Value line devices and to 72 MHz on other devices, the SysTick is clocked by the AHB clock (HCLK).

    '
  2. STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\GPIO\IOToggle

-Amel

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.

AvaTar
Lead
Posted on February 16, 2017 at 11:02

... - but my 1 second is about 9 seconds!!!

What am I missing?

Perhaps that obvious design bug in the SPL header files.

Check the value of the  define '

HSE_VALUE

' in your project. If you give none, it is silently set to 8.000.000 (or 25.000.000 for the CL parts) in the header

stm32f10x.h

, instead of throwing an error.

This usually makes your clock setting fail, and fall back to the default HSI clock.

Posted on February 16, 2017 at 10:52

I did use both for reference.

Toggling a GPIO works.

Receiving SysTick interrupts work.

Only the timing is terrible.

The STM32F101 family work on 36MHz and the board I'm currently testing has no external clock.

It's not a value line, so I use the STM32F10X_LD define.

My '1000ms' toggle turns out as 4.486 seconds.

4.486 * 8MHz ~= 36MHz.

HCLK_Frequency

is 8,000,000, when calling:

RCC_GetClocksFreq(&RCC_ClockFreq);

even though

SystemCoreClock

is 36,000,000.

I must admit that configuring all these clocks/plls is new to me.

Posted on February 16, 2017 at 11:09

... even though

SystemCoreClock

is 36,000,000.

Read the comments to the

SystemCoreClockUpdate()

function in system_stm32f10x.h. The (initial) value of the 

SystemCoreClock

variable is not necessarily correct. Or rather, it is initially incorrect, since it is initialized to the target clock frequency before the function

SystemInit()

is called.
Posted on February 16, 2017 at 11:12

Hi,

In this board I don't have an HSE - I'm supposed to use the HSI.

Posted on February 16, 2017 at 11:19

This is the clock configuration that works fine, created by the CubeMX.

0690X00000606K1QAI.png
Posted on February 16, 2017 at 12:20

That is o.k., but you need to check if the files

system_stm32f10x.c

and

system_stm32f10x.h

match your purpose. They had usually been generated by an Excel Sheet (perhaps still found somewhere on the ST downloads) for a specific configuration. The SPL examples mostly use the same configuration (HSE, max. core clock), which is not what you want then.

I suggest to step through the system init code with a debugger (or just read it), and see what it actually does and what changes you would need to make.

Posted on February 16, 2017 at 12:26

I agree... bummer... hoped someone has done it already

thanks