USARTSerial::USARTSerial(HAL_USART_Serial serial, Ring_Buffer *rx_buffer, Ring_Buffer *tx_buffer) { _serial = serial; // Default is blocking mode _blocking = true; HAL_USART_Init(serial, rx_buffer, tx_buffer); }
/* executes once at startup */ void setup() { // uint32_t config = SERIAL_STOP_BITS_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_BITS_8 | SERIAL_FLOW_CONTROL_RTS_CTS; uint32_t config = 0; HAL_USART_Init(HAL_USART_SERIAL1, &uart_rx_buffer, &uart_tx_buffer); HAL_USART_BeginConfig(HAL_USART_SERIAL1, 115200, config, NULL); }
void LBF_USART2_Init (void) { // Based on Cube MX //Emulate SPI for now husart2.Instance = USART2; husart2.Init.BaudRate = 2000000; //Max APBclk/16 husart2.Init.WordLength = USART_WORDLENGTH_8B; //9 bits for later - husart2.Init.StopBits = USART_STOPBITS_1; husart2.Init.Parity = USART_PARITY_NONE; husart2.Init.Mode = USART_MODE_TX; //USART_MODE_TX_RX; husart2.Init.CLKPolarity = USART_POLARITY_LOW; husart2.Init.CLKPhase = USART_PHASE_1EDGE; husart2.Init.CLKLastBit = USART_LASTBIT_ENABLE; HAL_USART_Init(&husart2); }
/* USART2 init function */ void MX_USART2_Init(void) { husart2.Instance = USART2; husart2.Init.BaudRate = 38400; husart2.Init.WordLength = USART_WORDLENGTH_8B; husart2.Init.StopBits = USART_STOPBITS_1; husart2.Init.Parity = USART_PARITY_NONE; husart2.Init.Mode = USART_MODE_TX_RX; husart2.Init.CLKPolarity = USART_POLARITY_LOW; husart2.Init.CLKPhase = USART_PHASE_1EDGE; husart2.Init.CLKLastBit = USART_LASTBIT_DISABLE; if (HAL_USART_Init(&husart2) != HAL_OK) { Error_Handler(); } }
USARTSerial::USARTSerial(HAL_USART_Serial serial, Ring_Buffer *rx_buffer, Ring_Buffer *tx_buffer) { _serial = serial; HAL_USART_Init(serial, rx_buffer, tx_buffer); }
static void HW_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Init STM32F401 discovery LEDs */ BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_LED_Init(LED5); BSP_LED_Init(LED6); /* Init SPI and I2C */ GYRO_IO_Init(); COMPASSACCELERO_IO_Init(); /* Init on-board AccelMag */ BSP_ACCELERO_Init(); /* Init BlueNRG CS, Reset, and IRQ pin */ BLUENRG_CS_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = BLUENRG_CS_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init(BLUENRG_CS_GPIO_PORT, &GPIO_InitStruct); HAL_GPIO_WritePin(BLUENRG_CS_GPIO_PORT, BLUENRG_CS_PIN, GPIO_PIN_SET); BLUENRG_RESET_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = BLUENRG_RESET_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(BLUENRG_RESET_GPIO_PORT, &GPIO_InitStruct); BLUENRG_IRQ_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = BLUENRG_IRQ_PIN; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(BLUENRG_IRQ_GPIO_PORT, &GPIO_InitStruct); #ifdef WITH_USART /* Init USART port */ UsartHandle.Instance = USART2; UsartHandle.Init.BaudRate = 9600; UsartHandle.Init.WordLength = USART_WORDLENGTH_8B; UsartHandle.Init.StopBits = USART_STOPBITS_1; UsartHandle.Init.Parity = USART_PARITY_NONE; UsartHandle.Init.Mode = USART_MODE_TX_RX; if (HAL_USART_Init(&UsartHandle) != HAL_OK) { ColorfulRingOfDeath(); } #endif #ifdef WITH_VCP /* Init Device Library */ USBD_Init(&hUSBDDevice, &VCP_Desc, 0); /* Add Supported Class */ USBD_RegisterClass(&hUSBDDevice, &USBD_CDC); /* Add CDC Interface Class */ USBD_CDC_RegisterInterface(&hUSBDDevice, &USBD_CDC_fops); /* Start Device Process */ USBD_Start(&hUSBDDevice); #endif }