Skip to main content
Visitor II
March 1, 2024
Question

XMODEM protocol for file transfer

  • March 1, 2024
  • 6 replies
  • 13212 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.

    6 replies

    Technical Moderator
    March 1, 2024
    pvall.1Author
    Visitor II
    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?

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

     

    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

     

    Technical Moderator
    March 1, 2024

    Thank you @Andrew Neil I totally forget the AN4657!

    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"

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

    pvall.1Author
    Visitor II
    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

    Super User
    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.1Author
    Visitor II
    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?

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

    Super User
    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.

    Super User
    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.