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

jump_to_application doesn't clean up after dapboot #45

Open
obra opened this issue Nov 9, 2021 · 2 comments
Open

jump_to_application doesn't clean up after dapboot #45

obra opened this issue Nov 9, 2021 · 2 comments

Comments

@obra
Copy link
Contributor

obra commented Nov 9, 2021

One common feature of bootloaders is that they try to leave the MCU's state as they found it, turning off interrupts, resetting clock config, etc.

I've tracked some weirdness I'm seeing in user applications down to dapboot not doing any of that. Is this a conscious choice or just something that hasn't been dealt with yet? I'm not experienced enough with opencm3 to propose a patch :/

@devanlai
Copy link
Owner

devanlai commented Nov 9, 2021

It's not exactly a conscious choice, more of a "it was good enough at the time so I didn't change it".

Off the top of my head, the bootloader doesn't turn on too many things:

  1. It does configure the main system clock and leave it running.
  2. It turns on and leaves on the GPIO peripherals and RTC backup register peripherals
  3. If it enters DFU mode, it turns on USB and leaves it on

If you want something a little more limited in scope than trying to fix everything everywhere, I think the easiest place to fix up just the things that your application is sensitive to would be in target_pre_main(), which gets called immediately before setting the stack pointer and jumping to the application's reset handler.

@obra
Copy link
Contributor Author

obra commented Nov 9, 2021

Understood. The specific manifestation of the problem I have is admittedly pretty special to my use of dapboot. Gigadevice's standard library assumes that clocks are in a known state at initialization time. And when they're not, all sorts of fun stuff happens, and the way our Gigadevice Arduino core works, it's a pain in the ass to inject code to bulletproof things in the right place on the user code side. (At the moment, I'm unwinding the chip trying to talk "regular" 100KHz I2C ...at 8MHz, but I haven't chased it all the way down yet.)

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

2 participants