|
Hierodule 1.6.2
Utility module set for STM32 MCUs
|
This module only covers the CDC mode for the USB peripheral, which lets you
HIERODULE_USB_Wrapper is the main item in the module, with the instance of which you can access the variables related to the ring buffer and use the module routines to implement your USB comm procedure.
The module does not address peripheral configuration and initialization, it is assumed those are performed beforehand. Make sure to have configured your USB peripheral accordingly.
First, update the CDC_Receive_FS routine defined within within usbd_cdc_if.c so that the module's reception callback routine will be invoked whenever an incoming transmission has been completed. Simply, add an include directive to the module at the top, then add a call to HIERODULE_USB_Receive_Callback right before the routine's return statement.
Except the painfully simplifed syntax and omitted source code, it should pretty much look like this.
Optionally, you can define a callback routine to be called at the end of a transmission.
You can also just pass a null pointer if you do not need anything done at the end of the transmission.
Next, initialize the wrapper with the callback routine and an arbitrary RX buffer size, 24 for this instance.
And that's it! The peripheral, and consequently the module, should be able to handle the incoming transmissions from the host. To set up data to be transmitted at the next transmission commenced by the host, simply use HIERODULE_USB_TransmitPackage
The first parameter to the routine is really an uint8_t pointer; your compiler might warn you about implicit casts, but you should be fine as long as it's a c-type string, a pointer or an array of uint8_t, char etc.
Likewise, use the same routine to set up the data response for the next transmission inside your transmission complete callback. You can parse the received bytes via HIERODULE_USB_GetNextByte. Or, you can directly access the buffer contents with the wrapper's instance, that's declared within the header file as extern.
Finally, you can "release" the wrapper to save memory.
This merely frees the ring buffer address and nullifies it. Make sure to initialize the wrapper with adequate buffer size before accessing it again.