lujji / stm8-bootloader

Serial bootloader for STM8 microcontrollers
MIT License
94 stars 27 forks source link

Are you using some auto bootload entry logic? #5

Closed baoshi closed 5 years ago

baoshi commented 5 years ago

Hi, fantastic software! Just one issue for me: I can't stay in bootloader mode if UART does not receive data in time. The watchdog resets the mcu. I need to comment out iwdg_init() in the main function, otherwise static uint8_t uart_read() { iwdg_refresh(); while (!(UART_SR & (1 << UART_SR_RXNE))); return UART_DR; } the while loop cannot exit and watch dog is not getting refreshed. So I suppose you have some automatic bootloader entry from PC host ?

lujji commented 5 years ago

Hi. The python script toggles reset via DTR line on the serial converter, which is done purely for convenience. Apart from that there is nothing special about the host utility. Perhaps the delay between bytes you're sending from your host is too long?

baoshi commented 5 years ago

I see. In my case watchdog times out because i'm manually press the button then start the python script. The watchdog times out before first preamble is received. Perhaps I can modify it to only start watchdog after 0xDEADBEEF

lujji commented 5 years ago

By "press" you mean push and release? The pin is supposed to be shorted to ground constantly (with a jumper or dip-switch). If you're using a button you can press and hold, start the script, wait until the bootloader starts updating, then release.

baoshi commented 5 years ago

I got it. The bootloader will cycle through watch dog reset and only start flash once preamble is received. Consider the issue closed. Btw is there any reason to enable watchdog other than let the bootloader to reset itself at the end of programming or when jumper is open?

lujji commented 5 years ago

Watchdog will also trigger in case CRC doesn't match or the update process gets interrupted.