Skip to content

Commit 14959e8

Browse files
committed
code crop
1 parent e3fcd8d commit 14959e8

File tree

8 files changed

+115
-64
lines changed

8 files changed

+115
-64
lines changed
-79 KB
Binary file not shown.

SAM-BA_MONITOR_ROMLESS.atsln

Lines changed: 0 additions & 22 deletions
This file was deleted.

SAM-BA_MONITOR_ROMLESS/device_config/device_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
#include "device_config_samc21j18a.h"
5858
#define SAM_BA_INTERFACE SAM_BA_UART_ONLY
5959
#define APP_START_ADDRESS DEFAULT_APP_START_ADDRESS
60+
#elif defined (__SAMC21E18A__)
61+
#include "device_config_samc21e18a.h"
62+
#define SAM_BA_INTERFACE SAM_BA_UART_ONLY
6063
#elif defined (__SAMDA1J16A__)
6164
#include "device_config_samda1j16a.h"
6265
#define SAM_BA_INTERFACE SAM_BA_BOTH_INTERFACES
@@ -73,7 +76,8 @@
7376
#error Unknown part number... Define part number and create device_config_xx.h
7477
#endif
7578

76-
#define SAM_BA_VERSION "v2.18"__DATE__" "__TIME__"\n\r"
79+
//#define SAM_BA_VERSION "v2.18"__DATE__" "__TIME__"\n\r"
80+
#define SAM_BA_VERSION "uB\n\r"
7781

7882
#ifndef SAM_BA_INTERFACE
7983
#define SAM_BA_INTERFACE SAM_BA_UART_ONLY

SAM-BA_MONITOR_ROMLESS/device_config/device_config_samc21j18a.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define COMPILER_PRAGMA(arg) _Pragma(#arg)
4141
#define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
4242
#define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
43-
#elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
43+
#elif defined ( __GNUC__ ) || defined(__clang__) /* GCC CS3 2009q3-68 */
4444
#include "sam.h"
4545
#define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
4646
#define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
@@ -56,6 +56,7 @@
5656

5757
#define PINMUX_UNUSED 0xFFFFFFFF
5858
#define BOOT_USART_MODULE SERCOM4
59+
#define BOOT_USART_MODULE_IDX 4
5960
#define BOOT_USART_MUX_SETTINGS (SERCOM_USART_CTRLA_RXPO(3) | SERCOM_USART_CTRLA_TXPO(1))
6061
#define BOOT_USART_PAD0 PINMUX_UNUSED
6162
#define BOOT_USART_PAD1 PINMUX_UNUSED
@@ -97,6 +98,7 @@ static inline void clock_configuration_for_usb(void)
9798

9899
static inline void clock_configuration_for_boot_usart(void)
99100
{
101+
#if !defined(BOOT_USART_MODULE_IDX)
100102
uint8_t inst = 0;
101103
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
102104

@@ -106,6 +108,9 @@ static inline void clock_configuration_for_boot_usart(void)
106108
break;
107109
}
108110
}
111+
#else
112+
uint8_t inst = BOOT_USART_MODULE_IDX;
113+
#endif
109114

110115
enable_sercom_digital_interface_clock(inst);
111116

SAM-BA_MONITOR_ROMLESS/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static void check_start_application(void)
8787
* Stay in SAM-BA if *(APP_START+0x4) == 0xFFFFFFFF
8888
* Application erased condition
8989
*/
90-
if (app_start_address == 0xFFFFFFFF) {
90+
// if (app_start_address == 0xFFFFFFFF) {
91+
if (app_start_address>>18) { //bit safer: value in range 256k
9192
/* Stay in Bootloader */
9293
return;
9394
}

SAM-BA_MONITOR_ROMLESS/sam_ba/sam_ba_monitor.c

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
2929
#include "cdc_enumerate.h"
3030
#include "device_config.h"
3131

32+
33+
#if (SAM_BA_INTERFACE == SAM_BA_UART_ONLY)
34+
#define HND(x) uart_if.x
35+
#else
36+
#define HND(x) ptr_monitor_if->x
37+
#endif
38+
3239
static void print_new_line(void);
33-
const char RomBOOT_Version[] = SAM_BA_VERSION;
40+
const char RomBOOT_Version[sizeof(SAM_BA_VERSION)-1] = SAM_BA_VERSION;
3441

3542
/* Provides one common interface to handle both USART and USB-CDC */
3643
typedef struct
@@ -72,25 +79,26 @@ const t_monitor_if usbcdc_if =
7279
t_monitor_if * ptr_monitor_if;
7380

7481
/* b_terminal_mode mode (ascii) or hex mode */
75-
volatile bool b_terminal_mode = false;
82+
//volatile bool b_terminal_mode = false;
83+
static const bool b_terminal_mode = false;
7684
volatile uint32_t sp;
7785

7886

7987
static void print_new_line(void)
8088
{
81-
ptr_monitor_if->putdata("\n\r", 2);
89+
HND(putdata)("\n\r", 2);
8290
}
8391

8492
void init_sam_ba_monitor_interface(void)
8593
{
8694
#if SAM_BA_UART_INTERFACE_ENABLED
8795
usart_open();
8896
#endif
89-
97+
9098
#if SAM_BA_USB_INTERFACE_ENABLED
9199
clock_configuration_for_usb();
92100
usb_init();
93-
#endif
101+
#endif
94102
}
95103

96104
void process_sam_ba_monitor(void)
@@ -102,7 +110,10 @@ void process_sam_ba_monitor(void)
102110
}
103111
#endif
104112

105-
#if SAM_BA_UART_INTERFACE_ENABLED
113+
#if (SAM_BA_INTERFACE == SAM_BA_UART_ONLY)
114+
sam_ba_monitor_run();
115+
for(;;);
116+
#elif SAM_BA_UART_INTERFACE_ENABLED
106117
if(uart_if.is_rx_ready() && (SHARP_CHARACTER == uart_if.get_c())) {
107118
ptr_monitor_if = (t_monitor_if*) &uart_if;
108119
sam_ba_monitor_run();
@@ -150,21 +161,20 @@ void sam_ba_putdata_term(uint8_t* data, uint32_t length)
150161
buf[1] = 'x';
151162
buf[length * 2 + 2] = '\n';
152163
buf[length * 2 + 3] = '\r';
153-
ptr_monitor_if->putdata(buf, length * 2 + 4);
164+
HND(putdata)(buf, length * 2 + 4);
154165
}
155166
else
156-
ptr_monitor_if->putdata(data, length);
167+
HND(putdata)(data, length);
157168
return;
158169
}
159170

171+
__attribute__((__noreturn__))
160172
void call_applet(uint32_t address)
161173
{
162174
uint32_t app_start_address;
163175

164176
cpu_irq_disable();
165177

166-
sp = __get_MSP();
167-
168178
/* Rebase the Stack Pointer */
169179
__set_MSP(*(uint32_t *) address);
170180

@@ -175,7 +185,8 @@ void call_applet(uint32_t address)
175185
app_start_address = *(uint32_t *)(address + 4);
176186

177187
/* Jump to application Reset Handler in the application */
178-
asm("bx %0"::"r"(app_start_address));
188+
__asm("bx %0"::"r"(app_start_address));
189+
__builtin_unreachable();
179190
}
180191

181192
/**
@@ -184,25 +195,24 @@ void call_applet(uint32_t address)
184195
void sam_ba_monitor_run(void)
185196
{
186197
uint32_t length;
187-
uint32_t j, u8tmp, current_number, command;
198+
uint32_t j, command, current_number, u8tmp;
188199
uint8_t *ptr_data, *ptr, data[SIZEBUFMAX];
189200

190-
ptr_data = 0;
191-
command = 'z';
192201
j=0;
193-
202+
command = 0;
203+
194204
// Start waiting some cmd
195205
while (1)
196206
{
197-
length = ptr_monitor_if->getdata(data, SIZEBUFMAX);
207+
length = HND(getdata)(data, SIZEBUFMAX);
198208
ptr = data;
199209
for (uint32_t i = 0; i < length; i++)
200210
{
201211
if (*ptr != 0xff)
202212
{
203213
if (*ptr == '#')
204214
{
205-
if (b_terminal_mode)
215+
/* if (b_terminal_mode)
206216
{
207217
print_new_line();
208218
}
@@ -230,27 +240,31 @@ void sam_ba_monitor_run(void)
230240
ptr--;
231241
//Do we expect more data ?
232242
if(j<current_number)
233-
ptr_monitor_if->getdata_xmd(ptr_data, current_number-j);
234-
235-
__asm("nop");
243+
HND(getdata_xmd)(ptr_data, current_number-j);
244+
245+
// __asm("nop");
236246
}
247+
*/
248+
/*
237249
else if (command == 'R')
238250
{
239-
ptr_monitor_if->putdata_xmd(ptr_data, current_number);
251+
HND(putdata_xmd)(ptr_data, current_number);
240252
}
241253
else if (command == 'O')
242254
{
243255
*ptr_data = (char) current_number;
244256
}
245-
else if (command == 'H')
257+
else
258+
if (command == 'H')
246259
{
247260
*((uint16_t *) ptr_data) = (uint16_t) current_number;
248261
}
249-
else if (command == 'W')
262+
else
263+
*/ if (command == 'W')
250264
{
251265
*((int *) ptr_data) = current_number;
252266
}
253-
else if (command == 'o')
267+
/* else if (command == 'o')
254268
{
255269
sam_ba_putdata_term(ptr_data, 1);
256270
}
@@ -259,47 +273,47 @@ void sam_ba_monitor_run(void)
259273
current_number = *((uint16_t *) ptr_data);
260274
sam_ba_putdata_term((uint8_t*) &current_number, 2);
261275
}
262-
else if (command == 'w')
276+
*/ else if (command == 'w')
263277
{
264278
current_number = *((uint32_t *) ptr_data);
265279
sam_ba_putdata_term((uint8_t*) &current_number, 4);
266280
}
281+
267282
else if (command == 'G')
268283
{
269284
call_applet(current_number);
270-
//ptr_monitor_if->put_c(0x6);
271-
/* Rebase the Stack Pointer */
272-
__set_MSP(sp);
273-
cpu_irq_enable();
285+
__builtin_unreachable();
274286
}
275-
else if (command == 'T')
287+
/* else if (command == 'T')
276288
{
277289
b_terminal_mode = 1;
278290
print_new_line();
279291
}
280292
else if (command == 'N')
281293
{
282-
if (b_terminal_mode == 0)
283-
{
284-
print_new_line();
285-
}
286-
b_terminal_mode = 0;
294+
//if (b_terminal_mode == 0)
295+
//{
296+
HND(putdata)((uint8_t *) RomBOOT_Version+2, 2);
297+
// print_new_line();
298+
//}
299+
//b_terminal_mode = 0;
287300
}
288-
else if (command == 'V')
301+
*/ else if (command == 'V')
289302
{
290-
ptr_monitor_if->putdata((uint8_t *) RomBOOT_Version, strlen(RomBOOT_Version));
303+
HND(putdata)((uint8_t *) RomBOOT_Version, sizeof(RomBOOT_Version)); //strlen(RomBOOT_Version));
291304
}
292305

293-
command = 'z';
306+
command = 0;
294307
current_number = 0;
295308

296309
if (b_terminal_mode)
297310
{
298-
ptr_monitor_if->putdata(">", 1);
311+
HND(putdata)(">", 1);
299312
}
300313
}
301314
else
302315
{
316+
/*
303317
if (('0' <= *ptr) && (*ptr <= '9'))
304318
{
305319
current_number = (current_number << 4) | (*ptr - '0');
@@ -322,6 +336,22 @@ void sam_ba_monitor_run(void)
322336
command = *ptr;
323337
current_number = 0;
324338
}
339+
*/
340+
if (*ptr == ',')
341+
{
342+
ptr_data = (uint8_t *) current_number;
343+
current_number = 0;
344+
}
345+
else
346+
{
347+
int val = htoi(*ptr);
348+
if (val < 0) {
349+
command = *ptr;
350+
current_number = 0;
351+
}else{
352+
current_number = (current_number << 4) | val;
353+
}
354+
}
325355
}
326356
ptr++;
327357
}

glue.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdint.h>
2+
#include <stdbool.h>
3+
#include "glue.h"
4+
5+
extern uint32_t _estack;
6+
extern uint32_t _srelocate, _erelocate, _etext;
7+
extern uint32_t _sbss, _ebss;
8+
9+
extern uint32_t Image$$STACK$$Base;
10+
extern uint32_t Image$$STACK$$Limit;
11+
12+
int main(void);
13+
14+
int htoi(char x) {
15+
unsigned int v=x;
16+
v-='0';
17+
if (v<10) return v;
18+
v|=0x20; //A->a
19+
v-='a'-'0';
20+
if (v<6) return v+10;
21+
return -1;
22+
}
23+
24+
__attribute__ ((section (".vectors"),used))
25+
const struct {
26+
uint32_t* SP;
27+
void* Entry;
28+
#if defined ( __CC_ARM )
29+
}vectors = {&Image$$STACK$$Limit, main};
30+
#else
31+
}vectors = {&_estack, main};
32+
#endif

glue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int htoi(char x);

0 commit comments

Comments
 (0)