Skip to main content
Associate
June 3, 2024
Solved

STM8 bootloader UART write memory

  • June 3, 2024
  • 6 replies
  • 11761 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

 

    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

    AA1
    Senior III
    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.

    Associate
    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

     

    AA1
    Senior III
    June 3, 2024

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

     

    AA1
    Senior III
    June 3, 2024

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

    Associate
    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.

    Tesla DeLorean
    Guru
    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

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Associate
    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.

    AA1
    Senior III
    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.

    Associate
    June 3, 2024

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

    Tesla DeLorean
    Guru
    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.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    AA1
    Senior III
    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?

     

    Associate
    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?

    AA1
    Senior III
    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.

     

    AA1
    Senior III
    June 6, 2024

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