Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "common.h"
#include "main.h"
Int2Str(uint8_t *, uint32_t)
Str2Int(uint8_t *, uint32_t *)
Serial_PutString(uint8_t *)
Serial_PutByte(uint8_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesIAP_Mainsrc/common.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file IAP/IAP_Main/Src/common.c * @author MCD Application Team * @brief This file provides all the common functions. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /** @addtogroup STM32F4xx_IAP_Main * @{ *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "common.h" #include "main.h" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Convert an Integer to a string * @param p_str: The string output pointer * @param intnum: The integer to be converted * @retval None *//* ... */ void Int2Str(uint8_t *p_str, uint32_t intnum) { uint32_t i, divider = 1000000000, pos = 0, status = 0; for (i = 0; i < 10; i++) { p_str[pos++] = (intnum / divider) + 48; intnum = intnum % divider; divider /= 10; if ((p_str[pos-1] == '0') & (status == 0)) { pos = 0; }if ((p_str[pos-1] == '0') & (status == 0)) { ... } else { status++; }else { ... } }for (i = 0; i < 10; i++) { ... } }{ ... } /** * @brief Convert a string to an integer * @param p_inputstr: The string to be converted * @param p_intnum: The integer value * @retval 1: Correct * 0: Error *//* ... */ uint32_t Str2Int(uint8_t *p_inputstr, uint32_t *p_intnum) { uint32_t i = 0, res = 0; uint32_t val = 0; if ((p_inputstr[0] == '0') && ((p_inputstr[1] == 'x') || (p_inputstr[1] == 'X'))) { i = 2; while ( ( i < 11 ) && ( p_inputstr[i] != '\0' ) ) { if (ISVALIDHEX(p_inputstr[i])) { val = (val << 4) + CONVERTHEX(p_inputstr[i]); }if (ISVALIDHEX(p_inputstr[i])) { ... } else { /* Return 0, Invalid input */ res = 0; break; }else { ... } i++; }while (( i < 11 ) && ( p_inputstr[i] != '\0' )) { ... } /* valid result */ if (p_inputstr[i] == '\0') { *p_intnum = val; res = 1; }if (p_inputstr[i] == '\0') { ... } }if ((p_inputstr[0] == '0') && ((p_inputstr[1] == 'x') || (p_inputstr[1] == 'X'))) { ... } else /* max 10-digit decimal input */ { while ( ( i < 11 ) && ( res != 1 ) ) { if (p_inputstr[i] == '\0') { *p_intnum = val; /* return 1 */ res = 1; }if (p_inputstr[i] == '\0') { ... } else if (((p_inputstr[i] == 'k') || (p_inputstr[i] == 'K')) && (i > 0)) { val = val << 10; *p_intnum = val; res = 1; }else if (((p_inputstr[i] == 'k') || (p_inputstr[i] == 'K')) && (i > 0)) { ... } else if (((p_inputstr[i] == 'm') || (p_inputstr[i] == 'M')) && (i > 0)) { val = val << 20; *p_intnum = val; res = 1; }else if (((p_inputstr[i] == 'm') || (p_inputstr[i] == 'M')) && (i > 0)) { ... } else if (ISVALIDDEC(p_inputstr[i])) { val = val * 10 + CONVERTDEC(p_inputstr[i]); }else if (ISVALIDDEC(p_inputstr[i])) { ... } else { /* return 0, Invalid input */ res = 0; break; }else { ... } i++; }while (( i < 11 ) && ( res != 1 )) { ... } }else { ... } return res; }{ ... } /** * @brief Print a string on the HyperTerminal * @param p_string: The string to be printed * @retval None *//* ... */ void Serial_PutString(uint8_t *p_string) { uint16_t length = 0; while (p_string[length] != '\0') { length++; }while (p_string[length] != '\0') { ... } HAL_UART_Transmit(&UartHandle, p_string, length, TX_TIMEOUT); }{ ... } /** * @brief Transmit a byte to the HyperTerminal * @param param The byte to be sent * @retval HAL_StatusTypeDef HAL_OK if OK *//* ... */ HAL_StatusTypeDef Serial_PutByte( uint8_t param ) { /* May be timeouted... */ if ( UartHandle.gState == HAL_UART_STATE_TIMEOUT ) { UartHandle.gState = HAL_UART_STATE_READY; }if (UartHandle.gState == HAL_UART_STATE_TIMEOUT) { ... } return HAL_UART_Transmit(&UartHandle, &param, 1, TX_TIMEOUT); }{ ... } /** * @} *//* ... */