1 | #include "main.h"
|
2 | #include "lwip.h"
|
3 |
|
4 | /* Private includes ----------------------------------------------------------*/
|
5 | /* USER CODE BEGIN Includes */
|
6 | #include "lwip/udp.h"
|
7 | #include "lwip/tcp.h"
|
8 | #include <string.h>
|
9 | /* USER CODE END Includes */
|
10 |
|
11 | /* Private typedef -----------------------------------------------------------*/
|
12 | /* USER CODE BEGIN PTD */
|
13 |
|
14 | /* USER CODE END PTD */
|
15 |
|
16 | /* Private define ------------------------------------------------------------*/
|
17 | /* USER CODE BEGIN PD */
|
18 |
|
19 | /* USER CODE END PD */
|
20 |
|
21 | /* Private macro -------------------------------------------------------------*/
|
22 | /* USER CODE BEGIN PM */
|
23 |
|
24 | /* USER CODE END PM */
|
25 |
|
26 | /* Private variables ---------------------------------------------------------*/
|
27 |
|
28 | QSPI_HandleTypeDef hqspi;
|
29 |
|
30 | UART_HandleTypeDef huart3;
|
31 |
|
32 | /* USER CODE BEGIN PV */
|
33 | static struct udp_pcb *udpPcb1_p;
|
34 | static struct tcp_pcb *telnet_pcb;
|
35 | struct netif gnetif;
|
36 |
|
37 | QSPI_CommandTypeDef sCommand;
|
38 |
|
39 | uint8_t aRxBuffer[100];
|
40 | char uartbufefr[10];
|
41 | char txbuffer[10];
|
42 | unsigned int test = 123;
|
43 | char teststring[100];
|
44 |
|
45 | enum telnet_states
|
46 | {
|
47 | ES_NONE = 0,
|
48 | ES_ACCEPTED,
|
49 | ES_RECEIVED,
|
50 | ES_CLOSING
|
51 | };
|
52 |
|
53 | struct telnet_struct
|
54 | {
|
55 | u8_t state; /* current connection state */
|
56 | u8_t retries;
|
57 | struct tcp_pcb *pcb; /* pointer on the current tcp_pcb */
|
58 | struct pbuf *p; /* pointer on the received/to be transmitted pbuf */
|
59 | };
|
60 |
|
61 | struct telnet_struct *ss;
|
62 |
|
63 | /* USER CODE END PV */
|
64 |
|
65 | /* Private function prototypes -----------------------------------------------*/
|
66 | void SystemClock_Config(void);
|
67 | static void MX_GPIO_Init(void);
|
68 | static void MX_QUADSPI_Init(void);
|
69 | static void MX_USART3_UART_Init(void);
|
70 | /* USER CODE BEGIN PFP */
|
71 | static void MPU_Config(void);
|
72 | void udpApp1_init(void);
|
73 | void udpApp1_sendTESTPacket(void);
|
74 | void telnet_init(void);
|
75 | err_t telnet_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
|
76 | static err_t telnet_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
|
77 | static void telnet_error(void *arg, err_t err);
|
78 | static err_t telnet_poll(void *arg, struct tcp_pcb *tpcb);
|
79 | static err_t telnet_sent(void *arg, struct tcp_pcb *tpcb, u16_t len);
|
80 | static void telnet_send(struct tcp_pcb *tpcb, struct telnet_struct *es);
|
81 | static void telnet_close(struct tcp_pcb *tpcb, struct telnet_struct *es);
|
82 | void telnet_sendstring(char* buf_str);
|
83 | /* USER CODE END PFP */
|
84 |
|
85 | /* Private user code ---------------------------------------------------------*/
|
86 | /* USER CODE BEGIN 0 */
|
87 |
|
88 | /* USER CODE END 0 */
|
89 |
|
90 | /**
|
91 | * @brief The application entry point.
|
92 | * @retval int
|
93 | */
|
94 | int main(void)
|
95 | {
|
96 | /* USER CODE BEGIN 1 */
|
97 | //struct tcp_send_struct *es;
|
98 | MPU_Config();
|
99 |
|
100 | /* USER CODE END 1 */
|
101 |
|
102 | /* Enable I-Cache---------------------------------------------------------*/
|
103 | SCB_EnableICache();
|
104 |
|
105 | /* Enable D-Cache---------------------------------------------------------*/
|
106 | SCB_EnableDCache();
|
107 |
|
108 | /* MCU Configuration--------------------------------------------------------*/
|
109 |
|
110 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
111 | HAL_Init();
|
112 |
|
113 | /* USER CODE BEGIN Init */
|
114 |
|
115 | /* USER CODE END Init */
|
116 |
|
117 | /* Configure the system clock */
|
118 | SystemClock_Config();
|
119 |
|
120 | /* USER CODE BEGIN SysInit */
|
121 |
|
122 | /* USER CODE END SysInit */
|
123 |
|
124 | /* Initialize all configured peripherals */
|
125 | MX_GPIO_Init();
|
126 | MX_LWIP_Init();
|
127 | MX_QUADSPI_Init();
|
128 | MX_USART3_UART_Init();
|
129 | /* USER CODE BEGIN 2 */
|
130 | //udpApp1_init();
|
131 | telnet_init();
|
132 |
|
133 | itoa(test,teststring);
|
134 |
|
135 | /* USER CODE END 2 */
|
136 |
|
137 | /* Infinite loop */
|
138 | /* USER CODE BEGIN WHILE */
|
139 | while (1)
|
140 | {
|
141 | MX_LWIP_Process();
|
142 | //sCommand.AddressMode = QSPI_ADDRESS_4_LINES;
|
143 | //sCommand.AddressSize = QSPI_ADDRESS_32_BITS;
|
144 | sCommand.Address = 0xFF;
|
145 | //sCommand.Instruction = 0x1;
|
146 | //sCommand.NbData = 1;
|
147 |
|
148 | //sCommand.DataMode = QSPI_DATA_4_LINES;
|
149 |
|
150 | //HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_11);
|
151 | //HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_RESET);
|
152 |
|
153 | if (HAL_QSPI_Command(&hqspi, &sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
154 | {
|
155 | Error_Handler();
|
156 | HAL_GPIO_TogglePin(GPIOB, LD3_Pin);
|
157 |
|
158 |
|
159 | }
|
160 | //HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_11);
|
161 |
|
162 |
|
163 |
|
164 | if (HAL_QSPI_Receive(&hqspi,aRxBuffer,HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
165 | {
|
166 | Error_Handler();
|
167 | HAL_GPIO_TogglePin(GPIOB, LD2_Pin);
|
168 | }
|
169 |
|
170 |
|
171 | //HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_SET);
|
172 | HAL_UART_Transmit(&huart3,aRxBuffer,sizeof(aRxBuffer),10);
|
173 | //HAL_UART_Transmit(&huart3,test,3,10);
|
174 |
|
175 |
|
176 | /*HAL_UART_Receive(&huart3,uartbufefr,sizeof(uartbufefr),10);
|
177 | memcpy(txbuffer, uartbufefr, sizeof(uartbufefr));
|
178 |
|
179 | MX_LWIP_Process();
|
180 |
|
181 | if(strcmp(txbuffer, "a" ) == 0)
|
182 | {
|
183 | telnet_sendstring(txbuffer);
|
184 | }
|
185 | else
|
186 | {
|
187 |
|
188 | }*/
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | //udpApp1_sendTESTPacket();
|
194 |
|
195 |
|
196 | //telnet_sendstring(aRxBuffer);
|
197 |
|
198 | /* USER CODE END WHILE */
|
199 |
|
200 | /* USER CODE BEGIN 3 */
|
201 | }
|
202 | /* USER CODE END 3 */
|
203 | }
|
204 |
|
205 |
|
206 | HAL_StatusTypeDef HAL_QSPI_Receive(QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout)
|
207 | {
|
208 | ....
|
209 | }
|
210 |
|
211 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
212 | {
|
213 | ...
|
214 | }
|