diff --git a/.vs/SAM-BA_MONITOR_ROMLESS/v14/.atsuo b/.vs/SAM-BA_MONITOR_ROMLESS/v14/.atsuo deleted file mode 100644 index 22ba6e8..0000000 Binary files a/.vs/SAM-BA_MONITOR_ROMLESS/v14/.atsuo and /dev/null differ diff --git a/SAM-BA_MONITOR_ROMLESS.atsln b/SAM-BA_MONITOR_ROMLESS.atsln deleted file mode 100644 index 9dde577..0000000 --- a/SAM-BA_MONITOR_ROMLESS.atsln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Atmel Studio Solution File, Format Version 11.00 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "SAM-BA_MONITOR_ROMLESS", "SAM-BA_MONITOR_ROMLESS\SAM-BA_MONITOR_ROMLESS.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|ARM = Debug|ARM - Release|ARM = Release|ARM - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.ActiveCfg = Debug|ARM - {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|ARM.Build.0 = Debug|ARM - {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|ARM.ActiveCfg = Release|ARM - {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|ARM.Build.0 = Release|ARM - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/SAM-BA_MONITOR_ROMLESS/device_config/device_config.h b/SAM-BA_MONITOR_ROMLESS/device_config/device_config.h index 2ec05fe..e601e17 100644 --- a/SAM-BA_MONITOR_ROMLESS/device_config/device_config.h +++ b/SAM-BA_MONITOR_ROMLESS/device_config/device_config.h @@ -57,6 +57,9 @@ #include "device_config_samc21j18a.h" #define SAM_BA_INTERFACE SAM_BA_UART_ONLY #define APP_START_ADDRESS DEFAULT_APP_START_ADDRESS +#elif defined (__SAMC21E18A__) + #include "device_config_samc21e18a.h" + #define SAM_BA_INTERFACE SAM_BA_UART_ONLY #elif defined (__SAMDA1J16A__) #include "device_config_samda1j16a.h" #define SAM_BA_INTERFACE SAM_BA_BOTH_INTERFACES @@ -73,7 +76,8 @@ #error Unknown part number... Define part number and create device_config_xx.h #endif -#define SAM_BA_VERSION "v2.18"__DATE__" "__TIME__"\n\r" +//#define SAM_BA_VERSION "v2.18"__DATE__" "__TIME__"\n\r" +#define SAM_BA_VERSION "uB\n\r" #ifndef SAM_BA_INTERFACE #define SAM_BA_INTERFACE SAM_BA_UART_ONLY diff --git a/SAM-BA_MONITOR_ROMLESS/device_config/device_config_samc21j18a.h b/SAM-BA_MONITOR_ROMLESS/device_config/device_config_samc21j18a.h index 4187337..d8a2ba8 100644 --- a/SAM-BA_MONITOR_ROMLESS/device_config/device_config_samc21j18a.h +++ b/SAM-BA_MONITOR_ROMLESS/device_config/device_config_samc21j18a.h @@ -40,7 +40,7 @@ #define COMPILER_PRAGMA(arg) _Pragma(#arg) #define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a) #define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4) -#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */ +#elif defined ( __GNUC__ ) || defined(__clang__) /* GCC CS3 2009q3-68 */ #include "sam.h" #define COMPILER_ALIGNED(a) __attribute__((__aligned__(a))) #define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4))) @@ -56,6 +56,7 @@ #define PINMUX_UNUSED 0xFFFFFFFF #define BOOT_USART_MODULE SERCOM4 +#define BOOT_USART_MODULE_IDX 4 #define BOOT_USART_MUX_SETTINGS (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1)) #define BOOT_USART_PAD0 PINMUX_UNUSED #define BOOT_USART_PAD1 PINMUX_UNUSED @@ -97,6 +98,7 @@ static inline void clock_configuration_for_usb(void) static inline void clock_configuration_for_boot_usart(void) { + #if !defined(BOOT_USART_MODULE_IDX) uint8_t inst = 0; Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; @@ -106,6 +108,9 @@ static inline void clock_configuration_for_boot_usart(void) break; } } + #else + uint8_t inst = BOOT_USART_MODULE_IDX; + #endif enable_sercom_digital_interface_clock(inst); diff --git a/SAM-BA_MONITOR_ROMLESS/main.c b/SAM-BA_MONITOR_ROMLESS/main.c index db9ec10..9324678 100644 --- a/SAM-BA_MONITOR_ROMLESS/main.c +++ b/SAM-BA_MONITOR_ROMLESS/main.c @@ -87,7 +87,8 @@ static void check_start_application(void) * Stay in SAM-BA if *(APP_START+0x4) == 0xFFFFFFFF * Application erased condition */ - if (app_start_address == 0xFFFFFFFF) { +// if (app_start_address == 0xFFFFFFFF) { + if (app_start_address>>18) { //bit safer: value in range 256k /* Stay in Bootloader */ return; } diff --git a/SAM-BA_MONITOR_ROMLESS/sam_ba/sam_ba_monitor.c b/SAM-BA_MONITOR_ROMLESS/sam_ba/sam_ba_monitor.c index efa6555..1dd8341 100644 --- a/SAM-BA_MONITOR_ROMLESS/sam_ba/sam_ba_monitor.c +++ b/SAM-BA_MONITOR_ROMLESS/sam_ba/sam_ba_monitor.c @@ -29,8 +29,15 @@ SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES #include "cdc_enumerate.h" #include "device_config.h" + +#if (SAM_BA_INTERFACE == SAM_BA_UART_ONLY) +#define HND(x) uart_if.x +#else +#define HND(x) ptr_monitor_if->x +#endif + static void print_new_line(void); -const char RomBOOT_Version[] = SAM_BA_VERSION; +const char RomBOOT_Version[sizeof(SAM_BA_VERSION)-1] = SAM_BA_VERSION; /* Provides one common interface to handle both USART and USB-CDC */ typedef struct @@ -72,13 +79,14 @@ const t_monitor_if usbcdc_if = t_monitor_if * ptr_monitor_if; /* b_terminal_mode mode (ascii) or hex mode */ -volatile bool b_terminal_mode = false; +//volatile bool b_terminal_mode = false; +static const bool b_terminal_mode = false; volatile uint32_t sp; static void print_new_line(void) { - ptr_monitor_if->putdata("\n\r", 2); + HND(putdata)("\n\r", 2); } void init_sam_ba_monitor_interface(void) @@ -86,11 +94,11 @@ void init_sam_ba_monitor_interface(void) #if SAM_BA_UART_INTERFACE_ENABLED usart_open(); #endif - + #if SAM_BA_USB_INTERFACE_ENABLED clock_configuration_for_usb(); usb_init(); - #endif + #endif } void process_sam_ba_monitor(void) @@ -102,7 +110,10 @@ void process_sam_ba_monitor(void) } #endif - #if SAM_BA_UART_INTERFACE_ENABLED + #if (SAM_BA_INTERFACE == SAM_BA_UART_ONLY) + sam_ba_monitor_run(); + for(;;); + #elif SAM_BA_UART_INTERFACE_ENABLED if(uart_if.is_rx_ready() && (SHARP_CHARACTER == uart_if.get_c())) { ptr_monitor_if = (t_monitor_if*) &uart_if; sam_ba_monitor_run(); @@ -150,21 +161,20 @@ void sam_ba_putdata_term(uint8_t* data, uint32_t length) buf[1] = 'x'; buf[length * 2 + 2] = '\n'; buf[length * 2 + 3] = '\r'; - ptr_monitor_if->putdata(buf, length * 2 + 4); + HND(putdata)(buf, length * 2 + 4); } else - ptr_monitor_if->putdata(data, length); + HND(putdata)(data, length); return; } +__attribute__((__noreturn__)) void call_applet(uint32_t address) { uint32_t app_start_address; cpu_irq_disable(); - sp = __get_MSP(); - /* Rebase the Stack Pointer */ __set_MSP(*(uint32_t *) address); @@ -175,7 +185,8 @@ void call_applet(uint32_t address) app_start_address = *(uint32_t *)(address + 4); /* Jump to application Reset Handler in the application */ - asm("bx %0"::"r"(app_start_address)); + __asm("bx %0"::"r"(app_start_address)); + __builtin_unreachable(); } /** @@ -184,17 +195,16 @@ void call_applet(uint32_t address) void sam_ba_monitor_run(void) { uint32_t length; - uint32_t j, u8tmp, current_number, command; + uint32_t j, command, current_number, u8tmp; uint8_t *ptr_data, *ptr, data[SIZEBUFMAX]; - ptr_data = 0; - command = 'z'; j=0; - + command = 0; + // Start waiting some cmd while (1) { - length = ptr_monitor_if->getdata(data, SIZEBUFMAX); + length = HND(getdata)(data, SIZEBUFMAX); ptr = data; for (uint32_t i = 0; i < length; i++) { @@ -202,7 +212,7 @@ void sam_ba_monitor_run(void) { if (*ptr == '#') { - if (b_terminal_mode) +/* if (b_terminal_mode) { print_new_line(); } @@ -230,27 +240,31 @@ void sam_ba_monitor_run(void) ptr--; //Do we expect more data ? if(jgetdata_xmd(ptr_data, current_number-j); - - __asm("nop"); + HND(getdata_xmd)(ptr_data, current_number-j); + +// __asm("nop"); } +*/ +/* else if (command == 'R') { - ptr_monitor_if->putdata_xmd(ptr_data, current_number); + HND(putdata_xmd)(ptr_data, current_number); } else if (command == 'O') { *ptr_data = (char) current_number; } - else if (command == 'H') + else + if (command == 'H') { *((uint16_t *) ptr_data) = (uint16_t) current_number; } - else if (command == 'W') + else +*/ if (command == 'W') { *((int *) ptr_data) = current_number; } - else if (command == 'o') +/* else if (command == 'o') { sam_ba_putdata_term(ptr_data, 1); } @@ -259,47 +273,47 @@ void sam_ba_monitor_run(void) current_number = *((uint16_t *) ptr_data); sam_ba_putdata_term((uint8_t*) ¤t_number, 2); } - else if (command == 'w') +*/ else if (command == 'w') { current_number = *((uint32_t *) ptr_data); sam_ba_putdata_term((uint8_t*) ¤t_number, 4); } + else if (command == 'G') { call_applet(current_number); - //ptr_monitor_if->put_c(0x6); - /* Rebase the Stack Pointer */ - __set_MSP(sp); - cpu_irq_enable(); + __builtin_unreachable(); } - else if (command == 'T') +/* else if (command == 'T') { b_terminal_mode = 1; print_new_line(); } else if (command == 'N') { - if (b_terminal_mode == 0) - { - print_new_line(); - } - b_terminal_mode = 0; + //if (b_terminal_mode == 0) + //{ + HND(putdata)((uint8_t *) RomBOOT_Version+2, 2); + // print_new_line(); + //} + //b_terminal_mode = 0; } - else if (command == 'V') +*/ else if (command == 'V') { - ptr_monitor_if->putdata((uint8_t *) RomBOOT_Version, strlen(RomBOOT_Version)); + HND(putdata)((uint8_t *) RomBOOT_Version, sizeof(RomBOOT_Version)); //strlen(RomBOOT_Version)); } - command = 'z'; + command = 0; current_number = 0; if (b_terminal_mode) { - ptr_monitor_if->putdata(">", 1); + HND(putdata)(">", 1); } } else { +/* if (('0' <= *ptr) && (*ptr <= '9')) { current_number = (current_number << 4) | (*ptr - '0'); @@ -322,6 +336,22 @@ void sam_ba_monitor_run(void) command = *ptr; current_number = 0; } +*/ + if (*ptr == ',') + { + ptr_data = (uint8_t *) current_number; + current_number = 0; + } + else + { + int val = htoi(*ptr); + if (val < 0) { + command = *ptr; + current_number = 0; + }else{ + current_number = (current_number << 4) | val; + } + } } ptr++; } diff --git a/glue.c b/glue.c new file mode 100644 index 0000000..0a58a71 --- /dev/null +++ b/glue.c @@ -0,0 +1,32 @@ +#include +#include +#include "glue.h" + +extern uint32_t _estack; +extern uint32_t _srelocate, _erelocate, _etext; +extern uint32_t _sbss, _ebss; + +extern uint32_t Image$$STACK$$Base; +extern uint32_t Image$$STACK$$Limit; + +int main(void); + +int htoi(char x) { + unsigned int v=x; + v-='0'; + if (v<10) return v; + v|=0x20; //A->a + v-='a'-'0'; + if (v<6) return v+10; + return -1; +} + +__attribute__ ((section (".vectors"),used)) +const struct { + uint32_t* SP; + void* Entry; +#if defined ( __CC_ARM ) +}vectors = {&Image$$STACK$$Limit, main}; +#else +}vectors = {&_estack, main}; +#endif diff --git a/glue.h b/glue.h new file mode 100644 index 0000000..e95350b --- /dev/null +++ b/glue.h @@ -0,0 +1 @@ +int htoi(char x); \ No newline at end of file