1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

cpu/stm32/qdec: test null callback pointer (#14125)

cpu/stm32/qdec: test if callback pointer is set

Callback pointer is not tested and could result in a hard fault
if the pointer is NULL.
Thus only activate interrupt if a callback provided.

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
This commit is contained in:
Gilles DOFFE 2020-07-10 15:05:53 +02:00 committed by GitHub
parent 547a880fa6
commit 892370121d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,9 +114,13 @@ int32_t qdec_init(qdec_t qdec, qdec_mode_t mode, qdec_cb_t cb, void *arg)
isr_ctx[qdec].cb = cb;
isr_ctx[qdec].arg = arg;
/* Enable the qdec's interrupt */
NVIC_EnableIRQ(qdec_config[qdec].irqn);
dev(qdec)->DIER |= TIM_DIER_UIE;
/* Enable the qdec's interrupt only if there is a callback provided */
if (cb) {
NVIC_EnableIRQ(qdec_config[qdec].irqn);
dev(qdec)->DIER |= TIM_DIER_UIE;
} else {
dev(qdec)->DIER &= ~TIM_DIER_UIE;
}
/* Reset counter and start qdec */
qdec_start(qdec);