Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more.
0

ItsyBitsy m4 Corrupted USB drive / Bootloader
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Do fuse settings protect bootloader or not ?

by danhalbert on Fri Feb 21, 2020 7:00 pm

If the fuse settings guard the section of flash memory containing the bootloader, how is it that the bootloader became corrupted during periodic, routine uploads of code? Is it possible that these boards got shipped without proper settings?


A few early batches of this board were shipped with the fuse settings incorrectly not protecting the bootloader, AND we have had a mysterious problem for some time in which the first 8 bytes beyond the protected region are set to zero after a power cycle, very occasionally (https://github.com/adafruit/uf2-samdx1/issues/95). So if the region is not protected at all, we sometimes see the first few bytes of the bootloader being zeroed.

I am planning to start debugging the zeroing problem soon. It might be a combination of a hardware issue and a software problem. It's very odd.

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by Govner on Fri Feb 21, 2020 7:05 pm

[quote removed]

Here's the J-Link output. Obviously it is connected and working with the SAMD51J19A.


Starting operation read registers

Reading register SW0_WORD_0...OK

Reading register SW0_WORD_1...OK

Reading register TEMP_LOG_WORD_0...OK

Reading register TEMP_LOG_WORD_1...OK

Reading register TEMP_LOG_WORD_2...OK

Reading register USER_WORD_0...OK

Reading register USER_WORD_1...OK

Reading register USER_WORD_2...OK

Read registers...OK


But, any attempt to actually "READ" the chip's contents fails with the following


--------------------------------------------
Reading ARM chip id failed.

Unable to enter programming mode. Verify device selection, interface settings, target power, security bit, and connections to the target device.
---------------------------------------------

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by Govner on Fri Feb 21, 2020 11:34 pm

[quote removed]

Here's the J-Link output. Obviously it is connected and working with the SAMD51J19A.


Starting operation read registers

Reading register SW0_WORD_0...OK

Reading register SW0_WORD_1...OK

Reading register TEMP_LOG_WORD_0...OK

Reading register TEMP_LOG_WORD_1...OK

Reading register TEMP_LOG_WORD_2...OK

Reading register USER_WORD_0...OK

Reading register USER_WORD_1...OK

Reading register USER_WORD_2...OK

Read registers...OK


But, any attempt to actually "READ" the chip's contents fails with the following


--------------------------------------------
Reading ARM chip id failed.

Unable to enter programming mode. Verify device selection, interface settings, target power, security bit, and connections to the target device.
---------------------------------------------
[/quote]



Isn't it strange that I can read this but Atmel denies access to reading the device contents?

AC_BIAS0 = 0x02
ADC0_BIASCOMP = 0x00
ADC0_BIASREFBUF = 0x02
ADC0_BIASR2R = 0x00
ADC1_BIASCOMP = 0x00
ADC1_BIASREFBUF = 0x00
ADC1_BIASR2R = 0x04
USB_TRANSN = 0x02
USB_TRANSP = 0x02
USB_TRIM = 0x00
ROOM_TEMP_VAL_INT = 0x42
ROOM_TEMP_VAL_DEC = 0x00
HOT_TEMP_VAL_INT = 0x00
HOT_TEMP_VAL_DEC = 0x00
ROOM_INT1V_VAL = 0x23
HOT_INT1V_VAL = 0x1D
ROOM_ADC_VAL_PTAT = 0x698
HOT_ADC_VAL_PTAT = 0x12
ROOM_ADC_VAL_CTAT = 0x9FF
HOT_ADC_VAL_CTAT = 0x49E
BOD33_DIS = [X]
BOD33USERLEVEL = 0xFF
BOD33_ACTION = BKUP
BOD33_HYST = 0x0F
NVMCTRL_BOOTPROT = 0
NVMCTRL_SEESBLK = 0x09
NVMCTRL_SEEPSZ = 0x03
RAMECC_ECCDIS = [ ]
WDT_ENABLE = [ ]
WDT_ALWAYSON = [X]
WDT_PER = CYC512
WDT_WINDOW = CYC8192
WDT_EWOFFSET = <none selected>
WDT_WEN = [X]
NVMCTRL_REGION_LOCKS = 0xAEECFF80

SW0_WORD_0 = 0x23000042 (valid)
SW0_WORD_1 = 0x23000042 (valid)
TEMP_LOG_WORD_0 = 0x23000042 (valid)
TEMP_LOG_WORD_1 = 0x126981D (valid)
TEMP_LOG_WORD_2 = 0xC949E9FF (valid)
USER_WORD_0 = 0xFFFFFFFF (valid)
USER_WORD_1 = 0xF69A9239 (valid)
USER_WORD_2 = 0xAEECFF80 (valid)

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by Govner on Sat Feb 22, 2020 1:00 am

[quote removed]


####################################
PROBABLE CAUSE OF THE ISSUES WITH J-LINK
####################################

The Atmel Studio (J-Link) "Target Voltage" could not be read, apparently. I did all the meticulous trouble-shooting of the cable integrity and verified over and over with the images in the Adafruit Learning document for this subject. The J-Link doesn't seem to be able to make a successful reading of the voltage and always reads 0.0v in the said display window. Additionally, the J-Link fails to READ the chip. I have tried to get Visual Studio/J-Link to READ the voltage and the contents on not only the Itsy Bitsy which I originally wanted to FLASH but I got out a brand new Itsy Bitsy M4 and connected it up just to eliminate variables. I have updated all the drivers to the latest version (6.63b) including the DLLs. I have tried everything possible except for trying another J-Link. Is it possible that the J-Link itself is bad? OBTW, I actually ordered an extra ribbon cable and swapping out cables, the same results occurs.

So, I have no other information to conclude anything but that the J-Link I have is a lemon. I will contact customer service and discuss returning this one and getting another.

The humor of all this is not lost. This all started when the bootloader which is never suppose to get bricked with fuses set properly, got bricked. The funny part is that when I read the Learning to program SAMD51 bootloader document, I followed the yellow 'bricked' road - bought Windows 10 Home ($139); bought J-Link Edu ($24 incl shipping); extra cable; bought SSD for Windows install ($79); and spent 3 days, getting absolutely nowhere. The funny part? To save a $19 ItsyBitsy (and repair on associated application hardware unit.) Justification? I was going to learn something new and useful. Obsessive tomfoolery's more like it.

Have mercy.

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by danhalbert on Sat Feb 22, 2020 1:21 am

Make sure there's a ground connection from the board to the J-Link. That would be one reason you wouldn't get a voltage reading.

We don't set the security bit. What I meant by "protected" is that it was protected against writing, by using BOOTPROT.

I'm sorry you went to such lengths, but I hope you enjoy your updated computer. :)

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by Govner on Sat Feb 22, 2020 2:05 am

Quote:
" Check your ground connection. "

: ) DUH. I thought I was the only comedian here. I'm kidding of course. All wiring is important obviously.


-------------------------------------------------
Here's a dump of the data J-Link connected to a known-good ItsyB M4 using J-Link's Commander app.

Please seriously scrutinize this data dump from the vantage point of your level of expertise. I, myself, see a couple of mysterious exceptions but then what do I know. One is the discrepancy that it sees a Core M0. Check it out.

Aside:
Customer service protocol suggests (and I gather) that forum admins attempt to 'fix' the issue then relay return recommendations to them. To provide you with all the information to make a determination as to what is next with this process, here's the data dump.

J-Link Commander seems to read the Vref just fine when controlled via this DOS command mode. (guess we can eliminate "Ground" from the discussion. (( sorry )).. couldn't resist.

Would you happen to know if it's possible (and specifics) to use J-Link Commander command interface to flash the bootloader's binary file? If so, we can just bypass the Atmel Studio and cut out all the mystery it creates.

Here ya go.

What does this tell you??

------------------------------------------- J-Link Commander ------------------------------------
J-Link>conf
USB-Address: 0
Enum. type: Real-SN is used
Real-SN: 801016788
KS-Power: Off (Default)
J-Link>f
Firmware: J-Link EDU Mini V1 compiled Jan 7 2020 16:53:19
Hardware: V1.00

J-Link>mem
Target connection not established yet but required for command.
Please specify device / core. <Default>: ATSAMD51J19
Type '?' for selection dialog
Device>
Please specify target interface:
J) JTAG (Default)
S) SWD
T) cJTAG
TIF>s
Specify target interface speed [kHz]. <Default>: 4000 kHz
Speed>
Device "ATSAMD51J19" selected.


Connecting to target via SWD
InitTarget() start
InitTarget()
InitTarget() end
InitTarget() end
Found SW-DP with ID 0x2BA01477
DPIDR: 0x2BA01477
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map seems to be reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: AHB-AP (IDR: 0x74770001)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0x41003000
CPUID register: 0x41003003. Implementer code: 0x41 (ARM)
Unknown core, assuming Cortex-M0
Found Cortex-M0 r0p3, Little endian.

**************************
WARNING: Identified core does not match configuration. (Found: Cortex-M0, Configured: Cortex-M4)
**************************

FPUnit: 0 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl[0] @ 41003000
ROMTbl[0][0]: 82006000, CID: 00000000, PID: 00000000 ???
ROMTbl[0][1]: E00FF000, CID: 00000000, PID: 00000000 ???
Cortex-M0 identified.
Syntax: mem <Addr>, <NumBytes>
J-Link>

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by Govner on Sat Feb 22, 2020 2:38 am

[quote removed by danhalbert for readability]


A friendly reminder regarding USER_WORD_0.NVMCTRL_BOOTPROT.... The Learning guide for flashing the M4s mentions changing the value to 0 to allow programming it but fails to mention the correct value to reset to USER_WORD_0.NVMCTRL_BOOTPROT register to replace the protections. I assume that it depends on the .bin file size but you would know better than I.

So, what did the data dump from the J-Link Commander tell you? (Especially about detecting the M0 Cortex instead of the target M4). Strange.

Thank you.

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by danhalbert on Sat Feb 22, 2020 9:42 am

I will take a look at the whole thread later, but could I request that you not quote yourself in replies, except selectively as necessary? It makes the threads somewhat hard to read. Also don't start a new thread if the old one will do. This is a new thread that is a continuation of a previous thread. Thanks.

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: SAMD51 : Is the 'Security Bit' set to protect the bootl

by danhalbert on Sat Feb 22, 2020 9:49 am

Could you post one or more clear, well-illuminated closeup pictures of your wiring, including the jumper from the J-Link to however you have connected to the board, and the jumpers from the board as well? Thanks.

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: Do fuse settings protect bootloader or not ?

by danhalbert on Sat Feb 22, 2020 12:41 pm

I have merged the three different threads of this debugging marathon into a single thread now so it's easier for me to follow what's been happening, and I've also removed some large quotes to make it easier to read.

To recap, if you could post photos of the wiring between the J-LInk and the board, that would be great. I'll try doing the same setup on Windows. If we can avoid using Atmel Studio that would be good: JCommander and JFlashLite are probably all we need. Those can be run natively on MacOS, if that would be easier for you. Besides your wife's MacBook, now with a Windows VM, what host computer were you using before?

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: Do fuse settings protect bootloader or not ?

by danhalbert on Sat Feb 22, 2020 3:55 pm

Update: I've now set up a Windows system as you did I have discovered that the guide had a very significant error: it says the chip to select for ItsyBitsy M4 is ATSAMD51J19A. But the Itsy Bitsy M4 chip is an ATSAMD51G19A. I got similar issues to yours with the wrong chip specified. In Tools->Device Programming, change the selection in the Device dropdown to ATSAMD51G19A, and try again.

I'm very sorry about this error and how much time it wasted for you. I have edited the guide to correct that section.

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: Do fuse settings protect bootloader or not ?

by Govner on Sun Feb 23, 2020 4:04 pm

Hi,

First a couple of points taken. Sorry for the long quotations. I see your point about making it more difficult to follow the problem content. My bad.

Second, as for the wiring, there's no need for any concerns. The wiring is fine and both J-Link and J-Commander work with the J-Link Edu Mini and my ItsyBitsy M4 setup. Reading/Writing to the chips with these tools in their native DOS environment works fine. It's not a wiring issue at all.

The chip designation correction from "SAMDJ19A" to 'G19A' ? Critical error. I will backtrack and give Atmel Studio another chance. It has been a dismal experience which is why I just reverted to using native J-Link utilities instead.

I appreciate the attention you are providing on the issue of programming the bootloader. If I might suggest something as we both work toward a better solution, Atmel Studio doesn't seem to be necessary and is VERY, VERY difficult to troubleshoot when it misbehaves. When it throws an error like "Unable to read....", the software suggests a half-dozen reasons for the error. One can spend days trying to go through all the 'reasons' (which all have large configuration menus themselves.) After a few days, I threw up my hands and, again, J-Link's native utilities provided all the tools I needed. But, what is missing from the equation and is NEEDED follows.

Once I figured out that J-Link Flash and J-Link Commander are the only tools needed, the question came to mind: "Why did I spend all this time with Atmel Studio (not to mention all the computer-related upgrades/purchases required to run it? " The installation of the Studio 7 and related jungle of it's components is far, far more difficult to employ successfully than the simple task (I discovered) of flashing the bootloader using other means. Atmel Studio 7 is impressive, no doubt about that, but it's just way, way overkill for this task. I am not sure but I would venture than J-Link even has previous versions, not requiring Win10, that would even get the job done since bootloader programming long preceded the Win10 stampede. But, I digress. What I would strongly recommend is simplification. Surely I'm not the only person following a 'Learning' document instruction that is terrific (when the cited software runs glitch-free) but little errors like the "J19A" vs "G19A" completely torpedoes all efforts of achieving success. The solution, I think, is to simplify the process by using J-Link's software and eliminate all the variables of adding layers of additional UIs. I think everyone would really appreciate a well-written, tested and verified procedure for flashing bootloaders of these products using J-Link tools, not Atmel's (which likely relies on J-Link DLLs anyway, I'm guessing). Please run this idea up the flagpole.

I am please to report that I have been successful in flashing a known-good Itsy Bitsy M4 bootloader. I have spend a night with the SAMD51 datasheet regarding the BOOTPROT bit settings. However, I still haven't figured out how to 'target' the particular location to write the applicable bin file size 16k-byte value. After flashing the .bin, what exact address and content format do I use with J-Link Flash Lite to protect the bootloader?

Thanks for editing/correcting the 'Learning' document on this topic. I will go through it again if necessary. That is NOT necessary if you could please tell me that the 'device type' correction was all that was changed.

Okay. So, once I get the info about writing the BOOTPROT specifics, I'll be able to close this process. Once I have conducted and perfected my end-to-end bootloader flashing experience, I would be happy to share the steps using J-Link's own software. That's an uphill learning experience for me so if you are already knowing how-to, please share it even if/when an Adafruit online "Learning How-to Use J-Link Utilities to Flash Bootloaders" is provided.

Lastly, thanks for the support regarding the manufacturing default of one of my ItsyBitsy boards (misaligned capacitor). I will contact support via email with this thread reference. Much appreciated.

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: Do fuse settings protect bootloader or not ?

by Govner on Sun Feb 23, 2020 5:25 pm

IMG_0048.jpg
IMG_0048.jpg (55.91 KiB) Viewed 24 times



IMG_0044.jpg
IMG_0044.jpg (51.37 KiB) Viewed 24 times



This is my HUB for the NRF24 2.4Ghz home network. I'd written a detailed description and referenced the displays but it got lost in cyberspace (edit time expired or something). Oh, well. In a nutshell, this hub contains the ITSY BITSY M4 (See top line, fine print, of the display).

I monitor and/or control: Air-conditioning HVAC handler/compressor; Rainfall and landscape watering control, external illumination, solar-powered irrigation controller; Hot water heater output; Brink's Security Home Sensors (replaces failed Brink's controller); Adafruit Nokia remote displays; I2C IR sensors and water detection sensors for ap-pliances that present failure risks (i.e., dishwasher, clothes washer & dryer, refridgerator water line, garage environmentals.

The Neopixels flash every time a node reports. This can't be caught in a freeze frame but about every second or so, a specific pixel and color flashes to indicate the relative health of each of the reporting nodes around the premises.

Almost all NRF24 transceiver nodes contain a Adafruit Pro Mini and BME280 temp/pres/hum sensor. One outside node utilizes the Adafruit Solar 6V panel and LiPo charger.

My PCB was designed for installing: Adafruit's ItsyBitsy M4, Metro Mini 328; I2C 64kbit EEPROM; I2C DS3231 RTC; Buck 3.3V PS with a precision, fast-acting over-voltage protection (3.6 v trigger); 1-Wire Sensor bus; Schmidt Trigger/Control button debounce; Adafruit 8-Neopixel Strip; Piezo buzzer; Adafruit BME280 Sensor; and NRF24L01 2.4Ghz Xcvr.


Flashing bootloaders is a much needed skill to maintain this system. Obviously, I rely heavily on Adafruit's efforts and support for these devices. Thanks again.

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Re: Do fuse settings protect bootloader or not ?

by danhalbert on Sun Feb 23, 2020 10:15 pm

The person who wrote the guide is familiar with Atmel Studio, and it was written from that point of view. However, we will definitely consider adding a section describing how to use the J-Link tools.

It is not easy to change the BOOTPROT fuse bits with the basic J-Link tools. The easiest thing to do is to replace the bootloader as you did, which leaves it unprotected, Then double-click to get the BOOT drive, and load the update-bootloader...uf2 file for your board. That will rewrite the bootloader (possibly just with an identical version), AND as part of the update process it also repairs the fuses, setting them to appropriate values.

danhalbert
 
Posts: 1966
Joined: Tue Aug 08, 2017 12:37 pm

Re: Do fuse settings protect bootloader or not ?

by Govner on Mon Feb 24, 2020 2:41 am

danhalbert wrote:…... and load the update-bootloader...uf2 file for your board. That will rewrite the bootloader (possibly just with an identical version), AND as part of the update process it also repairs the fuses, setting them to appropriate values.


Thanks. It's an interesting idea. Too bad that the .bin file can't force the same 'settings' as does the UF2 software.

Using Arduino IDE 100% of the time for developing software/hardware, I was actually looking forward to eliminating the UF2 file which would eliminate Window's incessant "dance" (I call it) with COM port inits. With every upload practically, there is the annoying popup and dialog about UF2. While Win10 doesn't seem as susceptible in this regard, prior to the UF2 debut (i.e. pre-serpentine boards), bootloader behaviors were far better in my experiences. The UF2 workaround would be a good shortcut for some to quell this bootloader repair problem, but I am holding out that you and your other programmers can share the precise info and transform this task into a learning moment. Learning the details is important so the knowledge can be applied to future challenges. Everyone wins.

"We don't do it because it's easy - we do it because it is hard." - JFK
So, please do add the necessary data to the 'how-to program bootloader' docs so this can be done with the low-level J-Link Flash tools.

I did give this my full attention before asking for help. In fact, being encouraged and carefully following the current "How-to Learning docs" on the Adafruit website, I did try another several hours (unsuccessfully) to get Atmel Studio 7 to perform and connect to the ItsyBitsy and read it. Over and over it throws the same error: "Can't read ..blah, blah, blah." Conversely, simply switching to J-Link software, (and not changing anything with wiring/hardware setup) , every J-Link tool just zings right along without hesitation and can read/write to the ItsyBitsy perfectly. If I had the details that you guys have, I believe that I could get this done using J-Link software. I can't imagine spending more days (3-4 so far) trying to trouble-shoot Win10/AS7. According to some tech authors, recent developments/shortcomings coincide with latest version updates of Windows 10. There is a lot of negativity on the web questioning why AS7 is not "working and playing well with others".

Focusing on J-Link is far more promising I believe so I really hope you all share the knowledge with us. A good solution will surely help customers dealing with their own corrupt bootloaders - providing them the much needed direction to fix things themselves, not to mention reducing perpetual forum threads like mine. : )

Thanks in advance for detailed info and for your time spent providing it. It's much appreciated.

Govner
 
Posts: 169
Joined: Wed Sep 14, 2016 4:42 pm

Please be positive and constructive with your questions and comments.