Files
templates/c/set-protocol/ports/stm32f407-usb-boot/boot_image.h

26 lines
939 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Проверки образа перед передачей управления приложению. Адрес стека и вектор сброса должны
* соответствовать памяти целевой платы; наличие байтов во Flash само по себе не означает
* готовность образа к запуску.
*/
#ifndef F407_BOOT_IMAGE_H
#define F407_BOOT_IMAGE_H
#include "boot_port.h"
#include <string.h>
static inline bool f407_vectors_valid(const uint8_t *image, uint32_t size)
{
uint32_t sp, pc;
if (size < 8 || size > F407_APP_SIZE) return false;
memcpy(&sp, image, 4);
memcpy(&pc, image + 4, 4);
return !(sp & 7) &&
((sp > 0x20000000UL && sp <= 0x20020000UL) ||
(sp > 0x10000000UL && sp <= 0x10010000UL)) &&
(pc & 1) && (pc & ~1UL) >= F407_APP_BASE &&
(pc & ~1UL) < F407_APP_BASE + size;
}
#endif