Why does the HAL USB CDC driver call malloc in an ISR context ... again?
Back in 2018 this question was posed and I have more information.
The answer to this question lays at the bottom of UM1734 where a static allocation code snippet is given.
There are two problems with this code snippet that will come back and bite the unwary developer (waves hand):
1) the snippet allocates 4 x 32-bit items in an array with no explanation as to how they will be used. Perhaps 4 pointers to 4 USB device descriptors? NO, NOT AT ALL.
These 4 x 32-bit values are used to house a 540 byte CDC device descriptor.
The various values in memory after this array are then sacrificed to the descriptor.
2) Their implementation allocates N x 32-bit values, whereas malloc expects N x 8-bit values, so 3/4 of your allocated space (if you managed to get past issue 1) will never get used. In a memory constrained system. Where every byte could be important.
Sigh, now I have to get ahold of my customer and let him know that the 250 units in the field need a firmware update. (insert fornication expletive here).
Andrei
