Timers 15-16-17 on Blue Pill

Post Reply
jcbuntu
Posts: 27
Joined: Wed Jun 02, 2021 1:47 pm
Location: Andon 06 - France

Timers 15-16-17 on Blue Pill

Post by jcbuntu »

Hello.
I wish use the timer 15 on a Blue Pill, with STM32duino IDE based on Roger's Clark core. I would use this timer for internal loop in my code, without GPIO action.
My informations are based on RM0041 (STM) and i prefer, for this, "bare metal" code.
I've seen that it's impossible to modify RCC_APB2ENR register ( RM0041 §6.3.7 p90) that is always fixed too 0x4E3D.
I use the following code :

Code: Select all

  noInterrupts();
          //Enable l'horloge du bus TIM1
  *APB2_ENR |=    (1<<16);                 //Set bit 16 (TIM15EN)

  *APB2_RSTR |=   (1<<16);
  *APB2_RSTR &=  ~(1<<16);  
  
  interrupts();


          //Enable bus TIM15
  *APB2_ENR |=   (1<<16);                 //Set bit 16 (TIM15EN)

          //Stop comptage
  *TIM15_CR1 &=  ~(1<<0);                  //Reset bit 0 (CEN)

          //Buffer  CNT
  *TIM15_CR1 |=   (1<<7);                  //set bit 7 (ARPE)

          //Divise CK_INT (72MHz) par 36000 (-> 2000Hz)
  *TIM15_PSC = 0x8CA0;            //Division de CK_INT

          //Pré-load du compteur à la tempo  ( 1000 -> 0.5s)
  *TIM15_ARR  = 0x03E8;
  
          //Enable CNT p333
  *TIM15_CR1 |=   (1<<0);                  //Set bit 0 (CEN)
This code works fine on timers 1,2,3,4 ... witch are enabled in RCC_APB2ENR and RCC_APB1ENR by STM32duino.
RM0041 indicate that STM32F103C8T6 is a medium density hardware and have timers 15,16,17 ( but not 12,13,14 !).

So, i have 2 questions :
**1 - why STM32duino set, by default, RCC_APB2ENR = 0x4E3D ?
**2 - why i can't modify this register ?

Code: Select all

Enter in Setup()    - APB2_ENR = 4E3D  APB1_ENR =  = 7  PSC = 1     ARR = FFFF
After Init TIM15() - APB2_ENR = 4E3D  APB1_ENR =  = 7  PSC = 8CA0  ARR = 3E8
NB : these registers variables work fine and are definite before in my code.
jcbuntu
Posts: 27
Joined: Wed Jun 02, 2021 1:47 pm
Location: Andon 06 - France

Re: Timers 15-16-17 on Blue Pill

Post by jcbuntu »

... sorry ! I've pushed submit function and not preview ... I've forgot -> Thank you for help.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Timers 15-16-17 on Blue Pill

Post by mrburnette »

Roger's core started from this previous effort... check right-hand pane.

http://docs.leaflabs.com/docs.leaflabs.com/index.html
jcbuntu
Posts: 27
Joined: Wed Jun 02, 2021 1:47 pm
Location: Andon 06 - France

Re: Timers 15-16-17 on Blue Pill

Post by jcbuntu »

Hello, mrburnette.

Sorry for my later answer ... and thank you for your's.
I've not seen where is the information ! Documentation say about timers on mapple, and it's only about timers 1 -> 8.
I would know in witch folder is the code file that init the STM32F103 . It's mean that some registers are re-writed AFTER user code is linked ...
i've had the same problem with interrupt handlers and solved this by over-writing core's files.
One thing is really OK : RM0041 have a chapiter about timers 15, 16 and 17 ( p. 390) on medium integration device, and roger's core lock them !
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Timers 15-16-17 on Blue Pill

Post by mrburnette »

Libmaple by Leaflabs is "Roger's core" baseline. Roger and the original forum stm32duinoforum.com took Leaflab's effort and enhanced it.

But only 4 timers are used in that implementation.

http://docs.leaflabs.com/docs.leaflabs.com/index.html

The timer class reference is here: http://docs.leaflabs.com/static.leaflab ... r.html#id4

STM32F103C8xx
The STM32F103xx medium-density performance line family incorporates the high-performance ARM®Cortex®-M3 32-bit RISC core operating at a 72 MHz frequency, high-speed embedded memories (Flash memory up to 128 Kbytes and SRAM up to 20 Kbytes), and an extensive range of enhanced I/Os and peripherals connected to two APB buses. All devices offer two 12-bit ADCs, three general purpose 16-bit timers plus one PWM timer, as well as standard and advanced communication interfaces: up to two I2Cs and SPIs, three USARTs, an USB and a CAN.
jcbuntu
Posts: 27
Joined: Wed Jun 02, 2021 1:47 pm
Location: Andon 06 - France

Re: Timers 15-16-17 on Blue Pill

Post by jcbuntu »

OK, confirmed by datasheet STM32F103X8 n°ID13587 §2.3.15. This STM32 have 4 timers ( + TIM6 and 7 for ADC).
So, i don't understand why RM0041 says that TIM15, 16, 17 are for all devices :
15 General-purpose timers (TIM15/16/17)
Low-density value line devices are STM32F100xx microcontrollers where the Flash
memory density ranges between 16 and 32 Kbytes.
Medium-density value line devices are STM32F100xx microcontrollers where the Flash
memory density ranges between 64 and 128 Kbytes.
High-density value line devices are STM32F100xx microcontrollers where the Flash
memory density ranges between 256 and 512 Kbytes.
This section applies to the whole STM32F100xx family, unless otherwise specified.
All is, probably, in "unless otherwise specified" ;)
I've seen, in the timer.h, that TIM 5,6,7,8 are defined in § Devices and § Register Map Base Pointers. I analyse this and return with you.
Thank you for your answer.
jcbuntu
Posts: 27
Joined: Wed Jun 02, 2021 1:47 pm
Location: Andon 06 - France

Re: Timers 15-16-17 on Blue Pill

Post by jcbuntu »

Timer.h in directorie

Code: Select all

.../hardware/Arduino_STM32-master/STM32F1/system/libmaple/stm323f1/include/series/timer.h
limit the timers for low and medium integration at TIM1 -> TIM4 and TIM1->TIM17 for LSI.
So, all is OK without RM 0041 which make me confusions ! ( fig 1 p.35 and table 1 p.36). Pitty !!!

thank you for help
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: Timers 15-16-17 on Blue Pill

Post by Bakisha »

jcbuntu wrote: Sat Sep 25, 2021 1:56 pm So, i don't understand why RM0041 says that TIM15, 16, 17 are for all devices :
RM0041 is reference manual for STM32F100xx.
RM0008 is for Bluepill (medium density, STM32F103xx). Page 40.
Post Reply

Return to “STM32F1 based boards”