2
\$\begingroup\$

I'm making a 100% customisable mouse, that can be programmed from an app.

  1. You program it in a node based language similar to the Unreal Engine 5 interface
  2. Your code is encoded to binary, and sent to an STM32F205RBT6
  3. It's then decoded there, and using some simple logic, run.

My problem is with step 2; I would like to send the data to the mouse for decoding, but how would I do this?

Some more info:
1. The data is dynamically sized, for example some nodes would be 50 bytes, but some would be 1kB, so report descriptors wouldn't work. EDIT: All of the nodes would be around 75 bytes in size
2. The data could take up to 20kB.

To clarify:
How do I send large quantities of binary data via HID.

My question is not about the PC side, it is about what would I need to do on the STM32

\$\endgroup\$
3
  • \$\begingroup\$ This is a design question \$\endgroup\$ Commented Jul 13, 2024 at 15:11
  • \$\begingroup\$ Taking a look at one of the many HID-based bootloaders could be useful. \$\endgroup\$ Commented Jul 13, 2024 at 18:29
  • \$\begingroup\$ Why do you need to do it via HID? \$\endgroup\$ Commented Jul 13, 2024 at 21:54

2 Answers 2

3
\$\begingroup\$

The obvious answer is, send large quantities of data in small packets, by defining a protocol for how to transfer it.

How to e.g. split 20 KB of data into packets containing e.g. 32 bytes each in order to transmit it is up to you.

Then on the MCU end you reverse the process, combine the data from small packets into one large blob of data before doing anything with it, or store it somewhere you want 32 bytes at a time.

It is likely that no such protocol yet exits so you may have to roll your own, but you may use something similar as an example.

Commonly protocols that have done similar things have existed for decades in the era where people transferred files over modems with acoustic coupling to a landline telephone handset.

Commonly packets might have some control information in addition to just sending data, such as this is now a start of tranfer of something with some total size, a length how much data this packt contains, a CRC or checksum to protect the data from errors, and maybe a counter to indicate packet sequence number so you know if some packet was lost and may need to be restarted or retransmitted. Commonly such a protocol would also have some response packets that define you got packet number X so transmit next packet, or that there was an error and request to retransmit, or some timeouts that retransmit something in case of the ACK/NAK packet was lost.

That's already very complex but feel free to make it as simple as possible, like just sending data packets with some flags that this is the start of data packet for a new thing, continuation packets, and final packet, so packets for short data could have these start and end flags both set and then you have long packets which signal that there will be more data after this and this is a continuation for previous packet. Again, some counters may be beneficial, like each small packet containing ID that this is a packet number X of transferring any binary blob number Y so again you can detect if packets were lost so nothing gets corrupted.

\$\endgroup\$
2
  • \$\begingroup\$ So I create a report descriptor at under 1024 bytes of data (for example 32 bytes), and then split it up into packets and send it, then add it all together again? \$\endgroup\$ Commented Jul 13, 2024 at 11:06
  • \$\begingroup\$ Oh, also, I was wrong on the question, they'll all be around 75 bytes each. I'll just edit it now. \$\endgroup\$ Commented Jul 13, 2024 at 11:08
0
\$\begingroup\$

So, Justme's answer got me going, and then after some more research using the information that Justme had provided, I settled on using a feature report. I believe that it is the simplest and easiest way, and it will be perfect for my needs:

... Feature Reports are NOT requested or sent by the PC on a regular basis, but only rarely, when the end user does something.

(Source)

You split it into packets, then input that into the feature report, and then you're done. Easy. :D

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.