Example #1
0
/** @brief: set registers acc to info in huart
 *  @details: used in HAL_UART3Debug_Init, private
 ****************************************************************/
static void MyUARTSetConfig(UART_HandleTypeDef * huart) {
	uint32_t tmpreg = 0x00;

	/* Check the parameters */
	assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
	assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
	assert_param(IS_UART_PARITY(huart->Init.Parity));
	assert_param(IS_UART_MODE(huart->Init.Mode));

	/*------- UART-associated USART registers setting : CR2 Configuration ------*/
	/* Configure the UART Stop Bits: Set STOP[13:12] bits according
	 * to huart->Init.StopBits value */
	MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits);

	/*------- UART-associated USART registers setting : CR1 Configuration ------*/
	/* Configure the UART Word Length, Parity and mode:
	 Set the M bits according to huart->Init.WordLength value
	 Set PCE and PS bits according to huart->Init.Parity value
	 Set TE and RE bits according to huart->Init.Mode value */
	tmpreg = (uint32_t) huart->Init.WordLength | huart->Init.Parity
			| huart->Init.Mode;
	MODIFY_REG(huart->Instance->CR1,
			(uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE),
			tmpreg);

	/*------- UART-associated USART registers setting : CR3 Configuration ------*/
	/* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */
	MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE),
			huart->Init.HwFlowCtl);

	/*------- UART-associated USART registers setting : BRR Configuration ------*/
	if ((huart->Instance == USART1)) {
		huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(),
				huart->Init.BaudRate);
	} else {
		huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(),
				huart->Init.BaudRate);
	}
}
Example #2
0
/**
 * @brief	Read settings from SPI FLASH
 * @param	None
 * @retval	None
 */
static ErrorStatus prvReadSettingsFromSpiFlash()
{
	/* Read to a temporary settings variable */
	UARTSettings settings = {0};
	if (SPI_FLASH_ReadBufferDMA((uint8_t*)&settings, FLASH_ADR_UART1_SETTINGS, sizeof(UARTSettings), 2000) == SUCCESS)
	{
		/* Check to make sure the data is reasonable */
		if (IS_UART_CONNECTION(settings.connection) &&
			IS_UART_BAUDRATE(settings.baudRate) &&
			IS_UART_POWER(settings.power) &&
			IS_UART_MODE_APP(settings.mode) &&
			IS_GUI_TEXT_FORMAT(settings.textFormat))
		{
			/* Try to take the settings semaphore */
			if (xSettingsSemaphore != 0 && xSemaphoreTake(xSettingsSemaphore, 100) == pdTRUE)
			{
				/* Copy to the real settings variable */
				memcpy(&prvCurrentSettings, &settings, sizeof(UARTSettings));
				prvCurrentSettings.power = UARTPower_5V;
				prvCurrentSettings.mode = UARTMode_TX_RX;
				uart1UpdateWithNewSettings();
				/* Give back the semaphore now that we are done */
				xSemaphoreGive(xSettingsSemaphore);
				return SUCCESS;
			}
			else
			{
				/* Something went wrong as we couldn't take the semaphore */
				return ERROR;
			}
		}
		else
			return ERROR;
	}
	else
		return ERROR;
}
Example #3
0
/** @brief: set registers acc to info in huart
 *  @details: used in HAL_UART3Debug_Init, private
 ****************************************************************/
static void MyUARTSetConfig(UART_HandleTypeDef *huart) {
	uint32_t tmpreg = 0x00;

	/* Check the parameters */
	assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
	assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
	assert_param(IS_UART_PARITY(huart->Init.Parity));
	assert_param(IS_UART_MODE(huart->Init.Mode));

	/*-------------------------- USART CR2 Configuration -----------------------*/
	tmpreg = huart->Instance->CR2;

	/* Clear STOP[13:12] bits */
	tmpreg &= (uint32_t) ~((uint32_t) USART_CR2_STOP);

	/* Configure the UART Stop Bits: Set STOP[13:12] bits according to huart->Init.StopBits value */
	tmpreg |= (uint32_t) huart->Init.StopBits;

	/* Write to USART CR2 */
	huart->Instance->CR2 = (uint32_t) tmpreg;

	/*-------------------------- USART CR1 Configuration -----------------------*/
	tmpreg = huart->Instance->CR1;

	/* Clear M, PCE, PS, TE and RE bits */
	tmpreg &= (uint32_t) ~((uint32_t) (USART_CR1_M | USART_CR1_PCE
			| USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8));

	/* Configure the UART Word Length, Parity and mode:
	 Set the M bits according to huart->Init.WordLength value
	 Set PCE and PS bits according to huart->Init.Parity value
	 Set TE and RE bits according to huart->Init.Mode value
	 Set OVER8 bit according to huart->Init.OverSampling value */
	tmpreg |= (uint32_t) huart->Init.WordLength | huart->Init.Parity
			| huart->Init.Mode | huart->Init.OverSampling;

	/* Write to USART CR1 */
	huart->Instance->CR1 = (uint32_t) tmpreg;

	/*-------------------------- USART CR3 Configuration -----------------------*/
	tmpreg = huart->Instance->CR3;

	/* Clear CTSE and RTSE bits */
	tmpreg &= (uint32_t) ~((uint32_t) (USART_CR3_RTSE | USART_CR3_CTSE));

	/* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */
	tmpreg |= huart->Init.HwFlowCtl;

	/* Write to USART CR3 */
	huart->Instance->CR3 = (uint32_t) tmpreg;

	/* Check the Over Sampling */
	if (huart->Init.OverSampling == UART_OVERSAMPLING_8) {
		/*-------------------------- USART BRR Configuration ---------------------*/
		if ((huart->Instance == USART1) || (huart->Instance == USART6)) {
			huart->Instance->BRR = UART_DIV_SAMPLING8(HAL_RCC_GetPCLK2Freq(),
					huart->Init.BaudRate);
		} else {
			huart->Instance->BRR = UART_DIV_SAMPLING8(HAL_RCC_GetPCLK1Freq(),
					huart->Init.BaudRate);
		}
	} else {
		/*-------------------------- USART BRR Configuration ---------------------*/
		if ((huart->Instance == USART1) || (huart->Instance == USART6)) {
			huart->Instance->BRR = UART_DIV_SAMPLING16(HAL_RCC_GetPCLK2Freq(),
					huart->Init.BaudRate);
		} else {
			huart->Instance->BRR = UART_DIV_SAMPLING16(HAL_RCC_GetPCLK1Freq(),
					huart->Init.BaudRate);
		}
	}
}