2017-03-21 00:41:49 +00:00
|
|
|
#include STM32_HAL_H
|
|
|
|
|
2017-04-17 16:07:34 +00:00
|
|
|
#include "common.h"
|
2017-03-21 00:41:49 +00:00
|
|
|
#include "display.h"
|
2017-10-11 10:58:36 +00:00
|
|
|
#include "rng.h"
|
2017-03-21 00:41:49 +00:00
|
|
|
|
2017-10-11 22:32:46 +00:00
|
|
|
void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func) {
|
2017-09-07 20:19:27 +00:00
|
|
|
display_orientation(0);
|
|
|
|
display_backlight(255);
|
2017-04-28 17:50:51 +00:00
|
|
|
display_print_color(COLOR_WHITE, COLOR_RED128);
|
2017-10-11 22:32:46 +00:00
|
|
|
display_printf("\nFATAL ERROR:\n");
|
|
|
|
if (expr) {
|
|
|
|
display_printf("expr: %s\n", expr);
|
|
|
|
}
|
|
|
|
if (msg) {
|
|
|
|
display_printf("msg : %s\n", msg);
|
|
|
|
}
|
2017-04-28 13:39:22 +00:00
|
|
|
if (file) {
|
2017-10-11 22:32:46 +00:00
|
|
|
display_printf("file: %s:%d\n", file, line);
|
2017-04-28 13:39:22 +00:00
|
|
|
}
|
|
|
|
if (func) {
|
2017-10-11 22:32:46 +00:00
|
|
|
display_printf("func: %s\n", func);
|
2017-04-28 13:39:22 +00:00
|
|
|
}
|
2017-10-12 14:02:40 +00:00
|
|
|
#ifdef GITREV
|
|
|
|
#define XSTR(s) STR(s)
|
|
|
|
#define STR(s) #s
|
|
|
|
display_printf("rev : %s\n", XSTR(GITREV));
|
|
|
|
#endif
|
2017-10-12 15:34:39 +00:00
|
|
|
shutdown();
|
2017-09-07 20:19:27 +00:00
|
|
|
for (;;);
|
2017-03-21 00:41:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 22:08:15 +00:00
|
|
|
uint32_t __stack_chk_guard = 0;
|
2017-10-11 19:15:22 +00:00
|
|
|
|
|
|
|
void __attribute__((noreturn)) __stack_chk_fail(void)
|
|
|
|
{
|
2017-10-26 21:51:39 +00:00
|
|
|
ensure(secfalse, "Stack smashing detected");
|
2017-10-11 19:15:22 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 13:39:22 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
void __assert_func(const char *file, int line, const char *func, const char *expr) {
|
2017-10-11 22:32:46 +00:00
|
|
|
__fatal_error(expr, "assert failed", file, line, func);
|
2017-04-28 13:39:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-05 15:31:05 +00:00
|
|
|
void hal_delay(uint32_t ms)
|
|
|
|
{
|
|
|
|
HAL_Delay(ms);
|
|
|
|
}
|
2017-10-12 22:36:12 +00:00
|
|
|
|
|
|
|
// reference RM0090 section 35.12.1 Figure 413
|
|
|
|
#define USB_OTG_HS_DATA_FIFO_RAM (USB_OTG_HS_PERIPH_BASE + 0x20000U)
|
|
|
|
#define USB_OTG_HS_DATA_FIFO_SIZE (4096U)
|
|
|
|
|
|
|
|
void clear_otg_hs_memory(void)
|
|
|
|
{
|
|
|
|
// use the HAL version due to section 2.1.6 of STM32F42xx Errata sheet
|
|
|
|
__HAL_RCC_USB_OTG_HS_CLK_ENABLE(); // enable USB_OTG_HS peripheral clock so that the peripheral memory is accessible
|
|
|
|
const uint32_t unpredictable = rng_get();
|
|
|
|
memset_reg((volatile void *) USB_OTG_HS_DATA_FIFO_RAM, (volatile void *) (USB_OTG_HS_DATA_FIFO_RAM + USB_OTG_HS_DATA_FIFO_SIZE), unpredictable);
|
|
|
|
memset_reg((volatile void *) USB_OTG_HS_DATA_FIFO_RAM, (volatile void *) (USB_OTG_HS_DATA_FIFO_RAM + USB_OTG_HS_DATA_FIFO_SIZE), 0);
|
|
|
|
__HAL_RCC_USB_OTG_HS_CLK_DISABLE(); // disable USB OTG_HS peripheral clock as the peripheral is not needed right now
|
|
|
|
}
|