Skip to main content
pvall.1
Associate III
March 1, 2024
Question

XMODEM protocol for file transfer

  • March 1, 2024
  • 15 replies
  • 13371 views

Hi,

I'm currently working on file transfer through the XMODEM protocol, and I want to implement the logic in STM32CubeIDE. If anyone has already implemented it, please share the source code. It would be helpful for me.

 

Thanks

    This topic has been closed for replies.

    15 replies

    mƎALLEm
    ST Technical Moderator
    March 1, 2024
    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    pvall.1
    pvall.1Author
    Associate III
    March 13, 2024

    Hi,

    I utilized the above code and changed it as per requirements. I am able to receive one packet correctly with a matching CRC value. However, when I send an ACK or NAK from the receiver end, the sender is not sending the second packet. What could be the possible reason?

    Andrew Neil
    Super User
    March 13, 2024

    Your ACK or NAK must be incorrect in some way.

    Try capturing the traffic from a "good" transfer, and compare with a failing one ...

    Does the sender give any error details to help?

    Have you tried with any other sender(s)?

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Andrew Neil
    Super User
    March 1, 2024

    See also Application note  AN4657, STM32 in-application programming (IAP) using the USART

    https://www.st.com/resource/en/application_note/an4657-stm32-inapplication-programming-iap-using-the-usart-stmicroelectronics.pdf

    Code is available as X-CUBE-IAP-USART:

    https://www.st.com/en/embedded-software/x-cube-iap-usart.html

    It actually uses YMODEM, but that's very similar to XMODEM:

    https://web.cecs.pdx.edu/~rootd/catdoc/guide/TheGuide_226.html

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    mƎALLEm
    ST Technical Moderator
    March 1, 2024

    Thank you @Andrew Neil I totally forget the AN4657!

    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    Andrew Neil
    Super User
    March 1, 2024

    IIRC, an (the?) advantage of YMODEM was that it tells you how much data is to come?

    Also, it defaults to 1K + CRC.

    "Ymodem is essentially Xmodem 1K that allows multiple batch file transfer"

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Andrew Neil
    Super User
    March 1, 2024

    Full description of the XMODEM, YMODEM, and ZMODEM protocols:

    https://techheap.packetizer.com/communication/modems/xmodem-ymodem_reference.html

    It's not that hard to implement from scratch...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    pvall.1
    pvall.1Author
    Associate III
    March 4, 2024

    Hi,

    Thanks for the reply.

    However, the source code provided above is for receiving X-Modem/Y-Modem packets from a serial COM port to a microcontroller using a USB-UART bridge. In my case, I want to send data stored on an SD card to UART in X-Modem format. There is no direct connection between USB and UART in my case, so whatever data I receive from USB needs to be stored on the SD card as a file, which will later be transmitted to UART through X-Modem format.

    Is there any source code available which suits my requirement?

    Thanks

    Pavel A.
    March 4, 2024

    @pvall.1 The Ymodem source provided by ST in "IAP" and other examples is very intermixed with flash write & erase routines. When I used it in my projects I had to decouple Ymodem logic from the internal flash stuff. It was tedious but not too hard. You can do the same to reuse these examples to send files from any source including files from SD. 

     

    pvall.1
    pvall.1Author
    Associate III
    March 7, 2024

    Hi @Pavel A.  Do we need to have USB-UART connector to receive data directly in X-Modem format  into microcontroller through Teraterm? Or any configuration is required to acheive this?

    Andrew Neil
    Super User
    March 7, 2024

    X-Modem is oblivious to what transport you use - it's just a stream of bytes.

    But, if you're using TeraTerm, then a UART link is the obvious way to go ...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Pavel A.
    March 7, 2024

    @pvall.1 Of course you can use any adapter from the TTL UART of the STM32 to a PC. For a modern PC that does not have RS-232 ports, TTL to USB adapter is the best choice. If compatibility with RS-232 is needed, use a passive TTL to RS-232 adapter.

    Pavel A.
    March 13, 2024

    Have you seen one of Ymodem examples from ST? they have Ymodem-1K in several examples and demo apps for several MCU models: IAP, SBSFU... It works well with latest Teraterm. Xmodem is older simpler protocol.