From 9cad66838e657c6ffe0828febac510e32b466873 Mon Sep 17 00:00:00 2001 From: cnlohr <lohr85@gmail.com> Date: Sat, 18 Feb 2023 23:54:50 -0800 Subject: [PATCH] Add configuration item for allowing re-use of PD7 as NRST or PP/IO --- minichlink/minichlink.c | 17 +++++++++++++++++ minichlink/test.bat | 7 ++++--- sandbox/sandbox.c | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/minichlink/minichlink.c b/minichlink/minichlink.c index 7a2dc21..6e89a6d 100644 --- a/minichlink/minichlink.c +++ b/minichlink/minichlink.c @@ -41,6 +41,7 @@ int bootloader_len = 512; int main( int argc, char ** argv ) { int status; + int must_be_end = 0; uint8_t rbuff[1024]; libusb_device_handle * devh = wch_link_base_setup(); @@ -50,6 +51,12 @@ int main( int argc, char ** argv ) { char * argchar = argv[iarg]; if( argchar[0] != '-' ) goto help; + if( must_be_end ) + { + fprintf( stderr, "Error: the command '%c' cannot be followed by other commands.\n", must_be_end ); + return -1; + } + keep_going: switch( argchar[1] ) { @@ -65,8 +72,16 @@ keep_going: case 'R': // Part one "immediately" places the part into reset. Part 2 says when we're done, leave part in reset. wch_link_multicommands( devh, 2, 4, "\x81\x0d\x01\x02", 4, "\x81\x0d\x01\x01" ); + must_be_end = 'R'; break; + // disable NRST pin (turn it into a GPIO) + case 'd': + wch_link_multicommands( devh, 2, 11, "\x81\x06\x08\x02\xf7\xff\xff\xff\xff\xff\xff", 4, "\x81\x0b\x01\x01" ); + break; + case 'D': + wch_link_multicommands( devh, 2, 11, "\x81\x06\x08\x02\xff\xff\xff\xff\xff\xff\xff", 4, "\x81\x0b\x01\x01" ); + break; // PROTECTION UNTESTED! /* case 'p': @@ -185,6 +200,8 @@ help: fprintf( stderr, " -f Disable 5V\n" ); fprintf( stderr, " -r Release from reest\n" ); fprintf( stderr, " -R Place into Reset\n" ); + fprintf( stderr, " -D Configure NRST as GPIO\n" ); + fprintf( stderr, " -d Configure NRST as NRST\n" ); // fprintf( stderr, " -P Enable Read Protection (UNTESTED)\n" ); // fprintf( stderr, " -p Disable Read Protection (UNTESTED)\n" ); fprintf( stderr, " -w [binary image to write]\n" ); diff --git a/minichlink/test.bat b/minichlink/test.bat index 3f9a1bf..912a017 100644 --- a/minichlink/test.bat +++ b/minichlink/test.bat @@ -3,7 +3,8 @@ tcc wch_erase.c libusb-1.0.dll tcc wch_reset.c libusb-1.0.dll tcc wch_write_simple.c libusb-1.0.dll +tcc minichlink.c libusb-1.0.dll -wch_erase.exe -wch_write_simple.exe ..\barebones\barebones.bin -wch_reset.exe +rem wch_erase.exe +rem wch_write_simple.exe ..\barebones\barebones.bin +rem wch_reset.exe diff --git a/sandbox/sandbox.c b/sandbox/sandbox.c index d2a92cf..895d1bc 100644 --- a/sandbox/sandbox.c +++ b/sandbox/sandbox.c @@ -61,6 +61,8 @@ int main() GPIOD->BSHR = 1; GPIOD->BSHR = 1<<16; GPIOD->BSHR = 1; + Delay_Ms( 1 ); GPIOD->BSHR = (128+64+1)<<16; + Delay_Ms( 1 ); } } -- GitLab