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

User code in bootloader #34

Open
dzarda opened this issue Jun 2, 2021 · 6 comments
Open

User code in bootloader #34

dzarda opened this issue Jun 2, 2021 · 6 comments

Comments

@dzarda
Copy link
Contributor

dzarda commented Jun 2, 2021

What is the "correct" procedure for injecting user code into the bootloader? For example I want to display some content on the display while the device is in DFU.

One solution might be adding user_init and user_poll to the existing main:

dfu_init();
user_init(); ///
while(1) {
    usbd_poll(&dfu);
    user_poll(); ///
}

Another solution might be to allow disabling the default main (and then calling dfu/usbd from user source:

#ifndef DFU_CUSTOM_MAIN
dfu_init();
while(1) {
    usbd_poll(&dfu);
}
#endif
@dmitrystu
Copy link
Owner

It's up to you. It's also possible to add two weak empty functions like void user_init(void) before the main loop and void user_task(state or somewhat_to_track_progress) inside the main loop to generalize this feature.

@dmitrystu
Copy link
Owner

I think it's a good idea to add void user_exit(void) before a system reset.

@dzarda
Copy link
Contributor Author

dzarda commented Jun 3, 2021

Yeah the weak definitions are probably the way to go.

@dzarda
Copy link
Contributor Author

dzarda commented Jun 3, 2021

Do we want user_init before OR after dfu_init?

@dmitrystu
Copy link
Owner

I think it doesn't matter.

@dzarda
Copy link
Contributor Author

dzarda commented Mar 23, 2023

I'm back at this thing again. I need to be able to perform custom user_verify() on each start (same stage as validate_checksum). Would you consider having DATA/BSS sections initialized before it? user_verify() would need access to that data.

Or more likely move the initialization directly after clock setup.

I can change it locally but I would want to opensource that feature if you're ok with it.

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