void MX_USART1_UART_Init(void) { huart1.Instance = USART1; huart1.Init.BaudRate = 38400; huart1.Init.WordLength = UART_WORDLENGTH_7B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ; huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; HAL_RS485Ex_Init(&huart1, UART_DE_POLARITY_HIGH, 0, 0); }
/** * @brief CDC_Control_FS * Manage the CDC class requests * @param cmd: Command code * @param pbuf: Buffer containing command data (request parameters) * @param length: Number of data to be sent (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length) { /* USER CODE BEGIN 5 */ switch (cmd) { case CDC_SEND_ENCAPSULATED_COMMAND: break; case CDC_GET_ENCAPSULATED_RESPONSE: break; case CDC_SET_COMM_FEATURE: break; case CDC_GET_COMM_FEATURE: break; case CDC_CLEAR_COMM_FEATURE: break; /*******************************************************************************/ /* Line Coding Structure */ /*-----------------------------------------------------------------------------*/ /* Offset | Field | Size | Value | Description */ /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ /* 4 | bCharFormat | 1 | Number | Stop bits */ /* 0 - 1 Stop bit */ /* 1 - 1.5 Stop bits */ /* 2 - 2 Stop bits */ /* 5 | bParityType | 1 | Number | Parity */ /* 0 - None */ /* 1 - Odd */ /* 2 - Even */ /* 3 - Mark */ /* 4 - Space */ /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ /*******************************************************************************/ case CDC_SET_LINE_CODING: linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24)); linecoding.format = pbuf[4]; linecoding.paritytype = pbuf[5]; linecoding.datatype = pbuf[6]; huart2.Init.BaudRate = linecoding.bitrate; switch (linecoding.format) { case 0 : huart2.Init.StopBits = UART_STOPBITS_1; break; case 1 : huart2.Init.StopBits = UART_STOPBITS_1_5; break; case 2 : huart2.Init.StopBits = UART_STOPBITS_2; break; } switch (linecoding.paritytype) { case 0 : huart2.Init.Parity = UART_PARITY_NONE; break; case 1 : huart2.Init.Parity = UART_PARITY_ODD; break; case 2 : huart2.Init.Parity = UART_PARITY_EVEN; break; } //UART_WORDLENGTH_7B switch (linecoding.datatype) { case 7 : huart2.Init.WordLength = UART_WORDLENGTH_7B; break; case 8 : huart2.Init.WordLength = UART_WORDLENGTH_8B; break; } HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 0, 0); break; case CDC_GET_LINE_CODING: pbuf[0] = (uint8_t)(linecoding.bitrate); pbuf[1] = (uint8_t)(linecoding.bitrate >> 8); pbuf[2] = (uint8_t)(linecoding.bitrate >> 16); pbuf[3] = (uint8_t)(linecoding.bitrate >> 24); pbuf[4] = linecoding.format; pbuf[5] = linecoding.paritytype; pbuf[6] = linecoding.datatype; break; case CDC_SET_CONTROL_LINE_STATE: break; case CDC_SEND_BREAK: break; default: break; } return (USBD_OK); /* USER CODE END 5 */ }