adafruit / uf2-samdx1

MSC bootloader (based on UF2) for SAMD21
Other
210 stars 182 forks source link

SAMD51: UART support timing issues #22

Open dhalbert opened 6 years ago

dhalbert commented 6 years ago

https://github.com/Microsoft/uf2-samd21/issues/42 from @MartinL1:

Thank you to everyone for the work on the UF2 bootloader.

I'm using a SAMD51 (SAMD51J20A) custom board. The USB CDC works perfectly with the Arduino IDE, however I've been having some trouble getting the UART support to work.

I powered the board without the native USB connection to prevent enumeration, put my custom board into bootloader mode with a double tap of the reset button, then attempted to upload a Blink sketch with the Arduino IDE, using an FTDI USB to serial board on a spare UART port, (in my case SERCOM5).

After looking at the code, I believe that line 128 of the "usart_sam_ba.c" file needs to be changed from:

// Baud rate 115200 - clock 8MHz -> BAUD value-50436
uart_basic_init(BOOT_USART_MODULE, 50436, BOOT_USART_PAD_SETTINGS);

to:

// Baud rate 115200 - clock 48MHz -> BAUD value-63018
uart_basic_init(BOOT_USART_MODULE, 63018, BOOT_USART_PAD_SETTINGS);

This is to account for GCLK0 now being set to 48MHz. The replacement line is taken from the Arduino Zero bootloader.

After this modification I'm now able to upload the sketch using the FTDI board, unfortunately though some timing issues still persist, as this only works on every second attempt.

dominicjprice commented 5 years ago

I'm seeing the same issue on a Trinket M0 board with the bootloader customised to use the UART on Sercom2. First attempt to upload fails, second succeeds.

alexwhittemore commented 5 years ago

@dominicjprice I don't mean to hijack the topic, but... How'd you customize the M0 to use a hardware UART for bootloading? I need to accomplish the same and I'm trying to dig in right now.

dominicjprice commented 5 years ago

Hi @alexwhittemore, have a look at my fork here https://github.com/dominicjprice/uf2-samdx1 and the projecthoop branch. The bootloader already contained the code for updating over UART, it just needed compiling in (and another method being left out due to size constraints).

alexwhittemore commented 5 years ago

What a guy, thank you!

slyalfa commented 3 years ago

Both the baud rate problem and the not uploading on first try should now be fixed with the PR that went in today