From b88c9c5f1fc7c983606e638d21a326e2cab22023 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Mar 2023 13:44:51 +0100 Subject: [PATCH 1/6] debug: add DEBUG_BREAKPOINT() macro --- core/lib/include/debug.h | 21 +++++++++++++++++++++ sys/include/architecture.h | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/core/lib/include/debug.h b/core/lib/include/debug.h index 4d93e3eee6..7c67b26155 100644 --- a/core/lib/include/debug.h +++ b/core/lib/include/debug.h @@ -59,6 +59,27 @@ extern "C" { #define DEBUG_PRINT(...) printf(__VA_ARGS__) #endif +/** + * @def DEBUG_BREAKPOINT + * + * @brief Set a debug breakpoint + * + * When `DEVELHELP` is enabled, this traps the CPU and allows to debug the + * program with e.g. `gdb`. + * Without `DEVELHELP` this turns into a no-op. + * + * @warning If no Debugger is attached, the CPU might get stuck here + * and consume a lot of power until reset. + * + * @param val Breakpoint context for debugger, usually ignored. + */ +#ifdef DEVELHELP +#include "architecture.h" +#define DEBUG_BREAKPOINT(val) ARCHITECTURE_BREAKPOINT(val) +#else +#define DEBUG_BREAKPOINT(val) (void)0 +#endif + /** * @name Debugging defines * @{ diff --git a/sys/include/architecture.h b/sys/include/architecture.h index ebd7ce1c31..90f9febd6d 100644 --- a/sys/include/architecture.h +++ b/sys/include/architecture.h @@ -33,6 +33,19 @@ extern "C" { #endif +/** + * @brief Set a breakpoint + * @warning If no Debugger is attached, the CPU might get stuck here + * and consume a lot of power until reset. + * @param[in] value Context value for debugger, usually ignored. + */ +#ifndef ARCHITECTURE_BREAKPOINT +/* If no breakpoint instruction is defined, busy wait for debugger + * to attach and break to ease backtrace + */ +#define ARCHITECTURE_BREAKPOINT(value) do {} while (1) +#endif + /* Provide doxygen doc centrally, instead of in every architecture_arch.h */ #ifdef DOXYGEN /** From e850dcd921f322aa8474fade3231e0984225fcfd Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Mar 2023 13:45:41 +0100 Subject: [PATCH 2/6] cpu/cortexm_common: define ARCHITECTURE_BREAKPOINT() --- cpu/cortexm_common/include/architecture_arch.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpu/cortexm_common/include/architecture_arch.h b/cpu/cortexm_common/include/architecture_arch.h index a393f6db6b..8bb8897691 100644 --- a/cpu/cortexm_common/include/architecture_arch.h +++ b/cpu/cortexm_common/include/architecture_arch.h @@ -26,7 +26,8 @@ extern "C" { /* Doc is provided centrally in architecture.h, hide this from Doxygen */ #ifndef DOXYGEN -#define ARCHITECTURE_WORD_BITS (32U) +#define ARCHITECTURE_WORD_BITS (32U) +#define ARCHITECTURE_BREAKPOINT(value) __BKPT(value) #endif /* DOXYGEN */ #ifdef __cplusplus From fe4cc9169d57360c4bd39a70c2dec4a58a40d4f1 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Mar 2023 13:51:03 +0100 Subject: [PATCH 3/6] cpu/native: define ARCHITECTURE_BREAKPOINT() --- cpu/native/include/architecture_arch.h | 8 ++++++++ cpu/native/native_cpu.c | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/cpu/native/include/architecture_arch.h b/cpu/native/include/architecture_arch.h index ef3ebf2fa5..1a9f7ae06d 100644 --- a/cpu/native/include/architecture_arch.h +++ b/cpu/native/include/architecture_arch.h @@ -24,9 +24,17 @@ extern "C" { #endif +/** + * @brief raise SIGTRAP + * + * We must not include signal.h directly into RIOT application namespace. + */ +void native_breakpoint(void); + /* Doc is provided centrally in architecture.h, hide this from Doxygen */ #ifndef DOXYGEN #define ARCHITECTURE_WORD_BITS (32U) +#define ARCHITECTURE_BREAKPOINT(v) native_breakpoint() #endif /* DOXYGEN */ #ifdef __cplusplus diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index 7e0cf5aaa5..5e9e96875a 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -99,6 +99,11 @@ int thread_isr_stack_usage(void) return -1; } +void native_breakpoint(void) +{ + raise(SIGTRAP); +} + static inline void *align_stack(uintptr_t start, int *stacksize) { const size_t alignment = sizeof(uintptr_t); From b2d54b8459e52e9863a042094c0bb3a978d00e20 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Mar 2023 13:51:25 +0100 Subject: [PATCH 4/6] core/assert: set breakpoint on failed assertion --- core/lib/assert.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/lib/assert.c b/core/lib/assert.c index fcbed9743e..e8b27723d8 100644 --- a/core/lib/assert.c +++ b/core/lib/assert.c @@ -18,6 +18,7 @@ #include "assert.h" #include "architecture.h" #include "cpu.h" +#include "debug.h" #include "panic.h" #if IS_USED(MODULE_BACKTRACE) #include "backtrace.h" @@ -30,6 +31,7 @@ __NORETURN void _assert_failure(const char *file, unsigned line) printf("failed assertion. Backtrace:\n"); backtrace_print(); #endif + DEBUG_BREAKPOINT(1); core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION."); } @@ -39,6 +41,7 @@ __NORETURN void _assert_panic(void) #if IS_USED(MODULE_BACKTRACE) backtrace_print(); #endif + DEBUG_BREAKPOINT(1); core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION."); } From 11344241b895b7f64c27144e8a271d950c00bcab Mon Sep 17 00:00:00 2001 From: Joshua DeWeese Date: Mon, 1 May 2023 16:17:25 -0400 Subject: [PATCH 5/6] cpu/stm32/periph/dac: optimize setting DAC The current implmentation right shifted the 16 bit value passed into `dac_set()` down to the 12 bits that the DAC is actually capable of. This patch drops the shift and instead writes the 16 bit value to the DAC's left aligned 12 bit wide data holding register. --- cpu/stm32/periph/dac.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cpu/stm32/periph/dac.c b/cpu/stm32/periph/dac.c index 468bfa6c4a..c043269711 100644 --- a/cpu/stm32/periph/dac.c +++ b/cpu/stm32/periph/dac.c @@ -73,18 +73,15 @@ void dac_set(dac_t line, uint16_t value) { assert(line < DAC_NUMOF); - /* scale set value to 12-bit */ - value = (value >> 4); - -#ifdef DAC_DHR12R2_DACC2DHR +#ifdef DAC_DHR12L2_DACC2DHR if (dac_config[line].chan & 0x01) { - dev(line)->DHR12R2 = value; + dev(line)->DHR12L2 = value; } else { - dev(line)->DHR12R1 = value; + dev(line)->DHR12L1 = value; } #else - dev(line)->DHR12R1 = value; + dev(line)->DHR12L1 = value; #endif } From bf768cbccbdd3b89871299a0fbda08523cb45ddf Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 May 2023 13:48:08 +0200 Subject: [PATCH 6/6] tests/unittests: allow passing `UNIT_TESTS` via env --- tests/unittests/Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/unittests/Makefile b/tests/unittests/Makefile index ea1caca504..2d3fb7472f 100644 --- a/tests/unittests/Makefile +++ b/tests/unittests/Makefile @@ -3,12 +3,14 @@ include ../Makefile.tests_common USEMODULE += embunit -ifeq (, $(filter tests-%, $(MAKECMDGOALS))) - # the $(dir) Makefile function leaves a trailing slash after the directory - # name, therefore we use patsubst instead. - UNIT_TESTS := $(patsubst %/Makefile,%,$(wildcard tests-*/Makefile)) -else - UNIT_TESTS := $(filter tests-%, $(MAKECMDGOALS)) +ifeq (, $(UNIT_TESTS)) + ifeq (, $(filter tests-%, $(MAKECMDGOALS))) + # the $(dir) Makefile function leaves a trailing slash after the directory + # name, therefore we use patsubst instead. + UNIT_TESTS := $(patsubst %/Makefile,%,$(wildcard tests-*/Makefile)) + else + UNIT_TESTS := $(filter tests-%, $(MAKECMDGOALS)) + endif endif DISABLE_MODULE += auto_init auto_init_%