diff options
author | Eugene Krashtan <Eugene.Krashtan@opensynergy.com> | 2019-03-11 12:47:58 +0200 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-03-24 12:10:11 -0400 |
commit | b822f389237981043a8033aa4232e8b084137b2c (patch) | |
tree | fec159e50a3314cabbe18352e26c10db39c6f621 /src/stm32f0/log.c | |
parent | 74c6a85cde9327b13a52b1d142b698e00e2d6122 (diff) | |
download | kutter-b822f389237981043a8033aa4232e8b084137b2c.tar.gz kutter-b822f389237981043a8033aa4232e8b084137b2c.tar.xz kutter-b822f389237981043a8033aa4232e8b084137b2c.zip |
stm32f0: New target STM32F0 added.
Signed-off-by: Eugene Krashtan <Eugene.Krashtan@opensynergy.com>
Diffstat (limited to 'src/stm32f0/log.c')
-rw-r--r-- | src/stm32f0/log.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/stm32f0/log.c b/src/stm32f0/log.c new file mode 100644 index 00000000..cbfb00cf --- /dev/null +++ b/src/stm32f0/log.c @@ -0,0 +1,79 @@ +/* + * log.c + * This file not required for regular Klipper usage, but hw/sw developer + * can use USART TX pin instead SWO for debugging purposes + * + * Created on: Jan 17, 2019 + * Author: eug + */ + +#include "string.h" +#include "stm32f0xx_hal.h" +#include "log.h" + +UART_HandleTypeDef huart2; + +void LogInit(void) +{ + huart2.Instance = USART2; + huart2.Init.BaudRate = 115200; + huart2.Init.WordLength = UART_WORDLENGTH_8B; + huart2.Init.StopBits = UART_STOPBITS_1; + huart2.Init.Parity = UART_PARITY_NONE; + huart2.Init.Mode = UART_MODE_TX; + huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart2.Init.OverSampling = UART_OVERSAMPLING_16; + huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + HAL_UART_Init(&huart2); + + lprint("hello"); +} + +/** +* @brief String out +* @param msg: Null-terminated string +* @retval None +*/ +void lprint(char *msg) +{ + HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), 100); +} + +/** +* @brief Binary data out +* @param msg: binary data +* @param len: data length +* @retval None +*/ +void lnprint(char *msg, size_t len) +{ + HAL_UART_Transmit(&huart2, (uint8_t *)msg, len, 100); +} + +/** +* @brief UART MSP Initialization +* @param huart: UART handle pointer +* @retval None +*/ +void HAL_UART_MspInit(UART_HandleTypeDef* huart) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(huart->Instance==USART2) + { + __HAL_RCC_USART2_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USART2 GPIO Configuration + PA2 ------> USART2_TX + PA3 ------> USART2_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF1_USART2; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + } +} |