STM32 gotchas
104.USB packet buffer memory in 'F042 is not bytewise writable

This issue has been reported here, and has not been confirmed by ST.

There are two types of USB modules in the various STM32: the device-only module (which only recently was expanded also by host mode in the 'G0Bx), and the device-host-OTG module licenced from Synopsys. The former is to be found in the lower-end 'F1 and 'L4, and in all 'L0, 'F0 and 'F3 which have USB at all.

This module has a heavy 16-bit legacy feel, underpinned by the fact that all its registers are 16-bit, although they are placed at 32-bit addresses. This may be also the reason for relatively weird access to the packet buffer memory, i.e. memory where outgoing data are stored by user and incoming data are stored by the hardware.

For this packet buffer memory, RM0091 rev.9 states:

The packet memory should be accessed only by byte (8-bit) or half-word (16-bit) accesses.

(and it also forbids word (32-bit) accesses). While reading it bytewise is OK, experiments on STM32F042 revealed, that writing the packet buffer memory byte-by-byte does not work as expected. Regardless of whether the byte is written to the lower or upper address of a halfword, it is in fact written simultaneously to both halfs of that halfword.

It is possible, that this behaviour can be found also in other STM32 models which feature the device-only USB module.