Ejemplo n.º 1
0
static int uart_stm32_fifo_read(struct device *dev, uint8_t *rx_data,
				  const int size)
{
	struct uart_stm32_data *data = DEV_DATA(dev);
	UART_HandleTypeDef *UartHandle = &data->huart;
	uint8_t num_rx = 0;

	while ((size - num_rx > 0) && __HAL_UART_GET_FLAG(UartHandle,
		UART_FLAG_RXNE)) {
		/* Clear the interrupt */
		__HAL_UART_CLEAR_FLAG(UartHandle, UART_FLAG_RXNE);

		/* Receive a character (8bit , parity none) */
#if defined(CONFIG_SOC_SERIES_STM32F1X) || defined(CONFIG_SOC_SERIES_STM32F4X)
		/* Use direct access for F1, F4 until Low Level API is available
		 * Once it is we can remove the if/else
		 */
		rx_data[num_rx++] = (uint8_t)(UartHandle->Instance->DR &
					(uint8_t)0x00FF);
#else
		rx_data[num_rx++] = LL_USART_ReceiveData8(UartHandle->Instance);
#endif
	}
	return num_rx;
}
Ejemplo n.º 2
0
void USART6_IRQHandler(void) {
	/* Check RXNE flag value in SR register */
	if(LL_USART_IsActiveFlag_RXNE(USART6) && LL_USART_IsEnabledIT_RXNE(USART6)) {
		/* RXNE flag will be cleared by reading of DR register (done in call) */
		/* Call function in charge of handling Character reception */
		if(rx_index >= RX_BUFFER_SIZE - 1) { 
			printf("Error, command too Big\r\n");
			rx_index = 0;
			return; 
		}

		uint8_t rx_char = LL_USART_ReceiveData8(USART6);
		if(echo) { printf("%c", rx_char); }

		rx_buffer[rx_index++] = rx_char;
		if(rx_char == '\r' || rx_char == '\n') {
			uint16_t bytes_consumed;
			if(rx_index == 1) { bytes_consumed = 1; }
			else {
				bytes_consumed = process_serial_buffer(rx_buffer, rx_index);
			}
			if(bytes_consumed >= rx_index) { rx_index = 0; }
			else { rx_index -= bytes_consumed; }
		}
	}
}
Ejemplo n.º 3
0
static int uart_stm32_poll_in(struct device *dev, unsigned char *c)
{
	USART_TypeDef *UartInstance = UART_STRUCT(dev);

	/* Clear overrun error flag */
	if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
		LL_USART_ClearFlag_ORE(UartInstance);
	}

	if (!LL_USART_IsActiveFlag_RXNE(UartInstance)) {
		return -1;
	}

	*c = (unsigned char)LL_USART_ReceiveData8(UartInstance);

	return 0;
}
Ejemplo n.º 4
0
static int uart_stm32_fifo_read(struct device *dev, u8_t *rx_data,
				  const int size)
{
	USART_TypeDef *UartInstance = UART_STRUCT(dev);
	u8_t num_rx = 0U;

	while ((size - num_rx > 0) &&
	       LL_USART_IsActiveFlag_RXNE(UartInstance)) {
		/* RXNE flag will be cleared upon read from DR|RDR register */

		/* Receive a character (8bit , parity none) */
		rx_data[num_rx++] = LL_USART_ReceiveData8(UartInstance);

		/* Clear overrun error flag */
		if (LL_USART_IsActiveFlag_ORE(UartInstance)) {
			LL_USART_ClearFlag_ORE(UartInstance);
		}
	}

	return num_rx;
}
Ejemplo n.º 5
0
void USART4_5_IRQHandler(void)
{
    int rx_ready = 0;
    char rx;

    CPSR_ALLOC();
    RHINO_CPU_INTRPT_DISABLE();

    if ( LL_USART_IsActiveFlag_RXNE(USART4) && (LL_USART_IsEnabledIT_RXNE(USART4 ) != RESET) )
    {
        /* no need to clear the RXNE flag because it is auto cleared by reading the data*/
        rx = LL_USART_ReceiveData8( USART4 );
        rx_ready = 1;
        //PRINTF("%c\r\n", rx);
    }
    if (rx_ready) {
#ifdef CONFIG_LINKWAN_TEST
        extern void linkwan_test_cli_cb(uint8_t cmd);
        linkwan_test_cli_cb(rx);
#endif
    }

    RHINO_CPU_INTRPT_ENABLE();
}