From b822f389237981043a8033aa4232e8b084137b2c Mon Sep 17 00:00:00 2001 From: Eugene Krashtan Date: Mon, 11 Mar 2019 12:47:58 +0200 Subject: stm32f0: New target STM32F0 added. Signed-off-by: Eugene Krashtan --- src/stm32f0/log.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/stm32f0/log.c (limited to 'src/stm32f0/log.c') 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); + } +} -- cgit v1.2.3-70-g09d2