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 <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <hardware/adc.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 uint8_t databuf[DUMP_SIZE];
static struct glitch_param_randrange offset; 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) { static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
offset.min = 10*1000; offset.min = 10*1000;
@ -53,14 +54,15 @@ static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
length.min = 100; length.min = 100;
length.max = 50/*26*/*1000; length.max = 50/*26*/*1000;
#if PINOUT_USE_DRAGONZAP #if PINOUT_USE_DRAGONZAP
length.adc_index = 0;//999; //length.adc_index = 0;//999;
#else #else
#error "a" #error "a"
length.adc_index = 999; //length.adc_index = 999;
#endif #endif
glitch_param_randrange_init(&offset); 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! // 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){ 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){ gparam.length_ns = (struct glitch_param){
.ud = &length, .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); return glitch_ready(&gparam);
} }
static void glitch_init_pwm_stuff(void) { static void glitch_init_pwm_stuff(void) {
@ -578,23 +580,26 @@ void cli_tool78_glitch_param_g10(void) {
zap_dac_set_shutdown(false); zap_dac_set_shutdown(false);
#endif #endif
//zap_max_init(false, true);
zap_max_use_vhi_jp300(true); zap_max_use_vhi_jp300(true);
zap_max_set_inhibit(false); 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"); printf("bad glitcher params!\n");
return; return;
} }
uint8_t passwd[10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uint8_t passwd[10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
enum tool78_stat st; enum tool78_stat st;
uint16_t vvv=0xffff;
int rr; int rr;
static uint8_t checkbuf[256]; static uint8_t checkbuf[256];
volatile uint32_t *off, *len;
bool first = true; bool first = true;
restart: restart:
/*glitch_disarm(); glitch_disarm();
busy_wait_ms(40);*/ /*busy_wait_ms(40);*/
st = tool78_init_ocd(hw, NULL, passwd); st = tool78_init_ocd(hw, NULL, passwd);
if (st == 0xc3) { if (st == 0xc3) {
@ -609,7 +614,14 @@ restart:
} }
//printf("result: 0x%02x ver=%04x\n", st, ver); //printf("result: 0x%02x ver=%04x\n", st, ver);
if (st != 0xf2 && st != 0xf0) { 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; goto deinit_bad;
} }
if (first) printf("result: 0x%02x\n", st); if (first) printf("result: 0x%02x\n", st);
@ -660,7 +672,6 @@ restart:
goto deinit_bad; goto deinit_bad;
} }
// wait for completion // wait for completion
rr = hw->recv(2, checkbuf, 150*1000); rr = hw->recv(2, checkbuf, 150*1000);
if (rr != 2) { if (rr != 2) {
@ -697,11 +708,22 @@ restart:
if (first) printf("all set, let's go\n"); if (first) printf("all set, let's go\n");
first = false; 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) { 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); rr = hw->recv(2, checkbuf, 150*1000);
//printf("rr=%d cb=%02x %02x\n", rr, checkbuf[0], checkbuf[1]); //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 && (checkbuf[0] != 'H' || checkbuf[1] != 'i')) rr = 0;
if (rr == 2) { if (rr == 2) {
rr = hw->recv(lenlen, checkbuf, 150*1000); rr = hw->recv(lenlen, checkbuf, 150*1000);
@ -711,6 +733,9 @@ restart:
if (rr <= 0) { if (rr <= 0) {
// timeout or something // timeout or something
printf("X"); 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(); hw->deinit();
goto do_reset_stuff; goto do_reset_stuff;
} else { } else {
@ -722,29 +747,31 @@ restart:
} }
} }
if (firstbad >= 0) { if (firstbad >= 0) {
volatile uint32_t //gpio_put(12, true);
*off = (volatile uint32_t*)&glitch_param_cur.offset_ns.cur, off = (volatile uint32_t*)&glitch_param_cur.offset_ns.cur;
*len = (volatile uint32_t*)&glitch_param_cur.length_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", printf("glitch first=%d last=%d off=%lu len=%lu vvv=%03x rr=%d v=%02x\n",
firstbad, lastbad, *off, *len, rr, checkbuf[firstbad]^0xaa); firstbad, lastbad, *off, *len, vvv, rr, checkbuf[firstbad]^0xaa);
//gpio_put(12, false);
} else { } else {
printf("."); printf(".");
printf("NN off=%lu len=%lu vv=%03x\n", *off, *len, vvv);
} }
} }
} }
deinit_bad: deinit_bad:
busy_wait_ms(1000); busy_wait_ms(500);
hw->deinit(); hw->deinit();
return; return;
do_reset_stuff: do_reset_stuff:
busy_wait_ms(1000); busy_wait_ms(300);
hw->deinit(); hw->deinit();
// glitch for way too long to power cycle // 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); busy_wait_ms(16);
sio_hw->gpio_clr = 1u << GLITCH_OUT_PIN; sio_hw->gpio_clr = 1u << ZAP_GLITCH_OUT;
goto restart; goto restart;
} }
@ -852,9 +879,9 @@ void cli_tool78_glitch_ocd_g10(void) {
// hw->deinit(); // hw->deinit();
// //
// // glitch for way too long to power cycle // // 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); // busy_wait_ms(16);
// sio_hw->gpio_clr = 1u << GLITCH_OUT_PIN; // sio_hw->gpio_clr = 1u << ZAP_GLITCH_OUT;
// //
// goto restart; // 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_wait_glitch_irq(trigctl_pio, trigctl_sm, true);
trigctl_ack_glitch_irq(trigctl_pio, trigctl_sm); 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_init(25);
gpio_set_dir(25, GPIO_OUT); gpio_set_dir(25, GPIO_OUT);
gpio_set_function(25, GPIO_FUNC_SIO);
gpio_put(25, false); gpio_put(25, false);
// let's not care about impl and always use core1 for now // let's not care about impl and always use core1 for now

View File

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