Giter VIP home page Giter VIP logo

uf2-samdx1's Introduction

UF2 Bootloader

This repository contains a bootloader, derived from Atmel's SAM-BA, which in addition to the USB CDC (serial) protocol, also supports the USB MSC (mass storage).

Build Status

UF2

UF2 (USB Flashing Format) is a name of a file format, developed by Microsoft, that is particularly suitable for flashing devices over MSC devices. The file consists of 512 byte blocks, each of which is self-contained and independent of others.

Each 512 byte block consist of (see uf2format.h for details):

  • magic numbers at the beginning and at the end
  • address where the data should be flashed
  • size of data
  • data (up to 476 bytes; for SAMD it's 256 bytes so it's easy to flash in one go)

Thus, it's really easy for the microcontroller to recognize a block of a UF2 file is written and immediately write it to flash.

Features

  • USB CDC (Serial emulation) monitor mode compatible with Arduino (including XYZ commands) and BOSSA flashing tool
  • USB MSC interface for writing UF2 files
  • reading of the contests of the flash as an UF2 file via USB MSC
  • UART Serial (real serial wire) monitor mode (typically disabled due to space constraints)
  • In-memory logging for debugging - use the logs target to extract the logs using openocd
  • double-tap reset to stay in the bootloader mode
  • automatic reset after UF2 file is written

Board identification

Configuration files for board foo are in boards/foo/board_config.h and board.mk. You can build it with make BOARD=foo. You can also create Makefile.user file with BOARD=foo to change the default.

The board configuration specifies the USB vendor/product name and ID, as well as the volume label (main thing that the operating systems show).

There is also BOARD_ID, which is meant to be machine-readable and specific to a given version of board hardware. The programming environment might use this to suggest packages to be imported (i.e., a package for a particular external flash chip, SD card etc.).

These configuration values can be read from INFO_UF2.TXT file. Presence of this file can be tested to see if the board supports UF2 flashing, while contest, particularly Board-ID field, can be used for feature detection.

The current flash contents of the board is exposed as CURRENT.UF2 file. This file includes the bootloader address space. The last word of bootloader space points to the string holding the INFO_UF2.TXT file, so it can be parsed by a programming environment to determine which board does the .UF2 file comes from.

Handover

When the user space application implements the USB MSC protocol, it's possible to handover execution to the bootloader in the middle of MSC file transfer, when the application detects that a UF2 block is written.

Details are being finalized.

Bootloader update

The bootloader will never write to its own flash area directly. However, the user code can write there. Thus, to update the bootloader, one can ship a user-space program, that contains the new version of the bootloader and copies it to the appropriate place in flash.

Such a program is generated during build in files update-bootloader*.uf2. If you're already running UF2 bootloader, the easiest way to update it, is to just copy this file to the exposed MSD drive.

The build also generates update-bootloader*.ino with an equivalent Arduino sketch. You can copy&paste it into Arduino IDE and upload it to the device.

Fuses

SAMD21

The SAMD21 supports a BOOTPROT fuse, which write-protects the flash area of the bootloader. Changes to this fuse only take effect after device reset.

OpenOCD exposes at91samd bootloader command to set this fuse. This command is buggy. It seems to reset both fuse words to 0xffffffff, which prevents the device from operating correctly (it seems to reboot very frequently). In scripts/fuses.tcl there is an OpenOCD script which correctly sets the fuse. It's invoked by dbgtool.js fuses. It can be also used to reset the fuses to sane values - just look at the comment at the top.

The bootloader update programs (both the .uf2 file and the Arduino sketch) clear the BOOTPROT (i.e., set it to 0x7) before trying to flash anything. After flashing is done, they set BOOTPROT to 8 kilobyte bootloader size (i.e, 0x2).

SAMD51

The SAMD51s bootloader protection can be temporarily disabled through an NVM command rather than a full erase and write of the AUX page. The boot protection will be checked and set by the self updaters.

So, if you've used self-updaters but want to load it directly, then you'll need to temporarily turn off the protection. In gdb the command is:

set ((Nvmctrl *)0x41004000UL)->CTRLB.reg = (0xA5 << 8) | 0x1a

Build

Requirements

Atmel Studio is not supported.

You will need a board with openocd support.

Arduino Zero (or M0 Pro) will work just fine as it has an integrated USB EDBG port. You need to connect both USB ports to your machine to debug - one is for flashing and getting logs, the other is for the exposed MSC interface.

Otherwise, you can use other SAMD21 board and an external openocd compatible debugger. IBDAP is cheap and seems to work just fine. Another option is to use Raspberry Pi and native bit-banging.

openocd will flash 16k, meaning that on SAMD21 the beginning of user program (if any) will be overwritten with 0xff. This also means that after fresh flashing of bootloader no double-tap reset is necessary, as the bootloader will not try to start application at 0xffffffff.

Build commands

The default board is zero. You can build a different one using:

make BOARD=metro_m0

If you're working on different board, it's best to create Makefile.user with say BOARD=metro to change the default. The names zero and metro refer to subdirectories of boards/.

There are various targets:

  • all - just compile the board
  • burn or b - compile and deploy to the board using openocd
  • logs or l - shows logs
  • run or r - burn, wait, and show logs

Typically, you will do:

make r

Configuration

There is a number of configuration parameters at the top of uf2.h file. Adjust them to your liking.

By default, you cannot enable all the features, as the bootloader would exceed the 8k(SAMD21)/16k(SAMD51) allocated to it by Arduino etc. It will assert on startup that it's not bigger than 8k(SAMD21)/16k(SAMD51). Also, the linker script will not allow it.

Three typical configurations are:

  • HID, WebUSB, MSC, plus flash reading via FAT; UART and CDC disabled; logging optional; recommended
  • USB CDC and MSC, plus flash reading via FAT; UART disabled; logging optional; this may have Windows driver problems
  • USB CDC and MSC, no flash reading via FAT (or at least index.htm disabled); UART enabled; logging disabled; no handover; no HID; only this one if you need the UART support in bootloader for whatever reason

CDC and MSC together will work on Linux and Mac with no drivers. On Windows, if you have drivers installed for the USB ID chosen, then CDC might work and MSC will not work; otherwise, if you have no drivers, MSC will work, and CDC will work on Windows 10 only. Thus, it's best to set the USB ID to one for which there are no drivers.

The bootloader sits at 0x00000000, and the application starts at 0x00002000 (SAMD21) or 0x00004000 (SAMD51).

Bootloader Hold Switch

A Board can be configured to sense the state of a GPIO and to hold the bootloader from running an application if it is in the appropriate state. To enable this, add the following to your board configuration header file.

// The Pin that will tell us to stay in the bootloader or not.
#define HOLD_PIN PIN_PA02

// Optional, define if a Pull up or pulldown is needed.
#define HOLD_PIN_PULLUP
//#define HOLD_PIN_PULLDOWN

// What is the Hold state of the GPIO, 0 or 1.
#define HOLD_STATE 1

Set HOLD_PIN to the appropriate GPIO and HOLD_STATE to the logic level which will hold the bootloader from running the application.

The definition of BOTH HOLD_PIN and HOLD_STATE triggers the inclusion of this feature. If either of these is undefined, this feature is not enabled.

If an internal pullup/pulldown is required for the IO, it can be enabled with the OPTIONAL HOLD_PIN_PULLUP or HOLD_PIN_PULLDOWN macros. If neither are defined, then no pullup/pulldown will be enabled for the io pin.

This switch is NOT dynamic. Once the bootloader has sensed this pin and decided not to run the application, then a change in this IO will not, itself, then cause the Application to run, without also resetting the board.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

License

See THIRD-PARTY-NOTICES.txt for the original SAM-BA bootloader license from Atmel.

The new code is licensed under MIT.

uf2-samdx1's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uf2-samdx1's Issues

48MHz GCLK0 Output on pin PB14

Shouldn't the lines 8 and 9 in the "init_samd51.c" file be commented out?

// Output GCLK0 to Metro M4 D5. This way we can see if/when we mess it up.
PORT->Group[1].PINCFG[14].bit.PMUXEN = true;
PORT->Group[1].PMUX[7].bit.PMUXE = 12;

It's just that these lines will cause the SAMD51 to output GCLK0 at 48MHz on port pin PB14, whenever the board's in bootloader mode. This is digital pin D5 on the Metro M4.

Bootloader Fails to Compile with arm-none-eabi-gcc 9

Hi All!

Full disclaimer, I am using this uf2 code to help me understand and write my own boot loader, I am a n00b atm.

So I started working with this uf2 bootloader, and the first wall I hit is when I run make in the project directory, I get the following output-

lib/cmsis/CMSIS/Include/core_cmFunc.h: In function 'main':
lib/cmsis/CMSIS/Include/core_cm0plus.h:85:28: error: listing the stack pointer register 'sp' in a clobber list is deprecated [-Werror=deprecated]
   85 |   #define __ASM            __asm__                                      /*!< asm keyword for GNU Compiler          */
      |                            ^~~~~~~
lib/cmsis/CMSIS/Include/core_cmFunc.h:456:3: note: in expansion of macro '__ASM'
  456 |   __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
      |   ^~~~~
lib/cmsis/CMSIS/Include/core_cm0plus.h:85:28: note: the value of the stack pointer after an 'asm' statement must be the same as it was before the statement
   85 |   #define __ASM            __asm__                                      /*!< asm keyword for GNU Compiler          */
      |                            ^~~~~~~
lib/cmsis/CMSIS/Include/core_cmFunc.h:456:3: note: in expansion of macro '__ASM'
  456 |   __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
      |   ^~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:177: build/zero/main.o] Error 1

So, my understanding is in the line __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp"); where the stack pointer is being set in core_cmFunc.h the compiler is having issues with the fact we are modifying it in this way, correct? According to micropython/micropython#4785 is this is due to the new arm-none-eabi-gcc package.

I will be trying to solve this issue myself, but if you have a solution to save me time it would be much appreciated. I know I could get it to compile by downgrading, but that seems like a silly solution.

SAMD51 firmware update dual banks

Hi,
I read, that the SAMD51 have the possibility to do firmware updates with writing the new firmware to BankA or BankB and then switching to the bank, containing the new firmware.

How to do this? Must the bootloader configuration be changed? Do you have an example for this?

Atmel Studio support --> How-to (enhancement & solution)

Solution:
Atmel studio supports external makefiles projects( using an available Extension ).

-- Importing the project --
1- Tools/Extension and Updates --> Available Downloads -->"Create Project from Makefile"
2- Tools/"Create Project from Makefile" --> Select the directory whre it is located

-- Building the bootloader project --
/Build/Build

-- Creating the .uf2 files --
/Debug/Options --> Build Events -->Post-build event command line ( will add theese commands in the auto-generated makefile )

------ event command line start -------
node $(Configuration)/scripts/bin2uf2.js $(Configuration)/$(OutputFileName).bin $(OutputFileName)
mv $(OutputFileName).uf2 $(Configuration)/
------ event command line end -------

make sure the bin2uf2.js script has been copied into your current project
$(Configuration)/scripts/bin2uf2.js

File too large warning on Windows

When copying a UF2 file generated by PXT onto the circuit playground, I get this error:

file_too_large

The file does get flashed correctly despite the error.

circuit playground support

master...adafruit:master

both bossa/msc tested and working, ready for trying out by pxt folks!

CDC+MSC works great - we'd prefer to use that since it maintains arduino support and works great with all OS's (win 7/10 doesnt need a special driver)

@mmoskal i can do a pull req or you can grab the commits yourself :)

Linker error - section .binfo LMA ... overlaps section .relocate LMA

While trying to compile with any board configuration f.e. make BOARD=generic.
I get an error at the linker phase saying
ld: section .binfo LMA [0000000000001ff0,0000000000001fff] overlaps section .relocate LMA [0000000000001fdc,00000000000020b3]
I'm running:
node: v6.11.1
arm-none-eabi-gcc: 5.4.1
OpenOCD: 0.9

Ubuntu 17.04

UF2 Bootloader UART Support

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.

Store filename and time?

Could we come up with a way to store the filename and datetime of the latest uf2 file? It'd be great to see PXT-v1.2.uf2, Arduino-1.8.uf2 or micropython-1.8.6.uf2 instead of Current.uf2 when in mass storage mode. Ideally it'd actually be in the flashed region so flashing other ways would also update it.

Some disk monitoring programs have trouble with UF2 FAT filesystem

Several people have discovered that running programs like AIDA64 and Hard Disk Sentinel cause Windows Explorer to hang when trying to read or write files from the UF2 "filesystem".

Some reports:
https://forums.adafruit.com/viewtopic.php?f=60&t=135400
https://forums.adafruit.com/viewtopic.php?f=52&t=140056
https://forums.adafruit.com/viewtopic.php?f=52&t=140028

I've reported this to AIDA64: https://forums.aida64.com/topic/4296-uf2-bootloader-usb-drive-and-aida64-cause-explorer-to-freeze/. They will investigate

I'm not sure where to place responsibility for this, but perhaps there's some extra emulation that might help. I don't think it's good for these programs to cause a freeze-up though, if a drive is not acting according to expectation -- they should fail more nicely.

add warning/indicator for enumeration failure

most customer confusion comes from charge-only cables.
lets have a 10-second enumeration timeout and warn the customer something went wrong by blinking the red LED instead of pulsing.
for cplay express i can have the neopixels warn, or even have a failure-tone beep

Support on linux / ChromeOS

heya doing the production test procedure - we use a raspberry pi to program and test but oddly enough can't get bossac to recognize the board. it does show up as a CDC device but doesn't reply to serial writes, so its something 'early' in the enumeration setup?

i'd like to support linux, at least raspi, if possible!

@mmoskal do you need a raspi3 to test with?

Flashing circuit playground from Android

Definitely not high priority, but I tried connecting the circuit playground to my phone to see if it would appear as a USB drive and let me flash it. Unfortunately, the OS doesn't seem to recognize it as a mass storage device. Instead I get a notification saying that there is a connected USB device and asking what I'd like to do with it. Choosing "Transfer files" ultimately causes the circuit playground to reset and the process to start over.

For reference, I am using a Google Pixel running Android 7.1.1 (with a USB-C to micro USB adapter) and bootloader version 1.8.0. I also tried a micro:bit out for fun and it actually does get recognized as a storage device, but is listed as corrupted (and Android won't copy any files to it).

Invalid files on FAT filesystem

It seems like PR #68 broke something in FAT filesystem implementation.

INFO_UF2.TXT file contains part of CURRENT.UF2 data (UF2 block no.2) instead of text info. Same goes for INDEX.HTM file (UF2 block no.3). CURRENT.UF2 file starts with block no.4 and has 2048 bytes of zeroes at the end.

When I compiled and uploaded v3.2.3 instead of master everything works fine.

There might be an issue on https://github.com/Microsoft/uf2-samdx1/blob/25deea9d30aaa054bab5db035f530e16b9e14b15/src/fat.c#L115 - DIRENTRIES_PER_SECTOR is 16 instead of 32 if I'm not mistaken.

Secure boot support

I would like a support for secure boot option by bootloader signing from external authentication ic like ATECC508 or ATSHA204

For reference please see the support for NRF52 here

Can't attach more than 2 devices in bootloader mode

I have an odd issue.
I'm using multiple Adafruit Metro M0 running an unmodified metro_m0_0-v2.0.0-adafruit.5-4-g0a2294c
Whenever I connect 2 Metros and put them in bootloader mode. A third or fourth Metro will not properly enumerate anymore. When I put the third in bootloader mode it just starts to flash rapidly. No MSC device popping up and no serial device either, as if it isn't connected to a computer at all.
Running 'lsusb' shows at least that USB enumeration worked and shows the VID:PID for that Metro (I assigned each metro their own PID for testing purposes).

I'm running Ubuntu 18.04.

dbgtool.js fails

I am attempted to burn the bootloader to a custom SAMD21 board.

When I "make r", the code compiles and I receive an error message when I get to the burn stage:

node scripts/dbgtool.js fuses
File: fuses
Fatal error: openocd not installed in Arduino

I looked into the dbgtool.js file and there are a couple hard paths that are not in my Arduino configuration:

https://github.com/Microsoft/uf2-samdx1/blob/d8dcad0f98a6152da01a584ab9ac2f2ef9b0f6c0/scripts/dbgtool.js#L66
and

https://github.com/Microsoft/uf2-samdx1/blob/d8dcad0f98a6152da01a584ab9ac2f2ef9b0f6c0/scripts/dbgtool.js#L74

My Arduino openocd installation is configured with the path "tools/openocd/0.9.0-arduino6-static" which is different than the one referenced in dbgtools.js.

With respect to the second reference, my Arduino hardware path is "hardware/samd/1.6.19/variants/arduino_zero/openocd_scripts/arduino_zero.cfg" which is different than the one reference in dbgtools.js.

Could someone please confirm what version of the Arduino environment uf2 requires? I am presently running 1.8.9 which is the latest stable release. I am not sure how to upgrade the version of openocd being used by the Arduino environment as there doesn't appear to be a way to do that from within Arduino and a google search has come up empty on this.

I changed the scripts to use the paths of my configuration. The result is that it appears to have programmed the bootloader though there was an error message:

File: build/witap_isb/bootloader-witap_isb-v3.4.0-dirty.map
Fatal error: Cannot find logStoreUF2 symbol in map file
make: *** [logs] Error 1

I am not sure what this is referring to.

The drive appears to mount. The LED is on solid. If I double tap the reset button, the LED fades in and out. So, I think everything is working?

Entering bootloader from application

I was wondering if its possible that the user application can start the bootloader?
I would like a software function that when called will enter my board into bootloader mode without the need to trigger the reset pin.

I'm using the Arduino environment with a SAMD21 board. I'dont have much knowledge of low level MCU programming but shouldn't I be able to call an assembler instruction to jump code execution to the bootloaders main function? Or maybe something even easier/safer than that?

Linker error - section .binfo LMA overlaps section .relocate LMA

I'm seeing issue #24 again. I'm using GCC 6.3.1, as suggested in the bug:

$ arm-none-eabi-gcc --version arm-none-eabi-gcc (15:6.3.1+svn253039-1build1) 6.3.1 20170620 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And get this error:

arm-none-eabi-gcc -Lbuild/zero -mthumb -mcpu=cortex-m0plus -Os -g -DSAMD21 -Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -save-temps -nostartfiles --specs=nano.specs --specs=nosys.specs \ -Tscripts/samd21j18a.ld \ -Wl,-Map,build/zero/bootloader-zero-v2.0.0-23-gc92ac1d.map -o build/zero/bootloader-zero-v2.0.0-23-gc92ac1d.elf build/zero/flash_samd21.o build/zero/init_samd21.o build/zero/startup_samd21.o build/zero/usart_sam_ba.o build/zero/utils.o build/zero/cdc_enumerate.o build/zero/fat.o build/zero/main.o build/zero/msc.o build/zero/sam_ba_monitor.o build/zero/uart_driver.o build/zero/hid.o /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: section .binfo LMA [0000000000001ff0,0000000000001fff] overlaps section .relocate LMA [0000000000001e60,000000000000202b] collect2: error: ld returned 1 exit status

The weird thing is that this used to work, and when I upgraded from Ubuntu 17.10 to 18.04, it broke. It looks like I was probably using GCC 5.4.1 before (that's the current version for 17.10).

uf2 write file fail

Hi, I have a new Arduino mkr1000 wifi after connecting in uf2 boot mode and drag a new uf2 sketch the connection fail a see this message.

  • UF2 Bootloader v2.0.0-12-g7e6819e-dirty SFHWRO
  • Model: Arduino MKR1000
  • Board-ID: SAMD21G18A-MKR1000-v0
  • OS: Mac OS X High Sierra

2018-09-20 09 02 58

FAT32

Can I suggest an upgrade to the bootloader allowing the device to be seen as a FAT32 device instead of FAT16.
iOS13 allows to see FAT32 devices, but not FAT16. If it was possible to change to FAT32, it would probably be possible to program a device using the USB connection on an iPhone or a iPad (with a OTG cable).

I have tried changing quite a bit in the fat.c file (mostly expanding the FAT_BootBlock to include FAT32 fields) as well as increasing the NUM_FAT_BLOCKS to 65526 in the uf2.h, but I think I am in over my head.

This functionality could be controlled by a define in the uf2.h file allowing the user to choose between FAT16 and FAT32.

problem with long file name renames

When one uses Save as on a download in Edge or IE, it does something like the following:

let fs = require("fs")
let sh = "e:/foobar-bazbazbaz.foo"
let ln = "e:/foobar-bazbazbaz.foo.abcdef.partial"
fs.writeFileSync(sh, "")
fs.writeFileSync(ln, new Buffer(100000))
fs.renameSync(ln, sh)

The last rename fails, probably due to lack of VFAT support.

Of course the UF2 file is written and everything works but we get an ugly error message.

Building for SAMD51 without UART

This is a query - rather than an issue.

How do you build a SAMD51 bootloader without the USART functionality?

I tried just removing all the arguments but it looks like they get re-added in anyway,

Any assistance would be great.

Thanks in advance.

SAMD21, update bootloader with security bit set

Hi Guys!

Does update bootloader functionality work with security bit set???
I got mine update firmware looping at setBootProt(7); in selfmain.c

So, clearly bootprot was not changed from 2 to 7 and app restarts.

Help!
Alex

Error in MKR1300

Hi
I'm trying to walk this on the MKR 1300, but when trying to load via USB Storage the transfer of the uf2 file never ends

and a sketch with Arduino the next error:

SAM-BA operation failed
Set binary mode
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
version()=v1.1 [Arduino:XYZ] Jul 26 2018 20:24:37
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x20002dd8
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010305
Chip ID      : 10010005
version()=v1.1 [Arduino:XYZ] Jul 26 2018 20:24:37
Version      : v1.1 [Arduino:XYZ] Jul 26 2018 20:24:37
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 5.005 seconds

Write 18800 bytes to flash (294 pages)
write(addr=0x20005000,size=0x1000)
Ha ocurrido un error mientras se enviaba el sketch

Thanks

Can't set the fuses

The scripts/dbgtool.js fuses command fails for about half of the chips that I have with:

$ scripts/dbgtool.js fuses
File: fuses
Starting /home/sheep/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino/bin/openocd -d2 -s /home/sheep/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino//share/openocd/scripts/ -f /home/sheep/.arduino15/packages/arduino/../adafruit/hardware/samd/1.0.19/variants/trinket_m0/openocd_scripts/arduino_zero.cfg -f scripts/fuses.tcl
Open On-Chip Debugger 0.9.0 (2015-09-02-10:42)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
debug_level: 2
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 300 kHz
adapter_nsrst_delay: 100
Info : Unable to match requested speed 300 kHz, using 240 kHz
Info : Unable to match requested speed 300 kHz, using 240 kHz
Info : clock speed 240 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.463901
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
Fuses:
d8e0c7fa
fffffc5d
*** Updating fuses! ***
d8e0c7ff
fffffc5d
Error: array2mem: Write @ 0x41004000, w=2, cnt=1, failed
/home/sheep/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino//share/openocd/scripts//memory.tcl:122: Error: memwrite16: 
in procedure 'script' 
at file "embedded:startup.tcl", line 60
in procedure 'cmd' called at file "scripts/fuses.tcl", line 50
in procedure 'memwrite16' called at file "scripts/fuses.tcl", line 24
at file "/home/sheep/.arduino15/packages/arduino/tools/openocd/0.9.0-arduino//share/openocd/scripts//memory.tcl", line 122

It seems like they are somehow locked, but doing chip-erase on them doesn't seem to help.

USB problems

We are currently testing the bootloader, but had some problems. For example the USB Descriptor Strings are not correct and if we access the USB device under Windows with the USB Device Tree Viewer then the USB mass storage device will not work after the access.

For the string problem, I think it is the transmitted length here:
https://github.com/Microsoft/uf2-samd21/blob/master/src/cdc_enumerate.c#L779
sendCtrl(&desc, sizeof(StringDescriptor));
I think it should be
sendCtrl(&desc, desc.len);

Support chips of 32kb??

Hi

Is it possible to support 32kb microcontrollers like the SAMD21E15B or SAMD21G15?

Thanks!

node v4.2.1 strict complaint

heya just tried to build and got

node scripts/gendata.js build/metro uf2-bootloader.bin
C:\Users\ladyada\Documents\Projects\atmel\Bootloader\microsoft-uf2-samd21\script
s\gendata.js:2
let fs = require("fs")
^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet sup
ported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:134:18)
    at node.js:961:3
make: *** [build/metro/selfdata.c] Error 1

fixed by adding "use strict" on the first line of gendata.js - @mmoskal let me know if you want me to commit this

Shouldn't check_start_application clear *DBL_TAP_PTR on BOD reset, also?

I've been experiencing an issue where poor power rails cause the bootloader to be entered spontaneously. You can simulate this by applying power to a Feather M0 by holding the ends of two wires together to complete the path to the positive power supply, and then rub them to make a series of interrupted power spikes.1

I think this is triggering the brown-out detection circuitry, and setting the RESET_CONTROLLER->RCAUSE.bit.BODxx bit(s), rather than RESET_CONTROLLER->RCAUSE.bit.POR. The code, as written in main.c interprets this as the user pressing the reset button, and it enters the boot loader.

Ignoring SINGLE_RESET, I think more robust code might look like this. I have not tested this as I currently have no way to load the boot loader:

    if (RESET_CONTROLLER->RCAUSE.bit.POR            //  If power-on reset
        || RESET_CONTROLLER->RCAUSE.bit.BOD12       //  or either brown-out
        || RESET_CONTROLLER->RCAUSE.bit.BOD33 ) {   //  reset, clear *DBL_TAP_PTR
        *DBL_TAP_PTR = 0;
    } else if (RESET_CONTROLLER->RCAUSE.bit.EXT     //  If user pressed reset button
                && *DBL_TAP_PTR == DBL_TAP_MAGIC) { //  AND it’s the second time through
        *DBL_TAP_PTR = 0;
        return; // stay in bootloader
    } else {                                        //  This should probably check RESET_CONTROLLER->RCAUSE.bit.EXT, too
        if (*DBL_TAP_PTR != DBL_TAP_MAGIC_QUICK_BOOT) {
            *DBL_TAP_PTR = DBL_TAP_MAGIC;
            delay(500);
        }
        *DBL_TAP_PTR = 0;
    }

This change should do a couple of things: treat power-on and brown-out-detect resets the same, and only count a /RESET assertion as the second press.

I’m not sure if the SAM51 has different BOD bits.


Footnotes

  1. In my case, I have an Adafruit solar lipo charger. When the battery is depleted and the sun is just beginning to shine on the panel, the power provided to the load can be spotty.

Single Button Press into Bootloader

I am attempting to build a custom binary release for a custom board, with reference about the reset procedure.

When looking through uf2.h

// If enabled, bootloader will start on power-on and every reset. A second reset
// will start the app. This only happens if the app says it wants that (see SINGLE_RESET() below).
// If disabled here or by the app, the bootloader will only start with double-click of the reset
// button.
#define USE_SINGLE_RESET 1

If this value is set to 0, should the expected result be that the bootloader will become active on a single reset ?

As when working in maker.makecode with the Arduino Zero it makes use of a single reset to enable the bootloader. In comparison to when converting a .bin file from Arduino to a .UF2 it would still require a second reset. This occures between uploads of the UF2 file from the different sources.

Add .bin for Seeed Wio Lite w600

As .ino files brick devices, and the Seeed Wio Lite W600 comes with firmware for use with arduino / c, but follows Feather footprint and pinouts, it would be awesome to make a CircuitPython port for replacing the default bootloader. Please and Thank you!

rename/update for '51

just realized this repo still mentions/called samd21 but it supports samd51 too now. wanna rename to uf2-samdx1 and/or update description?

Compiler flags

No long-calls will reduce the code size. Is there a reason why -mlong-calls is set?

-nostartfiles can also be set, because startup_samd21.c includes everything. This will also reduce the size.

CDC with MSC on Windows

@mmoskal Hi, I'm debugging some issues with the Adafruit board drivers on Windows 7 and UF2. For some people, installing the drivers prevents the UF2 MSC xBOOT drives from appearing when the bootloader is enabled. For other people (e.g., @ladyada) they still see the xBOOT drives even with the drivers installed. I've duplicated the problem on a fresh Win7 installation, but it doesn't show up completely consistently.

The README.md says using CDC and MSC together could be an issue:

... On Windows, if you have drivers installed for the USB ID chosen, then CDC might work and MSC will not work; otherwise, if you have no drivers, MSC will work, and CDC will work on Windows 10 only. Thus, it's best to set the USB ID to one for which there are no drivers.

When the drives don't appear, I notice that the composite USB device does not show up, only the CDC device (using Device Manager or http://www.uwe-sieber.de/usbtreeview_e.html to check this). I though this might be due to &MI=0 present or missing for the particular USB PID in the driver .inf file, but that doesn't seem to be it.

Could you expand on your comment above? Do you know the cause of the issue with respect to the drivers? Thanks!

SAMD SDU library

Can I suggest an option in the bootloader to choose to have the SAMD SDU library included in the bootloader. Possibly to choose whether to have or not using a #define in the uf2.h file.

I have tried to include the 4000 bytes from SAMD SDU library in multiple places, but without luck. I tried to change the .ld files to include the .sketch_boot section and adding the file, but I believe that I need to change some address sizes from 2k to 6k (for SAMD21) to get it to work, and I am not sure I get all the right places changed.

Today we just add the above library in Arduino, but if we could have it in the bootloader, it would not be forgotten. We have the problem that our software cannot be updated if the previously used software didn't use the library.

Network profiles showing up on Mac

Circuit Playground / Arduino Zero boards are showing up in as a Network profile on my Network settings on a Mac.
It's unclear to me when they're created, but I have a good odd 50 of them. It seems to me that it thinks the device is a Modem.

screen shot 2017-05-31 at 2 00 35 pm
screen shot 2017-05-31 at 2 00 29 pm
screen shot 2017-05-31 at 1 59 22 pm
screen shot 2017-05-31 at 1 57 35 pm

UF2 BOOT drives fail to handle SMART requests appropriately

See adafruit#50. Programs that make SMART requests to UF2 BOOT drives can cause the drive to lock up, not appear, etc. I'll look at this, but if one of you knows an obvious fix, let me know. Will PR any fixes back to you.

Extensive testing by @vitorio described in https://forums.adafruit.com/viewtopic.php?f=60&t=149791&p=743111#p743089. I also duplicated this finding. Example below. Note that the drive (or the driver?) is reporting SMART support is available.

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
[...]
/dev/sdc            7934       513      7421   7% /media/halbert/CPLAYBOOT


$ smartctl --all -d scsi /dev/sdc
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.15.0-47-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               CPlay Ex
Product:              press
Revision:             1.00
User Capacity:        8,192,000 bytes [8.19 MB]
Logical block size:   512 bytes
scsiModePageOffset: response length too short, resp_len=4 offset=4 bd_len=0
Device type:          disk
scsiModePageOffset: response length too short, resp_len=4 offset=4 bd_len=0
Local Time is:        Tue Apr 16 09:09:16 2019 EDT
SMART support is:     Available - device has SMART capability.
SMART support is:     Enabled
Temperature Warning:  Disabled or Not Supported

=== START OF READ SMART DATA SECTION ===
^C^C^C^C
[hangs, killed process, which became a zombie, eventually timed out]

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.