Comments (12)
This should not be hard to add.
So the use case is that ESD has done the equivalent of a double-click, and you want it to reset instead after a period of time?
Are these your own boards? Are you using this bootloader instead of the Arduino one because you're using UF2's?
from uf2-samdx1.
We tried replicating it using ESD gun which forces it into the bootloader mode, @lodhi-origo tried to remove the double-tap-magic from the main.c but the issue still persists.
Now we think having it reset after it stalls would be the ideal solution for our application and adding a timer after which it replicates the reset button would make it perfect for outdoors remote use.
Yes these are custom boards and we are using SAMD21G18A.
Thanks a bunch
from uf2-samdx1.
Hi Dan, The ESD has made the SAMD21 reboot to the point where it needs a double-click to continue execution. We would like to implement a timeout at this point, so if it is not getting a double-click, it will continue execution/boot and start the normal bin code/application after a number of seconds e.g. 15 seconds, which should be configurable.
from uf2-samdx1.
@lodhi-origo tried to remove the double-tap-magic from the main.c but the issue still persists.
That will make it worse, I think, because any reset will switch immediately to the bootloader and stay there.
I think it might be a question of whether it's really in the bootloader or is stuck in some other way. Does your custom board have an LED that pulses like the Adafruit boards when it's in the bootloader: slow "breathing" pulse when connected to USB, faster pulse when not connected?
More in the next post.
from uf2-samdx1.
from @lodhi-origo in discord:
I'm trying to add a timer in the bootloader uf2-samdx1 which is compatible with SAMD21G18A because our bootloader is getting stuck in the boot mode if exposed with ESD and we want it to jump to the firmware after x amount of time let's say 15 sec (for testing).
NOTE: We can use any bootloader as far as it is compatible with SAMD21.
The repo from adafruit/uf2-samdx1 is not compatible with ATmel/Microcip Studio so how can I use the debugerr J-Link EDU mini or ATMEL ICE to debug the code? Can you suggest alternative ways. Thanks
Right now building it through make which I've installed using chocolatey and I'm using VS Code with python3.
// Define the timeout duration in milliseconds
#define BOOTLOADER_TIMEOUT 15000 // 15 seconds
static volatile uint32_t millis = 0;
// Timer function to get current time in milliseconds
static uint32_t get_current_millis(void) {
// This should return the number of milliseconds since the system started
return millis;
}
void SysTick_Handler(void) {
millis++;
}
void init_systick(void) {
SysTick_Config(SystemCoreClock / 1000);
}
this is the code I'm using it to add a timer, but it needs to be adjusted in the repo in such a way that some parts will be going into different files and should be commented out from the
main.c
Also, I'm initializing the below two lines in the very start of the main(void)
SystemInit();
init_systick();
and then initializing the start_time
as below just before the while(1)
loop
uint32_t start_time = get_current_millis();
and lastly editing in the main while(1)
loop like below
// Check if the timeout has been reached
if (get_current_millis() - start_time > BOOTLOADER_TIMEOUT) {
//LED_MSC_ON();
check_start_application(); // Jump to the main application
break; // Exit the loop after jumping
}
Re the above: The systick is already running: it's used to do the LED pulsing. There is already a systick handler in
init_samd21.c
:
void SysTick_Handler(void) { LED_TICK(); }
You could add timeout checking there. Another thing I thought you might do is just count the number of LED pulses and stop after a few hundred or so.
You may not want to timeout the bootloader if you are connected to USB (check USB_OK()
), since that would mean someone is trying to update.
Re your proposed code:
// Check if the timeout has been reached
if (get_current_millis() - start_time > BOOTLOADER_TIMEOUT) {
//LED_MSC_ON();
check_start_application(); // Jump to the main application
break; // Exit the loop after jumping
}
Instead of check_start_application()
, I'd suggest doing resetIntoApp()
. That will set *DBL_TAP_PTR = DBL_TAP_MAGIC_QUICK_BOOT;
so it will go directly into the app, but it will do a hard reset first, which I think would be very good to reset any bad state caused by the ESD or power glitch or whatever.
BTW, in the above, if the break
executes, you will exit main()
, which may does nothing interesting. It doesn't necessarily do a reset. It might even do an infinite loop.
from uf2-samdx1.
t
That's also the thing that electronically I'm not sure if it is getting into the bootloader or stuck in some other way. However, we do have a pulsating led on our board and it will start pulsating when hit with ESD, so from this we are concluding that it is halting into the bootloader mode.
from uf2-samdx1.
For debugging, there is a "log to RAM" mechanism in the UF2 code, but I have not been successful at getting it to work.
However, I did not try for very long. Usually I instrument things by adding calls to the LED color changer or blinker, or toggle output conditions. For instance, I might blink the LED different numbers of times depending on where I am in the code. There is a helper routine for that.
I don't use Atmel Studio. I use a J-Link directly or from gdb. Writing the bootloader is a nuisance because of the fuses. It's tricky to write to the fuses from JLinkExe: you need to do the write and then step the program one instruction to get the write to complete.
from uf2-samdx1.
Hi Dan
I initialized ledOnToggleCount
in utils.c and increment it under curr == limit
is true when signal_end
is non-zero.
volatile uint32_t ledOnToggleCount = 0;
so the led_tick()
will become like this as below:
void led_tick() {
led_tick_on = true;
now++;
if (signal_end) {
if (now == signal_end - 1000) {
LED_MSC_ON();
}
if (now == signal_end) {
signal_end = 0;
}
} else {
uint8_t curr = now & 0xff;
if (curr == 0) {
LED_MSC_ON();
if (limit < 10 || limit > 250) {
led_tick_step = -led_tick_step;
}
limit += led_tick_step;
} else if (curr == limit) {
LED_MSC_OFF();
`ledOnToggleCount++; // Increment the counter here`
}
}
}
and then simply adding the below code in main.c after the USB_OK()
in while(1)
// Check if the timeout has been reached
if (ledOnToggleCount >= 200) {
resetIntoApp();
}
The code compiles successfully given that the ledOnToggleCount
is defined in uf2.h as extern but the board is still not getting reset after waiting 200 seconds or even 5 minutes.
from uf2-samdx1.
Could you push your code to a repo I can see? Thanks.
from uf2-samdx1.
Here is the fork from adafruit in which I add ledOnToggleCount and use two files from \lib\samd21\samd21a\gcc\gcc which I'm not sure if the linker files are correct for SAMD21G18A.
https://github.com/lodhi-origo/uf2-samdx1
from uf2-samdx1.
Hi Dan
By removing the brownout protection in the main.c file it will still work fine.
What are the scenarios that it will be useful ?
from uf2-samdx1.
By removing the brownout protection in the main.c file it will still work fine.
Hi - I don't know what you mean here. Did you mean that if you remove the brownout protection your problem goes away? It was added here: #198. See the (long) forum thread referenced there for why it was added.
from uf2-samdx1.
Related Issues (20)
- SAMD21 Clock Config HOT 5
- NeoKey Trinkey update files missing HOT 3
- SAME51 update for Adafruit Feather M4 CAN? HOT 2
- Compiling for the SAMDA1G16B HOT 5
- reset into bootloader from user code? HOT 4
- circuit playground express 3.14 macos Monterey HOT 4
- Having an issue with USB device disappearing if the programmer is not connected HOT 1
- Makefile issues HOT 4
- macOS 13.0 (Ventura) Finder gives error when uploading UF2 files HOT 4
- Linking issue HOT 1
- Custom pin mapping for ATSAMD21G18A HOT 1
- Problem building the project in VS code HOT 1
- Reading logs - how???? HOT 3
- MKR Vidor 4000 Arduino Sketch Upload halts at around 50% only when loaded via uf2 bootloader
- Building an "unlocked" (no flash write protection) bootloader? HOT 1
- Change the filesystem be changed to FAT or FAT32 ? HOT 1
- Double definition of WDT for SAMD51
- Add Wire Mux HOT 1
- Flash corruptioin on SAMD51 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uf2-samdx1.