Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ cmake-variants.yaml
CMakeUserPresets.json

# CLion
cmake-build-*/
cmake-build-*/

# Test executor runs
test-executor-build/
test-executor-results/
5 changes: 5 additions & 0 deletions hal/include/hal/lp_ticker_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ uint32_t lp_ticker_read(void);
* we want to wake up far in the future, we will instead set a wakeup for about (rollover period/2) ticks
* in the future, then reschedule the timer for the correct time.
*
* @note Some hardware implementations do not support setting an interrupt for after the ticker rolls over
* (e.g. the STM32 LPTIM, which implements a >= comparison for interrupts rather than an == comparison).
* For these implementations, it is acceptable to schedule the interrupt for the time that the ticker
* rolls over. Higher level code will then reschedule the interrupt for the correct time.
*
* Calling this function with timestamp of more than the supported
* number of bits returned by ::lp_ticker_get_info results in undefined
* behavior.
Expand Down
5 changes: 5 additions & 0 deletions hal/include/hal/us_ticker_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ uint32_t (us_ticker_read)(void);
* we want to wake up far in the future, we will instead set a wakeup for about (rollover period/2) ticks
* in the future, then reschedule the timer for the correct time.
*
* @note Some hardware implementations do not support setting an interrupt for after the ticker rolls over
* (e.g. the STM32 LPTIM, which implements a >= comparison for interrupts rather than an == comparison).
* For these implementations, it is acceptable to schedule the interrupt for the time that the ticker
* rolls over. Higher level code will then reschedule the interrupt for the correct time.
*
* Calling this function with timestamp of more than the supported
* number of bits returned by ::us_ticker_get_info results in undefined
* behavior.
Expand Down
4 changes: 2 additions & 2 deletions hal/tests/TESTS/mbed_hal/common_tickers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ void ticker_overflow_test(void)

const uint32_t after_overflow = intf->read();

// Interrupt should NOT have fired yet
TEST_ASSERT_EQUAL_INT(0, intFlag);
// Note: at this point the interrupt may or may not have fired, depending on implementation.
// See lp_ticker_set_interrupt() docs for details.

/* Now we are just after overflow. Wait a while assuming that ticker still counts. */
while (intf->read() < isrTicksAfterOverflow + TICKER_DELTA) {
Expand Down
2 changes: 1 addition & 1 deletion hal/tests/TESTS/mbed_hal/rtc_reset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(NOT "DEVICE_RTC=1" IN_LIST MBED_TARGET_DEFINITIONS)
set(TEST_SKIPPED "RTC is not supported for this target")
endif()

if(NOT "TARGET_K64F" IN_LIST MBED_TARGET_DEFINITIONS)
if("TARGET_K64F" IN_LIST MBED_TARGET_DEFINITIONS)
# Currently this test works OK, but causes the next 5-10 programming operations with OpenOCD to fail
set(TEST_SKIPPED "This test causes issues with this target's debug interface")
endif()
Expand Down
24 changes: 13 additions & 11 deletions targets/TARGET_STM/lp_ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

#endif // (DUAL_CORE) && (TARGET_STM32H7)


#define LPTIM_PERIOD 0xFFFF

LPTIM_HandleTypeDef LptimHandle;

Expand Down Expand Up @@ -267,7 +267,7 @@ void lp_ticker_init(void)
LptimHandle.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_FALLING;
#endif
#if defined(TARGET_STM32U5) || defined(TARGET_STM32U0)
LptimHandle.Init.Period = 0xFFFF;
LptimHandle.Init.Period = LPTIM_PERIOD;
#endif
#if defined (LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION)
LptimHandle.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
Expand Down Expand Up @@ -333,7 +333,7 @@ void lp_ticker_init(void)
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPOK);

HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF);
HAL_LPTIM_Counter_Start(&LptimHandle, LPTIM_PERIOD);

/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
Expand Down Expand Up @@ -465,9 +465,9 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)

/* If this target timestamp is close to the roll over of the ticker counter
* and current tick is also close to the roll over, then we are in danger zone.*/
if (((0xFFFF - LP_TIMER_SAFE_GUARD < timestamp) || (timestamp < LP_TIMER_SAFE_GUARD)) && (0xFFFA < last_read_counter)) {
if (((LPTIM_PERIOD - LP_TIMER_SAFE_GUARD < timestamp) || (timestamp < LP_TIMER_SAFE_GUARD)) && (0xFFFA < last_read_counter)) {
roll_over_flag = true;
/* Change the lp_delayed_counter buffer in that way so the value of (0xFFFF - LP_TIMER_SAFE_GUARD) is equal to 0.
/* Change the lp_delayed_counter buffer in that way so the value of (LPTIM_PERIOD - LP_TIMER_SAFE_GUARD) is equal to 0.
* By doing this it is easy to check if the value of timestamp get outdated by delaying its programming
* For example if LP_TIMER_SAFE_GUARD is set to 5
* (0xFFFA + LP_TIMER_SAFE_GUARD + 1) & 0xFFFF = 0
Expand Down Expand Up @@ -499,23 +499,26 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
}
}

/* Then check if this target timestamp is not in the past, or close to wrap-around
/* Then check if this target timestamp is in the past and we are not close to wrap-around.
* Let's assume last_read_counter = 0xFFFC, and we want to program timestamp = 0x100
* The interrupt will not fire before the CMPOK flag is OK, so there are 2 cases:
* in case CMPOK flag is set by HW after or at wrap-around, then this will fire only @0x100
* in case CMPOK flag is set before, it will indeed fire early, as for the wrap-around case.
* (this is because the comparison is implemented as ">= CMP" rather than "== CMP" as indicated
* by the reference manual, see https://community.st.com/t5/stm32-mcus-embedded-software/lptim-compare-interruption-sometimes-is-triggered-when-it-should/td-p/85513 )
*
* But that will take at least 3 cycles and the interrupt fires at the end of a cycle.
* In our case 0xFFFC + 3 => at the transition between 0xFFFF and 0.
* If last_read_counter was 0xFFFB, it should be at the transition between 0xFFFE and 0xFFFF.
* There might be crossing cases where it would also fire @ 0xFFFE, but by the time we read the counter,
* it may already have moved to the next one, so for now we've taken this as margin of error.
*/
if ((timestamp < last_read_counter) && (last_read_counter <= (0xFFFF - LP_TIMER_SAFE_GUARD))) {
/* Workaround, because limitation */
if ((timestamp < last_read_counter) && (last_read_counter <= (LPTIM_PERIOD - LP_TIMER_SAFE_GUARD))) {
/* Workaround, because limitation. Trigger the interrupt when we are about to roll over. */
#if defined(LPTIM_CHANNEL_1)
__HAL_LPTIM_COMPARE_SET(&LptimHandle, LPTIM_CHANNEL_1, ~0);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, LPTIM_CHANNEL_1, LPTIM_PERIOD);
#else
__HAL_LPTIM_COMPARE_SET(&LptimHandle, ~0);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, LPTIM_PERIOD);
#endif
} else {
/* It is safe to write */
Expand All @@ -524,7 +527,6 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
#else
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
#endif

}

/* We just programed the CMP so we'll need to wait for cmpok before
Expand Down
46 changes: 46 additions & 0 deletions targets/upload_method_cfg/NUCLEO_WL55JC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Mbed OS upload method configuration file for target NUCLEO_WL55JC.
# To change any of these parameters from their default values, set them in your build script between where you
# include mbed_toolchain_setup and where you add mbed os as a subdirectory.

# Notes:
# 1. Using this device with PyOCD requires installing a pack:
# $ pyocd pack install stm32wl55jcix
# However, in my testing, PyOCD appeared to flash successfully but the code does not run correctly.


# General config parameters
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT MBED)

# Config options for MBED
# -------------------------------------------------------------

set(MBED_UPLOAD_ENABLED TRUE)
set(MBED_RESET_BAUDRATE 115200)

# Config options for PYOCD
# -------------------------------------------------------------

#set(PYOCD_UPLOAD_ENABLED TRUE)
#set(PYOCD_TARGET_NAME stm32wl55jcix)
#set(PYOCD_CLOCK_SPEED 4000k)

# Config options for OPENOCD
# -------------------------------------------------------------

set(OPENOCD_UPLOAD_ENABLED TRUE)
set(OPENOCD_CHIP_CONFIG_COMMANDS
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/st_nucleo_wlx.cfg)

# Config options for STM32Cube
# -------------------------------------------------------------

set(STM32CUBE_UPLOAD_ENABLED TRUE)
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
set(STM32CUBE_GDBSERVER_ARGS --swd)

# Config options for stlink
# -------------------------------------------------------------

set(STLINK_UPLOAD_ENABLED TRUE)
set(STLINK_ARGS --connect-under-reset)
12 changes: 12 additions & 0 deletions targets/upload_method_cfg/openocd_cfgs/st_nucleo_wlx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OpenOCD config file for Nucleo WLx boards

adapter driver hla
hla_layout stlink
hla_device_desc "ST-LINK/V3"

# ST-LINK V3 0483:374e
hla_vid_pid 0x0483 0x374e

transport select hla_swd

source [find target/stm32wlx.cfg]