Compare commits
29
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb9827f821 | ||
|
|
d3dca674aa | ||
|
|
06f6f2b4f6 | ||
|
|
d2e58f6a8a | ||
|
|
1c497e1f1e | ||
|
|
476dd2212e | ||
|
|
5c2cf01ac1 | ||
|
|
f1078f48cb | ||
|
|
e307c02199 | ||
|
|
e2c0bcea68 | ||
|
|
4a8ab75e32 | ||
|
|
4ee7662b27 | ||
|
|
c4fe34f6f2 | ||
|
|
eb23f0e1cd | ||
|
|
528a8f698f | ||
|
|
d7f667bc61 | ||
|
|
acdcf88e51 | ||
|
|
6530fd9fe5 | ||
|
|
4ea9a57859 | ||
|
|
2a27fc3aca | ||
|
|
e5a1dcdff8 | ||
|
|
262b897103 | ||
|
|
d2fae0f934 | ||
|
|
1a39e9b46d | ||
|
|
25d9389924 | ||
|
|
b3c0af112c | ||
|
|
ef474b7f20 | ||
|
|
e98219c475 | ||
|
|
7ca69d4b76 |
No files matched your search
@@ -45,8 +45,8 @@ jobs:
|
|||||||
- name: Build busk
|
- name: Build busk
|
||||||
run: |
|
run: |
|
||||||
# Backup and modify memmap_default.ld for busk build
|
# Backup and modify memmap_default.ld for busk build
|
||||||
cp $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld.bak
|
cp $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld.bak
|
||||||
sed -i 's/RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k/RAM(rwx) : ORIGIN = 0x20038000, LENGTH = 32k/g' $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld
|
sed -i 's/RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k/RAM(rwx) : ORIGIN = 0x20038000, LENGTH = 32k/g' $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld
|
||||||
mkdir -p $GITHUB_WORKSPACE/build/busk
|
mkdir -p $GITHUB_WORKSPACE/build/busk
|
||||||
cd $GITHUB_WORKSPACE/build/busk
|
cd $GITHUB_WORKSPACE/build/busk
|
||||||
cmake $GITHUB_WORKSPACE/busk
|
cmake $GITHUB_WORKSPACE/busk
|
||||||
@@ -54,8 +54,8 @@ jobs:
|
|||||||
make clean
|
make clean
|
||||||
cd $GITHUB_WORKSPACE
|
cd $GITHUB_WORKSPACE
|
||||||
# Restore original memmap_default.ld from backup
|
# Restore original memmap_default.ld from backup
|
||||||
rm -f $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld
|
rm -f $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld
|
||||||
mv $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld.bak $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_standard_link/memmap_default.ld
|
mv $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld.bak $GITHUB_WORKSPACE/pico-sdk/src/rp2_common/pico_crt0/rp2040/memmap_default.ld
|
||||||
|
|
||||||
- name: Build usk
|
- name: Build usk
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
+3
-1
@@ -20,11 +20,13 @@ add_executable(usk main.c board_detect.c fuses.c pio_upload.c boot_detect.c conf
|
|||||||
|
|
||||||
target_compile_definitions(usk PRIVATE PICO_NO_BINARY_INFO)
|
target_compile_definitions(usk PRIVATE PICO_NO_BINARY_INFO)
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/generated")
|
||||||
|
|
||||||
pico_generate_pio_header(usk ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated)
|
pico_generate_pio_header(usk ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated)
|
||||||
pico_generate_pio_header(usk ${CMAKE_CURRENT_LIST_DIR}/emmc.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated)
|
pico_generate_pio_header(usk ${CMAKE_CURRENT_LIST_DIR}/emmc.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated)
|
||||||
|
|
||||||
pico_set_program_name(usk "usk")
|
pico_set_program_name(usk "usk")
|
||||||
pico_set_program_version(usk "2.7")
|
pico_set_program_version(usk "3.00")
|
||||||
|
|
||||||
pico_set_binary_type(usk no_flash)
|
pico_set_binary_type(usk no_flash)
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
# μsk
|
# Woody-NX μsk V3.00
|
||||||
|
|
||||||
|
Rehius-based RP2040 firmware with Woody-NX modifications: custom Picofly screen, battery indicator, S1/LVS integration, Samsung eMMC CMD1 adjustment, V3.00 version and brighter LEDs with red error codes. No PWM.
|
||||||
|
|
||||||
|
Original Rehius license retained. The prepared Switch loader and custom additions are embedded in payload.h; complete original Switch-loader core source is not part of this native firmware directory.
|
||||||
+22
-9
@@ -14,12 +14,13 @@ enum board_type {
|
|||||||
BOARD_XO,
|
BOARD_XO,
|
||||||
BOARD_IB,
|
BOARD_IB,
|
||||||
BOARD_PI,
|
BOARD_PI,
|
||||||
BOARD_SQ
|
BOARD_SQ,
|
||||||
|
BOARD_WT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum board_type cur_board = BOARD_WS;
|
enum board_type cur_board = BOARD_WS;
|
||||||
|
|
||||||
bool detect_by_pull_up(int frc_pin, int det_pin)
|
bool detect_by_pull(int frc_pin, int det_pin, bool up)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (frc_pin >= 0)
|
if (frc_pin >= 0)
|
||||||
@@ -27,9 +28,9 @@ bool detect_by_pull_up(int frc_pin, int det_pin)
|
|||||||
gpio_init(det_pin);
|
gpio_init(det_pin);
|
||||||
if (frc_pin >= 0)
|
if (frc_pin >= 0)
|
||||||
gpio_set_dir(frc_pin, true);
|
gpio_set_dir(frc_pin, true);
|
||||||
gpio_pull_up(det_pin);
|
gpio_set_pulls(det_pin, up, !up);
|
||||||
sleep_us(15);
|
sleep_us(15);
|
||||||
result = !gpio_get(det_pin);
|
result = gpio_get(det_pin) ^ up;
|
||||||
gpio_deinit(det_pin);
|
gpio_deinit(det_pin);
|
||||||
if (frc_pin >= 0)
|
if (frc_pin >= 0)
|
||||||
gpio_deinit(frc_pin);
|
gpio_deinit(frc_pin);
|
||||||
@@ -39,27 +40,32 @@ bool detect_by_pull_up(int frc_pin, int det_pin)
|
|||||||
|
|
||||||
bool test_xiao()
|
bool test_xiao()
|
||||||
{
|
{
|
||||||
return detect_by_pull_up(1, 2);
|
return detect_by_pull(1, 2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_itsy()
|
bool test_itsy()
|
||||||
{
|
{
|
||||||
return detect_by_pull_up(3, 2);
|
return detect_by_pull(3, 2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_pico()
|
bool test_pico()
|
||||||
{
|
{
|
||||||
return detect_by_pull_up(-1, 22);
|
return detect_by_pull(-1, 22, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_ws()
|
bool test_ws()
|
||||||
{
|
{
|
||||||
return detect_by_pull_up(-1, 25);
|
return detect_by_pull(-1, 25, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool test_wt()
|
||||||
|
{
|
||||||
|
return detect_by_pull(-1, 16, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_sqc()
|
bool test_sqc()
|
||||||
{
|
{
|
||||||
return detect_by_pull_up(-1, 17);
|
return detect_by_pull(-1, 17, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void detect_board()
|
void detect_board()
|
||||||
@@ -79,6 +85,8 @@ void detect_board()
|
|||||||
cur_board = BOARD_PI;
|
cur_board = BOARD_PI;
|
||||||
} else if (test_sqc()) {
|
} else if (test_sqc()) {
|
||||||
cur_board = BOARD_SQ;
|
cur_board = BOARD_SQ;
|
||||||
|
} else if (test_wt()) {
|
||||||
|
cur_board = BOARD_WT;
|
||||||
} else {
|
} else {
|
||||||
cur_board = BOARD_WS;
|
cur_board = BOARD_WS;
|
||||||
}
|
}
|
||||||
@@ -160,3 +168,8 @@ bool is_pico()
|
|||||||
{
|
{
|
||||||
return cur_board == BOARD_PI;
|
return cur_board == BOARD_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_tiny()
|
||||||
|
{
|
||||||
|
return cur_board == BOARD_WT;
|
||||||
|
}
|
||||||
+3
-2
@@ -1,11 +1,12 @@
|
|||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
|
|
||||||
bool detect_by_pull_up(int frc_pin, int det_pin);
|
bool detect_by_pull(int frc_pin, int det_pin, bool up);
|
||||||
|
|
||||||
void detect_board();
|
void detect_board();
|
||||||
int gli_pin();
|
int gli_pin();
|
||||||
int pwr_pin();
|
int pwr_pin();
|
||||||
int led_pin();
|
int led_pin();
|
||||||
bool is_pico();
|
bool is_pico();
|
||||||
|
bool is_tiny();
|
||||||
int scl_pin();
|
int scl_pin();
|
||||||
int sda_pin();
|
int sda_pin();
|
||||||
+26
-19
@@ -12,7 +12,7 @@ bool board_detected = false;
|
|||||||
|
|
||||||
bool wait_for_boot(int timeout_ms) {
|
bool wait_for_boot(int timeout_ms) {
|
||||||
absolute_time_t tio_full = make_timeout_time_ms(timeout_ms);
|
absolute_time_t tio_full = make_timeout_time_ms(timeout_ms);
|
||||||
absolute_time_t tio_cmd1 = tio_full;
|
absolute_time_t tio_shrt = tio_full;
|
||||||
init_glitch_pio();
|
init_glitch_pio();
|
||||||
reset_cpu();
|
reset_cpu();
|
||||||
uint32_t word=0, last_word=0;
|
uint32_t word=0, last_word=0;
|
||||||
@@ -20,32 +20,48 @@ bool wait_for_boot(int timeout_ms) {
|
|||||||
bool was_cmd1 = false;
|
bool was_cmd1 = false;
|
||||||
int reset_attempts = 0;
|
int reset_attempts = 0;
|
||||||
|
|
||||||
while(!time_reached(tio_full)) {
|
while(1) {
|
||||||
if (time_reached(tio_cmd1))
|
if (time_reached(tio_full))
|
||||||
{
|
{
|
||||||
if (reset_attempts > 4)
|
halt_with_error(3, 3);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (time_reached(tio_shrt))
|
||||||
|
{
|
||||||
|
if (reset_attempts > 10)
|
||||||
{
|
{
|
||||||
halt_with_error(0, 3);
|
if (was_read_zero) {
|
||||||
|
halt_with_error(1, 3);
|
||||||
|
}
|
||||||
|
else if (tio_shrt != tio_full) {
|
||||||
|
halt_with_error(0, 3);
|
||||||
|
}
|
||||||
|
else if (was_cmd1) {
|
||||||
|
halt_with_error(2, 3);
|
||||||
|
} else {
|
||||||
|
halt_with_error(3, 3);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
reset_attempts++;
|
reset_attempts++;
|
||||||
reset_cpu();
|
reset_cpu();
|
||||||
tio_cmd1 = tio_full;
|
tio_shrt = make_timeout_time_ms(1000);
|
||||||
}
|
}
|
||||||
if(!pio_sm_is_rx_fifo_empty(pio1, 0))
|
if(!pio_sm_is_rx_fifo_empty(pio1, 0))
|
||||||
{
|
{
|
||||||
word = pio_sm_get(pio1, 0);
|
word = pio_sm_get(pio1, 0);
|
||||||
if (last_word == 0x41000000 && word == 0x00F9) // cmd1 request
|
if (last_word == 0x41000000 && word == 0x00F9) // cmd1 request
|
||||||
{
|
{
|
||||||
tio_cmd1 = make_timeout_time_ms(20);
|
tio_shrt = make_timeout_time_ms(50);
|
||||||
was_cmd1 = true;
|
was_cmd1 = true;
|
||||||
}
|
}
|
||||||
else if (last_word == 0x00F9 && (word >> 24) == 0x3F) // cmd1 responce
|
else if (last_word == 0x00F9 && (word >> 24) == 0x3F) // cmd1 responce
|
||||||
{
|
{
|
||||||
tio_cmd1 = tio_full;
|
tio_shrt = tio_full;
|
||||||
}
|
}
|
||||||
else if (last_word == 0x51000000 && word == 0x0055) //read block 0
|
else if (last_word == 0x51000000 && word == 0x0055) //read block 0
|
||||||
{
|
{
|
||||||
tio_full = make_timeout_time_ms(100);
|
tio_shrt = make_timeout_time_ms(400);
|
||||||
was_read_zero = true;
|
was_read_zero = true;
|
||||||
} else if (was_read_zero && last_word == 0x4D000200 && word == 0x00B1) // read status - erista only
|
} else if (was_read_zero && last_word == 0x4D000200 && word == 0x00B1) // read status - erista only
|
||||||
{
|
{
|
||||||
@@ -58,13 +74,4 @@ bool wait_for_boot(int timeout_ms) {
|
|||||||
last_word = word;
|
last_word = word;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (was_read_zero) {
|
}
|
||||||
halt_with_error(1, 3);
|
|
||||||
}
|
|
||||||
else if (was_cmd1) {
|
|
||||||
halt_with_error(2, 3);
|
|
||||||
} else {
|
|
||||||
halt_with_error(3, 3);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "hardware/flash.h"
|
#include "hardware/flash.h"
|
||||||
#define OFFSET_DIV 10
|
#define OFFSET_DIV 8
|
||||||
#define OFFSET_MIN 6200
|
#define OFFSET_MIN 6200
|
||||||
#define OFFSET_MAX 6900
|
#define OFFSET_MAX 6900
|
||||||
|
|
||||||
#define VER_HI 2
|
#define VER_HI 3
|
||||||
#define VER_LO 73
|
#define VER_LO 0
|
||||||
|
|
||||||
bool is_configured();
|
bool is_configured();
|
||||||
void init_config();
|
void init_config();
|
||||||
|
|||||||
@@ -57,17 +57,12 @@ read_loop:
|
|||||||
|
|
||||||
.program glitch_dat_waiter
|
.program glitch_dat_waiter
|
||||||
.wrap_target
|
.wrap_target
|
||||||
mov x, y ; data length pre-loaded counter (512 + 16 - 1)
|
mov x, y ; data length pre-loaded counter (512 + 16 - 1) * 8
|
||||||
wait_for_start_bit:
|
wait 0 pin, 0
|
||||||
|
wait_for_data_pack:
|
||||||
wait 0 pin, 30
|
wait 0 pin, 30
|
||||||
wait 1 pin, 30
|
wait 1 pin, 30
|
||||||
jmp pin wait_for_start_bit ; wait for dat start bit of the rising edge
|
jmp x-- wait_for_data_pack
|
||||||
wait 0 pin, 30
|
|
||||||
skip_loop_dat:
|
|
||||||
wait 1 pin, 30
|
|
||||||
;in pins, 1 ; data sniffer (not needed anymore)
|
|
||||||
wait 0 pin, 30
|
|
||||||
jmp x-- skip_loop_dat ; skip the required data ticks
|
|
||||||
irq clear 1 ; 'data transfer done' trigger
|
irq clear 1 ; 'data transfer done' trigger
|
||||||
.wrap
|
.wrap
|
||||||
|
|
||||||
@@ -84,4 +79,4 @@ wait_for_timing:
|
|||||||
jmp x--, wait_for_timing side 0
|
jmp x--, wait_for_timing side 0
|
||||||
glitch_en:
|
glitch_en:
|
||||||
jmp y--, glitch_en side 1
|
jmp y--, glitch_en side 1
|
||||||
.wrap
|
.wrap
|
||||||
@@ -145,13 +145,12 @@ void inc_tries()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// random() for glitch offset array generation
|
// random() for glitch offset array generation
|
||||||
static uint32_t get_random_word() {
|
static uint32_t get_random_word(int cycles) {
|
||||||
uint32_t byte;
|
uint32_t byte;
|
||||||
int cycles = 32;
|
|
||||||
assert(rosc_hw->status & ROSC_STATUS_ENABLED_BITS);
|
assert(rosc_hw->status & ROSC_STATUS_ENABLED_BITS);
|
||||||
for(int i=0; i < cycles; i++) {
|
for(int i=0; i < cycles; i++) {
|
||||||
byte = ((byte << 1) | rosc_hw->randombit);
|
|
||||||
busy_wait_at_least_cycles(100);
|
busy_wait_at_least_cycles(100);
|
||||||
|
byte = ((byte << 1) | rosc_hw->randombit);
|
||||||
}
|
}
|
||||||
return byte;
|
return byte;
|
||||||
}
|
}
|
||||||
@@ -162,7 +161,7 @@ void prepare_random_array()
|
|||||||
for(int i = 0; i < OFFSET_CNT; i++)
|
for(int i = 0; i < OFFSET_CNT; i++)
|
||||||
offsets_array[i] = OFFSET_MIN + OFFSET_DIV*i;
|
offsets_array[i] = OFFSET_MIN + OFFSET_DIV*i;
|
||||||
for (int i = OFFSET_CNT - 1; i > 0; i--) {
|
for (int i = OFFSET_CNT - 1; i > 0; i--) {
|
||||||
size_t j = get_random_word() % (i+1);
|
size_t j = get_random_word(32) % (i+1);
|
||||||
int t = offsets_array[j];
|
int t = offsets_array[j];
|
||||||
offsets_array[j] = offsets_array[i];
|
offsets_array[j] = offsets_array[i];
|
||||||
offsets_array[i] = t;
|
offsets_array[i] = t;
|
||||||
@@ -178,7 +177,7 @@ bool glitch_try_offset(int offset, int * width, int edge_limit) {
|
|||||||
inc_tries();
|
inc_tries();
|
||||||
while (1) {
|
while (1) {
|
||||||
reset_cpu();
|
reset_cpu();
|
||||||
int gres = do_glitch(offset, *width, 300, 6);
|
int gres = do_glitch(offset + get_random_word(3), *width, 300, 6);
|
||||||
if (gres == GLITCH_RESULT_MISSING)
|
if (gres == GLITCH_RESULT_MISSING)
|
||||||
missing_count +=1; // MMC has failed to initialize
|
missing_count +=1; // MMC has failed to initialize
|
||||||
else
|
else
|
||||||
@@ -211,4 +210,4 @@ bool glitch_try_offset(int offset, int * width, int edge_limit) {
|
|||||||
if (edges > edge_limit) // this offset did not work
|
if (edges > edge_limit) // this offset did not work
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
bool write_payload();
|
bool write_payload();
|
||||||
|
|
||||||
// overclock to 200 MHz, pretty stable & enough for the glitch
|
// overclock to 200 MHz
|
||||||
void init_system() {
|
void init_system() {
|
||||||
vreg_set_voltage(VREG_VOLTAGE_1_30);
|
vreg_set_voltage(VREG_VOLTAGE_1_30);
|
||||||
set_sys_clock_khz(200000, true);
|
set_sys_clock_khz(200000, true);
|
||||||
@@ -94,13 +94,20 @@ int main()
|
|||||||
init_fuses();
|
init_fuses();
|
||||||
// LED & glitch & emmc PIO
|
// LED & glitch & emmc PIO
|
||||||
upload_pio();
|
upload_pio();
|
||||||
|
if (is_tiny())
|
||||||
|
{
|
||||||
|
gpio_put(led_pin(), 0);
|
||||||
|
sleep_us(100);
|
||||||
|
put_pixel(0);
|
||||||
|
sleep_us(100);
|
||||||
|
}
|
||||||
// check if this is the very first start
|
// check if this is the very first start
|
||||||
if (watchdog_caused_reboot() && boot_try == 0)
|
if (watchdog_caused_reboot() && boot_try == 0)
|
||||||
{
|
{
|
||||||
halt_with_error(1, 1);
|
halt_with_error(1, 1);
|
||||||
}
|
}
|
||||||
// is chip reset required
|
// is chip reset required
|
||||||
bool force_button = detect_by_pull_up(1, 0);
|
bool force_button = detect_by_pull(1, 0, 1);
|
||||||
// start LED
|
// start LED
|
||||||
put_pixel(PIX_blu);
|
put_pixel(PIX_blu);
|
||||||
// test pins
|
// test pins
|
||||||
|
|||||||
@@ -23,23 +23,13 @@ extern int ws_pio_offset;
|
|||||||
#define GPIO_IE PADS_BANK0_GPIO0_IE_BITS
|
#define GPIO_IE PADS_BANK0_GPIO0_IE_BITS
|
||||||
#define GPIO_OD_PD (GPIO_OD | PADS_BANK0_GPIO0_PDE_BITS)
|
#define GPIO_OD_PD (GPIO_OD | PADS_BANK0_GPIO0_PDE_BITS)
|
||||||
|
|
||||||
#define PTR_SAFE_RAM4 (void*)0x20040200
|
|
||||||
|
|
||||||
typedef void nopar();
|
typedef void nopar();
|
||||||
|
|
||||||
void __not_in_flash_func(zzz)() {
|
void __not_in_flash_func(zzz)() {
|
||||||
static bool not_first = 0;
|
|
||||||
if(!not_first)
|
|
||||||
{
|
|
||||||
not_first = 1;
|
|
||||||
memcpy(PTR_SAFE_RAM4, (void*)((uint32_t)zzz - 1), 0x200);
|
|
||||||
((nopar*)(PTR_SAFE_RAM4 + 1))();
|
|
||||||
}
|
|
||||||
*(uint32_t*)(0x4000803C + 0x3000) = 1; // go to 12 MHz
|
*(uint32_t*)(0x4000803C + 0x3000) = 1; // go to 12 MHz
|
||||||
uint32_t * vreg = (uint32_t*)0x40064000;
|
uint32_t * vreg = (uint32_t*)0x40064000;
|
||||||
vreg[1] &= ~1; // disable brownout
|
vreg[1] &= ~1; // disable brownout
|
||||||
*(uint32_t*)0x40060000 = 0x00d1e000; // disable rosc
|
*(uint32_t*)0x40060000 = 0x00d1e000; // disable rosc
|
||||||
*(uint32_t*)0x40004018 = 0xFF ^ (1 << 4); // disable SRAMs except ours
|
|
||||||
vreg[0] = 1; // lowest possible power
|
vreg[0] = 1; // lowest possible power
|
||||||
*(uint32_t*)0x40024000 = 0x00d1e000; // disable xosc
|
*(uint32_t*)0x40024000 = 0x00d1e000; // disable xosc
|
||||||
while(1);
|
while(1);
|
||||||
@@ -62,38 +52,46 @@ void finish_pins_except_leds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void finish_pins_leds() {
|
void finish_pins_leds() {
|
||||||
gpio_disable_input_output(led_pin());
|
if (!is_tiny())
|
||||||
|
{
|
||||||
|
gpio_disable_input_output(led_pin());
|
||||||
|
}
|
||||||
gpio_disable_input_output(pwr_pin());
|
gpio_disable_input_output(pwr_pin());
|
||||||
}
|
}
|
||||||
|
|
||||||
void halt_with_error(uint32_t err, uint32_t bits)
|
void halt_with_error(uint32_t long_mask, uint32_t blinks)
|
||||||
{
|
{
|
||||||
finish_pins_except_leds();
|
finish_pins_except_leds();
|
||||||
pio_set_sm_mask_enabled(pio0, 0xF, false);
|
pio_set_sm_mask_enabled(pio0, 0xF, false);
|
||||||
pio_set_sm_mask_enabled(pio1, 0xF, false);
|
pio_set_sm_mask_enabled(pio1, 0xF, false);
|
||||||
set_sys_clock_khz(48000, true);
|
set_sys_clock_khz(48000, true);
|
||||||
vreg_set_voltage(VREG_VOLTAGE_0_95);
|
vreg_set_voltage(VREG_VOLTAGE_0_95);
|
||||||
if (bits != 1)
|
if (blinks != 1)
|
||||||
{
|
{
|
||||||
put_pixel(0);
|
put_pixel(0);
|
||||||
sleep_ms(PAUSE_BEFORE);
|
sleep_ms(PAUSE_BEFORE);
|
||||||
}
|
}
|
||||||
for(int j = 0; j < CODE_REPEATS; j++)
|
for(int j = 0; j < CODE_REPEATS; j++)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < bits; i++)
|
for(int i = 0; i < blinks; i++)
|
||||||
{
|
{
|
||||||
bool is_long = err & (1 << (bits - i - 1));
|
// Long mask in reverse.
|
||||||
|
bool is_long = long_mask & (1 << (blinks - i - 1));
|
||||||
sleep_ms(is_long ? LONG_PAUSE_TIME : SHORT_PAUSE_TIME);
|
sleep_ms(is_long ? LONG_PAUSE_TIME : SHORT_PAUSE_TIME);
|
||||||
put_pixel(PIX_yel);
|
bool success = blinks == 1 && is_long == 0;
|
||||||
sleep_ms(is_long ? LONG_TIME : SHORT_TIME);
|
if (blinks == 1)
|
||||||
|
put_pixel(PIX_whi);
|
||||||
|
else
|
||||||
|
put_pixel(0x004600); // GRB red; preserve native error blink timing
|
||||||
|
sleep_ms(is_long ? LONG_TIME : success ? SHORT_TIME * 2 : SHORT_TIME);
|
||||||
put_pixel(0);
|
put_pixel(0);
|
||||||
if (i != bits - 1 || j != CODE_REPEATS - 1)
|
if (i != blinks - 1 || j != CODE_REPEATS - 1)
|
||||||
sleep_ms(is_long ? LONG_PAUSE_TIME : SHORT_PAUSE_TIME);
|
sleep_ms(is_long ? LONG_PAUSE_TIME : SHORT_PAUSE_TIME);
|
||||||
if (i == bits - 1 && j != CODE_REPEATS - 1)
|
if (i == blinks - 1 && j != CODE_REPEATS - 1)
|
||||||
sleep_ms(PAUSE_BETWEEN);
|
sleep_ms(PAUSE_BETWEEN);
|
||||||
}
|
}
|
||||||
// first write case, do not repeat this kind of error code
|
// first write case, do not repeat this kind of error code
|
||||||
if (bits == 1)
|
if (blinks == 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
finish_pins_leds();
|
finish_pins_leds();
|
||||||
@@ -125,7 +123,10 @@ void put_pixel(uint32_t pixel_grb)
|
|||||||
pio_sm_put_blocking(pio0, 3, pixel_grb << 8u);
|
pio_sm_put_blocking(pio0, 3, pixel_grb << 8u);
|
||||||
sleep_us(50);
|
sleep_us(50);
|
||||||
pio_sm_set_enabled(pio0, 3, false);
|
pio_sm_set_enabled(pio0, 3, false);
|
||||||
gpio_init(led_pin());
|
if (!is_tiny())
|
||||||
|
{
|
||||||
|
gpio_init(led_pin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpio_disable_input_output(int pin)
|
void gpio_disable_input_output(int pin)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#define PIX_blu 0x00003F
|
#define PIX_blu 0x0000D0
|
||||||
#define PIX_yel 0x151500
|
#define PIX_yel 0x383800
|
||||||
#define PIX_whi 0x111111
|
#define PIX_whi 0x383838
|
||||||
|
|
||||||
#define PIX_b 0x00000F
|
#define PIX_b 0x000015
|
||||||
|
|
||||||
void put_pixel(uint32_t pixel_grb);
|
void put_pixel(uint32_t pixel_grb);
|
||||||
|
|
||||||
void halt_with_error(uint32_t err, uint32_t bits);
|
void halt_with_error(uint32_t pause, uint32_t blinks);
|
||||||
|
|
||||||
void gpio_disable_input_output(int pin);
|
void gpio_disable_input_output(int pin);
|
||||||
|
|
||||||
@@ -14,4 +14,4 @@ void gpio_enable_input_output(int pin);
|
|||||||
|
|
||||||
void finish_pins_except_leds();
|
void finish_pins_except_leds();
|
||||||
|
|
||||||
void reset_cpu();
|
void reset_cpu();
|
||||||
@@ -393,7 +393,7 @@ bool init_op_cond() {
|
|||||||
simple_cmd_exec(MMC_GO_IDLE_STATE, 0);
|
simple_cmd_exec(MMC_GO_IDLE_STATE, 0);
|
||||||
if (!simple_cmd_exec_with_ret(MMC_SEND_OP_COND, 0, &res))
|
if (!simple_cmd_exec_with_ret(MMC_SEND_OP_COND, 0, &res))
|
||||||
return false;
|
return false;
|
||||||
int retry = 100;
|
int retry = 150;
|
||||||
while(--retry > 0) {
|
while(--retry > 0) {
|
||||||
if (!simple_cmd_exec_with_ret(MMC_SEND_OP_COND, SD_OCR_CCS | SD_OCR_VDD_18, &res))
|
if (!simple_cmd_exec_with_ret(MMC_SEND_OP_COND, SD_OCR_CCS | SD_OCR_VDD_18, &res))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+3
-3
@@ -43,9 +43,9 @@ void upload_pio()
|
|||||||
// MMC DAT sniffer
|
// MMC DAT sniffer
|
||||||
dsniff_pio_offset = pio_add_program(pio1, &glitch_dat_waiter_program);
|
dsniff_pio_offset = pio_add_program(pio1, &glitch_dat_waiter_program);
|
||||||
pio1->sm[G_DAT0_SM].shiftctrl = c.shiftctrl;
|
pio1->sm[G_DAT0_SM].shiftctrl = c.shiftctrl;
|
||||||
// set y to amount of data ticks to skip (512 + 16 - 1)
|
// set y to amount of data ticks to skip
|
||||||
val = 527;
|
val = 527;
|
||||||
for (int i = 2; i >= 0; i--) {
|
for (int i = 5; i >= 0; i--) {
|
||||||
pio_sm_exec(pio1, G_DAT0_SM, pio_encode_set(pio_y, (val >> i*4) & 15));
|
pio_sm_exec(pio1, G_DAT0_SM, pio_encode_set(pio_y, (val >> i*4) & 15));
|
||||||
pio_sm_exec(pio1, G_DAT0_SM, pio_encode_in(pio_y, 4));
|
pio_sm_exec(pio1, G_DAT0_SM, pio_encode_in(pio_y, 4));
|
||||||
}
|
}
|
||||||
@@ -58,4 +58,4 @@ void upload_pio()
|
|||||||
clk_pio_offset = pio_add_program(pio0, &sd_clk_program);
|
clk_pio_offset = pio_add_program(pio0, &sd_clk_program);
|
||||||
sdout_pio_offset = pio_add_program(pio0, &out_cmd_or_dat_program);
|
sdout_pio_offset = pio_add_program(pio0, &out_cmd_or_dat_program);
|
||||||
sdin_pio_offset = pio_add_program(pio0, &in_cmd_or_dat_program);
|
sdin_pio_offset = pio_add_program(pio0, &in_cmd_or_dat_program);
|
||||||
}
|
}
|
||||||
+41
-41
@@ -1,42 +1,42 @@
|
|||||||
import struct, zlib
|
import struct, zlib
|
||||||
|
|
||||||
blocks = []
|
blocks = []
|
||||||
last_off = 0x10000000
|
last_off = 0x10000000
|
||||||
|
|
||||||
def add_block(data, offset):
|
def add_block(data, offset):
|
||||||
global last_off
|
global last_off
|
||||||
if last_off != offset:
|
if last_off != offset:
|
||||||
for i in range((offset - last_off) // 256):
|
for i in range((offset - last_off) // 256):
|
||||||
blocks.append((b"\xFF" * 256, last_off + i * 256))
|
blocks.append((b"\xFF" * 256, last_off + i * 256))
|
||||||
assert len(data) == 256
|
assert len(data) == 256
|
||||||
blocks.append((data, offset))
|
blocks.append((data, offset))
|
||||||
last_off = offset + 256
|
last_off = offset + 256
|
||||||
|
|
||||||
def get_uf2():
|
def get_uf2():
|
||||||
total_blocks = len(blocks)
|
total_blocks = len(blocks)
|
||||||
result = b""
|
result = b""
|
||||||
for n, b in enumerate(blocks):
|
for n, b in enumerate(blocks):
|
||||||
uf2 = struct.pack("<IIIIIIII", 0x0A324655, 0x9E5D5157, 0x00002000, b[1], 256, n, total_blocks, 0xe48bff56) + b[0] + b"\x00" * (476 - 256) + struct.pack("<I", 0x0AB16F30)
|
uf2 = struct.pack("<IIIIIIII", 0x0A324655, 0x9E5D5157, 0x00002000, b[1], 256, n, total_blocks, 0xe48bff56) + b[0] + b"\x00" * (476 - 256) + struct.pack("<I", 0x0AB16F30)
|
||||||
assert len(uf2) == 512
|
assert len(uf2) == 512
|
||||||
result += uf2
|
result += uf2
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def add_blocks(data, offset):
|
def add_blocks(data, offset):
|
||||||
if len(data) % 256:
|
if len(data) % 256:
|
||||||
data += b"\xFF" * (256 - len(data) % 256)
|
data += b"\xFF" * (256 - len(data) % 256)
|
||||||
for i in range(0, len(data), 256):
|
for i in range(0, len(data), 256):
|
||||||
add_block(data[i:i+256], offset + i)
|
add_block(data[i:i+256], offset + i)
|
||||||
|
|
||||||
add_blocks(open("../busk/busk.bin", "rb").read(), 0x10000000)
|
add_blocks(open("../busk/busk.bin", "rb").read(), 0x10000000)
|
||||||
|
|
||||||
add_blocks(b"\xFF" * 256, 0x10000000 + 0xFF00)
|
add_blocks(b"\xFF" * 256, 0x10000000 + 0xFF00)
|
||||||
|
|
||||||
fw = open("usk.bin", "rb").read()
|
fw = open("usk.bin", "rb").read()
|
||||||
fw = struct.pack("<II", len(fw), zlib.crc32(fw)) + fw
|
fw = struct.pack("<II", len(fw), zlib.crc32(fw)) + fw
|
||||||
open("update.bin", "wb").write(fw)
|
open("update.bin", "wb").write(fw)
|
||||||
|
|
||||||
fw = fw + b"\xFF" * (0x3)
|
fw = fw + b"\xFF" * (0x3)
|
||||||
|
|
||||||
add_blocks(fw, 0x10000000 + 0x10000)
|
add_blocks(fw, 0x10000000 + 0x10000)
|
||||||
|
|
||||||
open("firmware.uf2", "wb").write(get_uf2())
|
open("firmware.uf2", "wb").write(get_uf2())
|
||||||
Reference in new issue
Block a user