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-04-28 13:39:22 +00:00
|
|
|
void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, int line, const char *func) {
|
2017-04-28 17:50:51 +00:00
|
|
|
for (volatile uint32_t delay = 0; delay < 10000000; delay++) {}
|
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);
|
|
|
|
display_printf("\nFATAL ERROR:\n%s\n", msg);
|
2017-04-28 13:39:22 +00:00
|
|
|
if (file) {
|
2017-04-28 17:50:51 +00:00
|
|
|
display_printf("File: %s:%d\n", file, line);
|
2017-04-28 13:39:22 +00:00
|
|
|
}
|
|
|
|
if (func) {
|
2017-04-28 17:50:51 +00:00
|
|
|
display_printf("Func: %s\n", func);
|
2017-04-28 13:39:22 +00:00
|
|
|
}
|
2017-09-07 20:19:27 +00:00
|
|
|
for (;;);
|
2017-03-21 00:41:49 +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-04-28 17:50:51 +00:00
|
|
|
display_printf("\nassert(%s)\n", expr);
|
2017-04-28 13:39:22 +00:00
|
|
|
__fatal_error("Assertion failed", file, line, func);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 00:41:49 +00:00
|
|
|
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
|
2017-04-28 13:39:22 +00:00
|
|
|
__fatal_error("uncaught exception", __FILE__, __LINE__, __FUNCTION__);
|
2017-03-21 00:41:49 +00:00
|
|
|
}
|
2017-03-23 15:22:58 +00:00
|
|
|
|
|
|
|
extern void SystemClock_Config(void);
|
|
|
|
|
|
|
|
void periph_init(void) {
|
|
|
|
|
|
|
|
// STM32F4xx HAL library initialization:
|
|
|
|
// - configure the Flash prefetch, instruction and data caches
|
|
|
|
// - configure the Systick to generate an interrupt each 1 msec
|
|
|
|
// - set NVIC Group Priority to 4
|
|
|
|
// - global MSP (MCU Support Package) initialization
|
|
|
|
HAL_Init();
|
|
|
|
|
|
|
|
// Set the system clock to be HSE
|
|
|
|
SystemClock_Config();
|
|
|
|
|
|
|
|
// Enable GPIO clocks
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
|
|
|
|
|
// Enable the CCM RAM
|
|
|
|
__HAL_RCC_CCMDATARAMEN_CLK_ENABLE();
|
|
|
|
|
|
|
|
// Clear the reset flags
|
|
|
|
PWR->CR |= PWR_CR_CSBF;
|
|
|
|
RCC->CSR |= RCC_CSR_RMVF;
|
|
|
|
|
|
|
|
// Enable CPU ticks
|
|
|
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // Enable DWT
|
|
|
|
DWT->CYCCNT = 0; // Reset Cycle Count Register
|
|
|
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // Enable Cycle Count Register
|
|
|
|
}
|
2017-03-29 18:50:45 +00:00
|
|
|
|
|
|
|
void jump_to(uint32_t start)
|
|
|
|
{
|
|
|
|
SCB->VTOR = start;
|
|
|
|
__asm__ volatile("msr msp, %0"::"g" (*(volatile uint32_t *)start));
|
|
|
|
(*(void (**)())(start + 4))();
|
|
|
|
}
|