Skip to content

Commit

Permalink
* Optimize pgm-esp32-s2-ch32xx.c
Browse files Browse the repository at this point in the history
 * Improve VS Code build
 * Fix stepping for older GDBs
  • Loading branch information
cnlohr committed Nov 15, 2024
1 parent c50b6bf commit c75c9ea
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 87 deletions.
19 changes: 17 additions & 2 deletions examples/debugprintfdemo/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cppStandard": "c++14",
"cppStandard": "c++20",
"intelliSenseMode": "linux-clang-x64",
"compilerArgs": [
"-DCH32V003FUN_BASE"
],
"configurationProvider": "ms-vscode.makefile-tools"
},
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../../ch32v003fun"
],
"defines": [],
"compilerPath": "riscv64-unknown-elf-gcc-10.1.0.exe",
"cppStandard": "c++20",
"compilerArgs": [
"-DCH32V003FUN_BASE"
],
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
"version": 4,
"enableConfigurationSquiggles": true
}
41 changes: 25 additions & 16 deletions examples/template/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
{
"configurations": [
{
"name": "RISCV32EC",
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../../ch32v003fun",
"${workspaceFolder}/../../extralibs",
"/usr/include/newlib" //why? the configurationProvider ought to find this
"${workspaceFolder}/../../ch32v003fun"
],
"defines": [
"CH32V003",
"__riscv",
"USE_SIGNALS",
"CH32V003FUN_BASE"
"defines": [],
"compilerPath": "/usr/bin/clang",
"cppStandard": "c++20",
"intelliSenseMode": "linux-clang-x64",
"compilerArgs": [
"-DCH32V003FUN_BASE"
],
"configurationProvider": "ms-vscode.makefile-tools"
},
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/../../ch32v003fun"
],
"defines": [],
"compilerPath": "riscv64-unknown-elf-gcc-10.1.0.exe",
"cppStandard": "c++20",
"compilerArgs": [
"-DCH32V003FUN_BASE"
],
"compilerPath": "/usr/bin/riscv64-unknown-elf-gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++17",
"intelliSenseMode": "gcc-x86", //works. Someday, intellisense might get riscv modes
"compilerArgs": [],
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
"version": 4,
"enableConfigurationSquiggles": true
}
34 changes: 10 additions & 24 deletions examples/template/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
{
"configurations": [
{
"name": "cppdbg GDB Debug Target",
"name": "GDB Debug Target",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/template.elf",
"program": "debugprintfdemo.elf",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"deploySteps": [ // 'make ...gdbserver' doesn't seem to work here. The Makefile calls 'minichlink -baG'... Needs -aG. Easier to add minichlink as a seperate step below
{
"type": "shell", //isn't there some way to call a task from tasks.json?
"command": "make --directory=${workspaceFolder} -j 1 closechlink flash",
},
{
"type": "shell",
"command": "${workspaceFolder}/../../minichlink/minichlink -aG",
"continueOn": "gdbserver running"
},
],
"preLaunchTask": "run_flash_and_gdbserver",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
},
"ignoreFailures": true
}
],
"svdPath": "${workspaceFolder}/../../misc/CH32V003xx.svd", // extension 'Peripheral Viewer' by mcu-debug (cortex-debug)
"miDebuggerPath": "gdb-multiarch",
"miDebuggerServerAddress": "localhost:2000",
"logging": {
"engineLogging": false
},
"miDebuggerServerAddress": "127.0.0.1:2000"
},
{
"name": "Run Only (In Terminal)",
"type": "node",
"request": "launch",
"program": "",
"preLaunchTask": "run_flash_and_gdbserver",
}
]
}
"preLaunchTask": "run_flash_and_monitor",
}
]
}
6 changes: 3 additions & 3 deletions examples/template/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"makefile.launchConfigurations": [
{
"cwd": "",
"sbinaryPath": "template.elf",
"sbinaryPath": "debugprintfdemo.elf",
"binaryArgs": []
}
],
"editor.insertSpaces": false,
"editor.tabSize": 4,
"files.associations": {
"ch32v003fun.h": "c"
},
}
}
}
49 changes: 23 additions & 26 deletions examples/template/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,49 @@
"tasks": [
{
"type": "shell",
"label": "build",
"label": "flash",
"presentation": {
"echo": true,
"focus": false,
"group": "build",
"panel": "shared",
"showReuseMessage": false
"showReuseMessage" : false
},
"group": {
"kind": "build",
"isDefault": true
},
"command": "make closechlink clean; make",
"problemMatcher": { // https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
},
"command": "make closechlink flash",
},
{
"type": "shell",
"label": "run_flash_and_monitor",
"presentation": {
"echo": true,
"focus": false,
"group": "build",
"panel": "shared",
"showReuseMessage" : false
},
"command": "make flash monitor",
},
{
"type": "shell",
"label": "run_flash_and_gdbserver",
"command": "make closechlink flash gdbserver",
"command": "make flash gdbserver",

"presentation": {
"echo": true,
"focus": false,
"group": "build",
"panel": "shared",
"showReuseMessage": false
"close": true,
"showReuseMessage" : false
},

"isBackground": true,
"options": {
"cwd": "${workspaceFolder}",
},
"runOptions": {
"instanceLimit": 2,
},
},
"group": "build",
"problemMatcher": {
"pattern": [
Expand All @@ -60,12 +56,13 @@
"message": 3
}
],

"background": {
"activeOnStart": false,
"beginsPattern": "^.*Image written.*",
"endsPattern": "^.*GDBServer*"
}
},
},
}
]
}
}
11 changes: 8 additions & 3 deletions minichlink/microgdbstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ void HandleGDBPacket( void * dev, char * data, int len )
data++;

char cmd = *(data++);
// printf( "DATA: [%c] %c%c%c%c%c%c%c%c%c\n",cmd, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );
//printf( "DATA: [%c] %c%c%c%c%c%c%c%c%c\n",cmd, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );

switch( cmd )
{
case 'q':
Expand Down Expand Up @@ -298,17 +299,21 @@ void HandleGDBPacket( void * dev, char * data, int len )
snprintf( map, mslen, MICROGDBSTUB_MEMORY_MAP, iss->flash_size, iss->sector_size, iss->ram_size );
SendReplyFull( map );
}
else if( StringMatch( data, "ThreadExtraInfo" ) )
SendReplyFull( "4E2F41" );
else if( data[0] == 'P' )
SendReplyFull( "m1" ); // Archaic threadid.
else
{
fprintf( stderr, "Unknown command: %s\n", data );
fprintf( stderr, "Unknown q command: q%s\n", data );
SendReplyFull( "" );
}
break;
case 'c':
case 'C':
// TODO: Support continue-from-another-address
RVDebugExec( dev, (cmd == 'C')?HALT_TYPE_CONTINUE_WITH_SIGNAL:HALT_TYPE_CONTINUE, 0, 0 );
//SendReplyFull( "OK" ); ... this will be sent from RVNetPoll
//The real reply will be sent from RVNetPoll
break;
case 's':
case 'S':
Expand Down
27 changes: 14 additions & 13 deletions minichlink/minichgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void SendReplyFull( const char * replyMessage );
int shadow_running_state = 1;
int last_halt_reason = 5;
uint32_t backup_regs[33]; //0..15 + PC, or 0..32 + PC
int gdbasserting_break = 0;
//int gdbasserting_break = 0;

#define MAX_SOFTWARE_BREAKPOINTS 128
int num_software_breakpoints = 0;
Expand Down Expand Up @@ -89,7 +89,7 @@ void RVNetConnect( void * dev )
}

int RVSendGDBHaltReason( void * dev )
{
{
char st[5];
sprintf( st, "T%02x", last_halt_reason );
SendReplyFull( st );
Expand Down Expand Up @@ -227,21 +227,22 @@ int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume, int
MCF.HaltMode( dev, HALT_MODE_HALT_BUT_NO_RESET );
RVCommandPrologue( dev );
MCF.SetEnableBreakpoints( dev, 1, 0 );
//printf( "STEP PC: %08x\n", backup_regs[iss->nr_registers_for_debug] );
return 0;
}

// Special case halt_reset_or_resume = 4: Skip instruction and resume.
if( halt_reset_or_resume == HALT_TYPE_CONTINUE_WITH_SIGNAL || halt_reset_or_resume == HALT_TYPE_CONTINUE )
{
if( gdbasserting_break )
{
// This is tricky, but I don't know how else to handle it.
// If GDB is stepping, and you ctrl+c, then, it will ignore that and keep going.
// Here I say if the user ctrl+c'd actually fail to switch run mode.
gdbasserting_break = 0;
SendReplyFull( "E 99" );
return 1;
}
//if( gdbasserting_break )
//{
// // This is tricky, but I don't know how else to handle it.
// // If GDB is stepping, and you ctrl+c, then, it will ignore that and keep going.
// // Here I say if the user ctrl+c'd actually fail to switch run mode.
// gdbasserting_break = 0;
// SendReplyFull( "T99" );
// return 1;
//}
// First see if we already know about this breakpoint
int matchingbreakpoint = -1;
// For this we want to advance PC.
Expand Down Expand Up @@ -494,8 +495,8 @@ void RVHandleDisconnect( void * dev )

void RVHandleGDBBreakRequest( void * dev )
{
if( !shadow_running_state )
gdbasserting_break = 1;
// if( !shadow_running_state )
// gdbasserting_break = 1;
MCF.HaltMode( dev, 5 );
}

Expand Down
Binary file modified minichlink/minichlink.exe
Binary file not shown.
Loading

0 comments on commit c75c9ea

Please sign in to comment.