Skip to content

Commit 8b20b79

Browse files
Override static NCM memory allocation
The NCM buffers are only accessed in a single file and under very limited circumstances. Use a SDKOVERRIDE to make a weak ncm_device with no memory usage, and put the TUSB ncd_device inside the lwip_usb folder. For apps which don't use NCM, this saves >6K of RAM. For apps which use NCM, there should be no change.
1 parent 7aa5371 commit 8b20b79

File tree

12 files changed

+1008
-0
lines changed

12 files changed

+1008
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Dummy shim to be overridden by lwip_usb_ncm
2+
#include <Arduino.h>
3+
#include "tusb_option.h"
4+
5+
#if (CFG_TUD_ENABLED && CFG_TUD_NCM)
6+
7+
#include <stdbool.h>
8+
#include <stdint.h>
9+
#include <stdio.h>
10+
11+
#include "device/usbd.h"
12+
#include "device/usbd_pvt.h"
13+
14+
#include "../../../pico-sdk/lib/tinyusb/src/class/net/ncm.h"
15+
#include "../../../pico-sdk/lib/tinyusb/src/class/net/net_device.h"
16+
17+
18+
extern bool tud_network_can_xmit(uint16_t size) __attribute((weak));
19+
bool tud_network_can_xmit(uint16_t size) {
20+
return false;
21+
}
22+
23+
extern void tud_network_xmit(void *ref, uint16_t arg) __attribute((weak));
24+
void tud_network_xmit(void *ref, uint16_t arg) {
25+
return;
26+
}
27+
28+
extern void tud_network_recv_renew(void) __attribute((weak));
29+
void tud_network_recv_renew(void) {
30+
}
31+
32+
extern void netd_init(void) __attribute((weak));
33+
void netd_init(void) {
34+
}
35+
36+
extern bool netd_deinit(void) __attribute((weak));
37+
bool netd_deinit(void) {
38+
return true;
39+
}
40+
41+
extern void netd_reset(uint8_t rhport) __attribute((weak));
42+
void netd_reset(uint8_t rhport) {
43+
(void) rhport;
44+
}
45+
46+
extern uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) __attribute((weak));
47+
uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
48+
return 0;
49+
}
50+
51+
extern bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) __attribute((weak));
52+
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
53+
return false;
54+
}
55+
56+
extern bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) __attribute((weak));
57+
bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) {
58+
return false;
59+
}
60+
61+
#endif // ( CFG_TUD_ENABLED && CFG_TUD_NCM )

lib/rp2040/liblwip-bt.a

-2.96 KB
Binary file not shown.

lib/rp2040/liblwip.a

-484 Bytes
Binary file not shown.

lib/rp2040/libpico.a

-34.9 KB
Binary file not shown.

lib/rp2350-riscv/liblwip-bt.a

-3.45 KB
Binary file not shown.

lib/rp2350-riscv/liblwip.a

-564 Bytes
Binary file not shown.

lib/rp2350-riscv/libpico.a

-101 KB
Binary file not shown.

lib/rp2350/liblwip-bt.a

-3.1 KB
Binary file not shown.

lib/rp2350/liblwip.a

-588 Bytes
Binary file not shown.

lib/rp2350/libpico.a

-35.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)