Coder Social home page Coder Social logo

Comments (16)

ataradov avatar ataradov commented on September 3, 2024

EDBG support on MAC is incomplete, since I don't have any Apple hardware.

It has the report size hard coded:

static int report_size = 512; // TODO: read actual report size

You probably need to change that value to 64 for your device, since it is likely to be a USB FS device.

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

After Changing the

static int report_size = 64; // TODO: read actual report size
in dbg_mac.c
The error still occurs..

from edbg.

ataradov avatar ataradov commented on September 3, 2024

Then you need to print out the values of the hid_buffer before hid_write() and after hid_read(). First byte must match. But more importantly you will know on what command it fails. Do that and provide the output.

int dbg_dap_cmd(uint8_t *data, int resp_size, int req_size)
{
  uint8_t cmd = data[0];
  int res;

  verbose("---\n");
  for (int i = 0; i < 16; i++)
    verbose("0x%02x ", data[i]);
  verbose("\n");

  memset(hid_buffer, 0xff, report_size + 1);

  hid_buffer[0] = 0x00; // Report ID
  memcpy(&hid_buffer[1], data, req_size);

  res = write(debugger_fd, hid_buffer, report_size + 1);
  if (res < 0)
    perror_exit("debugger write()");

  res = read(debugger_fd, hid_buffer, report_size + 1);
  if (res < 0)
    perror_exit("debugger read()");

  check(res, "empty response received");

  for (int i = 0; i < 16; i++)
    verbose("0x%02x ", hid_buffer[i]);
  verbose("\n");

  check(hid_buffer[0] == cmd, "invalid response received");

  res--;
  memcpy(data, &hid_buffer[1], (resp_size < res) ? resp_size : res);

  return res;
}

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

In the file dbg_mac.c.. there is "No hid_write() and hid_read()"..

In 2 ways I have applied the following code..

  1. In this method, I copy pasted the following code in the end of the dbg_mac.c file. Like wise, saved the file and run edbg.

I obtained same result.... of "Error invalid response received"

  1. In this method, I copy pasted the following code in the end of the dbg_mac.c file. Like wise as mentioned above. This time I have saved the file.. and run "make clean " and "make all".. in the edbg directory.
  • After executing make all.. I obtained a message like this...

Moreover, I was not able to find hid_write() and hid_read()..

from edbg.

ataradov avatar ataradov commented on September 3, 2024

The code here is for Linux version. Leave the existing mac code as is, just copy the part that prints the data.

And when running make sure to pass the "-b" argument to enable verbose output.

Also, are you sure it is using the newly built version of the edbg? Typically you need to run it like ./edbg ..... to run the version in the current directory and not in the path.

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

Okay..
I have edited dbg_mac.c

int dbg_dap_cmd(uint8_t *data, int resp_size, int req_size)
{
  uint8_t cmd = data[0];
  int res;

   verbose("---\n");
  for (int i = 0; i < 16; i++)
    verbose("0x%02x ", data[i]);
  verbose("\n");


  memset(hid_buffer, 0xff, report_size + 1);

  hid_buffer[0] = 0x00; // Report ID
  memcpy(&hid_buffer[1], data, req_size);

  res = hid_write(handle, hid_buffer, report_size + 1);
  if (res < 0)
  {
    message("Error: %ls\n", hid_error(handle));
    perror_exit("debugger write()");
  }

  res = hid_read(handle, hid_buffer, report_size + 1);
  if (res < 0)
    perror_exit("debugger read()");

  check(res, "empty response received");

   for (int i = 0; i < 16; i++)
    verbose("0x%02x ", hid_buffer[i]);
    verbose("\n");

  check(hid_buffer[0] == cmd, "invalid response received");

  res--;
  memcpy(data, &hid_buffer[1], (resp_size < res) ? resp_size : res);

  return res;
}

I have just edited the file by adding the verbose.. in the top and both.. (Please correct me, if I am going it wrong ?)

then, I run "make clean " and "make all"..

This time as you said I run the edbg in the edbg directory..

the code, i have used is

./edbg -bpv -e -t samd11 -f sam_ba_Generic_D11C14A_SAMD11C14A.bin

this time, I got a strange output.. like this??..

sreedhar@Sreedhars-MacBook-Pro edbg % ./edbg -bpv -e -t samd11 -f sam_ba_Generic_D11C14A_SAMD11C14A.bin
---
0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
---
0x00 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
---
0x01 0x00 0x00 0x90 0x01 0xef 0xe9 0xfe 0x7f 0x00 0x00 0x41 0x50 0xd1 0x05 0x01 
0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
---
0x03 0x90 0x01 0xef 0xe9 0xfe 0x7f 0x00 0x00 0x46 0x50 0xd1 0x05 0x01 0x00 0x00 
0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Error: invalid response received

Can you tell me what this HEX code trying to say..? , how do you decode this ?.. and how to rectify this issue?....

from edbg.

ataradov avatar ataradov commented on September 3, 2024

This looks like you have not actually corrected 512 -> 64. Do this change, recompile and try again.

If you did the change, then it looks like the debugger is just not responding to the information requests. This is the firmware issue in the debugger.

The first byte of the request and the response must match. But this could only happen if you send the exact number of bytes the device is expecting.

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

just forgot to do the change....

Right Now, I did the change from 512 to 64 and ran "make clean", "make all"

After executing "./edbg -bpv -e -t samd11 -f sam_ba_Generic_D11C14A_SAMD11C14A.bin"

I received

....
0x03 0x00 0x07 0x00 0x00 0x12 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Error: invalid response during transfer (count = 0/2, status = 7)

I got this interesting error.. so, what mistake I have did.. now? I love this debugging!!...

from edbg.

ataradov avatar ataradov commented on September 3, 2024

Now you don't have a target connected to the debugger. You can remove the hex print. The debugger now works.

Status = 7 meant that SWDIO line remained high, so there was no active response from the target device (D11 in this case)

from edbg.

ataradov avatar ataradov commented on September 3, 2024

Wait, the target got detected. So something else is wrong.

The target did not respond while the flash was erasing. Try to remove the erase command (-e) from the command line and see if the programming succeeds.

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

I have removed the -e command...

sreedhar@Sreedhars-MacBook-Pro edbg % ./edbg -b -p -v  -t samd11 -f sam_ba_Generic_D11C14A_SAMD11C14A.bin

0x03 0x50 0xd2 0x85 0xe9 0xfe 0x7f 0x00 0x00 0x19 0x81 0x3a 0x06 0x01 0x00 0x00 
0x03 0x00 0x07 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Error: invalid response during transfer (count = 0/3, status = 7)

Now I am facing.. this error

Error: invalid response during transfer (count = 0/3, status = 7)

from edbg.

ataradov avatar ataradov commented on September 3, 2024

Please don't add any more of thew hex stuff. It is no longer relevant.

Something is still wrong with the target device. Do you have a reset asserted by any chance?

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

I didn't had any

reset asserted by any chance

moreover.. I tried to run. program many times. and I got the result "Error: invalid response received" only..
and I didn't have any indication of reset assert..
I will try to run the code in a new chip and report you..

from edbg.

ataradov avatar ataradov commented on September 3, 2024

I meant asserted by some external circuitry. Based on the previous logs, your SWD communication is working, edbg managed to read the device id and recognize the part.

But then programming fails. So double check your power supply to the target and electrical stuff like this.

And yes, a new chip test would be useful too.

from edbg.

Sreedharbot avatar Sreedharbot commented on September 3, 2024

Hey..good news it is working.. & thanks

Initially, I have powered from 5V usb then I have removed that connection and powered from particle debugger. and the output was success..

Hey, if you are interested to share, how you were able to debug the issue. Please share.. ?? I'm very interested to known the backend process.. of this..??

What is USB FS device? , why i needed to do the change the value from 512 to 64.. and How did you conclude that there is some electrical issue.. (did you read from HEX code or ???) .

Please answer to the above question it will be helpful for me for my documentation...

from edbg.

ataradov avatar ataradov commented on September 3, 2024

Don't do bold text either. I can read fine.

I was able to tell because I ran into a similar issue some time ago with another person. Hex codes were useful in confirming the issue. You could see that debugger responded with 0xff for all but first command. 0xff is the error code. It means that it was interpreting extra byes (stuff over 64 bytes) as commands too. And that obviously would not work.

USB HID protocol that is used for CMSIS-DAP communication requires frames to be sent with fixed size. USB Full Speed devices support 64 bytes max, so this is the size that is commonly used. USB High Speed devices can go higher, so 512 or 1024 bytes are common.

Linux and Windows ports use OS-specific APIs to determine the size of the endpoint and automatically adjust. MAC port is not really maintained, since I don't use macs and don't have any apple hardware. So the size is just set to a fixed value.

from edbg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.