How to initialize STM32F103 controller

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
shema
Posts: 8
Joined: 22 Aug 2016 11:33

How to initialize STM32F103 controller

#1 Post by shema » 25 Aug 2022 17:34

Hello
I'm trying to wiggle a pin with your compiler but I'm not succeeding as I want.
I want these settings. I have used them with another compiler...

Code: Select all

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}


I manage to jiggle the pin, with the wrong frequency just that.

jpg1.jpg
jpg1.jpg (340.95 KiB) Viewed 1411 times
jpg2.jpg
jpg2.jpg (139.74 KiB) Viewed 1411 times
I want to use these settings…
I can't see the code that generates the compiler!!! But something is wrong.


jpg1.jpg
jpg1.jpg (340.95 KiB) Viewed 1411 times
Attachments
jpg3.jpg
jpg3.jpg (128.18 KiB) Viewed 1411 times

shema
Posts: 8
Joined: 22 Aug 2016 11:33

Re: How to initialize STM32F103 controller

#2 Post by shema » 26 Aug 2022 15:55

I entered the system clock (72. 000 000 MHz) as the MCU frequency. I set the input frequency to HCE/2 !!! Although my crystal is 8MHz !!! That's the only way I got the frequencies right.

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: How to initialize STM32F103 controller

#3 Post by Toley » 26 Aug 2022 23:06

Hi Shema,

If you use a BluePill module, here is the clock scheme I'm using. Good luck with your projects.
STM32F103C8T6_PLL_8_to_72MHz.zip
(825 Bytes) Downloaded 92 times
Serge T.
Learning is an endeless process but it must start somewhere!

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: How to initialize STM32F103 controller

#4 Post by Thomas.Pahl@t-online.de » 28 Aug 2022 07:08

Years ago i criticized the very simple project editor (i think it was with pic32). We use a computer to input the clock frequencies of crystal and system - but we have to calculate the deviders and pll-factors ourselves.

But we have AI :D

shema
Posts: 8
Joined: 22 Aug 2016 11:33

Re: How to initialize STM32F103 controller

#5 Post by shema » 28 Aug 2022 14:29

Toley wrote:
26 Aug 2022 23:06
Hi Shema,

If you use a BluePill module, here is the clock scheme I'm using. Good luck with your projects.
STM32F103C8T6_PLL_8_to_72MHz.zip
Sorry these are not the correct settings ... there is an error.

There is no way to initialize the controller properly...

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: How to initialize STM32F103 controller

#6 Post by Thomas.Pahl@t-online.de » 28 Aug 2022 15:28

Of course there is one.
Toleys sheme is a good way.

I don't know this special chip.
But I doubt if the pll can work with 8Mhz input. There is no hint in the reference.
The ST µCs I work with, only work with 4 to 5 MHz. In that case the pre-devider must be 2 and the multiplier 18.
Please experiment. That is half of the fun :D (when it works - after hours of try and error)

Edit: I have tested Toleys sheme - no errors (only compiling tested)

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: How to initialize STM32F103 controller

#7 Post by AntiMember » 28 Aug 2022 18:04

Toleys master settings are correct. 8)
I set the input frequency to HCE/2 !!! Although my crystal is 8MHz !!!
So the resonator or its strapping gives 16 MHz. Sometimes I had to change the resonator. But rarely.
More often problems with a low-frequency resonator.

shema
Posts: 8
Joined: 22 Aug 2016 11:33

Re: How to initialize STM32F103 controller

#8 Post by shema » 28 Aug 2022 20:26

So USB, it works.
But if Delay_ms(500); depends on SysTick, it returns the wrong delay !!!

**************************
Untitled-4.jpg
Untitled-4.jpg (245.23 KiB) Viewed 1341 times

STM32CubeMX - Everything is set up perfectly.

*************************

Untitled-2.jpg
Untitled-2.jpg (95.98 KiB) Viewed 1341 times

Post Reply

Return to “mikroC PRO for ARM General”