Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
7daa101d
Commit
7daa101d
authored
8 years ago
by
Peter Kietzmann
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #6492 from haukepetersen/fix_stm_timerspeed
cpu/stm32_common: fixed timer speed
parents
9f1721ab
0ffd4e14
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/stm32_common/periph/timer.c
+26
-9
26 additions, 9 deletions
cpu/stm32_common/periph/timer.c
with
26 additions
and
9 deletions
cpu/stm32_common/periph/timer.c
+
26
−
9
View file @
7daa101d
...
...
@@ -22,6 +22,28 @@
#include
"cpu.h"
#include
"periph/timer.h"
/**
* @brief Timer specific additional bus clock presacler
*
* This prescale factor is dependent on the actual APBx bus clock divider, if
* the APBx presacler is != 1, it is set to 2, if the APBx prescaler is == 1, it
* is set to 1.
*
* See reference manuals section 'reset and clock control'.
*/
static
const
uint8_t
apbmul
[]
=
{
#if (CLOCK_APB1 < CLOCK_CORECLOCK)
[
APB1
]
=
2
,
#else
[
APB1
]
=
1
,
#endif
#if (CLOCK_APB2 < CLOCK_CORECLOCK)
[
APB2
]
=
2
#else
[
APB2
]
=
1
#endif
};
/**
* @brief Interrupt context for each configured timer
*/
...
...
@@ -53,15 +75,10 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
dev
(
tim
)
->
CR1
=
0
;
dev
(
tim
)
->
CR2
=
0
;
dev
(
tim
)
->
ARR
=
timer_config
[
tim
].
max
;
/* set prescaler: the STM32F1 and STM32F2 introduce a clock multiplier of 2
* in the case the APB1 prescaler is != 1, so we need to catch this
* -> see reference manual section 7.2.1 and section 5.2, respectively */
#if (defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2)) \
&& (CLOCK_APB1 < CLOCK_CORECLOCK)
dev
(
tim
)
->
PSC
=
(((
periph_apb_clk
(
timer_config
[
tim
].
bus
)
*
2
)
/
freq
)
-
1
);
#else
dev
(
tim
)
->
PSC
=
((
periph_apb_clk
(
timer_config
[
tim
].
bus
)
/
freq
)
-
1
);
#endif
/* set prescaler */
dev
(
tim
)
->
PSC
=
(((
periph_apb_clk
(
timer_config
[
tim
].
bus
)
*
apbmul
[
timer_config
[
tim
].
bus
])
/
freq
)
-
1
);
/* generate an update event to apply our configuration */
dev
(
tim
)
->
EGR
=
TIM_EGR_UG
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment