diff options
author | Paul Selkirk <paul@psgd.org> | 2015-11-11 14:46:28 -0500 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2015-11-11 14:46:28 -0500 |
commit | 4c6b056b8467bb6513224527ff3120ef905de397 (patch) | |
tree | bb2cc71ae6931dce7327af54b17f42591aa16f75 /src/stm-uart.c | |
parent | df8f45c0d06e64b3901f1cce4e74cbde038737f2 (diff) |
Lots of cleanup.
Clean up and simplify(?) Makefile.
Add copyrights as needed.
Add include guard to stm-fmc.h.
Move MX_USART2_UART_Init back to stm-init.c for possible copyright reasons.
Move libc, src, and include files to top level.
Diffstat (limited to 'src/stm-uart.c')
-rw-r--r-- | src/stm-uart.c | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/stm-uart.c b/src/stm-uart.c deleted file mode 100644 index 7676645..0000000 --- a/src/stm-uart.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" -#include "stm-uart.h" - -#include <string.h> - -static UART_HandleTypeDef huart2; - -extern void Error_Handler(); - - -/* Private variables ---------------------------------------------------------*/ - -/* Private function prototypes -----------------------------------------------*/ - -/* USART2 init function */ -void MX_USART2_UART_Init(void) -{ - huart2.Instance = USART2; - huart2.Init.BaudRate = USART2_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(); - } -} - -void uart_send_char(uint8_t ch) -{ - HAL_UART_Transmit(&huart2, &ch, 1, 0x1); -} - -void uart_send_string(char *s) -{ - HAL_UART_Transmit(&huart2, (uint8_t *) s, strlen(s), 0x1); -} - -/* Generalized routine to send binary, decimal, and hex integers. - * This code is adapted from Chris Giese's printf.c - */ -void uart_send_number(uint32_t num, uint8_t digits, uint8_t radix) -{ - #define BUFSIZE 32 - char buf[BUFSIZE]; - char *where = buf + BUFSIZE; - - /* initialize buf so we can add leading 0 by adjusting the pointer */ - memset(buf, '0', BUFSIZE); - - /* build the string backwards, starting with the least significant digit */ - do { - uint32_t temp; - temp = num % radix; - where--; - if (temp < 10) - *where = temp + '0'; - else - *where = temp - 10 + 'A'; - num = num / radix; - } while (num != 0); - - if (where > buf + BUFSIZE - digits) - /* pad with leading 0 */ - where = buf + BUFSIZE - digits; - else - /* number is larger than the specified number of digits */ - digits = buf + BUFSIZE - where; - - HAL_UART_Transmit(&huart2, (uint8_t *) where, digits, 0x1); -} |