Skip to content

STM32 LPTICKER with LPTIM optimisation #8771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2018
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
18 changes: 14 additions & 4 deletions targets/TARGET_STM/lp_ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include "lp_ticker_api.h"
#include "mbed_error.h"

#if !defined(LPTICKER_DELAY_TICKS) || (LPTICKER_DELAY_TICKS < 3)
#warning "lpticker_delay_ticks value should be set to 3"
#endif

LPTIM_HandleTypeDef LptimHandle;

const ticker_info_t *lp_ticker_get_info()
Expand Down Expand Up @@ -145,6 +149,12 @@ void lp_ticker_init(void)

__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF);

/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, 0);
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init is normally called outside critical section, so this should presumably be fine usually, but I see one critical section call in ticker_resume, but I don't see that used? Just wondering if there's a potential IRQ latency issue there.

}
}

static void LPTIM1_IRQHandler(void)
Expand Down Expand Up @@ -191,12 +201,12 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
LptimHandle.Instance = LPTIM1;
irq_handler = (void (*)(void))lp_ticker_irq_handler;

__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
/* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
}
/* LPTICKER_DELAY_TICKS value prevents OS to call this set interrupt function before CMPOK */
MBED_ASSERT(__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == SET);
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);

lp_ticker_clear_interrupt();

Expand Down
17 changes: 17 additions & 0 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0744"],
"device_has_add": [
"ANALOGOUT",
Expand Down Expand Up @@ -2395,6 +2396,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0743"],
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
"device_has_add": [
Expand Down Expand Up @@ -2431,6 +2433,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0743"],
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
"device_has_add": [
Expand Down Expand Up @@ -2646,6 +2649,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"macros_add": ["USBHOST_OTHER"],
"supported_form_factors": ["ARDUINO"],
"detect_code": ["0816"],
Expand Down Expand Up @@ -2691,6 +2695,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"macros_add": [
"TRANSACTION_QUEUE_SIZE_SPI=2",
"USBHOST_OTHER",
Expand Down Expand Up @@ -2743,6 +2748,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"supported_form_factors": ["ARDUINO"],
"macros_add": ["USBHOST_OTHER"],
"detect_code": ["0818"],
Expand Down Expand Up @@ -2902,6 +2908,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0770"],
"device_has_add": [
"ANALOGOUT",
Expand Down Expand Up @@ -2932,6 +2939,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0779"],
"device_has_add": [
"ANALOGOUT",
Expand Down Expand Up @@ -2990,6 +2998,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0765"],
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"],
"device_has_add": [
Expand Down Expand Up @@ -3047,6 +3056,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0827"],
"macros_add": [
"USBHOST_OTHER",
Expand Down Expand Up @@ -3433,6 +3443,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0815"],
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
"device_has_add": [
Expand Down Expand Up @@ -3476,6 +3487,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0817"],
"macros_add": ["USB_STM_HAL", "USBHOST_OTHER"],
"device_has_add": [
Expand Down Expand Up @@ -3509,6 +3521,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"supported_form_factors": ["ARDUINO"],
"detect_code": ["0764"],
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"],
Expand Down Expand Up @@ -3540,6 +3553,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0820"],
"macros_add": ["USBHOST_OTHER", "TWO_RAM_REGIONS"],
"device_has_add": [
Expand Down Expand Up @@ -6844,6 +6858,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0822"],
"device_has_add": [
"ANALOGOUT",
Expand Down Expand Up @@ -6874,6 +6889,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0823"],
"device_has_add": [
"ANALOGOUT",
Expand Down Expand Up @@ -6908,6 +6924,7 @@
"value": 1
}
},
"overrides": { "lpticker_delay_ticks": 3 },
"detect_code": ["0776"],
"device_has_add": [
"ANALOGOUT",
Expand Down