Skip to content

Commit 7ce3670

Browse files
committed
STM: optimize us_ticker
Provide new optimizations for us_ticker and wait_us.
1 parent f31c0aa commit 7ce3670

File tree

13 files changed

+63
-2
lines changed

13 files changed

+63
-2
lines changed

targets/TARGET_STM/TARGET_STM32F0/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32f0xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32F1/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32f1xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32F2/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@
3636
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
3737
#include "stm32f2xx_ll_usart.h"
3838

39+
#include "us_ticker_defines.h"
40+
3941
#endif

targets/TARGET_STM/TARGET_STM32F3/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32f3xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32F4/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32f4xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32F7/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32f7xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32H7/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32h7xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32L0/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32l0xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32L1/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32l1xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32L4/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
4040
#include "stm32l4xx_ll_usart.h"
4141

42+
#include "us_ticker_defines.h"
43+
4244
#endif

targets/TARGET_STM/TARGET_STM32WB/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@
4040

4141
#include "stm32wbxx_ll_rtc.h"
4242

43+
#include "us_ticker_defines.h"
44+
4345
#endif

targets/TARGET_STM/us_ticker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "us_ticker_api.h"
2121
#include "PeripheralNames.h"
2222
#include "us_ticker_data.h"
23+
#include "us_ticker_defines.h"
2324

2425
TIM_HandleTypeDef TimMasterHandle;
2526

@@ -212,9 +213,10 @@ void us_ticker_init(void)
212213
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
213214
}
214215

215-
uint32_t us_ticker_read()
216+
uint32_t (us_ticker_read)()
216217
{
217-
return TIM_MST->CNT;
218+
/* Invoke the macro */
219+
return us_ticker_read();
218220
}
219221

220222
void us_ticker_set_interrupt(timestamp_t timestamp)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef MBED_US_TICKER_DEFINES_H
18+
#define MBED_US_TICKER_DEFINES_H_
19+
20+
#include "us_ticker_data.h"
21+
22+
/* All devices have 1MHz us_ticker */
23+
#define US_TICKER_PERIOD_NUM 1
24+
#define US_TICKER_PERIOD_DEN 1
25+
26+
#if TIM_MST_BIT_WIDTH == 16
27+
#define US_TICKER_MASK 0xFFFF
28+
#elif TIM_MST_BIT_WIDTH == 32
29+
#define US_TICKER_MASK 0xFFFFFFFF
30+
#else
31+
#error "Bad TIM_MST_BIT_WIDTH"
32+
#endif
33+
34+
/* Macro-optimised form of us_ticker_read */
35+
#define us_ticker_read() (TIM_MST->CNT)
36+
37+
#endif /* MBED_US_TICKER_DEFINES_H_ */

0 commit comments

Comments
 (0)