Skip to main content
Visitor II
June 3, 2024
Solved

STM8 bootloader UART write memory

  • June 3, 2024
  • 6 replies
  • 6778 views

Hello,
I am developing a firmware for a host device to flash STM8S via UART.
My issue is when I send a write command, STM8 didn't response anything.
- Host sends write command: 0x31 0xCE, STM8 responsed ACK 0x79 . Host replies 0xFF
- Host sends 5 bytes address and checksum: 0x00 0x00 0x88 0x00 0x88, STM8 responsed ACK 0x79. Host replies 0xFF

- Host sends 6 bytes (1 byte: number of data, 4 bytes data and 1 byte checksum): 0x03 0x00 0x00 0x00 0x00 0x03

 STM8 didn't reply anything.
I attached serial capture image.
Please help me. it took me a long time to check it

thaonguyen_0-1717408740348.png

 

    This topic has been closed for replies.
    Best answer by AA1

    As I said before, .S19 file is not a binary file, and this is the problem. .S19 is an ASCII file. Code is in hexadecimal and each line begins with an 'S' and an address. You can't read the file as is and send it to MCU. Search in Internet for .s19 file format.

     

    6 replies

    Visitor II
    June 3, 2024

    Maybe it is missing the erase/write routines. See UM0560 - STM8 bootloader, section 3.8.1 RAM erase/write routines.

    Also STM8S bootloader uses reply mode. Section 2.1.1 - The host must reply to all the bytes sent from the bootloader. I think 0xFF is the reply to 0x79. Maybe this works but reply byte should be the same as received. In this case 0x79.

    Visitor II
    June 3, 2024

    Hi @AA1 ,
    I am sure that wrote RAM erase/write rountines to RAM start at address 0x0000A0, and I read back data is correct.
    I just changed to reply same byte received, but it doesn't change, you can see image attached.
    could you recheck this issue to help me?

    thaonguyen_0-1717437941169.png

     

    Visitor II
    June 3, 2024

    UART settings is 1 start bit, 8 data bit, no parity bit, 1 stop bit?

     

    Visitor II
    June 3, 2024

    Also try UART settings 1 start bit, 8 data bit, even parity, 1 stop bit.

    Visitor II
    June 3, 2024

    Hi @AA1 ,
    I tried with wrong checksum then STM8 repsonses NACK
    I also tried to use parity even bit but no change.

    Graduate II
    June 3, 2024

    Why do you keep sending these 0xFF bytes?

    Sending them after the command likely means it's expecting 256 bytes of data, not 4 bytes.

    Also the protocol want's EVEN PARITY, ie 8E1, like the STM32 equivalent

    https://www.st.com/resource/en/user_manual/um0560-stm8-bootloader-stmicroelectronics.pdf

    Visitor II
    June 3, 2024

    Hi @Tesla DeLorean ,
    I am developing using UM560 document.
    my stm8 is stm8s105 (stm8s-discovery). I wrote both 128 bytes and 256 bytes and it still isn't working.

    pls help me with any idea.

    Visitor II
    June 3, 2024

    I think the protocol for STM8S uses reply mode. UM0560 - STM8 bootloader Section 2.1.1 - The host must reply to all the bytes sent from the bootloader. Otherwise first 0xFF sent would be the first byte of 4 bytes address and the checksum would be wrong, which is not the case.

    Visitor II
    June 3, 2024

    @I just saw that stm8 is restarted after Host sends data.
    any reason to do it restarted?

    Graduate II
    June 3, 2024

    Watchdog? Writing to the wrong area causing a fault?

    Perhaps use the Flash Demonstrator or ST tools to program via the loader, and monitor the COM port traffic.

    Visitor II
    June 4, 2024

    .s19 file is not a binary file. How do you wrote RAM erase/write routines to RAM.

    If above step is ok, other possibility is watchdog as Tesla DeLorean already said. Do you have watchdog enable by hardware in options bytes?

     

    Visitor II
    June 5, 2024

    Hi @AA1 ,
    I don't use Watchdog.

    I am writing content of routines file to RAM starting at address 0x0000A0. should it be correct?

    Visitor II
    June 5, 2024

    If you don't' use watchdog, invalid opcode reset seems the only possibility. And this happens because code at address 0x0000A0 is invalid. Show me the first bytes at address 0x0000A0.

     

    Visitor II
    June 6, 2024

    If the problem is solved, you should mark this topic as answered.