Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyquagsire23 committed Apr 27, 2023
1 parent 273229d commit 489a877
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 64 deletions.
28 changes: 7 additions & 21 deletions pico_defuse/src/pico_defuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ PIO pio_exi;
int debug_gpio_monitor_dmachan;
dma_channel_config debug_gpio_monitor_dmacfg;
uint debug_gpio_monitor_parallel_sm;
uint reset_cycle_accurate_sm;
uint exi_inject_sm;
uint exi_inject_offset;
uint debug_gpio_monitor_parallel_offset;
uint debug_gpio_monitor_serial_offset;
uint reset_cycle_accurate_offset;

#define MONITOR_SERIAL_DATA (0)
#define MONITOR_SERIAL_TEXT (1)
Expand Down Expand Up @@ -139,8 +137,12 @@ bool nrst_sense_state = false;
#define DEFUSE_BYTE_UNIT (0x4)

#ifdef DEFUSE_JTAG
#define RESET_RANGE_MIN (RESET_RANGE_MAX-(DEFUSE_BYTE_UNIT*0x20))
#define RESET_RANGE_MAX (0xE9C)
// Start from 0 and increase this to make it boot slightly faster,
// instead of just overshooting it for the guarantee
#define JTAG_VARIANCE (0)

#define RESET_RANGE_MIN (RESET_RANGE_MAX-(DEFUSE_BYTE_UNIT/2))
#define RESET_RANGE_MAX (0xEA8-JTAG_VARIANCE)
#else
#define RESET_RANGE_MIN (RESET_RANGE_MAX-(DEFUSE_BYTE_UNIT*0x40))
#define RESET_RANGE_MAX (0xE8C-(DEFUSE_BYTE_UNIT*0x7D))
Expand Down Expand Up @@ -239,12 +241,10 @@ void slow_one_time_init()
// We use two statemachines: one for the debug monitor, and one for the EXI injecting.
debug_gpio_monitor_parallel_sm = pio_claim_unused_sm(pio, true);
exi_inject_sm = pio_claim_unused_sm(pio_exi, true);
//reset_cycle_accurate_sm = pio_claim_unused_sm(pio_exi, true);

// The exi inject statemachine is only used during de_Fusing, it just watches
// for 64 EXI clks and shoves the line high so the SDboot bit gets read as 1.
exi_inject_offset = pio_add_program(pio_exi, &exi_inject_program);
//reset_cycle_accurate_offset = pio_add_program(pio_exi, &reset_cycle_accurate_program);

// The debug monitor has two programs: The parallel monitor, used to check boot0
// codes, and the serial monitor, which is used for the text console in minute/etc
Expand Down Expand Up @@ -284,9 +284,6 @@ void do_normal_reset()

void de_fuse()
{
//reset_cycle_accurate_program_init(pio_exi, reset_cycle_accurate_sm, reset_cycle_accurate_offset, PIN_NRST, 0, 1.0);
//pio_sm_set_enabled(pio_exi, reset_cycle_accurate_sm, false);

// Disable NRST sensing and take control of the line.
nrst_sense_set(false);

Expand Down Expand Up @@ -356,18 +353,6 @@ void de_fuse()
restore_interrupts(cookie);
#endif
#if 1
//reset_cycle_accurate_program_reset(pio_exi, reset_cycle_accurate_sm, reset_cycle_accurate_offset, PIN_NRST, reset_attempt, 1.0);
//pio_sm_set_enabled(pio_exi, reset_cycle_accurate_sm, true);
//sleep_ms(1);
/*for(int i = 0; i < 0x210; i++)
{
__asm volatile ("\n");
}*/
//pio_sm_set_enabled(pio_exi, reset_cycle_accurate_sm, false);
gpio_set_function(PIN_NRST, GPIO_FUNC_SIO);
#endif

// Clear out the FIFO so our results readout is clean.
for (int i = 0; i < 0x20; i++)
{
Expand Down Expand Up @@ -457,6 +442,7 @@ void de_fuse()
//sleep_ms(1000);
}

// JTAG has a much smaller window
#ifndef DEFUSE_JTAG
// TODO: do this after trying a NAND boot1?
// If no SD card is inserted, or an invalid one is inserted, boot0 stalls.
Expand Down
43 changes: 0 additions & 43 deletions pico_defuse/src/pico_defuse.pio
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ loop:
set pins, 0xF
jmp reset

.program reset_cycle_accurate
start:
; We can't mov the value 0x40 lol, pull it in this way.
pull block
mov x, osr
mov y, x

; set it high for exactly the number of cycles given
set pins, 0x0
loop2:
jmp y--, loop2

; back to low so we can hand the GPIO back
set pins, 0x0
stall:
jmp stall

.program exi_inject
start:
; We can't mov the value 0x40 lol, pull it in this way.
Expand Down Expand Up @@ -149,32 +132,6 @@ stall:
pio_sm_init(pio, sm, offset, &c);
}

void reset_cycle_accurate_program_init(PIO pio, uint sm, uint offset, uint rst_pin, uint rst_duration, float div) {
pio_sm_config c = pio_get_default_sm_config();

sm_config_set_set_pins(&c, rst_pin, 1);

sm_config_set_in_shift(&c, false, false, 32);
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

pio_sm_set_pins(pio, sm, 0x0);
pio_sm_set_consecutive_pindirs(pio, sm, rst_pin, 1, true);

pio_sm_init(pio, sm, offset, &c);

pio_sm_put(pio, sm, rst_duration);
}

void reset_cycle_accurate_program_reset(PIO pio, uint sm, uint offset, uint rst_pin, uint rst_duration, float div) {
pio_sm_config c = pio_get_default_sm_config();

pio_sm_set_pins(pio, sm, 0x0);
pio_gpio_init(pio, rst_pin);
pio_sm_init(pio, sm, offset, &c);

pio_sm_put(pio, sm, rst_duration);
}

void exi_inject_program_init(PIO pio, uint sm, uint offset, uint pin_clk, uint pin_data, float div) {
pio_sm_config c = pio_get_default_sm_config();

Expand Down

0 comments on commit 489a877

Please sign in to comment.