cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G Discovery UART MIDI

misterstarshine
Associate III
Posted on October 24, 2016 at 01:00

Hi.

I'd like to use the UART for MIDI input. I've configured the UART on my STM32F7-Discovery board and perform a led toggle whenever an incoming message is received. I'm using the interrupt mode similar to the Cube firmware example ''UART_TwoBoards_ComIT''. However my receive buffer is unchanged and I've initialized it with dummy-data just to confirm that it doesn't seem to get updated by the USART6_IrqHandler routine. What I get is a ''frame error'' in the UART_ErrorCallback routine. Could this have anything to do with the fact that a MIDI-note down consists of 3 bytes? When I hit a note on the MIDI-keyboard the IRQ-handler is only triggered once! This is unlike how I've worked with UART on other platforms. Then the incoming callback is triggered three times on a MIDI note-on event since it consists of 3 bytes.

void
USART6_IRQHandler(
void
)
{
extern
uint8_t aRxBuffer[];
BSP_LED_Toggle(LED1);
BSP_LCD_DisplayIntAt(0, 70, *(UartHandle.pRxBuffPtr), CENTER_MODE);
HAL_UART_IRQHandler(&UartHandle);
}
void
my_UART_Init(UART_HandleTypeDef *UartHandle)
{
UartHandle->Instance = USART6;
UartHandle->Init.BaudRate = 31250;
UartHandle->Init.WordLength = UART_WORDLENGTH_8B;
UartHandle->Init.StopBits = UART_STOPBITS_1;
UartHandle->Init.Parity = UART_PARITY_NONE;
UartHandle->Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle->Init.Mode = UART_MODE_TX_RX;
UartHandle->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if
(HAL_UART_DeInit(UartHandle) != HAL_OK)
{
Error_Handler();
}
if
(HAL_UART_Init(UartHandle) != HAL_OK)
{
Error_Handler();
}
}

#stm32f746g-discovery-uart-midi
2 REPLIES 2
Posted on October 24, 2016 at 02:17

I would suggest prioritizing the call back into the HAL handler, and not trying to paint to the LCD

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
misterstarshine
Associate III
Posted on October 24, 2016 at 11:52

That also crossed my mind. I've tried to run it with only the HAL_UART_IRQHandler(&UartHandle) but still this ''frame error''. The frame error problem seems to be caused by something else obviously.

Edit: I thought I could just take the hardware part for MIDI-in (4N35 optocoupler) since it worked well under a Teensy environment but that is a 5V environment however. I have found out that my setup suffers from noise problems. However the ''noise'' error code rarely showed up. Shortening the lead between the Rx input and optocoupler output allows me to get all three interrupt callbacks with no error callback at all. However nothing is still written to the receive buffer. The libraries I have access to don't have a USART_ReceiveData function implemented.