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

Would it be possible to adapt to serial via software? #8

Open
rtek1000 opened this issue Apr 11, 2023 · 4 comments
Open

Would it be possible to adapt to serial via software? #8

rtek1000 opened this issue Apr 11, 2023 · 4 comments

Comments

@rtek1000
Copy link

Hi,

Unfortunately the W1209 board does not have UART pin usability. But I'm managing to emulate USART using timers.

Would it be possible to emulate the serial port to use in the bootloader?

Ref.: https://github.com/rtek1000/W1209-firmware-modified/blob/master/W1209-firmware-Remote/w1209-firmware-modified-eclipse-remote/Core/Src/remote.c

https://github.com/rtek1000/W1209-firmware-modified/blob/master/W1209-firmware-Remote/w1209-firmware-modified-eclipse-remote/Core/Src/timer.c

@rtek1000
Copy link
Author

rtek1000 commented Apr 11, 2023

I modified it to use timers, but I haven't tested it yet, follow the link (935 bytes):

https://github.com/rtek1000/stm8-bootloader

@rtek1000
Copy link
Author

I managed to test it, there was a bug, because I was using interrupt, it took me a while to understand that you cannot use interrupt in the bootloader. Apparently working, I haven't tested it with very large application code.

Ideally, I wanted to implement my own interrupt table, however, it seems that it’s hard-coded inside SDCC. After spending some time with the documentation and browsing through the mailing lists, I just ended up looking at the compiler’s source code. There is a function createInterruptVect() inside SDCCglue.c which is responsible for generating the interrupt vectors. As it turns out, it checks whether or not main() is implemented and then proceeds with the interrupt table generation. So the solution was pretty simple: rename main into bootloader_main and no interrupt vectors will be generated.

So the solution was pretty simple: rename main into bootloader_main and no interrupt vectors will be generated.

https://lujji.github.io/blog/serial-bootloader-for-stm8/

@lujji
Copy link
Owner

lujji commented Apr 16, 2023

The interrupts are not working in bootloader because the interrupt table points to application IVT (see init.s). You could implement the ISR you're interested in and check if bootloader is active by testing some magic value in RAM for example. From there you could either continue executing the bootloader ISR code or jump to application ISR.

@rtek1000
Copy link
Author

I had tried to implement the interrupt in this file (init.s), but I couldn't. It would be interesting to have an example, perhaps with EXTI.

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