Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Won't flash using IDE 2.2.1 #312

Open
bmentink opened this issue Feb 21, 2024 · 68 comments
Open

Won't flash using IDE 2.2.1 #312

bmentink opened this issue Feb 21, 2024 · 68 comments

Comments

@bmentink
Copy link

Hi, I am trying to program LGTBF328P - MiniEVB nano board. I get the following error:

avrude error: protocol expects OK byte 0x10 but got 0xfc
avrdude error: unable to read signature data for part ATmega328P, rc=-3
avrdude error: unable to read signature data, rc=-3
Failed uploading: uploading error: exit status 1

Any idea's ?

@bmentink
Copy link
Author

Update: I wonder if I got some bad boards. I have 5 boards, 3 program ok, 2 won't.

@hmeijdam
Copy link

You could try to use one of the working ones for attempting to burn the bootloader on one of the defective boards.

@bmentink
Copy link
Author

bmentink commented Feb 22, 2024

You could try to use one of the working ones for attempting to burn the bootloader on one of the defective boards.

Can you show me how to connect the SPI pins? It is not clear from the board which ones connect to MOSI and MISO, CLK etc, seems to have a pin missing. Cheers (can only see SWC and SWD)

@hmeijdam
Copy link

You need LGTISP to burn the bootloader via SWD and SWC.

@bmentink
Copy link
Author

Thanks, will give it a try.

@bmentink
Copy link
Author

bmentink commented Feb 22, 2024

I loaded up a good LGT board with the LGTISP.ino sketch ok. However, when I go to program the bootloader to another LGT board connected with SWC,SWD etc it gives error.

avrdude error: programmer is out of sync
 ***failed;
avrdude error: programmer is out of sync
 ***failed;

I am somewhat confused as the instructions say to use AVR ISP as programmer, even though there is an " LGTSWD markii as ISP" option ??

@hmeijdam
Copy link

hmeijdam commented Feb 22, 2024

There is a LarduinoISP sketch amongst the examples. Did you compile and load that one?
It also mentions how to wire it up. You need to look at the right column under LGT8FX8P:

image

The LGTSWD Mark II is this one. Probably not what you have.

@bmentink
Copy link
Author

bmentink commented Feb 22, 2024

You linked the github site, it only shows these files, no examples. Please be specific.
Screenshot 2024-02-23 at 10 39 14 AM

You show me an Arduino as ESP, in your example above, I am using LGT to program LGT. ARe the pin connections the same?

@hmeijdam
Copy link

This is the example I mean. It comes with this core.

image

@bmentink
Copy link
Author

Right, you did not link that initially, now I understand. BUt the question remains, If I use LGT as ESP are the pin connections the same?

@hmeijdam
Copy link

LGT as ISP has these connections.
image
If that does not work, I will dig up my LGT's and hook them up. Has been a few years since I had to bootload one.

@bmentink
Copy link
Author

bmentink commented Feb 22, 2024

I don't have those examples .... maybe I have the wrong LGT library?

I got the library from here:
https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json

@bmentink
Copy link
Author

LGT as ISP has these connections. image If that does not work, I will dig up my LGT's and hook them up. Has been a few years since I had to bootload one.

I don't have those names, please give the corresponding D8,D10) etc ..

@hmeijdam
Copy link

Well.... you are posting your question in the Github forum of the core I am using, so I assumed you will have the LarduinoISP as well. But apparently not

Here are the pins

lgt8f328p_nano_qfp32l_pinout-1-1024x627

@bmentink
Copy link
Author

I have added the core I am using above, is it incorrect?

@hmeijdam
Copy link

hmeijdam commented Feb 22, 2024

That's the one I use.

@bmentink
Copy link
Author

That's the one I use.

So why no examples?

@hmeijdam
Copy link

I honestly have no clue.
Here is the LarduinoISP sketch


// 20 July 2020 David Buezas
// - Bundled and added menu utility
// * When uploading to the programmer,
//   select in the menu: Tools/Arduino as ISP/SERIAL_RX_BUFFER_SIZE to 250)
// * Before using the ISP to program another board, 
//   connect (in the ISP board) the reset pin to gnd via a capacitor,
//   or (at your own risk) short reset to vcc.
// https://github.com/dbuezas/lgt8fx/
//
// author : brother_yan (https://github.com/brother-yan/LGTISP)
//
// LarduinoISP for LGT8FX8P series
// Project fork from
//    - ArduinoISP version 04m3
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see 
//     http://www.opensource.org/licenses/bsd-license.php
//
// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name:    Arduino:          LGT8FX8P:
// slave reset: 10:               PC6/RESET 
// SWD:         12:               PE2/SWD
// SWC:         13:               PE0/SCK
// Make sure to 
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat   - shows the programmer is running
// 8: Error       - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
//
// 23 July 2011 Randall Bohn
// -Address Arduino issue 509 :: Portability of ArduinoISP
// http://code.google.com/p/arduino/issues/detail?id=509
//
// October 2010 by Randall Bohn
// - Write to EEPROM > 256 bytes
// - Better use of LEDs:
// -- Flash LED_PMODE on each flash commit
// -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress)
// - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync.
// - Use pins_arduino.h (should also work on Arduino Mega)
//
// October 2009 by David A. Mellis
// - Added support for the read signature command
// 
// February 2009 by Randall Bohn
// - Added support for writing to EEPROM (what took so long?)
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.
//
// January 2008 by Randall Bohn
// - Thanks to Amplificar for helping me with the STK500 protocol
// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
// - The SPI functions herein were developed for the AVR910_ARD programmer 
// - More information at http://code.google.com/p/mega-isp

// LarduinoISP for LGTF8FX8P Series
#include "swd_lgt8fx8p.h"

#if SERIAL_RX_BUFFER_SIZE < 250 // 64 bytes的RX缓冲不够大
#error : Please change the macro SERIAL_RX_BUFFER_SIZE to 250 (In the menu: Tools/Arduino as ISP/SERIAL_RX_BUFFER_SIZE)
#endif

#define RESET	10
#define LED_HB    9
#define LED_ERR   8
#define LED_PMODE 7
#define PROG_FLICKER true

#define HWVER 3
#define SWMAJ 5
#define SWMIN 1

// STK Definitions
#define STK_OK      0x10
#define STK_FAILED  0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC  0x14
#define STK_NOSYNC  0x15
#define CRC_EOP     0x20 //ok it is a space...

void pulse(int pin, int times);

void setup() 
{
  SWD_init();
  Serial.begin(115200);
  
  //pinMode(LED_PMODE, OUTPUT);
  //pulse(LED_PMODE, 2);
  //pinMode(LED_ERR, OUTPUT);
  //pulse(LED_ERR, 2);
  //pinMode(LED_HB, OUTPUT);
  //pulse(LED_HB, 2);
}

uint8_t error=0;
uint8_t pmode=0;

// address for reading and writing, set by 'U' command
int address;
uint8_t buff[256]; // global block storage

#define beget16(addr) (*addr * 256 + *(addr+1) )
typedef struct param {
  uint8_t devicecode;
  uint8_t revision;
  uint8_t progtype;
  uint8_t parmode;
  uint8_t polling;
  uint8_t selftimed;
  uint8_t lockbytes;
  uint8_t fusebytes;
  uint8_t flashpoll;
  uint16_t eeprompoll;
  uint16_t pagesize;
  uint16_t eepromsize;
  uint32_t flashsize;
}  parameter_t;
parameter_t param;

// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
uint8_t hbdelta=8;
void heartbeat() 
{
  if (hbval > 192) hbdelta = -hbdelta;
  if (hbval < 32) hbdelta = -hbdelta;
  hbval += hbdelta;
  analogWrite(LED_HB, hbval);
  delay(40);
}

void loop(void) 
{
  // is pmode active?
/*
  if (pmode) digitalWrite(LED_PMODE, HIGH); 
  else digitalWrite(LED_PMODE, LOW);
  // is taddress an error?
  if (error) digitalWrite(LED_ERR, HIGH); 
  else digitalWrite(LED_ERR, LOW);
*/
  // light the heartbeat LED
  //heartbeat();
  if (Serial.available()) 
    avrisp();
}

uint8_t getch() {
  while(!Serial.available());
  return Serial.read();
}

void fill(int n) 
{
  for (int x = 0; x < n; x++) {
    buff[x] = getch();
  }
}

#define PTIME 30
void pulse(int pin, int times) 
{
  do {
    digitalWrite(pin, HIGH);
    delay(PTIME);
    digitalWrite(pin, LOW);
    delay(PTIME);
  } 
  while (times--);
}

void prog_lamp(int state) 
{
  if (PROG_FLICKER)
    digitalWrite(LED_PMODE, state);
}

void empty_reply() 
{
  if (CRC_EOP == getch()) {
    Serial.print((char)STK_INSYNC);
    Serial.print((char)STK_OK);
  } 
  else {
    error++;
    Serial.print((char)STK_NOSYNC);
  }
}

void breply(uint8_t b) 
{
  if (CRC_EOP == getch()) {
    Serial.print((char)STK_INSYNC);
    Serial.print((char)b);
    Serial.print((char)STK_OK);
  } 
  else {
    error++;
    Serial.print((char)STK_NOSYNC);
  }
}

void get_version(uint8_t c) 
{
  switch(c) {
  case 0x80:
    breply(HWVER);
    break;
  case 0x81:
    breply(SWMAJ);
    break;
  case 0x82:
    breply(SWMIN);
    break;
  case 0x93:
    breply('S'); // serial programmer
    break;
  default:
    breply(0);
  }
}

void set_parameters() 
{
  // call this after reading paramter packet into buff[]
  param.devicecode = buff[0];
  param.revision   = buff[1];
  param.progtype   = buff[2];
  param.parmode    = buff[3];
  param.polling    = buff[4];
  param.selftimed  = buff[5];
  param.lockbytes  = buff[6];
  param.fusebytes  = buff[7];
  param.flashpoll  = buff[8]; 
  // ignore buff[9] (= buff[8])
  // following are 16 bits (big endian)
  param.eeprompoll = beget16(&buff[10]);
  param.pagesize   = beget16(&buff[12]);
  param.eepromsize = beget16(&buff[14]);

  // 32 bits flashsize (big endian)
  param.flashsize = buff[16] * 0x01000000
    + buff[17] * 0x00010000
    + buff[18] * 0x00000100
    + buff[19];

}

void start_pmode(uint8_t chip_erase) 
{
  digitalWrite(RESET, HIGH);
  pinMode(RESET, OUTPUT);
  delay(20);
  digitalWrite(RESET, LOW);
  
  SWD_init();
  SWD_Idle(10);
  
  pmode = SWD_UnLock(chip_erase);
  if (!pmode)
    pmode = SWD_UnLock(chip_erase);
}

void end_pmode()
{
  SWD_exit();
  pmode = 0;
  
  digitalWrite(RESET, HIGH);
  pinMode(RESET, INPUT);
}

void universal() 
{
  fill(4);

  if(buff[0] == 0x30 && buff[1] == 0x00) {
    switch(buff[2]) {
    case 0x00:
      breply(0x1e);
      break;
    case 0x01:
      breply(0x95);
      break;
    case 0x02:
      breply(0x0f);
      break;
    default:
      breply(0xff);
      break;  
    }
  } else if(buff[0] == 0xf0) {
    breply(0x00);
  } else {
    breply(0xff);
  }
}

void write_flash(int length) 
{
  fill(length);
  if (CRC_EOP == getch()) {
    Serial.print((char) STK_INSYNC);
    Serial.print((char) write_flash_pages(length));
  } 
  else {
    error++;
    Serial.print((char) STK_NOSYNC);
  }
}

uint8_t write_flash_pages(int length)
{
  int addr = address / 2;
  /*
  lgt8fx8p的flash是按4字节编址的,而avr是按2字节编址的,avrdude传过来的是按2字节编址的address
  avrisp()函数中也有证实:
  case 'U': // set address (word)
  */
  
  SWD_EEE_CSEQ(0x00, addr);
  SWD_EEE_CSEQ(0x84, addr);
  SWD_EEE_CSEQ(0x86, addr);
  
  for (int i = 0; i < length; i += 4)
    {
      SWD_EEE_Write(*((uint32_t *)(&buff[i])), addr);
      ++addr;
    }
  
  SWD_EEE_CSEQ(0x82, addr - 1);
  SWD_EEE_CSEQ(0x80, addr - 1);
  SWD_EEE_CSEQ(0x00, addr - 1);
  
  return STK_OK;
}

#define EECHUNK (32)
uint8_t write_eeprom(int length) 
{
  // address is a word address, get the byte address
  int start = address * 2;
  int remaining = length;
  if (length > param.eepromsize) {
    error++;
    return STK_FAILED;
  }
  while (remaining > EECHUNK) {
    write_eeprom_chunk(start, EECHUNK);
    start += EECHUNK;
    remaining -= EECHUNK;
  }
  write_eeprom_chunk(start, remaining);
  return STK_OK;
}

// write (length) bytes, (start) is a byte address
uint8_t write_eeprom_chunk(int start, int length) 
{
  // this writes byte-by-byte,
  // page writing may be faster (4 bytes at a time)
  fill(length);
  prog_lamp(LOW);
  for (int x = 0; x < length; x++) {
    int addr = start+x;
    // do e2prom program here
    // donothing for lgt8fx8d series
    delay(45);
  }
  prog_lamp(HIGH); 
  return STK_OK;
}

void program_page() 
{
  char result = (char) STK_FAILED;

  // get length
  uint16_t length = getch() << 8;
  length += getch();

  char memtype = getch();
  // flash memory @address, (length) bytes
  if (memtype == 'F') {
    write_flash(length);
    return;
  }
  if (memtype == 'E') {
    result = (char)write_eeprom(length);
    if (CRC_EOP == getch()) {
      Serial.print((char) STK_INSYNC);
      Serial.print(result);
    } 
    else {
      error++;
      Serial.print((char) STK_NOSYNC);
    }
    return;
  }
  Serial.print((char)STK_FAILED);
  return;
}

char flash_read_page(int length)
{
  int addr = address / 2;
  /*
  lgt8fx8p的flash是按4字节编址的,而avr是按2字节编址的,avrdude传过来的是按2字节编址的address
  avrisp()函数中也有证实:
  case 'U': // set address (word)
  */
  
  SWD_EEE_CSEQ(0x00, 0x01);
  
  uint32_t data;
  for (int i = 0; i < length; ++i)
    {
      if (i % 4 == 0)
        {
          data = SWD_EEE_Read(addr);
          ++addr;
        }
      Serial.print((char)((uint8_t *)&data)[i % 4]);
    }
  
  SWD_EEE_CSEQ(0x00, 0x01);
  
  return STK_OK;
}

char eeprom_read_page(uint16_t length) 
{
  // address again we have a word address
  uint16_t start = address * 2;
  for (int x = 0; x < length; x++) {
    uint16_t addr = start + x;
    // do ep2rom read here
    // but donothing for lgt8fx8d series (by now...)
    Serial.print((char) 0xff);
  }
  return STK_OK;
}

void read_page() 
{
  char result = (char)STK_FAILED;

  uint16_t length = getch() << 8;
  length += getch();
  char memtype = getch();
  if (CRC_EOP != getch()) {
    error++;
    Serial.print((char) STK_NOSYNC);
    return;
  }
  Serial.print((char) STK_INSYNC);

  if (memtype == 'F') result = flash_read_page(length);
  if (memtype == 'E') result = eeprom_read_page(length);
  Serial.print(result);
  return;
}

void read_signature() 
{
  if (CRC_EOP != getch()) {
    error++;
    Serial.print((char) STK_NOSYNC);
    return;
  }
  
  Serial.print((char) STK_INSYNC);
  Serial.print((char) 0x1e);
  Serial.print((char) 0x95);
  Serial.print((char) 0x0a);
  Serial.print((char) STK_OK);
}

//////////////////////////////////////////
//////////////////////////////////////////


////////////////////////////////////
////////////////////////////////////
volatile uint8_t chip_erased;
int avrisp() 
{ 
  uint8_t data, low, high;
  uint8_t ch = getch();
  switch (ch) {
  case '0': // signon
    error = 0;
    empty_reply();
    break;
  case '1':
    if (getch() == CRC_EOP) {
      Serial.print((char) STK_INSYNC);
      Serial.print("AVR ISP");
      Serial.print((char) STK_OK);
    } else {
      error++;
      Serial.print((char) STK_NOSYNC);
    }
    break;
  case 'A':
    get_version(getch());
    break;
  case 'B':	// optional for lgt8fx8d series
    fill(20);
    set_parameters();
    empty_reply();
    break;
  case 'E': // extended parameters - ignore for now
    fill(5);
    empty_reply();
    break;

  case 'P':
    if (pmode) {
      pulse(LED_ERR, 3);
    } else {
      start_pmode(0);
      chip_erased = 0;
    }
    if (pmode)
      empty_reply();
    else
      {
        if (CRC_EOP == getch()) {
          Serial.print((char)STK_INSYNC);
          Serial.print((char)STK_FAILED);
        } 
        else {
          error++;
          Serial.print((char)STK_NOSYNC);
        }
      }
    break;
  case 'U': // set address (word)
    address = getch();
    address += (getch() << 8);
    empty_reply();
    break;
  case 0x60: //STK_PROG_FLASH
    low = getch();
    high = getch();
    empty_reply();
    break;
  case 0x61: //STK_PROG_DATA
    data = getch();
    empty_reply();
    break;
  case 0x64: //STK_PROG_PAGE
    if (!chip_erased)
      {
        error = 0;
        end_pmode();
        start_pmode(1);
        chip_erased = 1;
      }
    program_page();
    break;
  case 0x74: //STK_READ_PAGE 't'
    read_page();    
    break;
  case 'V': //0x56
    universal();
    break;
  case 'Q': //0x51
    error=0;
    end_pmode();
    empty_reply();
    break;
  case 0x75: //STK_READ_SIGN 'u'
    read_signature();
    break;
    // expecting a command, not CRC_EOP
    // this is how we can get back in sync
  case CRC_EOP:
    error++;
    Serial.print((char) STK_NOSYNC);
    break;

    // anything else we will return STK_UNKNOWN
  default:
    error++;
    if (CRC_EOP == getch()) 
      Serial.print((char)STK_UNKNOWN);
    else
      Serial.print((char)STK_NOSYNC);
  }
}

@bmentink
Copy link
Author

THanks, these are the examples I have:
Screenshot 2024-02-23 at 11 02 05 AM

So just put the above code on the LGT board that has to act as ISP, right?
In that case, what is the LGTISP.ino I put on from github do then?

@hmeijdam
Copy link

LGTISP.ino may be a newer or older version. I have not used it myself as I usually grab my dedicated SWDICE programmer.

The sketch I just uploaded here I have used a while back. But I just found my box with LGT's so let me try if it still works.

@bmentink
Copy link
Author

Thanks will wait. Meantime I tried connecting the programming pins at the end of the board to the target board pins, but that did not work either. So Still unsure of pin connections.

@hmeijdam
Copy link

Just tested and works fine

First burn the LarduinoISP.ino to your working Nano

Then hook it up like

// pin name:    Programmer NANO         Target LGT8FX8P:
// reset:                   10:            PC6/RESET 
// SWD:                     12:           PE2/SWD
// SWC:                     13:           PE0/SCK

Keep AVRISP as programmer and press "burn Bootloader"

image

I burned it to a "promini style" LGT board, as my second Nano has no pinheaders yet. But you will select the board you have to get the bootloader that goes with your board.

@bmentink
Copy link
Author

bmentink commented Feb 22, 2024

First burn the LarduinoISP.ino to your working Nano

I keep teling you, I am not using an Arduino Nano as ISP, I am using LGT Nano, do I still use pins 10,12,13 on the ISP side ?

@hmeijdam
Copy link

I also used LGT Nano

@bmentink
Copy link
Author

Well I get this using those pinouts:

avrdude error: programmer is not responding
avrdude warning: attempt 1 of 10: not in sync: resp=0x00
avrdude warning: ignoring mismatch in unused bits of lock
        (device 0xff != input 0x3f); to prevent this warning set
        unused bits to 1 when writing (double check with datasheet)
avrdude error: programmer is not responding
avrdude warning: attempt 1 of 10: not in sync: resp=0x00
avrdude warning: ignoring mismatch in unused bits of lock
        (device 0xff != input 0x3f); to prevent this warning set
        unused bits to 1 when writing (double check with datasheet)

@bmentink
Copy link
Author

I have to go out, will pick this up later. Thanks for the help.

@hmeijdam
Copy link

This is how I wired it up

image

@bmentink
Copy link
Author

I have exactly that!

@bmentink
Copy link
Author

bmentink commented Feb 23, 2024

I'm back now if you have any more suggestions. I am using LarduinoISP.ino, but LGTISP.ino does not work either.

@dbuezas
Copy link
Owner

dbuezas commented Feb 23, 2024

Have you seen the tutorial in this repo?
https://github.com/dbuezas/lgt8fx/blob/master/lgt8f/libraries/LarduinoISP/readme.md

@Devilscave
Copy link

Devilscave commented Jun 4, 2024

I have to get involved in this topic now. I have exactly the same problem. I have an LGT Nano as target and also an LGT Nano as ISP programmer. I have installed the Larduino and also read the example, which I have also installed on my LGT ISP as prescribed and then connected the ISP to the target as specified.
GND -> GND
5v -> VCC
D10 -> RESET
D12 -> SWD
D13 -> SWC
I have tried different variants and also set various build rates in code line 88. All without success. It always says Sync does not match or Target does not respond. It is devinitiv a sketch without bootloader on the target, now I have to load a bootloader again but it doesn't like it.
Thats my Error:

avrdude: stk500_program_enable(): failed to enter programming mode
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
Fehler beim Brennen des Bootloaders.

I have just tried again with a definitely working LGT EVB board, and come to the same result. I can't install the bootloader on this one either, with the same error message mentioned here.

@Devilscave
Copy link

OK guys I have found the error, even if I can't really explain it to myself.
Maybe it concerns you too. I have noticed that in all explanations here always a "GREEN" LGT8 Nano with Micro USB is used.
I tried all the time with a "PURPLE" LGT Nano whit USB-C and always failed.
But I had one of the green ones and used it and did everything exactly as indicated... installed the LarduinoISP.ino and connected it to a MiniEVB as I did before with the purple LGT. But this time it worked immediately in 2-3 seconds.
Then I connected the green LGT Nano to the purple LGT Nano and within 2-3 seconds the bootloader was on.
And I was able to upload my sketch to the purple LGT via USB as normal.
So in my case it was definitely the purple LGT Nano. In the meantime, I also tried using an Arduino Nano V3 as an ISP, which also only produced sync errors, but others.
I think there should be a strong differentiation between purple and green in the instructions and I think these should also be strictly separated and named individually in further descriptions. Perhaps it is also due to the more precise setting, one difference between the two is that the purple LGT has an external 16MHz crystal while the green one works with the internal 32MHz crystal.
I think this is where you should start. Please try it out for yourself.

@dbuezas
Copy link
Owner

dbuezas commented Jun 5, 2024

The external crystal won't be used unless you specifically configure the board to use it. I made myself a connector with pogo pins and the reset cap and it has been a lot more reliable ever since. This leds me to believe that the ISP is particularly sensitive to bad connection issues (and also prone to them because of the temptation of "quickly" use jumper cables held with the hand)

@wollewald
Copy link
Contributor

Hi @Devilscave , I am keen to try myself. I understood that the combination of the purple lgt based board and the green does not work. But I am not sure which board you used as programmer and which as target. Can you tell me that detail?

Another point: you said you tried an Arduino Nano V3. This means a conventional one based on an ATmega328P? This is not a surprise that this does not work.

@dbuezas
Copy link
Owner

dbuezas commented Jun 5, 2024

Which purple one, the LQFP48 (larger) or LQFP32?

@lalo-uy
Copy link

lalo-uy commented Jun 5, 2024

Hi @Devilscave , I am keen to try myself. I understood that the combination of the purple lgt based board and the green does not work. But I am not sure which board you used as programmer and which as target. Can you tell me that detail?

Another point: you said you tried an Arduino Nano V3. This means a conventional one based on an ATmega328P? This is not a surprise that this does not work.

Didn't know that Atmega328 do not work. What about an ESP-12 Uno board?

@wollewald
Copy link
Contributor

Hi @lalo-uy , to be more precise: it possible to use a classic Arduino Nano but not if you follow the instructions here:

https://github.com/dbuezas/lgt8fx/tree/master/lgt8f/libraries/LarduinoISP

In oder to set the Serial RX Buffer to 250 Bytes you can't use the convenient way:

Screenshot 2024-06-05 204552

Since you have to choose the board on which you want to upload the LArduinoISP sketch, you won't see this setting. Therefore, you have to make this setting manually in HardwareSerial.h which you hould find here:

...\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino

If you should choose this way it works (I have tried beacuse I was curious), but I would recommend to spend little money for a second LGT8F328P based board instead..

With the ESP-12 Uno board it might work directly if the buffer is >= 250 bytes. Just check if the LArduinoISP sketch compiles. Done in a few seconds!

@Devilscave
Copy link

@wollewald

Hallo@Devilscave, ich möchte es unbedingt selbst ausprobieren. Mir ist klar, dass die Kombination aus der violetten, LGT-basierten Platine und der grünen nicht funktioniert. Aber ich bin mir nicht sicher, welche Platine Sie als Programmierer und welche als Ziel verwendet haben. Können Sie mir das genauer erklären?

In my text it says exactly when I used which one. I only tried a purple LGT in my first post and that didn't work.
In my second post where it worked, I used the green programmer as described in the text.

Noch ein Punkt: Du hast gesagt, du hättest es mit einem Arduino Nano V3 versucht. Meinst du damit einen konventionellen auf Basis eines ATmega328P? Es ist keine Überraschung, dass dieser nicht funktioniert.

I figured if it works with a UNO, why not. But I already encountered the error when programming that I can't make the bit settings at all, funnily enough the Nano eats the sketch anyway.

@dbuezas

Welches violette Modell, LQFP48 (größer) oder LQFP32?

LQFP32

@wollewald
Copy link
Contributor

Hi @Devilscave, I can reproduce the issue with the purple LQFP32. It does not work as a programmer, at least when following the standard procedure. I tried burning the bootloader on a green LQFP32 as well as on a purple LQFP32 using the purple LQFP32 as programmer. I also tried a purple LQFP48 as a programmer and that worked perfectly. So, it is a specific problem of the purple LQFP32.

I don't know what the problem is and how to fix it. My gut feel says it is related to the CH9340C USB-to-TTL Chip on the purple LQFP32 board and how it is wired. But I have no proof for that.

@dbuezas
Copy link
Owner

dbuezas commented Jun 6, 2024

That's very odd.
isp.zip
I don't have a purple LQFP32 to test it my self, would you test this isp code with it?
The only difference is that the pins change:

  • SWD -> PC5 - A5
  • RESET -> PC4 - A4
  • SWC -> PC3 - A3

Since the pcb layout is different, I wonder if some pin is either not connected or has some unwanted pulldown or capacitive coupling with the xtal on PB6 and 7 (same port as the original isp code uses).

(I use the ISP like this so that the pins between programmer and programmed are aligned)

Regarding the USB to TTL chip, what is your hunch based on? the serial part should only affect pc <-> isp, and that obviously works if serial burning works.

Also, it may be worth trying setting the clock differently, e.g using the external one.

@Devilscave
Copy link

I have to try it again now, because yesterday I must have shot something on one of the purple LGTs, it works to load sketches on it, but runs much too fast and the sketches only make measurements, it almost seems to me as if the bootloader is wrong.

@wollewald
Copy link
Contributor

Hi @dbuezas , I have tried your sketch and get the same error like before:

error_msg_purple

In order to confirm that I have not wired something wrongly, I have done the same with green LQFP32 and it worked.

Then I found something interesting. I changed back to the purple LQFP32 and uploaded the standard LArduinoISP sketch. Then I connected the purple LQFP32 to a USB-to-TTL Adapter instead of the PC directly:
VCC -> VCC
GND -> GND
RX -> TX
TX -> RX

It looked like this:

20240607_182728

All the rest is set up as one would do using the normal procedure. And it works! I was able to burn the the bootlader and to upload sketches using the purple LQFP32 as a programmer. I really think the problem is the CH9340C Chip.

There are also purple LQFP32 boards available which other USB-to-TTL Chips than the CH9340C. I have order some from China, so it will take a while until I can test. If anyone reads this and has such a board, it would be great to know if these can be used as programmer.

@Devilscave, can you check which chip you have on your board?

@Devilscave
Copy link

Devilscave commented Jun 7, 2024

@Devilscave, can you check which chip you have on your board?

I also have the CH340C on all the purple ones.
The green LGT has the HT42B534-2

@wollewald
Copy link
Contributor

@Devilscave , thank you. But I don't have the CH340C, I have the CH9340C. It's a small difference in the name, but these are dfferent chips. Sorry, but can you double check?
@Devilscave , danke. Aber ich habe nicht den CH340C, ich habe den CH9340C. Es ist nur ein kleiner Unterschied im Namen, aber es sind verschiedene Chips. Entschuldigung, aber können Sie das noch einmal überprüfen?

@dbuezas
Copy link
Owner

dbuezas commented Jun 7, 2024

That's very interesting, i really didn't expect that. Serial communication works normally at any baudrate otherwise?

Übrigens, lass uns auf Englisch bleiben, das hier wird wahrscheinlich von anderen auch gelesen.

Or maybe the reset line is held too long? I think that's controlled by the usb-ttl chip. The capacitor trick could serve to test that.

@Devilscave
Copy link

Devilscave commented Jun 7, 2024

@Devilscave, danke. Aber ich habe nicht den CH340C, sondern den CH 9 340C. Es ist ein kleiner Unterschied im Namen, aber das sind unterschiedliche Chips. Tut mir leid, aber können Sie das noch einmal überprüfen?

No it's a CH340C

20240607_202800

Übrigens, lass uns auf Englisch bleiben, das hier wird wahrscheinlich von anderen auch gelesen.

Sorry, I worked with a page translator and he simply translated my English answer as well. I've changed it.

@wollewald
Copy link
Contributor

@Devilscave , thank you. Helpful information. Then it's something else on the board. Yesterday I tried to use a purple LQFP48 board which uses a CH340C hip like yours and that work as a programmer.

@dbuezas , usually I take a 10µF capacitor. I also tried a 100 µF and a 100 nF capacitor and no capacitor. It all didn't work. Or what do you mean with capacitor trick?

@dbuezas
Copy link
Owner

dbuezas commented Jun 7, 2024

Yes I meant a cap at the reset pin. I thought maybe the programmer maybe was reset for too long by dtr.

I burnt my isp without bootloader to avoid accidentally flashing it instead of the target device. I wonder if the purple ones come with a different bootloader?

@wollewald
Copy link
Contributor

I have just burned a new bootloader on the purple LQFP32 and tried again to use it as programmer. But no success. Maybe I will have a good idea over night.

@dbuezas
Copy link
Owner

dbuezas commented Jun 9, 2024

Could it be that the serial doesn't work well at the specific baudrate used when isp programming?

@wollewald
Copy link
Contributor

At least worth a try to change the baud rate. I am quite busy currently and so I cannot promise trying this within the next days.
It might also help to compare the circuit diagrams of the purple LQFP32 board vs the green one and the purple LQFP48 board which do work. Unfortunately, I have not found circuit diagrams for the purple boards.

@wollewald
Copy link
Contributor

I have some news. I have now received purple LQFP32 boards with a CH340C from two different shops and both work as programmers as they should. I double checked that the purple board with the CH9340C still did not work. Since @Devilscave tried a board with a CH340C chip, which did not the difference between the CH340C and the CH9340C should not be the reason. I have burned on all boards the same bootloader, so this is also not the reason. I have no idea yet why some of these boards do not work. Maybe a bad batch of the PCBs? Here's a photo of one board that is working and another which does not. I can't see obvious differences:

WNFF5895

So, good that this is no general issue, but bad that we don't know why the problematic boards behave like they do and how to identify them (before you buy them!).

@Devilscave
Copy link

Devilscave commented Jun 18, 2024

@wollewald Maybe you could, since you own both boards and they seem to be identical, simply swap the CH340 chips across. If the error moves, it is the chip, if it stays, it is the board.
If the non-functioning one happens to be the top one on yout picture, I almost assume it is a fake ch9340, the labeling is different and much worse executed. This often tests for counterfeits as the manufacturers usually have very good labeling.
EDIT: ahh i see thet the upper one is the CH9340C
But change it across.

@wollewald
Copy link
Contributor

Hi @Devilscave , good idea. Let me check if get the chip desoldered and transferred without damage.

@Devilscave
Copy link

here the Pinouts from the two ICs
ch340 vergleich

@LaZsolt
Copy link
Collaborator

LaZsolt commented Jun 19, 2024

I have an idea about the problematic serial converter chip, CH9340C.
The pin 8 low level selecting the dedicated baud rate mode, whatever that means.
So lift up pin 8 from PCB for deselect the dedicated baud rate mode.

@wollewald
Copy link
Contributor

Hi @LaZsolt , you are the hero! I cut the pin 8 and then it worked. To be absolutely sure, I reconnected pin 8, then it did not work, disconnected again and it worked. And it does not seem to have negative side effects. I can still upload sketches to the board when not used as programmer. Cutting the pin is not the nicest workaround, but at least we know what that issue is. However, this is only an explanation for the boards that I used. It does not explain why the board of @Devilscave does not work as a programmer since his one has a CH340C chip. @Devilscave , do you still know where you ordered your board? I would buy a board from the same source and hope that they have not changed the design meanwhile.

@Devilscave
Copy link

@wollewald
I have just checked my source of supply, (aliexpress) )unfortunately the shop no longer has an LGT8 in its range.

@dbuezas
Copy link
Owner

dbuezas commented Jun 20, 2024

@Devilscave there's dozens of other shops offering them, they're all fine :)

@Devilscave
Copy link

@dbuezas I know, I don't want to buy any, but Wollewald asked for my source of supply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants