Skip to content
Snippets Groups Projects
Unverified Commit 5175db3d authored by CNLohr's avatar CNLohr Committed by GitHub
Browse files

Merge pull request #71 from cnlohr/improve_libraribility

Make it easier to librarify minichlink. + Pull static libgcc.a from t…
parents 59a16f3f 3d525e43
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ CFLAGS+= \
-nostdlib \
-I. -Wall
LDFLAGS+=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections -L../../misc -lgcc
LDFLAGS+=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections -L$(CH32V003FUN)/../misc -lgcc
SYSTEM_C:=$(CH32V003FUN)/ch32v003fun.c
......
......@@ -38,7 +38,7 @@ minichlink.so : $(C_S)
gcc -o $@ $^ $(LDFLAGS) $(CFLAGS) $(INCS) -shared -fPIC
minichlink.dll : $(C_S)
x86_64-w64-mingw32-gcc -o $@ $^ $(LDFLAGS) $(CFLAGS) $(INCS) -shared
x86_64-w64-mingw32-gcc -o $@ $^ $(LDFLAGS) $(CFLAGS) $(INCS) -shared -DMINICHLINK_AS_LIBRARY
install_udev_rules :
cp 99-WCH-LinkE.rules /etc/udev/rules.d/
......
......@@ -11,14 +11,14 @@
#include "minichlink.h"
#include "../ch32v003fun/ch32v003fun.h"
static int64_t StringToMemoryAddress( const char * number );
static void StaticUpdatePROGBUFRegs( void * dev );
static int InternalUnlockBootloader( void * dev );
static int64_t StringToMemoryAddress( const char * number ) __attribute__((used));
static void StaticUpdatePROGBUFRegs( void * dev ) __attribute__((used));
static int InternalUnlockBootloader( void * dev ) __attribute__((used));
void TestFunction(void * v );
struct MiniChlinkFunctions MCF;
int main( int argc, char ** argv )
void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO )
{
void * dev = 0;
if( (dev = TryInit_WCHLinkE()) )
......@@ -34,6 +34,24 @@ int main( int argc, char ** argv )
fprintf( stderr, "Found NHC-Link042 Programmer\n" );
}
else
{
fprintf( stderr, "Error: Could not initialize any supported programmers\n" );
return 0;
}
SetupAutomaticHighLevelFunctions( dev );
if( MCFO )
{
*MCFO = &MCF;
}
return dev;
}
#if !defined( MINICHLINK_AS_LIBRARY ) && !defined( MINICHLINK_IMPORT )
int main( int argc, char ** argv )
{
void * dev = MiniCHLinkInitAsDLL( 0 );
if( !dev )
{
fprintf( stderr, "Error: Could not initialize any supported programmers\n" );
return -32;
......@@ -516,7 +534,7 @@ unimplemented:
fprintf( stderr, "Error: Command '%s' unimplemented on this programmer.\n", lastcommand );
return -1;
}
#endif
#if defined(WINDOWS) || defined(WIN32) || defined(_WIN32)
#define strtoll _strtoi64
......
No preview for this file type
......@@ -130,8 +130,22 @@ struct InternalState
#define DMCFGR 0x7D
#define DMSHDWCFGR 0x7E
#if defined( WIN32 ) || defined( _WIN32 )
#if defined( MINICHLINK_AS_LIBRARY )
#define DLLDECORATE __declspec(dllexport)
#elif defined( MINICHLINK_IMPORT )
#define DLLDECORATE __declspec(dllimport)
#else
#define DLLDECORATE
#endif
#else
#define DLLDECORATE
#endif
void * MiniCHLinkInitAsDLL(struct MiniChlinkFunctions ** MCFO) DLLDECORATE;
extern struct MiniChlinkFunctions MCF;
// Returns 'dev' on success, else 0.
void * TryInit_WCHLinkE();
void * TryInit_ESP32S2CHFUN();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment