Currently the defaults set for STM32F042 in STM32CubeMX v4.22.1, FW 1.9.0 for USB CDC will not compile after generation.
This is because the USB CDC Rx and Tx Buffers are set to 2048B each by default, which is too much considering the micro has 6kB RAM. In previous versions this was set to the minimum 4B and caused no problems (at least for me).
Can you please update the defaults to be compilable by default?
P.S. It took me quite a long time to figure this out, and it was only thanks to having a project I created with cube before.