SAM0 USB Host Mass Storage Bootloader Application with CRC Check.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <string.h>
#include "conf_usb_host.h"
#include "conf_bootloader.h"
#include "main.h"
Macros | |
#define | MSC_DELAY_SOF_COUNT 1000 |
Functions | |
static void | bootloader_system_init (void) |
Initializes the device for the bootloader. More... | |
static void | check_boot_mode (void) |
static bool | integrity_check_in_disk (void) |
Function to check the integrity of the firmware in usb disk. More... | |
static bool | integrity_check_in_flash (void) |
Function to check the integrity of the firmware in internal flash. More... | |
int | main (void) |
Main function. More... | |
void | main_usb_connection_event (uhc_device_t *dev, bool b_present) |
Callback on enumeration status change of a MSC device. More... | |
void | main_usb_sof_event (void) |
Notify that a SOF has been sent (each 1 ms) More... | |
static bool | program_memory (void) |
Function to program the Flash. More... | |
static void | start_application (void) |
Function to start the application. More... | |
static void | start_application_with_wdt (void) |
Function to issue a WDT reset to start the application. More... | |
Variables | |
COMPILER_WORD_ALIGNED volatile uint8_t | buffer [FLASH_BUFFER_SIZE] |
static DIR | file_dir |
static FIL | file_object |
static uint32_t | firmware_crc = 0 |
static FATFS | fs |
char | input_file_name [] |
static volatile bool | lun_connected = false |
static TCHAR | root_directory [20] = {'0', ':', 0} |
static volatile uint32_t | sof_count = 0 |
#define MSC_DELAY_SOF_COUNT 1000 |
Referenced by main().
|
static |
Initializes the device for the bootloader.
References cpu_irq_enable, delay_ms, port_config::direction, LED0_PIN, nvm_config::manual_page_write, nvm_get_config_defaults(), nvm_set_config(), port_get_config_defaults(), PORT_PIN_DIR_OUTPUT, port_pin_set_config(), sleepmgr_init(), system_init(), and uhc_start().
Referenced by main().
|
static |
References APP_START_ADDRESS, board_init(), BUTTON_0_ACTIVE, BUTTON_0_PIN, port_pin_get_input_level(), and start_application().
Referenced by main().
|
static |
Function to check the integrity of the firmware in usb disk.
References APP_BINARY_OFFSET, APP_CRC_POLYNOMIAL_TYPE, APP_SIGNATURE, buffer, CRC_TYPE_16, dma_crc_disable(), dma_crc_get_checksum(), dma_crc_get_config_defaults(), dma_crc_io_calculation(), dma_crc_io_enable(), f_close(), f_lseek(), f_open(), f_read(), FA_OPEN_EXISTING, FA_READ, firmware_crc, FLASH_BUFFER_SIZE, input_file_name, and dma_crc_config::type.
Referenced by main().
|
static |
Function to check the integrity of the firmware in internal flash.
References APP_BINARY_OFFSET, APP_CRC_POLYNOMIAL_TYPE, APP_START_ADDRESS, CRC_TYPE_16, dma_crc_disable(), dma_crc_get_checksum(), dma_crc_get_config_defaults(), dma_crc_io_calculation(), dma_crc_io_enable(), firmware_crc, FLASH_BUFFER_SIZE, FIL::fsize, nvm_read_buffer(), and dma_crc_config::type.
Referenced by program_memory().
int main | ( | void | ) |
Main function.
Execution starts here.
References APP_MAX_SIZE, bootloader_system_init(), check_boot_mode(), cpu_irq_disable, f_close(), f_mount(), f_open(), f_opendir(), FA_OPEN_EXISTING, FA_READ, FR_OK, FIL::fsize, input_file_name, integrity_check_in_disk(), lun_connected, MSC_DELAY_SOF_COUNT, program_memory(), root_directory, sof_count, start_application_with_wdt(), uhc_stop(), and uhi_msc_mem_get_lun().
void main_usb_connection_event | ( | uhc_device_t * | dev, |
bool | b_present | ||
) |
Callback on enumeration status change of a MSC device.
Notify that a USB device has been connected or disconnected.
References lun_connected, sof_count, and UNUSED.
void main_usb_sof_event | ( | void | ) |
Notify that a SOF has been sent (each 1 ms)
References sof_count.
|
static |
Function to program the Flash.
Decrypt the firmware and program it.
References APP_BINARY_OFFSET, APP_START_ADDRESS, buffer, cpu_irq_disable, cpu_irq_enable, f_close(), f_open(), f_read(), FA_OPEN_EXISTING, FA_READ, FLASH_BUFFER_SIZE, FIL::fsize, input_file_name, integrity_check_in_flash(), LED0_ACTIVE, LED0_INACTIVE, LED0_PIN, nvm_erase_row(), nvm_write_buffer(), port_pin_set_output_level(), and STATUS_BUSY.
Referenced by main().
|
static |
|
static |
Function to issue a WDT reset to start the application.
This will reset the clock & peripheral configurations.
Referenced by main().
COMPILER_WORD_ALIGNED volatile uint8_t buffer[FLASH_BUFFER_SIZE] |
Referenced by dma_crc_io_calculation(), integrity_check_in_disk(), and program_memory().
|
static |
|
static |
|
static |
Referenced by integrity_check_in_disk(), and integrity_check_in_flash().
|
static |
Referenced by chk_mounted(), and f_mount().
char input_file_name[] |
Referenced by integrity_check_in_disk(), main(), and program_memory().
Referenced by main(), and main_usb_connection_event().
|
static |
Referenced by main(), main_usb_connection_event(), and main_usb_sof_event().