Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file debug.c
Sergunb 0:8918a71cdbe9 3 * @brief Debugging facilities
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 10 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 11 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 12 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 13 *
Sergunb 0:8918a71cdbe9 14 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 17 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 18 *
Sergunb 0:8918a71cdbe9 19 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 20 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 22 *
Sergunb 0:8918a71cdbe9 23 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 24 * @version 1.7.6
Sergunb 0:8918a71cdbe9 25 **/
Sergunb 0:8918a71cdbe9 26
Sergunb 0:8918a71cdbe9 27 //Dependencies
Sergunb 0:8918a71cdbe9 28 #include "stm32f7xx.h"
Sergunb 0:8918a71cdbe9 29 #include "stm32f7xx_hal.h"
Sergunb 0:8918a71cdbe9 30 #include "debug.h"
Sergunb 0:8918a71cdbe9 31
Sergunb 0:8918a71cdbe9 32 //Variable declaration
Sergunb 0:8918a71cdbe9 33 static UART_HandleTypeDef UART_Handle;
Sergunb 0:8918a71cdbe9 34
Sergunb 0:8918a71cdbe9 35
Sergunb 0:8918a71cdbe9 36 /**
Sergunb 0:8918a71cdbe9 37 * @brief Debug UART initialization
Sergunb 0:8918a71cdbe9 38 * @param[in] baudrate UART baudrate
Sergunb 0:8918a71cdbe9 39 **/
Sergunb 0:8918a71cdbe9 40
Sergunb 0:8918a71cdbe9 41 void debugInit(uint32_t baudrate)
Sergunb 0:8918a71cdbe9 42 {
Sergunb 0:8918a71cdbe9 43 GPIO_InitTypeDef GPIO_InitStructure;
Sergunb 0:8918a71cdbe9 44
Sergunb 0:8918a71cdbe9 45 //Enable GPIOD clock
Sergunb 0:8918a71cdbe9 46 __HAL_RCC_GPIOD_CLK_ENABLE();
Sergunb 0:8918a71cdbe9 47 //Enable USART3 clock
Sergunb 0:8918a71cdbe9 48 __HAL_RCC_USART3_CLK_ENABLE();
Sergunb 0:8918a71cdbe9 49
Sergunb 0:8918a71cdbe9 50 //Configure USART3_TX (PD8)
Sergunb 0:8918a71cdbe9 51 GPIO_InitStructure.Pin = GPIO_PIN_8;
Sergunb 0:8918a71cdbe9 52 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
Sergunb 0:8918a71cdbe9 53 GPIO_InitStructure.Pull = GPIO_PULLUP;
Sergunb 0:8918a71cdbe9 54 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
Sergunb 0:8918a71cdbe9 55 GPIO_InitStructure.Alternate = GPIO_AF7_USART3;
Sergunb 0:8918a71cdbe9 56 HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
Sergunb 0:8918a71cdbe9 57
Sergunb 0:8918a71cdbe9 58 //Configure USART3_RX (PD9)
Sergunb 0:8918a71cdbe9 59 GPIO_InitStructure.Pin = GPIO_PIN_9;
Sergunb 0:8918a71cdbe9 60 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
Sergunb 0:8918a71cdbe9 61 GPIO_InitStructure.Pull = GPIO_PULLUP;
Sergunb 0:8918a71cdbe9 62 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
Sergunb 0:8918a71cdbe9 63 GPIO_InitStructure.Alternate = GPIO_AF7_USART3;
Sergunb 0:8918a71cdbe9 64 HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
Sergunb 0:8918a71cdbe9 65
Sergunb 0:8918a71cdbe9 66 //Configure USART3
Sergunb 0:8918a71cdbe9 67 UART_Handle.Instance = USART3;
Sergunb 0:8918a71cdbe9 68 UART_Handle.Init.BaudRate = baudrate;
Sergunb 0:8918a71cdbe9 69 UART_Handle.Init.WordLength = UART_WORDLENGTH_8B;
Sergunb 0:8918a71cdbe9 70 UART_Handle.Init.StopBits = UART_STOPBITS_1;
Sergunb 0:8918a71cdbe9 71 UART_Handle.Init.Parity = UART_PARITY_NONE;
Sergunb 0:8918a71cdbe9 72 UART_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
Sergunb 0:8918a71cdbe9 73 UART_Handle.Init.Mode = UART_MODE_TX_RX;
Sergunb 0:8918a71cdbe9 74 HAL_UART_Init(&UART_Handle);
Sergunb 0:8918a71cdbe9 75 }
Sergunb 0:8918a71cdbe9 76
Sergunb 0:8918a71cdbe9 77
Sergunb 0:8918a71cdbe9 78 /**
Sergunb 0:8918a71cdbe9 79 * @brief Display the contents of an array
Sergunb 0:8918a71cdbe9 80 * @param[in] stream Pointer to a FILE object that identifies an output stream
Sergunb 0:8918a71cdbe9 81 * @param[in] prepend String to prepend to the left of each line
Sergunb 0:8918a71cdbe9 82 * @param[in] data Pointer to the data array
Sergunb 0:8918a71cdbe9 83 * @param[in] length Number of bytes to display
Sergunb 0:8918a71cdbe9 84 **/
Sergunb 0:8918a71cdbe9 85
Sergunb 0:8918a71cdbe9 86 void debugDisplayArray(FILE *stream,
Sergunb 0:8918a71cdbe9 87 const char_t *prepend, const void *data, size_t length)
Sergunb 0:8918a71cdbe9 88 {
Sergunb 0:8918a71cdbe9 89 uint_t i;
Sergunb 0:8918a71cdbe9 90
Sergunb 0:8918a71cdbe9 91 for(i = 0; i < length; i++)
Sergunb 0:8918a71cdbe9 92 {
Sergunb 0:8918a71cdbe9 93 //Beginning of a new line?
Sergunb 0:8918a71cdbe9 94 if((i % 16) == 0)
Sergunb 0:8918a71cdbe9 95 fprintf(stream, "%s", prepend);
Sergunb 0:8918a71cdbe9 96 //Display current data byte
Sergunb 0:8918a71cdbe9 97 fprintf(stream, "%02" PRIX8 " ", *((uint8_t *) data + i));
Sergunb 0:8918a71cdbe9 98 //End of current line?
Sergunb 0:8918a71cdbe9 99 if((i % 16) == 15 || i == (length - 1))
Sergunb 0:8918a71cdbe9 100 fprintf(stream, "\r\n");
Sergunb 0:8918a71cdbe9 101 }
Sergunb 0:8918a71cdbe9 102 }
Sergunb 0:8918a71cdbe9 103
Sergunb 0:8918a71cdbe9 104
Sergunb 0:8918a71cdbe9 105 /**
Sergunb 0:8918a71cdbe9 106 * @brief Write character to stream
Sergunb 0:8918a71cdbe9 107 * @param[in] c The character to be written
Sergunb 0:8918a71cdbe9 108 * @param[in] stream Pointer to a FILE object that identifies an output stream
Sergunb 0:8918a71cdbe9 109 * @return On success, the character written is returned. If a writing
Sergunb 0:8918a71cdbe9 110 * error occurs, EOF is returned
Sergunb 0:8918a71cdbe9 111 **/
Sergunb 0:8918a71cdbe9 112
Sergunb 0:8918a71cdbe9 113 int_t fputc(int_t c, FILE *stream)
Sergunb 0:8918a71cdbe9 114 {
Sergunb 0:8918a71cdbe9 115 //Standard output or error output?
Sergunb 0:8918a71cdbe9 116 if(stream == stdout || stream == stderr)
Sergunb 0:8918a71cdbe9 117 {
Sergunb 0:8918a71cdbe9 118 //Character to be written
Sergunb 0:8918a71cdbe9 119 uint8_t ch = c;
Sergunb 0:8918a71cdbe9 120
Sergunb 0:8918a71cdbe9 121 //Transmit data
Sergunb 0:8918a71cdbe9 122 HAL_UART_Transmit(&UART_Handle, &ch, 1, HAL_MAX_DELAY);
Sergunb 0:8918a71cdbe9 123
Sergunb 0:8918a71cdbe9 124 //On success, the character written is returned
Sergunb 0:8918a71cdbe9 125 return c;
Sergunb 0:8918a71cdbe9 126 }
Sergunb 0:8918a71cdbe9 127 //Unknown output?
Sergunb 0:8918a71cdbe9 128 else
Sergunb 0:8918a71cdbe9 129 {
Sergunb 0:8918a71cdbe9 130 //If a writing error occurs, EOF is returned
Sergunb 0:8918a71cdbe9 131 return EOF;
Sergunb 0:8918a71cdbe9 132 }
Sergunb 0:8918a71cdbe9 133 }
Sergunb 0:8918a71cdbe9 134