picoemp stuff for g10 glitching (doesn't work...)

This commit is contained in:
Triss 2022-05-02 03:21:00 +02:00
parent 83aca5a0fb
commit 37a41e5f83
5 changed files with 74 additions and 46 deletions

View File

@ -47,12 +47,14 @@ 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_randrange/*adc*/ length;
//static struct glitch_param_const length;
static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
offset.min = 10*1000;
offset.max = 35433*1000;
length.min = 100;
length.max = 50/*26*/*1000;
length.max = 10*50/*26*/*1000;
//length.value = 5*1000; // 5 us
#if PINOUT_USE_DRAGONZAP
//length.adc_index = 0;//999;
#else
@ -61,6 +63,7 @@ static bool glitch_init_core1_stuff(bool exttrig, uint glitchpin) {
#endif
glitch_param_randrange_init(&offset);
glitch_param_const_init(&length);
glitch_param_randrange_init(&length);
//glitch_param_adc_init(&length);
@ -580,9 +583,9 @@ 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);
/*zap_max_use_vhi_jp300(true);
zap_max_set_inhibit(false);*/
zap_picoemp_init();
if (!glitch_init_core1_stuff(true, ZAP_GLITCH_OUT)) {
printf("bad glitcher params!\n");
@ -598,9 +601,13 @@ void cli_tool78_glitch_param_g10(void) {
bool first = true;
restart:
zap_picoemp_set_armed(false);
glitch_disarm();
/*busy_wait_ms(40);*/
zap_picoemp_set_armed(true);
while (!zap_picoemp_has_hv()) ;
st = tool78_init_ocd(hw, NULL, passwd);
if (st == 0xc3) {
printf("aa\n");
@ -615,9 +622,9 @@ restart:
//printf("result: 0x%02x ver=%04x\n", st, ver);
if (st != 0xf2 && st != 0xf0) {
if (st == 0xf3) { // idk
gpio_put(12, true);
//gpio_put(12, true);
printf("init: 0x%02x off=%lu len=%lu vv=%03x\n", st, *off, *len, vvv);
gpio_put(12, false);
//gpio_put(12, false);
goto do_reset_stuff;
} else {
printf("init: 0x%02x\n", st);
@ -716,62 +723,73 @@ restart:
gpio_set_dir(7, GPIO_IN);*/
while (true) {
//vvv = zap_adc_read(1);
/*//vvv = zap_adc_read(1);
vvv = (random() & 0x3ff) + 0x400;
zap_dac_set_b(vvv);
zap_dac_latch();
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();
if (rr == 2 && (checkbuf[0] != 'H' || checkbuf[1] != 'i')) rr = 0;
if (rr == 2) {
rr = hw->recv(lenlen, checkbuf, 150*1000);
//printf("recv data rr=%d\n", rr);
}
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 {
int firstbad = -1, lastbad = -1;
for (int i = 0; i < rr; ++i) {
if (checkbuf[i] != (0xaa^0xff)) {
if (firstbad == -1) firstbad = i;
lastbad = i;
}
bool first_ = true;
do {
if (rr == 2 && (checkbuf[0] != 'H' || checkbuf[1] != 'i')) rr = 0;
if (rr == 2) {
rr = hw->recv(lenlen, checkbuf, 150*1000);
//printf("recv data rr=%d\n", rr);
}
if (firstbad >= 0) {
//gpio_put(12, true);
if (rr <= 0) {
if (!first_) break;
// 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("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);
//printf("X off=%lu len=%lu vv=%03x\n", *off, *len, vvv);
hw->deinit();
goto do_reset_stuff;
} else {
printf(".");
printf("NN off=%lu len=%lu vv=%03x\n", *off, *len, vvv);
int firstbad = -1, lastbad = -1;
for (int i = 0; i < rr; ++i) {
if (checkbuf[i] != (0xaa^0xff)) {
if (firstbad == -1) firstbad = i;
lastbad = i;
}
}
if (firstbad >= 0) {
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);
}
}
}
first_=false;
if (!zap_picoemp_has_hv()) {
rr = hw->recv(2, checkbuf, 150*1000);
} else break;
} while (true);
}
deinit_bad:
zap_picoemp_set_armed(false);
busy_wait_ms(500);
hw->deinit();
return;
do_reset_stuff:
zap_picoemp_set_armed(false);
busy_wait_ms(300);
hw->deinit();
// glitch for way too long to power cycle
sio_hw->gpio_set = 1u << ZAP_GLITCH_OUT;
//sio_hw->gpio_set = 1u << ZAP_GLITCH_OUT;
busy_wait_ms(16);
sio_hw->gpio_clr = 1u << ZAP_GLITCH_OUT;
//sio_hw->gpio_clr = 1u << ZAP_GLITCH_OUT;
goto restart;
}

View File

@ -12,11 +12,11 @@ void zap_adc_init(void) {
adc_gpio_init(ZAP_ADC_A);
adc_gpio_init(ZAP_ADC_B);
//adc_gpio_init(ZAP_ADC_REF);
adc_gpio_init(ZAP_ADC_CHG);
}
uint16_t zap_adc_read(int idx) {
if (idx < 0 || idx >= 2/*3*/) return 0xf000;
if (idx < 0 || idx >= 3/*3*/) return 0xf000;
adc_select_input(idx);
return adc_read();

View File

@ -10,6 +10,7 @@
#include <hardware/pwm.h>
#include <pico/time.h>
#include "zap_adc.h"
#include "zap_pinout.h"
#include "zap_picoemp.h"
@ -24,10 +25,11 @@ void zap_picoemp_init(void) {
gpio_set_slew_rate(ZAP_PICOEMP_HVP, GPIO_SLEW_RATE_FAST);
gpio_set_function(ZAP_PICOEMP_HVP, GPIO_FUNC_SIO);
gpio_set_dir(ZAP_PICOEMP_CHG, GPIO_IN);
zap_adc_init();
/*gpio_set_dir(ZAP_PICOEMP_CHG, GPIO_IN);
gpio_set_pulls(ZAP_PICOEMP_CHG, false, false);
gpio_set_inover(ZAP_PICOEMP_CHG, GPIO_OVERRIDE_INVERT);
gpio_set_function(ZAP_PICOEMP_CHG, GPIO_FUNC_SIO);
gpio_set_function(ZAP_PICOEMP_CHG, GPIO_FUNC_SIO);*/
zap_picoemp_set_armed(false);
}
@ -81,13 +83,17 @@ void zap_picoemp_set_armed(bool arm) {
}
void zap_picoemp_pulse(void) {
gpio_put(ZAP_PICOEMP_HVP, true);
/*gpio_put(ZAP_PICOEMP_HVP, true);
busy_wait_us_32(5);
gpio_put(ZAP_PICOEMP_HVP, false);
busy_wait_us_32(5);
busy_wait_us_32(5);*/
gpio_put(ZAP_PICOEMP_HVP, true);
busy_wait_us_32(5);
gpio_put(ZAP_PICOEMP_HVP, false);
busy_wait_ms(250);
}
uint16_t zap_picoemp_chg_get(void) {
return zap_adc_read(2);
}

View File

@ -10,8 +10,12 @@ void zap_picoemp_init(void);
bool zap_picoemp_get_armed(void);
void zap_picoemp_set_armed(bool arm);
uint16_t zap_picoemp_chg_get(void);
static inline bool zap_picoemp_has_hv(void) {
return zap_picoemp_chg_get() < ((uint32_t)((0.85f/3.3f)*0xfff));
}
void zap_picoemp_pulse(void);
#endif

View File

@ -24,10 +24,10 @@
#define ZAP_ADC_A 26
#define ZAP_ADC_B 27
/*#define ZAP_ADC_REF 28*/
#define ZAP_ADC_CHG 28
#define ZAP_PICOEMP_PWM 14
#define ZAP_PICOEMP_CHG 15
/*#define ZAP_PICOEMP_CHG 15*/
#define ZAP_PICOEMP_HVP ZAP_GLITCH_OUT
#endif