2020-12-07 21:39:07 +01:00
|
|
|
#include <stdint.h>
|
2020-12-14 20:29:51 +01:00
|
|
|
#include <stm32/stm32f4xx.h>
|
|
|
|
#include <cmsis/core_cm4.h>
|
2020-12-21 17:20:49 +01:00
|
|
|
#include "hex-parser.h"
|
|
|
|
#include <fatfs/ff.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
static volatile unsigned int wait_tick;
|
2020-12-14 20:29:51 +01:00
|
|
|
|
|
|
|
static void watchdog_ack(void)
|
|
|
|
{
|
|
|
|
IWDG->KR = 0xAAAA;
|
|
|
|
}
|
|
|
|
|
2020-12-21 17:20:49 +01:00
|
|
|
void sdio_wait_ms(unsigned int ms)
|
|
|
|
{
|
|
|
|
wait_tick = 0;
|
|
|
|
while (wait_tick < ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static FATFS _fs;
|
|
|
|
#define fs (&_fs)
|
|
|
|
|
|
|
|
static void __attribute__((noreturn)) ram_code_exit(bool updated)
|
|
|
|
{
|
|
|
|
(void)updated;
|
|
|
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
while(1);
|
|
|
|
}
|
2020-12-07 21:39:07 +01:00
|
|
|
|
|
|
|
int ram_code_main(void)
|
|
|
|
{
|
2020-12-21 17:20:49 +01:00
|
|
|
FRESULT fres;
|
|
|
|
|
2020-12-14 20:29:51 +01:00
|
|
|
SysTick_Config(168000UL);
|
|
|
|
__enable_irq();
|
|
|
|
|
2020-12-21 17:20:49 +01:00
|
|
|
fres = f_mount(fs, "0:/", 1);
|
|
|
|
if (fres != FR_OK) {
|
|
|
|
ram_code_exit(false);
|
|
|
|
}
|
|
|
|
|
2020-12-14 20:29:51 +01:00
|
|
|
while(1) {
|
|
|
|
__WFI();
|
|
|
|
}
|
|
|
|
|
2020-12-07 21:39:07 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-12-14 20:29:51 +01:00
|
|
|
|
|
|
|
void SysTick_Handler(void)
|
|
|
|
{
|
|
|
|
static uint32_t tick_cnt = 0;
|
|
|
|
|
2020-12-21 17:20:49 +01:00
|
|
|
wait_tick++;
|
2020-12-14 20:29:51 +01:00
|
|
|
tick_cnt++;
|
|
|
|
watchdog_ack();
|
|
|
|
if (tick_cnt >= 250) {
|
|
|
|
GPIOB->ODR ^= (1<<2);
|
|
|
|
tick_cnt = 0;
|
|
|
|
}
|
|
|
|
}
|