Problems getting UART5 reception working with byte-level interrupts (SOLVED)
This situation arose when working with the Nucleo-G0B1RE board and Cube Version: 1.18.1.
It was desired to do per-byte reception over UART channel 5 on PD2/3 with interrupts. The VAST majority of articles discussing this process state to use the HAL_UART_RxCpltCallback() function to read the byte from the UART buffer, since this function gets called by the ISR chain on UART interrupt. However, these same articles also frequently fail to mention the following:
1) The HAL_UART_RxCpltCallback won't get called unless it gets registered first. This can be done with the HAL_UART_RegisterCallback() function...
2) ...BUT, even if you register functions in this manner, they won't be used unless enabled by internal configuration files. To do that, you have to pull up the IOC file and go to the Project Manager section. Go to the "Advanced Settings" and you will see that you have to explicitly enable callbacks for each peripheral (Not known if enabling USART also triggers UART callbacks if UART is not also enabled).
3) BUT, even if you do that, the HAL_UART_RxCpltCallback still won't be used. There are around eight places in the code that would invoke this callback, and none of them were linked to basic byte reception, they were all tied to some advanced feature. To get this function to be triggered, it had to be stored as the RxISR function for the UART object, which didn't involve a registration function, just a simple assignment to the UART object created by Cube:
huart5.RxISR = HAL_UART_RxCpltCallback; // Note: UART5 being usedThis was manually placed at the end of the UART initialization function created by Cube.
4) Even with this done, the callback wasn't getting invoked. Why? Because Cube didn't correctly enable all the required interrupt settings. There's a single tickbox you can check to enable interrupts for UART5, however, this is just the "allow an interrupt on any UART sub-activity" global UART setting. To get the RX interrupt going, this had to be added manually as well (again, also placed at the end of the Cube UART init function).
__HAL_UART_ENABLE_IT(&huart5, UART_IT_RXNE); // Receive data register not emptyThere does not seem to be any configuration options available in Cube to make sure that any of these sub-interrupt enable bits are set by default in their code generation process. Hopefully this information will be helpful to others.
