things are working again, turns out renesas lied about timings

This commit is contained in:
Triss 2021-12-03 02:53:47 +01:00
parent bbd127da3f
commit 518a3277c6
7 changed files with 53 additions and 34 deletions

View File

@ -215,6 +215,15 @@ static void tool78_prototest() {
// RL78/G11: 0x10 0x00 0x06 0x52 0x35 0x46 0x31 0x30 0x35 0x34 0x41 0x20 0x20 0xff 0x3f 0x00 0xff 0x17 0x0f 0x03 0x00 0x03 // RL78/G11: 0x10 0x00 0x06 0x52 0x35 0x46 0x31 0x30 0x35 0x34 0x41 0x20 0x20 0xff 0x3f 0x00 0xff 0x17 0x0f 0x03 0x00 0x03
// flg=fe bot=03 fsws=0000 fswe=000f // flg=fe bot=03 fsws=0000 fswe=000f
/*
sig result=0x06
result: 0x06. sig:
0x10 0x00 0x06 0x52 0x35 0x46 0x31 0x30 0x35 0x34 0x41 0x20 0x20 0xff 0x3f 0x00 0xff 0x17 0x0f 0x03 0x00 0x03
secget: 0x06
sec: flg=fe bot=03 fsws=0000 fswe=000f
blank check: 0x06
*/
// NOTE: RL78 ONLY // NOTE: RL78 ONLY
struct tool78_security sec; struct tool78_security sec;
memset(&sec, 0, sizeof sec); memset(&sec, 0, sizeof sec);
@ -224,19 +233,17 @@ static void tool78_prototest() {
//st = tool78_do_security_release(&tool78_hw_rl78_uart1); //st = tool78_do_security_release(&tool78_hw_rl78_uart1);
//printf("sec rel: 0x%02x\n", st); //printf("sec rel: 0x%02x\n", st);
st = tool78_do_block_blank_check(hw, 0, 0x3ff, false);
/*st = tool78_do_block_blank_check(hw, 0, 0x0ff, false);
printf("blank check: 0x%02x\n", st); printf("blank check: 0x%02x\n", st);
/*st = tool78_do_programming(hw, 0, 0x000ff, DATA_test_rom);
st = tool78_do_programming(hw, 0, 0x000ff, DATA_test_rom);
printf("programming: 0x%02x\n", st);*/ printf("programming: 0x%02x\n", st);*/
st = tool78_do_verify(hw, 0, 0x0ff, DATA_test_rom); /*st = tool78_do_verify(hw, 0, 0x0ff, DATA_test_rom);
printf("verify: 0x%02x\n", st); printf("verify: 0x%02x\n", st);*/
} }
static void tool78_ocdtest() { static void tool78_ocdtest() {
uint8_t passwd[10] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; uint8_t passwd[10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint16_t ver=0; uint16_t ver=0;
enum tool78_stat st = tool78_init_ocd(&tool78_hw_rl78_uart1, &ver, passwd); enum tool78_stat st = tool78_init_ocd(&tool78_hw_rl78_uart1, &ver, passwd);
printf("result: 0x%02x ver=%04x\n", st, ver); printf("result: 0x%02x ver=%04x\n", st, ver);

View File

@ -180,6 +180,7 @@ static enum tool78_stat tool78_data_recv(struct tool78_hw* hw, uint8_t* buf,
int expected_len, int timeout_us_first) { int expected_len, int timeout_us_first) {
uint8_t pre[10]; // stx, len uint8_t pre[10]; // stx, len
uint8_t post[2]; // cksum, etx/etb uint8_t post[2]; // cksum, etx/etb
//printf("recv to=%d\n", timeout_us_first);
int rr = hw->recv(1, &pre[0], timeout_us_first); int rr = hw->recv(1, &pre[0], timeout_us_first);
//printf("data recv rr=%d\n", rr); //printf("data recv rr=%d\n", rr);
@ -192,10 +193,10 @@ static enum tool78_stat tool78_data_recv(struct tool78_hw* hw, uint8_t* buf,
return (hw->flags & tool78_hw_flag_done_reset) return (hw->flags & tool78_hw_flag_done_reset)
? tool78_stat_busy : tool78_stat_protocol_error; ? tool78_stat_busy : tool78_stat_protocol_error;
rr = hw->recv(1, &pre[1], 100); rr = hw->recv(1, &pre[1], 100*100);
//printf("rr=%d pre[1]=0x%02x\n", rr, pre[1]); //printf("rr=%d (0x%08lx) pre[1]=0x%02x\n", rr, (uint32_t)rr, pre[1]);
if (rr != 1) { if (rr != 1) {
/*for (int i = 0; i < rr; ++i) /*for (int i = 0; i < rr && rr < 256; ++i)
printf("pre[%d]=0x%02x\n", i+1, pre[i+1]); printf("pre[%d]=0x%02x\n", i+1, pre[i+1]);
printf("interr\n");*/ printf("interr\n");*/
return tool78_stat_internal_error; return tool78_stat_internal_error;
@ -210,10 +211,10 @@ static enum tool78_stat tool78_data_recv(struct tool78_hw* hw, uint8_t* buf,
return tool78_stat_protocol_error; return tool78_stat_protocol_error;
} }
rr = hw->recv(len, buf, 1000*len); rr = hw->recv(len, buf, 1000*len*100);
if (rr != len) return tool78_stat_internal_error; if (rr != len) return tool78_stat_internal_error;
rr = hw->recv(2, post, 200); rr = hw->recv(2, post, 200*100);
if (rr != 2) return tool78_stat_internal_error; if (rr != 2) return tool78_stat_internal_error;
if (post[1] != tool78_frame_etx && post[1] != tool78_frame_etb) { if (post[1] != tool78_frame_etx && post[1] != tool78_frame_etb) {
return tool78_stat_protocol_error; return tool78_stat_protocol_error;
@ -265,7 +266,7 @@ static enum tool78_stat tool78_wait_status(struct tool78_hw* hw, int l, int time
busy_wait_us_32(timeout_us/64); busy_wait_us_32(timeout_us/64);
} }
//printf("wait t/o\n"); printf("wait t/o\n");
return tool78_stat_timeout_error; return tool78_stat_timeout_error;
} }
@ -574,9 +575,9 @@ enum tool78_stat tool78_do_silicon_signature(struct tool78_hw* hw,
return tool78_stat_bad_mcu_for_cmd; return tool78_stat_bad_mcu_for_cmd;
} }
//gpio_set_function(18, GPIO_FUNC_SIO); /*gpio_set_function(18, GPIO_FUNC_SIO);
//gpio_set_dir(18, true); gpio_set_dir(18, true);
//gpio_put(18, true); gpio_put(18, true);*/
memset(sig_dest, 0, 27); memset(sig_dest, 0, 27);
enum tool78_stat st = tool78_cmd_send(hw, tool78_cmd_silicon_signature, 0, NULL); enum tool78_stat st = tool78_cmd_send(hw, tool78_cmd_silicon_signature, 0, NULL);
@ -769,10 +770,10 @@ int tool78_ocd_version(struct tool78_hw* hw, uint16_t* ver) {
if (rr != 3) return -1; if (rr != 3) return -1;
*ver = bytes[1] | ((uint16_t)bytes[2] << 8); *ver = bytes[1] | ((uint16_t)bytes[2] << 8);
printf("ver=%04x\n", *ver); //printf("ver=%04x\n", *ver);
return 0; return 0;
} }
int tool78_ocd_connect(struct tool78_hw* hw, const uint8_t passwd[10], uint8_t ck_off) { int tool78_ocd_connect(struct tool78_hw* hw, const uint8_t passwd[10]) {
busy_wait_ms(1); busy_wait_ms(1);
uint8_t stuff[11]; uint8_t stuff[11];
uint8_t connst, cksum; uint8_t connst, cksum;
@ -781,11 +782,13 @@ int tool78_ocd_connect(struct tool78_hw* hw, const uint8_t passwd[10], uint8_t c
// stuff[1] is tool78ocd_cmd_connect echoed back // stuff[1] is tool78ocd_cmd_connect echoed back
rr = hw->recv(2, &stuff[1], 100000); rr = hw->recv(2, &stuff[1], 100000);
connst=stuff[2];
if (rr != 2) return -1; if (rr != 2) return -1;
connst=stuff[2];
if (connst == 0xf0 || connst == 0xf4) return connst;
// connst==0xf1
memcpy(stuff, passwd, 10); memcpy(stuff, passwd, 10);
cksum = stuff[10] = tool78_calc_ocd_checksum8(10, passwd) + ck_off; cksum = stuff[10] = tool78_calc_ocd_checksum8(10, passwd);
busy_wait_ms(1); busy_wait_ms(1);
rr = hw->send(11, stuff, -1); rr = hw->send(11, stuff, -1);
@ -794,10 +797,10 @@ int tool78_ocd_connect(struct tool78_hw* hw, const uint8_t passwd[10], uint8_t c
rr = hw->recv(2, &stuff[9], 100000); rr = hw->recv(2, &stuff[9], 100000);
if (rr != 2) return -2; if (rr != 2) return -2;
printf("cksum=0x%02x conn=%02x pw=%02x\n", /*printf("cksum=0x%02x conn=%02x pw=%02x\n",
cksum, connst, stuff[10]); cksum, connst, stuff[10]);*/
return (uint32_t)connst | ((uint32_t)stuff[10] << 8); return stuff[10];//(uint32_t)connst | ((uint32_t)stuff[10] << 8);
} }
int tool78_ocd_read(struct tool78_hw* hw, uint16_t off, uint8_t len, int tool78_ocd_read(struct tool78_hw* hw, uint16_t off, uint8_t len,
uint8_t* data) { uint8_t* data) {
@ -885,7 +888,7 @@ static enum tool78_stat tool78_init_common(struct tool78_hw* hw) {
printf("hw inited\n"); printf("hw inited\n");
st = tool78_do_generic_baudrate(hw); st = tool78_do_generic_baudrate(hw);
printf("baudrate result=0x%02x\n", st); //printf("baudrate result=0x%02x\n", st);
if (st != tool78_stat_ack) return st; if (st != tool78_stat_ack) return st;
return st; return st;
@ -896,7 +899,7 @@ enum tool78_stat tool78_init_sfp(struct tool78_hw* hw, tool78_silicon_sig_t* sig
if (st != tool78_stat_ack) return st; if (st != tool78_stat_ack) return st;
st = tool78_do_silicon_signature(hw, sig); st = tool78_do_silicon_signature(hw, sig);
printf("sig result=0x%02x\n", st); //printf("sig result=0x%02x\n", st);
if (st != tool78_stat_ack) return st; if (st != tool78_stat_ack) return st;
return st; return st;
@ -909,14 +912,16 @@ enum tool78_stat tool78_init_ocd(struct tool78_hw* hw, uint16_t* ver,
if (st != tool78_stat_ack) return st; if (st != tool78_stat_ack) return st;
st = tool78_ocd_version(hw, ver); st = tool78_ocd_version(hw, ver);
if (st) return st;
uint8_t i = 0; st = tool78_ocd_connect(hw, passwd);
/*uint8_t i = 0;
do { do {
st = tool78_ocd_connect(hw, passwd, i); st = tool78_ocd_connect(hw, passwd, i);
++i; ++i;
if (i == 0) break; if (i == 0) break;
} while ((st & 0xff00) == 0xf300 && (st & 0xff) == 0xf1); } while ((st & 0xff00) == 0xf300 && (st & 0xff) == 0xf1);*/
return st; return st;
} }

View File

@ -42,7 +42,7 @@ enum tool78_stat tool78_do_security_release(struct tool78_hw* hw);
//int tool78_ocd_reset(struct tool78_hw* hw); //int tool78_ocd_reset(struct tool78_hw* hw);
int tool78_ocd_version(struct tool78_hw* hw, uint16_t* ver); int tool78_ocd_version(struct tool78_hw* hw, uint16_t* ver);
int tool78_ocd_connect(struct tool78_hw* hw, const uint8_t passwd[10], uint8_t ck_off); int tool78_ocd_connect(struct tool78_hw* hw, const uint8_t passwd[10]);
int tool78_ocd_read(struct tool78_hw* hw, uint16_t off, uint8_t len, int tool78_ocd_read(struct tool78_hw* hw, uint16_t off, uint8_t len,
uint8_t* data); // only is able to read from 0xf0000 uint8_t* data); // only is able to read from 0xf0000
int tool78_ocd_write(struct tool78_hw* hw, uint16_t addr, uint8_t len, int tool78_ocd_write(struct tool78_hw* hw, uint16_t addr, uint8_t len,

View File

@ -66,6 +66,8 @@ enum tool78_entry {
enum tool78_cmd { enum tool78_cmd {
// only used in UART comms (i.e. not in 78k0/Kx2 SPI) // only used in UART comms (i.e. not in 78k0/Kx2 SPI)
tool78_cmd_reset = 0x00, tool78_cmd_reset = 0x00,
// TODO: RL78/G13 v3.03: 3, 4, 6, 8, 0x16, 0x21, 0x10, 0x11 // 0x12, 0x14, 0x15
// => 0x10 and on: FSL only
tool78_cmd_verify = 0x13, tool78_cmd_verify = 0x13,
// undocumented, RL78 only? // undocumented, RL78 only?
tool78_cmd_verify_internal = 0x19, tool78_cmd_verify_internal = 0x19,
@ -167,7 +169,7 @@ static inline uint8_t tool78_calc_ocd_checksum8(size_t len, const uint8_t* data)
for (size_t i = 0; i < len; ++i) r = r + data[i]; for (size_t i = 0; i < len; ++i) r = r + data[i];
r = (r - 1) & 0xff; r = (r - 1) & 0xff;
// if corrupt checksum: // if corrupt checksum:
r = (r + 1) & 0xff; // r = (r + 1) & 0xff;
return r; return r;
} }

View File

@ -293,15 +293,18 @@ void tool78_entryseq_rl78(enum tool78_entry typ) {
gpio_set_function(PINOUT_TOOL78_nRESET , GPIO_FUNC_SIO); gpio_set_function(PINOUT_TOOL78_nRESET , GPIO_FUNC_SIO);
gpio_set_function(PINOUT_TOOL78_RL78_TOOL0, GPIO_FUNC_SIO); gpio_set_function(PINOUT_TOOL78_RL78_TOOL0, GPIO_FUNC_SIO);
busy_wait_us_32(500); // tSU //busy_wait_us_32(500); // tSU
busy_wait_ms(4);
gpio_put(PINOUT_TOOL78_nRESET, true); gpio_put(PINOUT_TOOL78_nRESET, true);
busy_wait_us_32(750); // 750us + tHD //busy_wait_us_32(750); // 750us + tHD
busy_wait_ms(4);
gpio_put(PINOUT_TOOL78_RL78_TOOL0, true); gpio_put(PINOUT_TOOL78_RL78_TOOL0, true);
busy_wait_us_32(20); // tTM //busy_wait_us_32(20); // tTM
busy_wait_ms(2);
} }
void tool78_deinit_rl78(void) { void tool78_deinit_rl78(void) {
gpio_put(PINOUT_TOOL78_nRESET, false); gpio_put(PINOUT_TOOL78_nRESET, false);

View File

@ -34,7 +34,8 @@ static bool trl78_uart1_init(void) {
uint8_t byte = (uint8_t)typ; uint8_t byte = (uint8_t)typ;
trl78_uart1_send(1, &byte, -1); trl78_uart1_send(1, &byte, -1);
busy_wait_us_32(70); // tMB //busy_wait_us_32(70); // tMB
busy_wait_ms(4);
// now a baudrate set command needs to be sent, but we leave that to the // now a baudrate set command needs to be sent, but we leave that to the
// upper (command processing) layer as it has to know about those timings // upper (command processing) layer as it has to know about those timings

View File

@ -32,7 +32,8 @@ static bool trl78_uart2_init(void) {
uint8_t byte = (uint8_t)tool78_entry_rl78_uart2; uint8_t byte = (uint8_t)tool78_entry_rl78_uart2;
trl78_uart2_send(1, &byte, -1); trl78_uart2_send(1, &byte, -1);
busy_wait_us_32(70); // tMB //busy_wait_us_32(70); // tMB
busy_wait_ms(4);
// now init the real UART lines // now init the real UART lines
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff, tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,