Browse Source

Fix some warnings and optimise for size

Looks like removing printf drops about 10kB.
Brian Starkey 2 years ago
parent
commit
9bdc2fded0
3 changed files with 26 additions and 12 deletions
  1. 1
    0
      CMakeLists.txt
  2. 16
    8
      main.c
  3. 9
    4
      tcp_comm.c

+ 1
- 0
CMakeLists.txt View File

16
 pico_enable_stdio_usb(picowota 1)
16
 pico_enable_stdio_usb(picowota 1)
17
 
17
 
18
 pico_add_extra_outputs(picowota)
18
 pico_add_extra_outputs(picowota)
19
+set_target_properties(picowota PROPERTIES COMPILE_FLAGS "-Wall -Os")
19
 
20
 
20
 target_include_directories(picowota PRIVATE ${CMAKE_CURRENT_LIST_DIR})
21
 target_include_directories(picowota PRIVATE ${CMAKE_CURRENT_LIST_DIR})
21
 
22
 

+ 16
- 8
main.c View File

27
 
27
 
28
 #include "tcp_comm.h"
28
 #include "tcp_comm.h"
29
 
29
 
30
+#ifdef DEBUG
31
+#include <stdio.h>
32
+#include "pico/stdio_usb.h"
33
+#define DBG_PRINTF_INIT() stdio_usb_init()
34
+#define DBG_PRINTF(...) printf(__VA_ARGS__)
35
+#else
36
+#define DBG_PRINTF_INIT() { }
37
+#define DBG_PRINTF(...) { }
38
+#endif
39
+
30
 extern const char *wifi_ssid;
40
 extern const char *wifi_ssid;
31
 extern const char *wifi_pass;
41
 extern const char *wifi_pass;
32
 critical_section_t critical_section;
42
 critical_section_t critical_section;
511
 
521
 
512
 int main()
522
 int main()
513
 {
523
 {
514
-	stdio_init_all();
515
-
516
-	sleep_ms(1000);
524
+	DBG_PRINTF_INIT();
517
 
525
 
518
 	if (cyw43_arch_init()) {
526
 	if (cyw43_arch_init()) {
519
-		printf("failed to initialise\n");
527
+		DBG_PRINTF("failed to initialise\n");
520
 		return 1;
528
 		return 1;
521
 	}
529
 	}
522
 
530
 
523
 	cyw43_arch_enable_sta_mode();
531
 	cyw43_arch_enable_sta_mode();
524
 
532
 
525
-	printf("Connecting to WiFi...\n");
533
+	DBG_PRINTF("Connecting to WiFi...\n");
526
 	if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
534
 	if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
527
-		printf("failed to connect.\n");
535
+		DBG_PRINTF("failed to connect.\n");
528
 		return 1;
536
 		return 1;
529
 	} else {
537
 	} else {
530
-		printf("Connected.\n");
538
+		DBG_PRINTF("Connected.\n");
531
 	}
539
 	}
532
 
540
 
533
 	critical_section_init(&critical_section);
541
 	critical_section_init(&critical_section);
550
 	for ( ; ; ) {
558
 	for ( ; ; ) {
551
 		err_t err = tcp_comm_listen(tcp, TCP_PORT);
559
 		err_t err = tcp_comm_listen(tcp, TCP_PORT);
552
 		if (err != ERR_OK) {
560
 		if (err != ERR_OK) {
553
-			printf("Failed to start server: %d\n", err);
561
+			DBG_PRINTF("Failed to start server: %d\n", err);
554
 			sleep_ms(1000);
562
 			sleep_ms(1000);
555
 			continue;
563
 			continue;
556
 		}
564
 		}

+ 9
- 4
tcp_comm.c View File

15
 
15
 
16
 #include "tcp_comm.h"
16
 #include "tcp_comm.h"
17
 
17
 
18
-#define DEBUG_printf printf
18
+#ifdef DEBUG
19
+#include <stdio.h>
20
+#define DEBUG_printf(...) printf(__VA_ARGS__)
21
+#else
22
+#define DEBUG_printf(...) { }
23
+#endif
24
+
19
 #define POLL_TIME_S 5
25
 #define POLL_TIME_S 5
20
 
26
 
21
 #define COMM_MAX_NARG     5
27
 #define COMM_MAX_NARG     5
94
 {
100
 {
95
 	ctx->conn_state = CONN_STATE_WAIT_FOR_SYNC;
101
 	ctx->conn_state = CONN_STATE_WAIT_FOR_SYNC;
96
 	ctx->rx_bytes_needed = sizeof(uint32_t);
102
 	ctx->rx_bytes_needed = sizeof(uint32_t);
103
+
104
+	return 0;
97
 }
105
 }
98
 
106
 
99
 static int tcp_comm_sync_complete(struct tcp_comm_ctx *ctx)
107
 static int tcp_comm_sync_complete(struct tcp_comm_ctx *ctx)
159
 
167
 
160
 static int tcp_comm_data_begin(struct tcp_comm_ctx *ctx, uint32_t data_len)
168
 static int tcp_comm_data_begin(struct tcp_comm_ctx *ctx, uint32_t data_len)
161
 {
169
 {
162
-	const struct comm_command *cmd = ctx->cmd;
163
-
164
 	ctx->conn_state = CONN_STATE_READ_DATA;
170
 	ctx->conn_state = CONN_STATE_READ_DATA;
165
 	ctx->rx_bytes_needed = data_len;
171
 	ctx->rx_bytes_needed = data_len;
166
 
172
 
168
 		return tcp_comm_data_complete(ctx);
174
 		return tcp_comm_data_complete(ctx);
169
 	}
175
 	}
170
 
176
 
171
-
172
 	return 0;
177
 	return 0;
173
 }
178
 }
174
 
179
 

Loading…
Cancel
Save