Skip to content

Commit 2267161

Browse files
committed
[VIDORBL] port to IRQ architecture
1 parent 91e34f5 commit 2267161

File tree

3 files changed

+85
-48
lines changed

3 files changed

+85
-48
lines changed

bootloaders/zero/board_definitions_arduino_mkrvidor4000.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@
7777
#define PMIC_SERCOM SERCOM0
7878

7979
#define ENABLE_JTAG_LOAD 1
80-
#define TDI 12
81-
#define TDO 15
82-
#define TCK 13
83-
#define TMS 14
84-
85-
#define LAST_FLASH_PAGE (0x200000 - 0x1000)
86-
#define SCRATCHPAD_FLASH_PAGE (0x200000 - 0x2000)
87-
//#define LAST_FLASH_PAGE (0x100000 - 0x1000)
80+
#define TDI 12
81+
#define TDO 15
82+
#define TCK 13
83+
#define TMS 14
84+
#define MB_INT 28
85+
86+
#define LAST_FLASH_PAGE (0x200000 - 0x1000)
87+
#define SCRATCHPAD_FLASH_PAGE (0x200000 - 0x2000)
8888

8989
typedef struct __attribute__((packed)) {
9090
uint32_t offset;

bootloaders/zero/board_driver_jtag.c

+73-36
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ int jtagInit(void)
508508
outpin_init(TDI);
509509
outpin_init(TCK);
510510

511+
mbPinSet();
512+
511513
port_pin_set_output_level (TMS, 1);
512514
port_pin_set_output_level (TDI, 1);
513515
port_pin_set_output_level (TCK, 0);
@@ -575,7 +577,7 @@ int jtagWriteBuffer(unsigned int address, const uint8_t *data, size_t len)
575577
Js_Shiftdr();
576578
address = (address << 2) | 0x00000003;
577579
ReadTDOBuf(32, &address, 0, 0);
578-
ReadTDOBuf(32 * len, data, 0, 0);
580+
ReadTDOBuf(32 * len+2, data, 0, 0);
579581
return len;
580582
}
581583

@@ -610,7 +612,72 @@ int jtagReadBuffer(unsigned int address, uint8_t *data, size_t len)
610612
return len;
611613
}
612614

613-
#define MB_BASE 0x00000000
615+
#define MB_BASE 0x00000000
616+
#define MB_TIMEOUT 5000
617+
618+
/**
619+
*/
620+
int mbPinSet(void)
621+
{
622+
#ifdef MB_INT
623+
uint32_t rpc[1];
624+
rpc[0] = 0;
625+
jtagWriteBuffer(MB_BASE, (const uint8_t *)rpc, 1);
626+
outpin_init(MB_INT);
627+
outpin_off(MB_INT);
628+
#endif
629+
}
630+
631+
/**
632+
* Sends len words (32 bit) via messagebox
633+
*/
634+
int mbCmdSend(uint32_t* data, int len)
635+
{
636+
int ret;
637+
#ifdef MB_INT
638+
ret = jtagWriteBuffer(MB_BASE, (const uint8_t *)data, len);
639+
if (ret!=len) {
640+
return -10;
641+
}
642+
outpin_on(MB_INT);
643+
outpin_off(MB_INT);
644+
#else
645+
jtagWriteBuffer(MB_BASE + 1, (const uint8_t *)(&data[1]), len-1);
646+
jtagWriteBuffer(MB_BASE, (const uint8_t *)data, 1);
647+
#endif
648+
649+
do {
650+
jtagReadBuffer(MB_BASE, (uint8_t*)&ret, 1);
651+
} while (ret);
652+
653+
jtagReadBuffer(MB_BASE + 1, (uint8_t*)&ret, 1);
654+
655+
return ret;
656+
}
657+
658+
/**
659+
* Writes len words (32 bit) via messagebox at a specified address
660+
*/
661+
int mbWrite(uint32_t address, void* data, int len)
662+
{
663+
jtagWriteBuffer(MB_BASE + address, (const uint8_t *)data, len);
664+
return 0;
665+
}
666+
667+
/**
668+
* Reads len words (32 bit) using messagebox from a specified address
669+
*/
670+
int mbRead(uint32_t address, void* data, int len)
671+
{
672+
uint32_t *p = (uint32_t*)data;
673+
int i;
674+
675+
for (i=0; i<len; i++) {
676+
jtagReadBuffer(MB_BASE + address + i, (uint8_t*)&p[i], 1);
677+
}
678+
return 0;
679+
}
680+
614681
#define MB_DEV_FLASH 0x01000000
615682

616683
void jtagFlashEraseBlock(uint32_t offset)
@@ -620,12 +687,7 @@ void jtagFlashEraseBlock(uint32_t offset)
620687
rpc[1] = 2;
621688
rpc[2] = offset;
622689

623-
jtagWriteBuffer(MB_BASE + 1, (const uint8_t *)(&rpc[1]), 2);
624-
jtagWriteBuffer(MB_BASE, (const uint8_t *)rpc, 1);
625-
626-
do {
627-
jtagReadBuffer(MB_BASE, (uint8_t*)rpc, 1);
628-
} while (rpc[0]);
690+
mbCmdSend(rpc, 3);
629691
}
630692

631693
void jtagFlashWriteBlock(uint32_t offset, size_t len, uint32_t* data)
@@ -635,23 +697,7 @@ void jtagFlashWriteBlock(uint32_t offset, size_t len, uint32_t* data)
635697
rpc[1] = offset;
636698
rpc[2] = len;
637699
memcpy(&rpc[3], data, len);
638-
639-
jtagWriteBuffer(MB_BASE + 1, (const uint8_t *)(&rpc[1]), 2 + (len + 3) / 4);
640-
jtagWriteBuffer(MB_BASE, (const uint8_t *)rpc, 1);
641-
642-
do {
643-
jtagReadBuffer(MB_BASE, (uint8_t*)rpc, 1);
644-
} while (rpc[0]);
645-
}
646-
647-
static unsigned char lookup[16] = {
648-
0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
649-
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf,
650-
};
651-
652-
static uint8_t reverse(uint8_t n) {
653-
// Reverse the top and bottom nibble then swap them.
654-
return (lookup[n & 0b1111] << 4) | lookup[n >> 4];
700+
mbCmdSend(rpc, 3+((len + 3)/4));
655701
}
656702

657703
void jtagFlashReadBlock(uint32_t offset, size_t len, uint8_t* buf)
@@ -661,17 +707,8 @@ void jtagFlashReadBlock(uint32_t offset, size_t len, uint8_t* buf)
661707
rpc[1] = offset;
662708
rpc[2] = len;
663709

664-
jtagWriteBuffer(MB_BASE + 1, (const uint8_t *)(&rpc[1]), 2);
665-
jtagWriteBuffer(MB_BASE, (const uint8_t *)rpc, 1);
666-
667-
do {
668-
jtagReadBuffer(MB_BASE, (uint8_t*)rpc, 1);
669-
} while (rpc[0]);
670-
671-
size_t i;
672-
for (i = 0; i < 1 + (len + 3) / 4; i++) {
673-
jtagReadBuffer(MB_BASE + 2 + i, (uint8_t*)&rpc[2 + i], 1);
674-
}
710+
mbCmdSend(rpc, 3);
711+
mbRead(2, &rpc[2], (len + 3) / 4 + 1);
675712

676713
uint8_t* newbuf = (uint8_t*)&rpc[3];
677714
for (int i = 0; i < len; i++) {

bootloaders/zero/sam_ba_monitor.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,14 @@ static void sam_ba_monitor_loop(void)
564564
if ((uint32_t)ptr_data == 0x40000) {
565565
data = (uint8_t*)buf;
566566
for (int j =0; j<size; ) {
567-
jtagFlashReadBlock(SCRATCHPAD_FLASH_PAGE + j, 512, &data[j]);
568-
j += 512;
567+
jtagFlashReadBlock(SCRATCHPAD_FLASH_PAGE + j, 256, &data[j]);
568+
j += 256;
569569
}
570570
} else if ((uint32_t)ptr_data >= 0x41000) {
571571
data = (uint8_t*)buf;
572572
for (int j =0; j<size; ) {
573-
jtagFlashReadBlock((uint32_t)ptr_data + offset - 0x41000 + j, 512, &data[j]);
574-
j += 512;
573+
jtagFlashReadBlock((uint32_t)ptr_data + offset - 0x41000 + j, 256, &data[j]);
574+
j += 256;
575575
}
576576
} else {
577577
data = (uint8_t *)ptr_data;

0 commit comments

Comments
 (0)