Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/AP_Bootloader/support.h
9383 views
1
#pragma once
2
3
#include <AP_HAL_ChibiOS/AP_HAL_ChibiOS.h>
4
5
#define LED_ACTIVITY 1
6
#define LED_BOOTLOADER 2
7
8
#ifndef AP_FLASH_ECC_CHECK_ENABLED
9
#define AP_FLASH_ECC_CHECK_ENABLED defined(STM32H7) && CH_CFG_USE_HEAP
10
#endif
11
12
/* board info forwarded from board-specific code to booloader */
13
struct boardinfo {
14
uint32_t board_type;
15
uint32_t board_rev;
16
uint32_t fw_size;
17
uint32_t extf_size;
18
} __attribute__((packed));
19
20
extern struct boardinfo board_info;
21
22
void init_uarts(void);
23
int16_t cin(unsigned timeout_ms);
24
int cin_word(uint32_t *wp, unsigned timeout_ms);
25
void cout(const uint8_t *data, uint32_t len);
26
void port_setbaud(uint32_t baudrate);
27
#if defined(BOOTLOADER_FORWARD_OTG2_SERIAL)
28
bool update_otg2_serial_forward(void);
29
#endif
30
void flash_init();
31
32
uint32_t flash_func_read_word(uint32_t offset);
33
bool flash_func_write_word(uint32_t offset, uint32_t v);
34
bool flash_func_write_words(uint32_t offset, uint32_t *v, uint8_t n);
35
uint32_t flash_func_sector_size(uint32_t sector);
36
bool flash_func_is_erased(uint32_t sector);
37
bool flash_func_erase_sector(uint32_t sector, bool force_erase = false);
38
uint32_t flash_func_read_otp(uint32_t idx);
39
uint32_t flash_func_read_sn(uint32_t idx);
40
void flash_set_keep_unlocked(bool);
41
void lock_bl_port(void);
42
43
bool flash_write_flush(void);
44
bool flash_write_buffer(uint32_t address, const uint32_t *v, uint8_t nwords);
45
46
uint32_t get_mcu_id(void);
47
uint32_t get_mcu_desc(uint32_t len, uint8_t *buf);
48
49
uint32_t board_get_rtc_signature(void);
50
void board_set_rtc_signature(uint32_t sig);
51
52
void led_on(unsigned led);
53
void led_off(unsigned led);
54
void led_toggle(unsigned led);
55
56
void thread_sleep_ms(uint32_t ms);
57
void thread_sleep_us(uint32_t us);
58
59
void custom_startup(void);
60
61
#if AP_FLASH_ECC_CHECK_ENABLED
62
void check_ecc_errors(void);
63
#endif
64
65
// printf to debug uart (or USB)
66
extern "C" {
67
void uprintf(const char *fmt, ...) FMT_PRINTF(1,2);
68
}
69
70
// generate a LED sequence forever
71
void led_pulses(uint8_t npulses);
72
73
typedef struct mcu_des_t {
74
uint16_t mcuid;
75
const char *desc;
76
} mcu_des_t;
77
78
typedef struct mcu_rev_t {
79
uint16_t revid;
80
char rev;
81
} mcu_rev_t;
82
83