Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minichlink programmer precedence issues #391

Open
lhartmann opened this issue Sep 9, 2024 · 2 comments
Open

minichlink programmer precedence issues #391

lhartmann opened this issue Sep 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@lhartmann
Copy link

Current behavior: When both WCHLink and Ardulink are attached, it is not possible to use ardulink.

$ minichlink -c /dev/ttyACM2
Found WCH Link
WCH Programmer is LinkE version 2.11
Chip Type: 003
Setup success

Expected behavior: Explicit command line flags should have precedence over autodetect.

BTW, I also can not see a way to choose which WCHLink to use if there is more than one connected.

@TommyMurphyTM1234
Copy link
Contributor

Current behavior: When both WCHLink and Ardulink are attached, it is not possible to use ardulink.

$ minichlink -c /dev/ttyACM2
Found WCH Link
WCH Programmer is LinkE version 2.11
Chip Type: 003
Setup success

Expected behavior: Explicit command line flags should have precedence over autodetect.

Seems to be down to this:

Specify the Ardulink serial port:

But then WCHLink (and other options) still takes precedence because init_hints->serial_port is only checked last:

  • else
    {
    if( (dev = TryInit_WCHLinkE()) )
    {
    fprintf( stderr, "Found WCH Link\n" );
    }
    else if( (dev = TryInit_ESP32S2CHFUN()) )
    {
    fprintf( stderr, "Found ESP32S2 Programmer\n" );
    }
    else if ((dev = TryInit_NHCLink042()))
    {
    fprintf( stderr, "Found NHC-Link042 Programmer\n" );
    }
    else if ((dev = TryInit_B003Fun()))
    {
    fprintf( stderr, "Found B003Fun Bootloader\n" );
    }
    else if ( init_hints->serial_port && (dev = TryInit_Ardulink(init_hints)))
    {
    fprintf( stderr, "Found Ardulink Programmer\n" );
    }
    }

BTW, I also can not see a way to choose which WCHLink to use if there is more than one connected.

Does -C ardulink make any difference?

Although, even if it should work, this looks odd - why TryInit_B003Fun() instead of TryInit_Ardulink() for the Ardulink case?

  • const char * specpgm = init_hints->specific_programmer;
    if( specpgm )
    {
    if( strcmp( specpgm, "linke" ) == 0 )
    dev = TryInit_WCHLinkE();
    else if( strcmp( specpgm, "esp32s2chfun" ) == 0 )
    dev = TryInit_ESP32S2CHFUN();
    else if( strcmp( specpgm, "nchlink" ) == 0 )
    dev = TryInit_NHCLink042();
    else if( strcmp( specpgm, "b003boot" ) == 0 )
    dev = TryInit_B003Fun();
    else if( strcmp( specpgm, "ardulink" ) == 0 )
    dev = TryInit_B003Fun();
    }

BTW, I also can not see a way to choose which WCHLink to use if there is more than one connected.

Yes - doesn't look like this caters for the possibility of multiple WCHLinkE's?

  • void * TryInit_WCHLinkE()
    {
    libusb_device_handle * wch_linke_devh;
    wch_linke_devh = wch_link_base_setup(0);
    if( !wch_linke_devh ) return 0;
    struct LinkEProgrammerStruct * ret = malloc( sizeof( struct LinkEProgrammerStruct ) );
    memset( ret, 0, sizeof( *ret ) );
    ret->devh = wch_linke_devh;
    ret->lasthaltmode = 0;
    MCF.ReadReg32 = LEReadReg32;
    MCF.WriteReg32 = LEWriteReg32;
    MCF.FlushLLCommands = LEFlushLLCommands;
    MCF.SetupInterface = LESetupInterface;
    MCF.Control3v3 = LEControl3v3;
    MCF.Control5v = LEControl5v;
    MCF.Unbrick = LEUnbrick;
    MCF.ConfigureNRSTAsGPIO = LEConfigureNRSTAsGPIO;
    MCF.ConfigureReadProtection = LEConfigureReadProtection;
    MCF.Exit = LEExit;
    return ret;
    };

@eeucalyptus
Copy link
Collaborator

I see, the priority based handling has the advantage of being convenient, lean and intuitive at the same time. But I guess since you ran into it, it's worth allowing explicit selection too. Would you consider submitting a PR with a proposed explicit handling?

@eeucalyptus eeucalyptus added the enhancement New feature or request label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants