Skip to content

Commit eb014da

Browse files
committed
Bootloader: added a command to calculate checksum of blocks of memory
1 parent 6c53bbe commit eb014da

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

bootloaders/zero/sam_ba_monitor.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "cdc_enumerate.h"
3737

3838
const char RomBOOT_Version[] = SAM_BA_VERSION;
39-
const char RomBOOT_ExtendedCapabilities[] = "[Arduino:XY]";
39+
const char RomBOOT_ExtendedCapabilities[] = "[Arduino:XYZ]";
4040

4141
/* Provides one common interface to handle both USART and USB-CDC */
4242
typedef struct
@@ -186,9 +186,8 @@ void sam_ba_monitor_run(void)
186186
}
187187
}
188188

189-
#if 0
190189
// Prints a 32-bit integer in hex.
191-
void printn(uint32_t n) {
190+
void put_uint32(uint32_t n) {
192191
char buff[8];
193192
int i;
194193
for (i=0; i<8; i++) {
@@ -199,7 +198,6 @@ void printn(uint32_t n) {
199198
}
200199
ptr_monitor_if->putdata(buff, 8);
201200
}
202-
#endif
203201

204202
void sam_ba_monitor_loop(void)
205203
{
@@ -393,6 +391,27 @@ void sam_ba_monitor_loop(void)
393391
// Notify command completed
394392
ptr_monitor_if->putdata("Y\n\r", 3);
395393
}
394+
else if (command == 'Z')
395+
{
396+
// This command calculate CRC for a given area of memory.
397+
// It's useful to quickly check if a transfer has been done
398+
// successfully.
399+
400+
// Syntax: Z[START_ADDR],[SIZE]#
401+
// Returns: Z[CRC]#
402+
403+
uint8_t *data = (uint8_t *)ptr_data;
404+
uint32_t size = current_number;
405+
uint16_t crc = 0;
406+
uint32_t i = 0;
407+
for (i=0; i<size; i++)
408+
crc = add_crc(*data++, crc);
409+
410+
// Send response
411+
ptr_monitor_if->putdata("Z", 1);
412+
put_uint32(crc);
413+
ptr_monitor_if->putdata("#\n\r", 3);
414+
}
396415

397416
command = 'z';
398417
current_number = 0;

bootloaders/zero/samd21_sam_ba.bin

620 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)