independent programmer
This commit is contained in:
parent
03bf92f505
commit
821380d21c
@ -188,7 +188,7 @@ static int InitializeSWDSWIO( struct SWIOState * state )
|
|||||||
if( MCFReadReg32( state, DMSTATUS, &dmstatus ) != 0 ||
|
if( MCFReadReg32( state, DMSTATUS, &dmstatus ) != 0 ||
|
||||||
MCFReadReg32( state, DMCONTROL, &dmcontrol ) != 0 )
|
MCFReadReg32( state, DMCONTROL, &dmcontrol ) != 0 )
|
||||||
{
|
{
|
||||||
//BB_PRINTF_DEBUG( "Could not read from RVSWD connection\n" );
|
BB_PRINTF_DEBUG( "Could not read from RVSWD connection\n" );
|
||||||
state->opmode = 0;
|
state->opmode = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ static int InitializeSWDSWIO( struct SWIOState * state )
|
|||||||
( ( dmstatus >> 8 ) & 0xf ) != 0x03 ) ||
|
( ( dmstatus >> 8 ) & 0xf ) != 0x03 ) ||
|
||||||
dmcontrol != 1 )
|
dmcontrol != 1 )
|
||||||
{
|
{
|
||||||
//BB_PRINTF_DEBUG( "DMSTATUS invalid (Probably no RVSWD chip)\n" );
|
BB_PRINTF_DEBUG( "DMSTATUS invalid (Probably no RVSWD chip)\n" );
|
||||||
state->opmode = 0;
|
state->opmode = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ static int InitializeSWDSWIO( struct SWIOState * state )
|
|||||||
BB_PRINTF_DEBUG( "Found RVSWD interface\n" );
|
BB_PRINTF_DEBUG( "Found RVSWD interface\n" );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//printf( "TIMEOUT\n" );
|
BB_PRINTF_DEBUG( "TIMEOUT\n" );
|
||||||
return -55;
|
return -55;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ static inline void ConfigureIOForRVSWD(void)
|
|||||||
// Single wire input-output SDI (just SWDIO)
|
// Single wire input-output SDI (just SWDIO)
|
||||||
static inline void ConfigureIOForRVSWIO(void)
|
static inline void ConfigureIOForRVSWIO(void)
|
||||||
{
|
{
|
||||||
BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
//BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ static void MCFWriteReg32( struct SWIOState * state, uint8_t command, uint32_t v
|
|||||||
{
|
{
|
||||||
// only supported mode is SWD
|
// only supported mode is SWD
|
||||||
if (state->opmode != 2) {
|
if (state->opmode != 2) {
|
||||||
BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
//BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ static int MCFReadReg32( struct SWIOState * state, uint8_t command, uint32_t * v
|
|||||||
{
|
{
|
||||||
// only supported mode is SWD
|
// only supported mode is SWD
|
||||||
if (state->opmode != 2) {
|
if (state->opmode != 2) {
|
||||||
BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
//BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,5 +192,6 @@ static int MCFReadReg32( struct SWIOState * state, uint8_t command, uint32_t * v
|
|||||||
read_end:
|
read_end:
|
||||||
interrupts();
|
interrupts();
|
||||||
sleep_us(STOP_WAIT);
|
sleep_us(STOP_WAIT);
|
||||||
|
BB_PRINTF_DEBUG("wrong parity: %d\n", parity_read);
|
||||||
return (parity == parity_read) ? 0 : -1;
|
return (parity == parity_read) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,29 +2,16 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SerialUSB.h>
|
#include <SerialUSB.h>
|
||||||
|
|
||||||
//#define BB_PRINTF_DEBUG(...) Serial.printf(__VA_ARGS__)
|
#define BB_PRINTF_DEBUG(...) Serial.printf(__VA_ARGS__)
|
||||||
#define BB_PRINTF_DEBUG(...)
|
//#define BB_PRINTF_DEBUG(...)
|
||||||
#include "bitbang_rvswdio.h"
|
#include "bitbang_rvswdio.h"
|
||||||
#include "bitbang_rvswdio_pico.h"
|
#include "bitbang_rvswdio_pico.h"
|
||||||
|
|
||||||
#define PROTOCOL_START '!'
|
|
||||||
#define PROTOCOL_ACK '+'
|
|
||||||
#define PROTOCOL_TEST '?'
|
|
||||||
#define PROTOCOL_POWER_ON 'p'
|
|
||||||
#define PROTOCOL_POWER_OFF 'P'
|
|
||||||
#define PROTOCOL_WRITE_REG 'w'
|
|
||||||
#define PROTOCOL_READ_REG 'r'
|
|
||||||
|
|
||||||
bool last_dtr = false;
|
|
||||||
SWIOState state = {.opmode = 2};
|
SWIOState state = {.opmode = 2};
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.setTimeout(100);
|
Serial.setTimeout(100);
|
||||||
ConfigureIOForRVSWD();
|
|
||||||
|
|
||||||
// We do NOT block waiting for Serial here,
|
|
||||||
// we handle the connection dynamically in the loop.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -35,46 +22,28 @@
|
|||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Monitor DTR line to simulate Arduino Reset behavior
|
|
||||||
bool current_dtr = Serial.dtr();
|
|
||||||
if (current_dtr && !last_dtr) {
|
|
||||||
// minichlink just opened the port
|
|
||||||
ConfigureIOForRVSWD();
|
|
||||||
while (Serial.available() > 0) { Serial.read(); }
|
|
||||||
delay(100);
|
|
||||||
Serial.write(PROTOCOL_START); // Announce readiness
|
|
||||||
}
|
|
||||||
last_dtr = current_dtr;
|
|
||||||
|
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
char cmd = Serial.read();
|
char cmd = Serial.read();
|
||||||
|
int ret = 0;
|
||||||
uint8_t reg;
|
uint8_t reg;
|
||||||
uint32_t val;
|
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case PROTOCOL_TEST:
|
case '!':
|
||||||
Serial.write(PROTOCOL_ACK);
|
state = {};
|
||||||
|
ret = InitializeSWDSWIO(&state);
|
||||||
|
if (ret != 0) {
|
||||||
|
Serial.printf("error initializing SWD: %d\n", ret);
|
||||||
break;
|
break;
|
||||||
case PROTOCOL_POWER_ON:
|
}
|
||||||
// Not needed for rvswd
|
ret = DetermineChipTypeAndSectorInfo(&state, NULL);
|
||||||
sleep_us(10);
|
if (ret != 0) {
|
||||||
Serial.write(PROTOCOL_ACK);
|
Serial.printf("failed to determine chip type: %d\n", ret);
|
||||||
break;
|
break;
|
||||||
case PROTOCOL_POWER_OFF:
|
}
|
||||||
// Not needed for rvswd
|
Serial.printf("chip type is %x\n", state.target_chip_type);
|
||||||
sleep_us(10);
|
|
||||||
Serial.write(PROTOCOL_ACK);
|
|
||||||
break;
|
break;
|
||||||
case PROTOCOL_WRITE_REG:
|
default:
|
||||||
if (Serial.readBytes((char*)®, sizeof(uint8_t)) != 1) break;
|
Serial.printf("unknown command '%c'\n", cmd);
|
||||||
if (Serial.readBytes((char*)&val, sizeof(uint32_t)) != 4) break;
|
|
||||||
MCFWriteReg32(&state, reg, val);
|
|
||||||
Serial.write(PROTOCOL_ACK);
|
|
||||||
break;
|
|
||||||
case PROTOCOL_READ_REG:
|
|
||||||
if (Serial.readBytes((char*)®, sizeof(uint8_t)) != 1) break;
|
|
||||||
MCFReadReg32(&state, reg, &val);
|
|
||||||
Serial.write((char*)&val, sizeof(uint32_t));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user