Microchip® Advanced Software Framework

sam0/applications/usb_msc_bootloader/bootloader/main.c File Reference

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)
 
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 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 void bootloader_system_init ( void  )
static
static void check_boot_mode ( void  )
static
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 bool program_memory ( void  )
static

Function to program the Flash.

Decrypt the firmware and program it.

References buffer, buffer_size, cpu_irq_disable, cpu_irq_enable, f_close(), f_open(), f_read(), FA_OPEN_EXISTING, FA_READ, FIL::fsize, i, input_file_name, nvm_erase_row(), nvm_write_buffer(), port_pin_set_output_level(), and STATUS_BUSY.

Referenced by main().

static void start_application ( void  )
static

Function to start the application.

Referenced by check_boot_mode().

static void start_application_with_wdt ( void  )
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]
DIR file_dir
static
FIL file_object
static
FATFS fs
static
char input_file_name[]
Initial value:
= {
FIRMWARE_IN_FILE_NAME
}

Referenced by main(), and program_memory().

volatile bool lun_connected = false
static

Referenced by main(), and main_usb_connection_event().

TCHAR root_directory[20] = {'0', ':', 0}
static

Referenced by main().

volatile uint32_t sof_count = 0
static