aboutsummaryrefslogtreecommitdiff
path: root/src/uart-test/stm_init.c
diff options
context:
space:
mode:
authorFredrik Thulin <fredrik@thulin.net>2015-06-28 16:30:08 +0200
committerFredrik Thulin <fredrik@thulin.net>2015-06-28 16:30:08 +0200
commitc4678339908e413cbc6751cf863267807acafc85 (patch)
tree3692460e9e5b390f542a53b768599f1a012267dc /src/uart-test/stm_init.c
parentf6818cce54b99eecfc0d67437095d5adb955ee2c (diff)
Enable dual USART output functionality.
In other words, enable the USART connected to the serial port on the Raspberry Pi GPIO header. Sending a newline to either USART directs the generated entropy to that USART.
Diffstat (limited to 'src/uart-test/stm_init.c')
-rw-r--r--src/uart-test/stm_init.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/uart-test/stm_init.c b/src/uart-test/stm_init.c
index ad39080..384c4f8 100644
--- a/src/uart-test/stm_init.c
+++ b/src/uart-test/stm_init.c
@@ -40,11 +40,13 @@
#include "stm_init.h"
UART_HandleTypeDef huart1;
+UART_HandleTypeDef huart2;
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define UART1_BAUD_RATE 460800
+#define UART2_BAUD_RATE 115200
/* Private macro -------------------------------------------------------------*/
@@ -57,6 +59,7 @@ static void SystemClock_Config(void);
static void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
+static void MX_USART2_UART_Init(void);
/* Private functions ---------------------------------------------------------*/
/**
@@ -89,6 +92,7 @@ void stm_init(void)
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
+ MX_USART2_UART_Init();
}
@@ -138,8 +142,7 @@ static void SystemClock_Config(void)
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV8;
RCC_OscInitStruct.PLL.PLLQ = 7;
- if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
+ if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}
@@ -149,8 +152,7 @@ static void SystemClock_Config(void)
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* AHB prescaler */
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* APB1 prescaler /1 gives 42 MHz APB1 */
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; /* APB2 prescaler /1 gives 42 MHz APB2 */
- if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
- {
+ if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
Error_Handler();
}
@@ -179,11 +181,11 @@ void MX_GPIO_Init(void)
__GPIOC_CLK_ENABLE();
/*Configure LED GPIO pins PB12==red, PB13==yellow, PB14==green, PB15==blue */
- GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
+ GPIO_InitStruct.Pin = LED_RED | LED_YELLOW | LED_GREEN | LED_BLUE;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+ HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
/*Configure GPIO pin : PC9 (RCC_MCO_2) */
GPIO_InitStruct.Pin = GPIO_PIN_9;
@@ -209,22 +211,42 @@ void MX_GPIO_Init(void)
void MX_USART1_UART_Init(void)
{
- huart1.Instance = USART1;
- huart1.Init.BaudRate = UART1_BAUD_RATE;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- 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.Instance = USART1;
+ huart1.Init.BaudRate = UART1_BAUD_RATE;
+ huart1.Init.WordLength = UART_WORDLENGTH_8B;
+ 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;
- if(HAL_UART_Init(&huart1) != HAL_OK) {
+ if (HAL_UART_Init(&huart1) != HAL_OK) {
/* Initialization Error */
Error_Handler();
}
}
+/* USART2 init function */
+void MX_USART2_UART_Init(void)
+{
+
+ huart2.Instance = USART2;
+ huart2.Init.BaudRate = UART2_BAUD_RATE;
+ huart2.Init.WordLength = UART_WORDLENGTH_8B;
+ huart2.Init.StopBits = UART_STOPBITS_1;
+ huart2.Init.Parity = UART_PARITY_NONE;
+ huart2.Init.Mode = UART_MODE_TX_RX;
+ huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart2.Init.OverSampling = UART_OVERSAMPLING_16;
+
+ if (HAL_UART_Init(&huart2) != HAL_OK) {
+ /* Initialization Error */
+ Error_Handler();
+ }
+}
+
+
/**
* @brief This function is executed in case of error occurrence.
* @param None