Skip to main content
Visitor II
June 14, 2021
Question

USB device and eeprom writing

  • June 14, 2021
  • 2 replies
  • 2120 views

I am using a STM32F4 on a custom board that is connected to PC software through USB (configured as custom HID device). I have this problem: when the PC send data to the board, the data has to be written in the eeprom memory (one byte at each transmission), but it seems that the writing operation is too slow and the communication stop. What could be the solution? I tried to make slower request of writing from the PC software but nothing changes. Thank you

    This topic has been closed for replies.

    2 replies

    Super User
    June 14, 2021

    > What could be the solution?

    Multitasking, in any of its form, starting from state-machine-based cooperative multitasking (a.k.a. polling), through interrupts-based approach, all the way to using any of the RTOSes.

    JW

    Super User
    June 14, 2021

    Do the operation within the main loop instead of the interrupt. Transfer it to a buffer and set a flag such that the main loop knows to start writing.

    VCapuAuthor
    Visitor II
    June 14, 2021

    I managed in that way, with a small buffer, but the problem is that a great number of data is written each time and the quantity is not fixed, so I would prefer to write the bytes one at a time. I am trying to do that by slowing the commands of writing, but I have still some problem.

    Super User
    June 14, 2021
    1. Try to write to the eeprom less data, less frequently (cache data, rewrite only changed bytes). OTOH if the eeprom can write more than a byte at once (by "pages", bursts) - use that mode.
    2. Increase the bus frequency of the I2C: if it is 100 KHz, increase to 400 if the eeprom allows (it should).
    3. Detect I2C errors and implement recovery. This couples with (1), While you recover I2C, the app works with the cache and its flow is not affected.
    4. Ditch that old eeprom and use this.