3434#endif
3535LOG_MODULE_REGISTER (usbd_cdc_acm , CONFIG_USBD_CDC_ACM_LOG_LEVEL );
3636
37- UDC_BUF_POOL_DEFINE (cdc_acm_ep_pool ,
38- DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) * 2 ,
39- USBD_MAX_BULK_MPS , sizeof (struct udc_buf_info ), NULL );
40-
4137#define CDC_ACM_DEFAULT_LINECODING {sys_cpu_to_le32(115200), 0, 0, 8}
4238#define CDC_ACM_DEFAULT_INT_EP_MPS 16
4339#define CDC_ACM_INTERVAL_DEFAULT 10000UL
@@ -131,8 +127,15 @@ struct cdc_acm_uart_data {
131127
132128static void cdc_acm_irq_rx_enable (const struct device * dev );
133129
134- struct net_buf * cdc_acm_buf_alloc (const uint8_t ep )
130+ #if CONFIG_USBD_CDC_ACM_BUF_POOL
131+ UDC_BUF_POOL_DEFINE (cdc_acm_ep_pool ,
132+ DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) * 2 ,
133+ USBD_MAX_BULK_MPS , sizeof (struct udc_buf_info ), NULL );
134+
135+ static struct net_buf * cdc_acm_buf_alloc (struct usbd_class_data * const c_data ,
136+ const uint8_t ep )
135137{
138+ ARG_UNUSED (c_data );
136139 struct net_buf * buf = NULL ;
137140 struct udc_buf_info * bi ;
138141
@@ -146,6 +149,17 @@ struct net_buf *cdc_acm_buf_alloc(const uint8_t ep)
146149
147150 return buf ;
148151}
152+ #else
153+ /*
154+ * The required buffer is 128 bytes per instance on a full-speed device. Use
155+ * common (UDC) buffer, as this results in a smaller footprint.
156+ */
157+ static struct net_buf * cdc_acm_buf_alloc (struct usbd_class_data * const c_data ,
158+ const uint8_t ep )
159+ {
160+ return usbd_ep_buf_alloc (c_data , ep , USBD_MAX_BULK_MPS );
161+ }
162+ #endif /* CONFIG_USBD_CDC_ACM_BUF_POOL */
149163
150164#if CONFIG_USBD_CDC_ACM_WORKQUEUE
151165static struct k_work_q cdc_acm_work_q ;
@@ -635,7 +649,7 @@ static void cdc_acm_tx_fifo_handler(struct k_work *work)
635649 return ;
636650 }
637651
638- buf = cdc_acm_buf_alloc (cdc_acm_get_bulk_in (c_data ));
652+ buf = cdc_acm_buf_alloc (c_data , cdc_acm_get_bulk_in (c_data ));
639653 if (buf == NULL ) {
640654 atomic_clear_bit (& data -> state , CDC_ACM_TX_FIFO_BUSY );
641655 cdc_acm_work_schedule (& data -> tx_fifo_work , K_MSEC (1 ));
@@ -669,7 +683,6 @@ static void cdc_acm_rx_fifo_handler(struct k_work *work)
669683 const struct cdc_acm_uart_config * cfg ;
670684 struct usbd_class_data * c_data ;
671685 struct net_buf * buf ;
672- uint8_t ep ;
673686 int ret ;
674687
675688 data = CONTAINER_OF (work , struct cdc_acm_uart_data , rx_fifo_work );
@@ -692,8 +705,7 @@ static void cdc_acm_rx_fifo_handler(struct k_work *work)
692705 return ;
693706 }
694707
695- ep = cdc_acm_get_bulk_out (c_data );
696- buf = cdc_acm_buf_alloc (ep );
708+ buf = cdc_acm_buf_alloc (c_data , cdc_acm_get_bulk_out (c_data ));
697709 if (buf == NULL ) {
698710 return ;
699711 }
@@ -703,7 +715,8 @@ static void cdc_acm_rx_fifo_handler(struct k_work *work)
703715
704716 ret = usbd_ep_enqueue (c_data , buf );
705717 if (ret ) {
706- LOG_ERR ("Failed to enqueue net_buf for 0x%02x" , ep );
718+ LOG_ERR ("Failed to enqueue net_buf for 0x%02x" ,
719+ cdc_acm_get_bulk_out (c_data ));
707720 net_buf_unref (buf );
708721 }
709722}
0 commit comments