Skip to content

Commit

Permalink
System works with LinkE programmer and identifies (But doesn't fully …
Browse files Browse the repository at this point in the history
…work with S2)

Also fix 2 warnings.
  • Loading branch information
cnlohr committed Mar 6, 2023
1 parent 199a6a9 commit 8501baa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 377 deletions.
7 changes: 4 additions & 3 deletions ch32v003evt/embedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ int mini_vpprintf(int (*puts)(char* s, int len, void* buf), void* buf, const cha
static int __puts_uart(char *s, int len, void *buf)
{
_write( 0, s, len );
return len;
}

int printf(const char* format, ...)
Expand Down Expand Up @@ -105,9 +106,9 @@ int wctomb(char *s, wchar_t wc)
}
size_t strlen(const char *s) { const char *a = s;for (; *s; s++);return s-a; }
size_t strnlen(const char *s, size_t n) { const char *p = memchr(s, 0, n); return p ? p-s : n;}
void *memset(void *dest, int c, size_t n) { unsigned char *s = dest; for (; n; n--, s++) *s = c; }
char *strcpy(char *d, const char *s) { for (; (*d=*s); s++, d++); }
char *strncpy(char *d, const char *s, size_t n) { for (; n && (*d=*s); n--, s++, d++); }
void *memset(void *dest, int c, size_t n) { unsigned char *s = dest; for (; n; n--, s++) *s = c; return dest; }
char *strcpy(char *d, const char *s) { for (; (*d=*s); s++, d++); return d; }
char *strncpy(char *d, const char *s, size_t n) { for (; n && (*d=*s); n--, s++, d++); return d; }
int strcmp(const char *l, const char *r)
{
for (; *l==*r && *l; l++, r++);
Expand Down
7 changes: 5 additions & 2 deletions examples/blink/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ int main()
GPIOD->CFGLR &= ~(0xf<<(4*0));
GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*0);

GPIOD->CFGLR &= ~(0xf<<(4*4));
GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*4);

while(1)
{
GPIOD->BSHR = 1; // Turn on GPIOD0
GPIOD->BSHR = (1<<0) | (1<<4); // Turn on GPIOD0
Delay_Ms( 100 );
GPIOD->BSHR = 1<<16; // Turn off GPIOD0
GPIOD->BSHR = (1<<(16+0)) | (1<<(16+4)); // Turn off GPIOD0
Delay_Ms( 100 );
}
}
2 changes: 1 addition & 1 deletion minichlink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TOOLS:=minichlink

all : $(TOOLS)

CFLAGS:=-O1 -g
CFLAGS:=-O0 -g3
LDFLAGS:=-lpthread -lusb-1.0 -ludev

minichlink : minichlink.c pgm-wch-linke.c pgm-esp32s2-ch32xx.c
Expand Down
44 changes: 33 additions & 11 deletions minichlink/minichlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ struct MiniChlinkFunctions MCF;
int main( int argc, char ** argv )
{
void * dev = 0;
if( (dev = TryInit_WCHLinkE() ) );
else if( (dev = TryInit_ESP32S2CHFUN() ) );
if( (dev = TryInit_WCHLinkE()) )
{
fprintf( stderr, "Found WCH LinkE\n" );
}
else if( (dev = TryInit_ESP32S2CHFUN()) )
{
fprintf( stderr, "Found ESP32S2 Programmer\n" );
}
else
{
fprintf( stderr, "Error: Could not initialize any supported programmers\n" );
Expand All @@ -36,11 +42,18 @@ int main( int argc, char ** argv )
}
}

int iarg;
char * argchar = argv[iarg];
for( iarg = 1; iarg < argc; iarg++ )
int iarg = 1;
const char * lastcommand = 0;
for( ; iarg < argc; iarg++ )
{
if( argchar[0] != '-' ) goto help;
char * argchar = argv[iarg];

lastcommand = argchar;
if( argchar[0] != '-' )
{
fprintf( stderr, "Error: Need prefixing - before commands\n" );
goto help;
}
if( must_be_end )
{
fprintf( stderr, "Error: the command '%c' cannot be followed by other commands.\n", must_be_end );
Expand All @@ -50,7 +63,9 @@ int main( int argc, char ** argv )
keep_going:
switch( argchar[1] )
{
default: goto help;
default:
fprintf( stderr, "Error: Unknown command %c\n", argchar[1] );
goto help;
case '3':
if( MCF.Control3v3 )
MCF.Control3v3( dev, 1 );
Expand Down Expand Up @@ -137,10 +152,18 @@ int main( int argc, char ** argv )
{
int i;
int transferred;
if( argchar[2] != 0 ) goto help;
if( argchar[2] != 0 )
{
fprintf( stderr, "Error: can't have char after paramter field\n" );
goto help;
}
iarg++;
argchar = 0; // Stop advancing
if( iarg + 2 >= argc ) goto help;
if( iarg + 2 >= argc )
{
fprintf( stderr, "Error: missing file for -o.\n" );
goto help;
}
uint64_t offset = SimpleReadNumberInt( argv[iarg++], -1 );
uint64_t amount = SimpleReadNumberInt( argv[iarg++], -1 );
if( offset > 0xffffffff || amount > 0xffffffff )
Expand Down Expand Up @@ -186,7 +209,6 @@ int main( int argc, char ** argv )
iarg++;
argchar = 0; // Stop advancing
if( iarg >= argc ) goto help;

// Write binary.
int i;
FILE * f = fopen( argv[iarg], "rb" );
Expand Down Expand Up @@ -257,7 +279,7 @@ int main( int argc, char ** argv )
return -1;

unimplemented:
fprintf( stderr, "Error: Command '%c' unimplemented on this programmer.\n", argchar[1] );
fprintf( stderr, "Error: Command '%s' unimplemented on this programmer.\n", lastcommand );
return -1;
}

Expand Down
1 change: 0 additions & 1 deletion minichlink/pgm-wch-linke.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static inline libusb_device_handle * wch_link_base_setup( int inhibit_startup )

if( !found )
{
fprintf( stderr, "Error: couldn't find wch link device\n" );
return 0;
}

Expand Down
Loading

0 comments on commit 8501baa

Please sign in to comment.