Skip to content

Commit

Permalink
Added support for TI CCxxxx chips to Tag_Flasher, AP_and_Flasher and …
Browse files Browse the repository at this point in the history
…Mini_AP_v4.
  • Loading branch information
skiphansen committed Jul 27, 2024
1 parent d0ccd8f commit 73e472e
Show file tree
Hide file tree
Showing 6 changed files with 602 additions and 18 deletions.
47 changes: 46 additions & 1 deletion ESP32_AP-Flasher/src/usbflasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ USBCDC USBSerial;
#include "web.h"
#include "webflasher.h"
#include "zbs_interface.h"
#include "cc_interface.h"

QueueHandle_t flasherCmdQueue;

Expand Down Expand Up @@ -310,6 +311,7 @@ typedef enum {

CMD_SELECT_ZBS243 = 60,
CMD_SELECT_NRF82511 = 61,
CMD_SELECT_CC = 62,

CMD_SELECT_PORT = 70,

Expand All @@ -323,15 +325,17 @@ typedef enum {
CMD_WRITE_ERROR = 99,

} ZBS_UART_PROTO;
uint32_t FLASHER_VERSION = 0x00000031;
uint32_t FLASHER_VERSION = 0x00000032;

#define CONTROLLER_ZBS243 0
#define CONTROLLER_NRF82511 1
#define CONTROLLER_CC 2
uint8_t selectedController = 0;
uint8_t selectedFlasherPort;
uint32_t currentFlasherOffset;
flasher* zbsflasherp = nullptr;
nrfswd* nrfflasherp = nullptr;
CC_interface *ccflasherp = nullptr;

void processFlasherCommand(struct flasherCommand* cmd, uint8_t transportType) {
uint8_t* tempbuffer;
Expand Down Expand Up @@ -400,6 +404,9 @@ void processFlasherCommand(struct flasherCommand* cmd, uint8_t transportType) {
} else if (selectedController == CONTROLLER_ZBS243) {
if (zbsflasherp == nullptr) return;
zbsflasherp->zbs->erase_flash();
} else if (selectedController == CONTROLLER_CC) {
if (ccflasherp == nullptr) return;
ccflasherp->erase_chip();
}
sendFlasherAnswer(CMD_ERASE_FLASH, NULL, 0, transportType);
break;
Expand Down Expand Up @@ -451,6 +458,14 @@ void processFlasherCommand(struct flasherCommand* cmd, uint8_t transportType) {
currentFlasherOffset = 0;
selectedController = CONTROLLER_NRF82511;
break;
case CMD_SELECT_CC:
ccflasherp = new CC_interface;
ccflasherp->begin(FLASHER_EXT_CLK,FLASHER_EXT_MISO,FLASHER_EXT_RESET);
temp_buff[0] = 1;
sendFlasherAnswer(CMD_SELECT_CC, temp_buff, 1,transportType);
currentFlasherOffset = 0;
selectedController = CONTROLLER_CC;
break;
case CMD_READ_FLASH:
wsSerial("> read flash");
uint8_t* bufferp;
Expand Down Expand Up @@ -481,6 +496,19 @@ void processFlasherCommand(struct flasherCommand* cmd, uint8_t transportType) {
sendFlasherAnswer(CMD_READ_FLASH, bufferp, cur_len, transportType);
if (bufferp != nullptr) free(bufferp);
}
} else if (selectedController == CONTROLLER_CC) {
if (ccflasherp == nullptr) return;
if (currentFlasherOffset >= 32768) {
sendFlasherAnswer(CMD_COMPLETE, temp_buff, 1,transportType);
} else {
bufferp = (uint8_t*)malloc(1024);
if (bufferp == nullptr) return;
cur_len = (32768 - currentFlasherOffset >= 1024) ? 1024 : 32768 - currentFlasherOffset;
ccflasherp->read_code_memory(currentFlasherOffset,cur_len,bufferp);
currentFlasherOffset += cur_len;
sendFlasherAnswer(CMD_READ_FLASH, bufferp, cur_len,transportType);
free(bufferp);
}
}
break;
case CMD_READ_INFOPAGE:
Expand Down Expand Up @@ -550,6 +578,15 @@ void processFlasherCommand(struct flasherCommand* cmd, uint8_t transportType) {
currentFlasherOffset += cmd->len;
sendFlasherAnswer(CMD_WRITE_FLASH, NULL, 0, transportType);
}
} else if (selectedController == CONTROLLER_CC) {
if (currentFlasherOffset >= 32768) {
sendFlasherAnswer(CMD_COMPLETE, temp_buff, 1, transportType);
} else {
if (ccflasherp == nullptr) return;
ccflasherp->write_code_memory(currentFlasherOffset, cmd->data, cmd->len);
currentFlasherOffset += cmd->len;
sendFlasherAnswer(CMD_WRITE_FLASH, NULL, 0, transportType);
}
}
break;
case CMD_WRITE_INFOPAGE:
Expand Down Expand Up @@ -603,6 +640,10 @@ void processFlasherCommand(struct flasherCommand* cmd, uint8_t transportType) {
cmdSerial.println("Not yet implemented!");
}
break;

default:
cmdSerial.printf("Ignored flasher command 0x%x.\r\n",cmd->command);
break;
}
}

Expand All @@ -618,6 +659,10 @@ void flasherCommandTimeout() {
delete nrfflasherp;
nrfflasherp = nullptr;
}
if (ccflasherp != nullptr) {
delete ccflasherp;
ccflasherp = nullptr;
}
lastCmdTimeStamp = 0;
}

Expand Down
58 changes: 58 additions & 0 deletions Tag_Flasher/ESP32_Flasher/include/cc_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma once
#include <Arduino.h>

typedef void (*callbackPtr)(uint8_t percent);

class CC_interface
{
public:
uint16_t begin(uint8_t CC, uint8_t DD, uint8_t RESET);
void set_callback(callbackPtr callBack = nullptr);
uint8_t set_lock_byte(uint8_t lock_byte);
uint8_t erase_chip();
void read_code_memory(uint16_t address, uint16_t len, uint8_t buffer[]);
void read_xdata_memory(uint16_t address, uint16_t len, uint8_t buffer[]);
void write_xdata_memory(uint16_t address, uint16_t len, uint8_t buffer[]);
void set_pc(uint16_t address);
uint8_t clock_init();
uint8_t write_code_memory(uint16_t address, uint8_t buffer[], int len);
uint8_t verify_code_memory(uint16_t address, uint8_t buffer[], int len);
uint8_t opcode(uint8_t opCode);
uint8_t opcode(uint8_t opCode, uint8_t opCode1);
uint8_t opcode(uint8_t opCode, uint8_t opCode1, uint8_t opCode2);
uint8_t WR_CONFIG(uint8_t config);
uint8_t WD_CONFIG();
/* Send one byte and return one byte as answer */
uint8_t send_cc_cmdS(uint8_t cmd);
/* Send one byte and returns two bytes as answer */
uint16_t send_cc_cmd(uint8_t cmd);
void cc_send_byte(uint8_t in_byte);
uint8_t cc_receive_byte();
void enable_cc_debug();
void reset_cc();

private:
boolean dd_direction = 0; // 0=OUT 1=IN
uint8_t _CC_PIN = -1;
uint8_t _DD_PIN = -1;
uint8_t _RESET_PIN = -1;
uint8_t flash_opcode[30] = {
0x75, 0xAD, 0x00, // Set Flash Address HIGH
0x75, 0xAC, 0x00, // Set Flash Address LOW
0x90, 0xF0, 0x00, // Set RAM Address to 0xF000
0x75, 0xAE, 0x02, // Enable Flash Writing
0x7D, 0x08, // Set Loop value to Half size as we write 2bytes at once 0x100
0xE0, // Put DPTR to A
0xF5, 0xAF, // Put A to FWDATA
0xA3, // Increase DPTR;
0xE0, // Put DPTR to A
0xF5, 0xAF, // Put A to FWDATA
0xA3, // Increase DPTR
0xE5, 0xAE, // Wait till writing is done
0x20, 0xE6, 0xFB,
0xDD, 0xF1, // Loop trough all bytes
0xA5 // Breakpoint
};
callbackPtr _callback = nullptr;
};

Loading

0 comments on commit 73e472e

Please sign in to comment.