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

Merge pull request #187 from cnlohr/bugfixes_and_usb_bootloader_work

Commits to wrong branch by accident.
parents aa6f2439 8ee7bbdf
No related branches found
No related tags found
No related merge requests found
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../../ch32v003fun"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"compilerArgs": [
"-DCH32V003FUN_BASE"
],
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
\ No newline at end of file
{
"configurations": [
{
"name": "GDB Debug Target",
"type": "cppdbg",
"request": "launch",
"program": "template.elf",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"deploySteps": [
{
"type": "shell",
"continueOn": "GDBServer",
"command": "make --directory=${workspaceFolder} closechlink flash gdbserver"
},
],
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "gdb-multiarch",
"miDebuggerServerAddress": "127.0.0.1:2000"
},
{
"name": "Run Only (In Terminal)",
"type": "node",
"request": "launch",
"program": "",
"preLaunchTask": "run_flash_and_gdbserver",
}
]
}
{
"cmake.configureOnOpen": false,
"makefile.launchConfigurations": [
{
"cwd": "",
"sbinaryPath": "blink.elf",
"binaryArgs": []
}
],
"editor.insertSpaces": false,
"editor.tabSize": 4,
"files.associations": {
"ch32v003fun.h": "c"
}
}
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "flash",
"presentation": {
"echo": true,
"focus": false,
"group": "build",
"panel": "shared",
"showReuseMessage" : false
},
"command": "make closechlink flash",
},
{
"type": "shell",
"label": "run_flash_and_gdbserver",
"command": "make closechlink flash gdbserver",
"presentation": {
"echo": true,
"focus": false,
"group": "build",
"panel": "shared",
"close": true,
"showReuseMessage" : false
},
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}",
},
"runOptions": {
"instanceLimit": 2,
},
"group": "build",
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": false,
"beginsPattern": "^.*Image written.*",
"endsPattern": "^.*GDBServer*"
}
},
}
]
}
all : flash
TARGET:=sandbox
TARGET:=template
include ../../ch32v003fun/ch32v003fun.mk
......
/* Small example showing how to use the SWIO programming pin to
do printf through the debug interface */
/* Template app on which you can build your own. */
#include "ch32v003fun.h"
#include <stdio.h>
uint32_t count;
// Tell the compiler to put this code in the .data section. That
// will cause the startup code to copy it from flash into RAM where
// it can be easily modified at runtime.
void SRAMCode( ) __attribute__(( section(".data"))) __attribute__((noinline)) __attribute__((noreturn));
void SRAMCode( )
{
asm volatile(
"li a0, 0x40011410\n"
"li a1, (1 | (1<<4))\n"
"li a2, (1 | (1<<4))<<16\n"
"1: c.sw a1, 0(a0)\n"
" c.sw a2, 0(a0)\n"
" j 1b\n" );
__builtin_unreachable();
}
int main()
{
SystemInit48HSI();
SetupDebugPrintf();
// Boost CPU supply.
EXTEN->EXTEN_CTR = EXTEN_LDO_TRIM;
// Enable GPIOs
RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC;
......@@ -47,6 +25,14 @@ int main()
GPIOC->CFGLR &= ~(0xf<<(4*0));
GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*0);
SRAMCode();
while(1)
{
GPIOD->BSHR = 1 | (1<<4); // Turn on GPIOs
GPIOC->BSHR = 1;
printf( "+%lu\n", count++ );
GPIOD->BSHR = (1<<16) | (1<<(16+4)); // Turn off GPIODs
GPIOC->BSHR = (1<<16);
printf( "-%lu\n", count++ );
}
}
......@@ -28,27 +28,46 @@ struct MiniChlinkFunctions MCF;
void * MiniCHLinkInitAsDLL( struct MiniChlinkFunctions ** MCFO, const init_hints_t* init_hints )
{
void * dev = 0;
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()))
const char * specpgm = init_hints->specific_programmer;
if( specpgm )
{
fprintf( stderr, "Found B003Fun Bootloader\n" );
if( strcmp( specpgm, "linke" ) == 0 )
dev = TryInit_WCHLinkE();
else if( strcmp( specpgm, "esp32s2chfun" ) == 0 )
dev = dev = TryInit_ESP32S2CHFUN();
else if( strcmp( specpgm, "nchlink" ) == 0 )
dev = dev = TryInit_NHCLink042();
else if( strcmp( specpgm, "b003boot" ) == 0 )
dev = dev = TryInit_B003Fun();
else if( strcmp( specpgm, "ardulink" ) == 0 )
dev = dev = TryInit_B003Fun();
}
else if ((dev = TryInit_Ardulink(init_hints)))
else
{
fprintf( stderr, "Found Ardulink Programmer\n" );
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" );
}
}
else
if( !dev )
{
fprintf( stderr, "Error: Could not initialize any supported programmers\n" );
return 0;
......@@ -93,6 +112,12 @@ int main( int argc, char ** argv )
if( i < argc )
hints.serial_port = argv[i];
}
else if( strncmp( v, "-c", 2 ) == 0 )
{
i++;
if( i < argc )
hints.specific_programmer = argv[i];
}
}
void * dev = MiniCHLinkInitAsDLL( 0, &hints );
......@@ -173,13 +198,14 @@ keep_going:
else
goto unimplemented;
break;
case 'C': // For specifying programmer
case 'c':
// COM port argument already parsed previously
// COM port or programmer argument already parsed previously
// we still need to skip the next argument
iarg+=1;
if( iarg >= argc )
{
fprintf( stderr, "-c argument (COM port) required 2 arguments\n" );
fprintf( stderr, "-c/C argument required 2 arguments\n" );
goto unimplemented;
}
break;
......
No preview for this file type
......@@ -158,7 +158,8 @@ struct InternalState
/* could be expanded with more in the future (e.g., PID/VID hints, priorities, ...)*/
/* not all init functions currently need these hints. */
typedef struct {
const char* serial_port;
const char * serial_port;
const char * specific_programmer;
} init_hints_t;
void * MiniCHLinkInitAsDLL(struct MiniChlinkFunctions ** MCFO, const init_hints_t* init_hints) DLLDECORATE;
......
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