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

MacOS fails programming SAM S70, Windows succeeds #106

Open
mbavaro opened this issue Sep 12, 2019 · 12 comments
Open

MacOS fails programming SAM S70, Windows succeeds #106

mbavaro opened this issue Sep 12, 2019 · 12 comments

Comments

@mbavaro
Copy link

mbavaro commented Sep 12, 2019

I spent some time yesterday trying to figure why programming on my MAC wouldn't work.. it kept returning early with this error:

$ bossac -p /dev/tty.usbmodem1443201 -i -U -e -w -v -b BaseboardMCU7.bin 
Device       : ATSAMS70x21
Version      : v1.1 Oct 13 2014 12:02:31
Address      : 0x400000
Pages        : 4096
Page Size    : 512 bytes
Total Size   : 2048KB
Planes       : 1
Lock Regions : 128
Locked       : none
Security     : false
Boot Flash   : false
Erase flash

Done in 7.694 seconds
Write 68208 bytes to flash (134 pages)

Then switched to Windows (GUI) and everything went smoothly, and the operation completed in a few seconds.
I suspect something might be up with PosixSerialPort.cpp.. but I have not tried on Linux honestly. Anybody else noticed the same behavior?
I tried all sorts of things with stty -f /dev/cu.usbmodemxxx and stty -f /dev/tty.usbmodemxxx taking care to keep the serial port file descriptor open but nothing helped.. and after all the port configuration is probably overridden when BOSSA starts.

@peter-moran
Copy link

I believe I have the same issue, on Mac OSX Mojave

bossac --info --port /dev/tty.usbmodem141201 --erase --write --verify --boot --reset firmware.bin
Device       : ATSAME70x21
Version      : v1.2 Jan  6 2016 09:57:32
Address      : 0x400000
Pages        : 4096
Page Size    : 512 bytes
Total Size   : 2048KB
Planes       : 1
Lock Regions : 128
Locked       : none
Security     : false
Boot Flash   : false
Erase flash

Done in 7.136 seconds
Write 943716 bytes to flash (1844 pages)
[                              ] 0% (0/1844 pages)
SAM-BA operation failed

Any following attempts produce:

bossac --info --port /dev/tty.usbmodem141201 --erase --write --verify --boot --reset firmware.bin
No device found on /dev/tty.usbmodem141201

If I power cycle, I get the first error again.

@droftarts
Copy link

droftarts commented Mar 18, 2020

Same issue, Mac OSX Mojave, Bossa 1.9.1, both GUI and command line versions. Works on Windows.

bossac -i -p /dev/tty.usbmodem14101 -e -w -v -b Duet3Firmware_MB6HC.bin -R
Device       : ATSAME70x20
Version      : v1.2 Jan  6 2016 09:57:32
Address      : 0x400000
Pages        : 2048
Page Size    : 512 bytes
Total Size   : 1024KB
Planes       : 1
Lock Regions : 64
Locked       : none
Security     : false
Boot Flash   : false
Erase flash

Done in 3.626 seconds
Write 560772 bytes to flash (1096 pages)
[                              ] 0% (0/1096 pages)
Flash command failed

@beikeland
Copy link

beikeland commented Mar 20, 2020

I suspect something might be up with PosixSerialPort.cpp.. but I have not tried on Linux honestly. Anybody else noticed the same behavior?

I've flashed a ATSAME70x20 using bossac from a Raspberry Pi running Raspbian buster, no trouble there.

@beikeland
Copy link

beikeland commented May 3, 2020

Over on the Duet3D forums there a even a few cases of windows failing in a seemingly similar manor, unsure if usb cable issues or the same underlying problem. (confirmed same board, same cable, same binary, change from Windows to Raspbery Pi and flashing work)

Possibly related to #121 ?

I wasn't able to build bossac.exe to test with current mingw will see if I can try the 7.3.0 version mentioned in another issue when i find the time. (usleep was deprecated in the current mingw).

@joverbee
Copy link

I seem to be hitting a similar problem on a ATSAME70X21 running on Mac OSX High Sierra (no chance to test on windows yet). In my case it always writes 18 pages before failing. Have tested the suggestion with adding an extra wait after flush() in Samba.cpp as per #121 , but made no difference. I also have the 'feeling' that the writing is really slow at about 35s for writing ~9000 bytes (that would be nearly 2400baud? far away from the intended high baudrate of >900kbaud)

./bossac -e -w -v -b -i -p cu.usbmodemFD121 firmware.bin
Device       : ATSAME70x21
Version      : v1.1 Oct 13 2014 12:02:31
Address      : 0x400000
Pages        : 4096
Page Size    : 512 bytes
Total Size   : 2048KB
Planes       : 1
Lock Regions : 128
Locked       : none
Security     : false
Boot Flash   : false
Erase flash

Done in 7.086 seconds
Write 60708 bytes to flash (119 pages)
[====                          ] 15% (18/119 pages)
SAM-BA operation failed

@joverbee
Copy link

joverbee commented Oct 27, 2020

I dug a bit deeper and found that it stops writing at address 400E0C08 where the _port->read in readword() in Samba.cpp returns only 2 bytes instead of 4. Tried playing a bit with timeouts, but to no avail so far.
Checked on pc with SAMBA tool and the file uploads fine.

@kaysievers
Copy link

I've seen a similar issue. This appears to work for me: #150

@joverbee
Copy link

I bought a PC laptop so problem should have resolved itself (at least for me).

@msxmatt
Copy link

msxmatt commented Aug 18, 2022

Hi all, same issue here with SAMS70N20B and Mac OS X Monterey. Built the latest BOSSA version including #150. It works fine in Windows 10 and Linux but fails on Mac. Any further thoughts on this issue?

@msxmatt
Copy link

msxmatt commented Aug 19, 2022

Did a little looking around and it seems like one of the USB buffers may be capped at 384 bytes on Mac. I was able compare HEX dumps of my S70 when I programmed with BOSSA vs my programmer and see that 128 bytes were missing every 512 bytes (S70 page size).

I fixed it by splitting up the SAM-BA write commands into chunks <= 384 bytes for Mac. Here's a snippet of my modified code from the Samba::write command:

    // Split up large USB transfers into multiple writes
    // (Mac only, USB buffer maxes out at 384 bytes)
    if (_isUsb && _port->getSplitLargeXfers() && size > MAX_XFER_SIZE) {

        // Initialize counter and chunk size at max
        int bytes_left = size;
        int chunk_size = MAX_XFER_SIZE;

        // Iterate through the write chunks
        for (int i = 0; bytes_left > 0; i++, bytes_left -= chunk_size) {

            // Last write, transfer the remainder
            if (bytes_left < MAX_XFER_SIZE) {
                chunk_size = bytes_left;
            }
        
            if (_debug)
                printf("%s(addr=%#x,size=%#x)\n", __FUNCTION__, (addr + (i * MAX_XFER_SIZE)), chunk_size);

            // Issue SAM-BA write command for chunk
            snprintf((char*) cmd, sizeof(cmd), "S%08X,%08X#", (addr + (i * MAX_XFER_SIZE)), chunk_size);
            if (_port->write(cmd, sizeof(cmd) - 1) != sizeof(cmd) - 1)
                throw SambaError();

            // Write chunk data out
             _port->flush();
            writeBinary((buffer + (i * MAX_XFER_SIZE)), chunk_size);
        }
    }

MAX_XFER_SIZE is set to 384 bytes.

Now I can program my S70 from Mac no problem. Hopefully this might help others with this problem.

@dc42
Copy link

dc42 commented Nov 7, 2024

@msxmatt it looks like you changed the SerialPort class to add method getSplitLargeTransfers(). Did you change it to return true only when running it on a Mac, if so how; or did you do something else?

@droftarts
Copy link

@msxmatt I'm struggling to get Bossa working on MacOS to flash SAM S70, and I saw your comment. I found where to put your code snippet in Samba.cpp, replacing lines 521 to 525.

if (_isUsb)

And added a define for MAX_XFER_SIZE just before your code: #define MAX_XFER_SIZE 384

However, I get this error message during compilation:

CPP COMMON src/Samba.cpp
src/Samba.cpp:529:26: error: no member named 'getSplitLargeXfers' in 'SerialPort'
  529 |     if (_isUsb && _port->getSplitLargeXfers() && size > MAX_XFER_SIZE) {
      |                   ~~~~~~~^
1 error generated.
make: *** [obj/Samba.o] Error 1

If I leave out "_port->getSplitLargeXfers() &&", Bossa compiles and runs, but I get an error when trying to connect to the port, and it returns "SAM-BA operation failed".

Did you add code elsewhere, as @dc42 suggests? If so, could you post that code too, please? Unfortunately, I'm not much of a programmer! And if you don't mind, if I can get this working, I'll post it as a Pull Request so other people can compile a working MacOS version.

Thanks!

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

8 participants