Kashish Haresh Shah
/
HXCClientShield
HXC Client Shield Repository.
Driver/debug.c@3:5e1a54378107, 2021-04-19 (annotated)
- Committer:
- kashish_mbed
- Date:
- Mon Apr 19 17:43:09 2021 +0000
- Revision:
- 3:5e1a54378107
- Parent:
- 0:bacc6e701fb4
Successful Build file with CmdProcess Functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kashish_mbed | 0:bacc6e701fb4 | 1 | /****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 2 | * @file debug.c |
kashish_mbed | 0:bacc6e701fb4 | 3 | * @author MCD Application Team |
kashish_mbed | 0:bacc6e701fb4 | 4 | * @version V1.1.4 |
kashish_mbed | 0:bacc6e701fb4 | 5 | * @date 08-January-2018 |
kashish_mbed | 0:bacc6e701fb4 | 6 | * @brief debug API |
kashish_mbed | 0:bacc6e701fb4 | 7 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 8 | * @attention |
kashish_mbed | 0:bacc6e701fb4 | 9 | * |
kashish_mbed | 0:bacc6e701fb4 | 10 | * <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V. |
kashish_mbed | 0:bacc6e701fb4 | 11 | * All rights reserved.</center></h2> |
kashish_mbed | 0:bacc6e701fb4 | 12 | * |
kashish_mbed | 0:bacc6e701fb4 | 13 | * Redistribution and use in source and binary forms, with or without |
kashish_mbed | 0:bacc6e701fb4 | 14 | * modification, are permitted, provided that the following conditions are met: |
kashish_mbed | 0:bacc6e701fb4 | 15 | * |
kashish_mbed | 0:bacc6e701fb4 | 16 | * 1. Redistribution of source code must retain the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 17 | * this list of conditions and the following disclaimer. |
kashish_mbed | 0:bacc6e701fb4 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
kashish_mbed | 0:bacc6e701fb4 | 19 | * this list of conditions and the following disclaimer in the documentation |
kashish_mbed | 0:bacc6e701fb4 | 20 | * and/or other materials provided with the distribution. |
kashish_mbed | 0:bacc6e701fb4 | 21 | * 3. Neither the name of STMicroelectronics nor the names of other |
kashish_mbed | 0:bacc6e701fb4 | 22 | * contributors to this software may be used to endorse or promote products |
kashish_mbed | 0:bacc6e701fb4 | 23 | * derived from this software without specific written permission. |
kashish_mbed | 0:bacc6e701fb4 | 24 | * 4. This software, including modifications and/or derivative works of this |
kashish_mbed | 0:bacc6e701fb4 | 25 | * software, must execute solely and exclusively on microcontroller or |
kashish_mbed | 0:bacc6e701fb4 | 26 | * microprocessor devices manufactured by or for STMicroelectronics. |
kashish_mbed | 0:bacc6e701fb4 | 27 | * 5. Redistribution and use of this software other than as permitted under |
kashish_mbed | 0:bacc6e701fb4 | 28 | * this license is void and will automatically terminate your rights under |
kashish_mbed | 0:bacc6e701fb4 | 29 | * this license. |
kashish_mbed | 0:bacc6e701fb4 | 30 | * |
kashish_mbed | 0:bacc6e701fb4 | 31 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" |
kashish_mbed | 0:bacc6e701fb4 | 32 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT |
kashish_mbed | 0:bacc6e701fb4 | 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
kashish_mbed | 0:bacc6e701fb4 | 34 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY |
kashish_mbed | 0:bacc6e701fb4 | 35 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT |
kashish_mbed | 0:bacc6e701fb4 | 36 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
kashish_mbed | 0:bacc6e701fb4 | 37 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
kashish_mbed | 0:bacc6e701fb4 | 38 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
kashish_mbed | 0:bacc6e701fb4 | 39 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
kashish_mbed | 0:bacc6e701fb4 | 40 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
kashish_mbed | 0:bacc6e701fb4 | 41 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
kashish_mbed | 0:bacc6e701fb4 | 42 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
kashish_mbed | 0:bacc6e701fb4 | 43 | * |
kashish_mbed | 0:bacc6e701fb4 | 44 | ****************************************************************************** |
kashish_mbed | 0:bacc6e701fb4 | 45 | */ |
kashish_mbed | 0:bacc6e701fb4 | 46 | |
kashish_mbed | 0:bacc6e701fb4 | 47 | /* Includes ------------------------------------------------------------------*/ |
kashish_mbed | 0:bacc6e701fb4 | 48 | #include <stdarg.h> |
kashish_mbed | 0:bacc6e701fb4 | 49 | #include "hw.h" |
kashish_mbed | 0:bacc6e701fb4 | 50 | #include "tiny_vsnprintf.h" |
kashish_mbed | 3:5e1a54378107 | 51 | #include "debug.h" |
kashish_mbed | 0:bacc6e701fb4 | 52 | |
kashish_mbed | 0:bacc6e701fb4 | 53 | static UART_HandleTypeDef debugUart; |
kashish_mbed | 0:bacc6e701fb4 | 54 | static char buffTx[256]; |
kashish_mbed | 0:bacc6e701fb4 | 55 | |
kashish_mbed | 0:bacc6e701fb4 | 56 | //static bool Debug_UART_Init(void); |
kashish_mbed | 0:bacc6e701fb4 | 57 | |
kashish_mbed | 0:bacc6e701fb4 | 58 | /** |
kashish_mbed | 0:bacc6e701fb4 | 59 | * @brief Initializes the debug |
kashish_mbed | 0:bacc6e701fb4 | 60 | * @param None |
kashish_mbed | 0:bacc6e701fb4 | 61 | * @retval None |
kashish_mbed | 0:bacc6e701fb4 | 62 | */ |
kashish_mbed | 0:bacc6e701fb4 | 63 | void DBG_Init( void ) |
kashish_mbed | 0:bacc6e701fb4 | 64 | { |
kashish_mbed | 0:bacc6e701fb4 | 65 | #ifdef DEBUG |
kashish_mbed | 0:bacc6e701fb4 | 66 | GPIO_InitTypeDef gpioinitstruct = {0}; |
kashish_mbed | 0:bacc6e701fb4 | 67 | |
kashish_mbed | 0:bacc6e701fb4 | 68 | /* Enable the GPIO_B Clock */ |
kashish_mbed | 0:bacc6e701fb4 | 69 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
kashish_mbed | 0:bacc6e701fb4 | 70 | |
kashish_mbed | 0:bacc6e701fb4 | 71 | /* Configure the GPIO pin */ |
kashish_mbed | 0:bacc6e701fb4 | 72 | gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP; |
kashish_mbed | 0:bacc6e701fb4 | 73 | gpioinitstruct.Pull = GPIO_PULLUP; |
kashish_mbed | 0:bacc6e701fb4 | 74 | gpioinitstruct.Speed = GPIO_SPEED_HIGH; |
kashish_mbed | 0:bacc6e701fb4 | 75 | |
kashish_mbed | 0:bacc6e701fb4 | 76 | gpioinitstruct.Pin = (GPIO_PIN_12 | GPIO_PIN_13| GPIO_PIN_14 | GPIO_PIN_15); |
kashish_mbed | 0:bacc6e701fb4 | 77 | HAL_GPIO_Init(GPIOB, &gpioinitstruct); |
kashish_mbed | 0:bacc6e701fb4 | 78 | |
kashish_mbed | 0:bacc6e701fb4 | 79 | /* Reset debug Pins */ |
kashish_mbed | 0:bacc6e701fb4 | 80 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); |
kashish_mbed | 0:bacc6e701fb4 | 81 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); |
kashish_mbed | 0:bacc6e701fb4 | 82 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); |
kashish_mbed | 0:bacc6e701fb4 | 83 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); |
kashish_mbed | 0:bacc6e701fb4 | 84 | #if 0 |
kashish_mbed | 0:bacc6e701fb4 | 85 | HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1); |
kashish_mbed | 0:bacc6e701fb4 | 86 | #endif |
kashish_mbed | 0:bacc6e701fb4 | 87 | |
kashish_mbed | 0:bacc6e701fb4 | 88 | __HAL_RCC_DBGMCU_CLK_ENABLE( ); |
kashish_mbed | 0:bacc6e701fb4 | 89 | |
kashish_mbed | 0:bacc6e701fb4 | 90 | HAL_DBGMCU_EnableDBGSleepMode( ); |
kashish_mbed | 0:bacc6e701fb4 | 91 | HAL_DBGMCU_EnableDBGStopMode( ); |
kashish_mbed | 0:bacc6e701fb4 | 92 | HAL_DBGMCU_EnableDBGStandbyMode( ); |
kashish_mbed | 0:bacc6e701fb4 | 93 | |
kashish_mbed | 0:bacc6e701fb4 | 94 | #else /* DEBUG */ |
kashish_mbed | 0:bacc6e701fb4 | 95 | /* sw interface off*/ |
kashish_mbed | 0:bacc6e701fb4 | 96 | GPIO_InitTypeDef GPIO_InitStructure = {0}; |
kashish_mbed | 0:bacc6e701fb4 | 97 | |
kashish_mbed | 0:bacc6e701fb4 | 98 | GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
kashish_mbed | 0:bacc6e701fb4 | 99 | GPIO_InitStructure.Pull = GPIO_NOPULL; |
kashish_mbed | 0:bacc6e701fb4 | 100 | GPIO_InitStructure.Pin = (GPIO_PIN_13 | GPIO_PIN_14); |
kashish_mbed | 0:bacc6e701fb4 | 101 | __GPIOA_CLK_ENABLE(); |
kashish_mbed | 0:bacc6e701fb4 | 102 | HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); |
kashish_mbed | 0:bacc6e701fb4 | 103 | __GPIOA_CLK_DISABLE(); |
kashish_mbed | 0:bacc6e701fb4 | 104 | |
kashish_mbed | 0:bacc6e701fb4 | 105 | // ToDo : Code below does something and code wont work. Need to investigate more. |
kashish_mbed | 0:bacc6e701fb4 | 106 | //__HAL_RCC_DBGMCU_CLK_ENABLE( ); |
kashish_mbed | 0:bacc6e701fb4 | 107 | //HAL_DBGMCU_DisableDBGSleepMode( ); |
kashish_mbed | 0:bacc6e701fb4 | 108 | //HAL_DBGMCU_DisableDBGStopMode( ); |
kashish_mbed | 0:bacc6e701fb4 | 109 | //HAL_DBGMCU_DisableDBGStandbyMode( ); |
kashish_mbed | 0:bacc6e701fb4 | 110 | //__HAL_RCC_DBGMCU_CLK_DISABLE( ); |
kashish_mbed | 0:bacc6e701fb4 | 111 | #endif |
kashish_mbed | 0:bacc6e701fb4 | 112 | |
kashish_mbed | 0:bacc6e701fb4 | 113 | Debug_UART_Init(); |
kashish_mbed | 0:bacc6e701fb4 | 114 | } |
kashish_mbed | 0:bacc6e701fb4 | 115 | |
kashish_mbed | 0:bacc6e701fb4 | 116 | void Debug_UART_Init(void) |
kashish_mbed | 0:bacc6e701fb4 | 117 | { |
kashish_mbed | 0:bacc6e701fb4 | 118 | debugUart.Instance = DBG_UARTX; |
kashish_mbed | 0:bacc6e701fb4 | 119 | debugUart.Init.BaudRate = 9600; |
kashish_mbed | 0:bacc6e701fb4 | 120 | debugUart.Init.WordLength = UART_WORDLENGTH_8B; |
kashish_mbed | 0:bacc6e701fb4 | 121 | debugUart.Init.StopBits = UART_STOPBITS_1; |
kashish_mbed | 0:bacc6e701fb4 | 122 | debugUart.Init.Parity = UART_PARITY_NONE; |
kashish_mbed | 0:bacc6e701fb4 | 123 | debugUart.Init.Mode = UART_MODE_TX_RX; |
kashish_mbed | 0:bacc6e701fb4 | 124 | debugUart.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
kashish_mbed | 0:bacc6e701fb4 | 125 | debugUart.Init.OverSampling = UART_OVERSAMPLING_16; |
kashish_mbed | 0:bacc6e701fb4 | 126 | debugUart.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; |
kashish_mbed | 0:bacc6e701fb4 | 127 | debugUart.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; |
kashish_mbed | 0:bacc6e701fb4 | 128 | |
kashish_mbed | 0:bacc6e701fb4 | 129 | HAL_UART_Init(&debugUart); |
kashish_mbed | 0:bacc6e701fb4 | 130 | } |
kashish_mbed | 0:bacc6e701fb4 | 131 | |
kashish_mbed | 0:bacc6e701fb4 | 132 | void Debug_UART_SendBytes(const char *format, ...) |
kashish_mbed | 0:bacc6e701fb4 | 133 | { |
kashish_mbed | 0:bacc6e701fb4 | 134 | va_list args; |
kashish_mbed | 0:bacc6e701fb4 | 135 | static __IO uint16_t len = 0; |
kashish_mbed | 0:bacc6e701fb4 | 136 | uint16_t current_len; |
kashish_mbed | 0:bacc6e701fb4 | 137 | |
kashish_mbed | 0:bacc6e701fb4 | 138 | va_start(args, format); |
kashish_mbed | 0:bacc6e701fb4 | 139 | |
kashish_mbed | 0:bacc6e701fb4 | 140 | BACKUP_PRIMASK(); |
kashish_mbed | 0:bacc6e701fb4 | 141 | DISABLE_IRQ(); |
kashish_mbed | 0:bacc6e701fb4 | 142 | if (len != 0) |
kashish_mbed | 0:bacc6e701fb4 | 143 | { |
kashish_mbed | 0:bacc6e701fb4 | 144 | if (len != sizeof(buffTx)) |
kashish_mbed | 0:bacc6e701fb4 | 145 | { |
kashish_mbed | 0:bacc6e701fb4 | 146 | current_len = len; /* use current_len instead of volatile len in below computation */ |
kashish_mbed | 0:bacc6e701fb4 | 147 | len = current_len + tiny_vsnprintf_like(buffTx + current_len, sizeof(buffTx) - current_len, format, args); |
kashish_mbed | 0:bacc6e701fb4 | 148 | } |
kashish_mbed | 0:bacc6e701fb4 | 149 | RESTORE_PRIMASK(); |
kashish_mbed | 0:bacc6e701fb4 | 150 | va_end(args); |
kashish_mbed | 0:bacc6e701fb4 | 151 | return; |
kashish_mbed | 0:bacc6e701fb4 | 152 | } |
kashish_mbed | 0:bacc6e701fb4 | 153 | else |
kashish_mbed | 0:bacc6e701fb4 | 154 | { |
kashish_mbed | 0:bacc6e701fb4 | 155 | len = tiny_vsnprintf_like(buffTx, sizeof(buffTx), format, args); |
kashish_mbed | 0:bacc6e701fb4 | 156 | } |
kashish_mbed | 0:bacc6e701fb4 | 157 | |
kashish_mbed | 0:bacc6e701fb4 | 158 | current_len = len; |
kashish_mbed | 0:bacc6e701fb4 | 159 | RESTORE_PRIMASK(); |
kashish_mbed | 0:bacc6e701fb4 | 160 | HAL_UART_Transmit(&debugUart, (uint8_t *)buffTx, current_len, 5000); |
kashish_mbed | 0:bacc6e701fb4 | 161 | len = 0; // ToDo |
kashish_mbed | 0:bacc6e701fb4 | 162 | va_end(args); |
kashish_mbed | 0:bacc6e701fb4 | 163 | } |
kashish_mbed | 0:bacc6e701fb4 | 164 | |
kashish_mbed | 3:5e1a54378107 | 165 | uint8_t Debug_Read_Char(char * c) |
kashish_mbed | 3:5e1a54378107 | 166 | { |
kashish_mbed | 3:5e1a54378107 | 167 | if(HW_UART_Modem_IsNewCharReceived()){ |
kashish_mbed | 3:5e1a54378107 | 168 | HW_UART_Modem_GetNewChar(); |
kashish_mbed | 3:5e1a54378107 | 169 | // DBG_PRINTF("Debug RX %c \n\r",*c); |
kashish_mbed | 3:5e1a54378107 | 170 | return 1; |
kashish_mbed | 3:5e1a54378107 | 171 | } |
kashish_mbed | 3:5e1a54378107 | 172 | return 0; |
kashish_mbed | 3:5e1a54378107 | 173 | } |
kashish_mbed | 3:5e1a54378107 | 174 | |
kashish_mbed | 3:5e1a54378107 | 175 | void Debug_Reset_Input_Buffer(void) |
kashish_mbed | 3:5e1a54378107 | 176 | { |
kashish_mbed | 3:5e1a54378107 | 177 | HW_UART_ResetBuffer(); |
kashish_mbed | 3:5e1a54378107 | 178 | } |
kashish_mbed | 3:5e1a54378107 | 179 | |
kashish_mbed | 0:bacc6e701fb4 | 180 | /** |
kashish_mbed | 0:bacc6e701fb4 | 181 | * @brief Error_Handler |
kashish_mbed | 0:bacc6e701fb4 | 182 | * @param None |
kashish_mbed | 0:bacc6e701fb4 | 183 | * @retval None |
kashish_mbed | 0:bacc6e701fb4 | 184 | */ |
kashish_mbed | 0:bacc6e701fb4 | 185 | void Error_Handler( void ) |
kashish_mbed | 0:bacc6e701fb4 | 186 | { |
kashish_mbed | 0:bacc6e701fb4 | 187 | DBG_PRINTF("Error_Handler\n\r"); |
kashish_mbed | 0:bacc6e701fb4 | 188 | while(1); |
kashish_mbed | 0:bacc6e701fb4 | 189 | } |
kashish_mbed | 0:bacc6e701fb4 | 190 | |
kashish_mbed | 0:bacc6e701fb4 | 191 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
kashish_mbed | 0:bacc6e701fb4 | 192 | |
kashish_mbed | 0:bacc6e701fb4 | 193 | |
kashish_mbed | 0:bacc6e701fb4 | 194 |