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 ||
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
@ -198,7 +198,7 @@ static int InitializeSWDSWIO( struct SWIOState * state )
|
||||
( ( dmstatus >> 8 ) & 0xf ) != 0x03 ) ||
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
@ -207,7 +207,7 @@ static int InitializeSWDSWIO( struct SWIOState * state )
|
||||
BB_PRINTF_DEBUG( "Found RVSWD interface\n" );
|
||||
return 0;
|
||||
}
|
||||
//printf( "TIMEOUT\n" );
|
||||
BB_PRINTF_DEBUG( "TIMEOUT\n" );
|
||||
return -55;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ static inline void ConfigureIOForRVSWD(void)
|
||||
// Single wire input-output SDI (just SWDIO)
|
||||
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
|
||||
if (state->opmode != 2) {
|
||||
BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||
//BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ static int MCFReadReg32( struct SWIOState * state, uint8_t command, uint32_t * v
|
||||
{
|
||||
// only supported mode is SWD
|
||||
if (state->opmode != 2) {
|
||||
BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||
//BB_PRINTF_DEBUG( "TODO: add support for SWIO\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -192,5 +192,6 @@ static int MCFReadReg32( struct SWIOState * state, uint8_t command, uint32_t * v
|
||||
read_end:
|
||||
interrupts();
|
||||
sleep_us(STOP_WAIT);
|
||||
BB_PRINTF_DEBUG("wrong parity: %d\n", parity_read);
|
||||
return (parity == parity_read) ? 0 : -1;
|
||||
}
|
||||
|
||||
@ -1,90 +1,59 @@
|
||||
#include "pico/time.h"
|
||||
#include <Arduino.h>
|
||||
#include <SerialUSB.h>
|
||||
#include "pico/time.h"
|
||||
#include <Arduino.h>
|
||||
#include <SerialUSB.h>
|
||||
|
||||
//#define BB_PRINTF_DEBUG(...) Serial.printf(__VA_ARGS__)
|
||||
#define BB_PRINTF_DEBUG(...)
|
||||
#include "bitbang_rvswdio.h"
|
||||
#include "bitbang_rvswdio_pico.h"
|
||||
#define BB_PRINTF_DEBUG(...) Serial.printf(__VA_ARGS__)
|
||||
//#define BB_PRINTF_DEBUG(...)
|
||||
#include "bitbang_rvswdio.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'
|
||||
SWIOState state = {.opmode = 2};
|
||||
|
||||
bool last_dtr = false;
|
||||
SWIOState state = {.opmode = 2};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setTimeout(100);
|
||||
ConfigureIOForRVSWD();
|
||||
|
||||
// We do NOT block waiting for Serial here,
|
||||
// we handle the connection dynamically in the loop.
|
||||
}
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setTimeout(100);
|
||||
}
|
||||
|
||||
|
||||
void setup1()
|
||||
{
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
}
|
||||
void setup1()
|
||||
{
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
void loop() {
|
||||
if (Serial.available() > 0) {
|
||||
char cmd = Serial.read();
|
||||
int ret = 0;
|
||||
uint8_t reg;
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
char cmd = Serial.read();
|
||||
uint8_t reg;
|
||||
uint32_t val;
|
||||
|
||||
switch (cmd) {
|
||||
case PROTOCOL_TEST:
|
||||
Serial.write(PROTOCOL_ACK);
|
||||
break;
|
||||
case PROTOCOL_POWER_ON:
|
||||
// Not needed for rvswd
|
||||
sleep_us(10);
|
||||
Serial.write(PROTOCOL_ACK);
|
||||
break;
|
||||
case PROTOCOL_POWER_OFF:
|
||||
// Not needed for rvswd
|
||||
sleep_us(10);
|
||||
Serial.write(PROTOCOL_ACK);
|
||||
break;
|
||||
case PROTOCOL_WRITE_REG:
|
||||
if (Serial.readBytes((char*)®, sizeof(uint8_t)) != 1) break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (cmd) {
|
||||
case '!':
|
||||
state = {};
|
||||
ret = InitializeSWDSWIO(&state);
|
||||
if (ret != 0) {
|
||||
Serial.printf("error initializing SWD: %d\n", ret);
|
||||
break;
|
||||
}
|
||||
ret = DetermineChipTypeAndSectorInfo(&state, NULL);
|
||||
if (ret != 0) {
|
||||
Serial.printf("failed to determine chip type: %d\n", ret);
|
||||
break;
|
||||
}
|
||||
Serial.printf("chip type is %x\n", state.target_chip_type);
|
||||
break;
|
||||
default:
|
||||
Serial.printf("unknown command '%c'\n", cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop1()
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, 1);
|
||||
delay(200);
|
||||
digitalWrite(LED_BUILTIN, 0);
|
||||
delay(200);
|
||||
}
|
||||
void loop1()
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, 1);
|
||||
delay(200);
|
||||
digitalWrite(LED_BUILTIN, 0);
|
||||
delay(200);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user