diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c index 1651faaab2..eae3314eb0 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c @@ -353,3 +353,74 @@ void stm32_cacheBufferFlush(const void *p, size_t size) { cacheBufferFlush(p, size); } + + +#ifdef HAL_GPIO_PIN_FAULT +/* + optional support for hard-fault debugging using soft-serial output to a pin + To use this setup a pin like this: + + Pxx FAULT OUTPUT HIGH + + for some pin Pxx + + On a STM32F405 the baudrate will be around 42kBaud. Use the + auto-baud function on your logic analyser to decode +*/ +/* + send one bit out a debug line + */ +static void fault_send_bit(ioline_t line, uint8_t b) +{ + palWriteLine(line, b); + for (uint32_t i=0; i<1000; i++) { + palWriteLine(line, b); + } +} + +/* + send a byte out a debug line + */ +static void fault_send_byte(ioline_t line, uint8_t b) +{ + fault_send_bit(line, 0); // start bit + for (uint8_t i=0; i<8; i++) { + uint8_t bit = (b & (1U<