From 0e09dc75c0915167718dc90b167e87e46d94e53e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jun 2018 10:55:34 +1000 Subject: [PATCH] HAL_ChibiOS: flush all memory on chSysHalt() this makes debugging a lot easier, as gdb can see the values in dcache --- libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h | 8 +++++--- libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h index 348817bd46..a8e316c81a 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h @@ -520,11 +520,13 @@ * @brief System halt hook. * @details This hook is invoked in case to a system halting error before * the system is halted. + * + * We flush all memory on STM32F7 to allow gdb to access variables currently + * in the dcache */ - #define CH_CFG_SYSTEM_HALT_HOOK(reason) do { \ - extern int printf(const char *fmt, ...); \ - printf(reason); \ + extern void memory_flush_all(void); \ + memory_flush_all(); \ } while(0) /** diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c index 2482e9628e..4efdc2d385 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c @@ -17,6 +17,7 @@ #include #include #include +#include void stm32_timer_set_input_filter(stm32_tim_t *tim, uint8_t channel, uint8_t filter_mode) { @@ -54,3 +55,13 @@ void show_stack_usage(void) } while (tp != NULL); } #endif + +/* + flush all memory. Used in chSysHalt() + */ +void memory_flush_all(void) +{ +#if defined(STM32F7) && STM32_DMA_CACHE_HANDLING == TRUE + dmaBufferFlush(HAL_RAM_BASE_ADDRESS, HAL_RAM_SIZE_KB * 1024U); +#endif +}