/* * main.h * * Created: 12/20/2021 12:22:25 PM * Author: david */ #ifndef MAIN_H_ #define MAIN_H_ #include "sam.h" #include "clock_config.h" #include "pin_config.h" #include "flash_prog.h" #include "tusb.h" #include "i2c.h" #include "crc_calc.h" volatile uint32_t board_millis(void); void Delay_Millis(uint32_t delayms); #define HID_CODE_FOR_SOFTWARE_VERSION (0x2A) // ASCII '*' #define HID_CODE_FOR_BOOT_APP (0x42) // ASCII 'B' #define HID_CODE_FOR_CLEAR_APP (0x22) // ASCII '"' (double quote) #define HID_CODE_FOR_ERASE_FLASH (0x65) // ASCII 'e' #define HID_CODE_FOR_WRITE_DATA (0x44) // ASCII 'D' #define HID_CODE_FOR_PROGRAM_DATA (0x50) // ASCII 'P' #define HID_CODE_FOR_WRITE_SIG (0x64) // ASCII 'd' #define HID_CODE_FOR_PROGRAM_SIG (0x70) // ASCII 'p' #define HID_CODE_FOR_READ_SIG (0x53) // ASCII 'S' #define HID_CODE_FOR_READ_CRC (0x43) // ASCII 'C' #define HID_CODE_FOR_CALC_CRC (0x4D) // ASCII 'M' #define HID_CODE_FOR_ROM_BOOTLOADER (0x49) // ASCII 'I' // When the General Purpose Backup Registers have specific // values in them (loaded in by the application, or this // bootloader on a previous restart), specific actions // should be taken. // Power cycling will clear these registers, so it will // always be possible to break any unforseen infinite loops just by pulling the plug. // If Reg0 and Reg1 are set to the following values, this means // the bootloader needs to skip checking the app integrity and just // stay in bootloader mode #define BKUP_REG0_CODE_FOR_USB_BOOTLOADER (0x000000BBu) #define BKUP_REG1_CODE_FOR_USB_BOOTLOADER (0x0000001Au) // If Reg0 and Reg1 are set to these values (well technically, the bits 8-15 of // Reg1, because bits 0-7 are used to count number of resets) then the // internal ROM-based I2C bootloader will be launched. To force a launch of // the internal bootloader, the following things need to happen: // - GPNVM bit 1 needs to be cleared. This makes the mcu start booting // into ROM instead of Flash // - Reset using external pin 10 times in a row. The reset pin can be // set as an output, causing the mcu to reset itself. // After those happen, regardless of whether or not the Flash code // has a passing CRC code, the ROM bootloader will run. If nothing // changes in the Flash you can get back to the application code // by cycling power. #define BKUP_REG0_CODE_FOR_ROM_BOOTLOADER (0x000000AAu) #define BKUP_REG1_MASK_FOR_ROM_BOOTLOADER (0x00002C00u) #define FLASH_PAGE_SIZE (0x200u) // From SAMG55 datasheet typedef enum { BOARD_VER_UNKNOWN = 0, BOARD_VER_BS1 = 1, BOARD_VER_BS2 = 2 } board_ver_t; #endif /* MAIN_H_ */