-
Notifications
You must be signed in to change notification settings - Fork 174
Open
Description
Ccloader can not work with the Arduino with 168p microcontrоller due lack of the RAM. This Patch resolve this issue. After uploading sketch to the Arduino there is need to disconnect DTR -> Reset (if it used).
--- CCLoader.ino 2020-11-19 10:21:59.000000000 +0300
+++ ccloader168.ino 2020-11-19 11:29:07.000000000 +0300
@@ -452,6 +452,47 @@
}
/**************************************************************************//**
+* @brief Verify 1-32767 bytes from DUP's flash against a given buffer on the
+* programmer.
+* @param bank Flash bank to read from [0-7]
+* @param address Flash memory start address [0x0000 - 0x7FFF]
+* @param values Pointer to destination buffer.
+* @return Error. Zero if no errors
+******************************************************************************/
+unsigned char verify_flash_memory_block(unsigned char bank,unsigned short flash_addr,
+ unsigned short num_bytes, unsigned const char *values)
+{
+ unsigned char instr[3];
+ unsigned short i;
+ unsigned short xdata_addr = (0x8000 + flash_addr);
+ unsigned char err = 0;
+ unsigned char val;
+
+ // 1. Map flash memory bank to XDATA address 0x8000-0xFFFF
+ write_xdata_memory(DUP_MEMCTR, bank);
+
+ // 2. Move data pointer to XDATA address (MOV DPTR, xdata_addr)
+ instr[0] = 0x90;
+ instr[1] = HIBYTE(xdata_addr);
+ instr[2] = LOBYTE(xdata_addr);
+ debug_command(CMD_DEBUG_INSTR_3B, instr, 3);
+
+ for (i = 0; i < num_bytes; i++)
+ {
+ // 3. Move value pointed to by DPTR to accumulator (MOVX A, @DPTR)
+ instr[0] = 0xE0;
+ val = debug_command(CMD_DEBUG_INSTR_1B, instr, 1);
+ err = values[i] != val ? 1 : err;
+
+ // 4. Increment data pointer (INC DPTR)
+ instr[0] = 0xA3;
+ debug_command(CMD_DEBUG_INSTR_1B, instr, 1);
+ }
+
+ return err;
+}
+
+/**************************************************************************//**
* @brief Writes 4-2048 bytes to DUP's flash memory. Parameter \c num_bytes
* must be a multiple of 4.
* @param src Pointer to programmer's source buffer (in XDATA space)
@@ -526,9 +567,11 @@
Serial.begin(115200);
// If using Leonado as programmer,
//it should add below code,otherwise,comment it.
- while(!Serial);
+ // while(!Serial);
}
+unsigned char rxBuf[514];
+
void loop()
{
unsigned char chip_id = 0;
@@ -536,6 +579,13 @@
unsigned char Continue = 0;
unsigned char Verify = 0;
+ for (unsigned char j = 0; j < 3; j++){
+ digitalWrite(LED, HIGH);
+ delay(50);
+ digitalWrite(LED, LOW);
+ delay(50);
+ }
+
while(!Continue) // Wait for starting
{
@@ -583,7 +633,6 @@
digitalWrite(LED, HIGH);
unsigned char Done = 0;
unsigned char State = WAITING;
- unsigned char rxBuf[514];
unsigned int BufIndex = 0;
unsigned int addr = 0x0000;
while(!Done)
@@ -633,18 +682,25 @@
{
unsigned char bank = addr / (512 * 16);
unsigned int offset = (addr % (512 * 16)) * 4;
- unsigned char read_data[512];
- read_flash_memory_block(bank, offset, 512, read_data); // Bank, address, count, dest.
- for(unsigned int i = 0; i < 512; i++)
- {
- if(read_data[i] != rxBuf[i])
- {
- // Fail
+ // unsigned char read_data[512];
+ // read_flash_memory_block(bank, offset, 512, read_data); // Bank, address, count, dest.
+ // for(unsigned int i = 0; i < 512; i++)
+ // {
+ // if(read_data[i] != rxBuf[i])
+ // {
+ // // Fail
+ // State = WAITING;
+ // Serial.write(ERRO);
+ // chip_erase();
+ // return;
+ // }
+ // }
+ unsigned char err = verify_flash_memory_block(bank, offset, 512, rxBuf);
+ if (err) {
State = WAITING;
Serial.write(ERRO);
chip_erase();
return;
- }
}
}
addr += (unsigned int)128; socram8888
Metadata
Metadata
Assignees
Labels
No labels