rl78/g10 paramsearch: functional, but not finding any good param set

This commit is contained in:
Triss 2022-04-28 15:44:44 +02:00
parent d45c4a95a9
commit 83aca5a0fb
3 changed files with 59 additions and 25 deletions

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hardware/adc.h>
@ -45,7 +46,7 @@ sec: flg=fe bot=03 fsws=0000 fswe=003f
static uint8_t databuf[DUMP_SIZE];
static struct glitch_param_randrange offset;
static struct glitch_param_adc length;
static struct glitch_param_randrange/*adc*/ length;
static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
offset.min = 10*1000;
@ -53,14 +54,15 @@ static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
length.min = 100;
length.max = 50/*26*/*1000;
#if PINOUT_USE_DRAGONZAP
length.adc_index = 0;//999;
//length.adc_index = 0;//999;
#else
#error "a"
length.adc_index = 999;
//length.adc_index = 999;
#endif
glitch_param_randrange_init(&offset);
glitch_param_adc_init(&length);
glitch_param_randrange_init(&length);
//glitch_param_adc_init(&length);
// REGC = 2.11V / 0.47..1 uF // WUFM: REGC = 1.80V // BUT: OCD mode: always 2.1!
static struct glitch_params gparam = (struct glitch_params){
@ -95,9 +97,9 @@ static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
};
gparam.length_ns = (struct glitch_param){
.ud = &length,
.getter = glitch_param_adc_fn
.getter = glitch_param_randrange_fn,//adc_fn
};
gparam.trigger_in_pin = exttrig ? TRIGGER_IN_PIN : (-1);
gparam.trigger_in_pin = exttrig ? TRIGGER_IN_PIN/*7*/ : (-1);
return glitch_ready(&gparam);
}
static void glitch_init_pwm_stuff(void) {
@ -578,23 +580,26 @@ void cli_tool78_glitch_param_g10(void) {
zap_dac_set_shutdown(false);
#endif
//zap_max_init(false, true);
zap_max_use_vhi_jp300(true);
zap_max_set_inhibit(false);
if (!glitch_init_core1_stuff(true, GLITCH_OUT_PIN)) {
if (!glitch_init_core1_stuff(true, ZAP_GLITCH_OUT)) {
printf("bad glitcher params!\n");
return;
}
uint8_t passwd[10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
enum tool78_stat st;
uint16_t vvv=0xffff;
int rr;
static uint8_t checkbuf[256];
volatile uint32_t *off, *len;
bool first = true;
restart:
/*glitch_disarm();
busy_wait_ms(40);*/
glitch_disarm();
/*busy_wait_ms(40);*/
st = tool78_init_ocd(hw, NULL, passwd);
if (st == 0xc3) {
@ -609,7 +614,14 @@ restart:
}
//printf("result: 0x%02x ver=%04x\n", st, ver);
if (st != 0xf2 && st != 0xf0) {
printf("init: 0x%02x\n", st);
if (st == 0xf3) { // idk
gpio_put(12, true);
printf("init: 0x%02x off=%lu len=%lu vv=%03x\n", st, *off, *len, vvv);
gpio_put(12, false);
goto do_reset_stuff;
} else {
printf("init: 0x%02x\n", st);
}
goto deinit_bad;
}
if (first) printf("result: 0x%02x\n", st);
@ -660,7 +672,6 @@ restart:
goto deinit_bad;
}
// wait for completion
rr = hw->recv(2, checkbuf, 150*1000);
if (rr != 2) {
@ -697,11 +708,22 @@ restart:
if (first) printf("all set, let's go\n");
first = false;
gpio_init(12);
gpio_set_dir(12, GPIO_OUT);
gpio_set_function(12, GPIO_FUNC_SIO);
gpio_put(12, false);
/*gpio_init(7);
gpio_set_dir(7, GPIO_IN);*/
while (true) {
//glitch_arm();
//vvv = zap_adc_read(1);
vvv = (random() & 0x3ff) + 0x400;
zap_dac_set_b(vvv);
zap_dac_latch();
glitch_arm();
rr = hw->recv(2, checkbuf, 150*1000);
//printf("rr=%d cb=%02x %02x\n", rr, checkbuf[0], checkbuf[1]);
//glitch_disarm();
glitch_disarm();
if (rr == 2 && (checkbuf[0] != 'H' || checkbuf[1] != 'i')) rr = 0;
if (rr == 2) {
rr = hw->recv(lenlen, checkbuf, 150*1000);
@ -711,6 +733,9 @@ restart:
if (rr <= 0) {
// timeout or something
printf("X");
off = (volatile uint32_t*)&glitch_param_cur.offset_ns.cur;
len = (volatile uint32_t*)&glitch_param_cur.length_ns.cur;
printf("X off=%lu len=%lu vv=%03x\n", *off, *len, vvv);
hw->deinit();
goto do_reset_stuff;
} else {
@ -722,29 +747,31 @@ restart:
}
}
if (firstbad >= 0) {
volatile uint32_t
*off = (volatile uint32_t*)&glitch_param_cur.offset_ns.cur,
*len = (volatile uint32_t*)&glitch_param_cur.length_ns.cur;
printf("glitch first=%d last=%d off=%lu len=%lu rr=%d v=%02x\n",
firstbad, lastbad, *off, *len, rr, checkbuf[firstbad]^0xaa);
//gpio_put(12, true);
off = (volatile uint32_t*)&glitch_param_cur.offset_ns.cur;
len = (volatile uint32_t*)&glitch_param_cur.length_ns.cur;
printf("glitch first=%d last=%d off=%lu len=%lu vvv=%03x rr=%d v=%02x\n",
firstbad, lastbad, *off, *len, vvv, rr, checkbuf[firstbad]^0xaa);
//gpio_put(12, false);
} else {
printf(".");
printf("NN off=%lu len=%lu vv=%03x\n", *off, *len, vvv);
}
}
}
deinit_bad:
busy_wait_ms(1000);
busy_wait_ms(500);
hw->deinit();
return;
do_reset_stuff:
busy_wait_ms(1000);
busy_wait_ms(300);
hw->deinit();
// glitch for way too long to power cycle
sio_hw->gpio_set = 1u << GLITCH_OUT_PIN;
sio_hw->gpio_set = 1u << ZAP_GLITCH_OUT;
busy_wait_ms(16);
sio_hw->gpio_clr = 1u << GLITCH_OUT_PIN;
sio_hw->gpio_clr = 1u << ZAP_GLITCH_OUT;
goto restart;
}
@ -852,9 +879,9 @@ void cli_tool78_glitch_ocd_g10(void) {
// hw->deinit();
//
// // glitch for way too long to power cycle
// sio_hw->gpio_set = 1u << GLITCH_OUT_PIN;
// sio_hw->gpio_set = 1u << ZAP_GLITCH_OUT;
// busy_wait_ms(16);
// sio_hw->gpio_clr = 1u << GLITCH_OUT_PIN;
// sio_hw->gpio_clr = 1u << ZAP_GLITCH_OUT;
//
// goto restart;
//

View File

@ -186,7 +186,8 @@ static void CORE1_FUNC(glitch_core1_thread_pio)(void) {
trigctl_wait_glitch_irq(trigctl_pio, trigctl_sm, true);
trigctl_ack_glitch_irq(trigctl_pio, trigctl_sm);
gpio_put(25, true);
//gpio_put(25, true);
//sio_hw->gpio_togl = 1u<<25;
}
}
@ -295,6 +296,7 @@ bool CORE0_FUNC(glitch_ready)(const struct glitch_params* params) {
gpio_init(25);
gpio_set_dir(25, GPIO_OUT);
gpio_set_function(25, GPIO_FUNC_SIO);
gpio_put(25, false);
// let's not care about impl and always use core1 for now

View File

@ -16,6 +16,7 @@ public _start:
irq clear 0 rel
mov isr, x
public waitinsn:
wait 1 pin 0 ; or "wait irq 1 rel"
@ -31,6 +32,10 @@ lenloop:
irq set 0 rel
;set x, 15
mov x, isr
offloop2:
jmp x-- offloop2 ;[15]
public wait2:
wait 0 pin 0 ; or "nop"