@@ -185,11 +185,6 @@ struct usbd_event {
185185K_HEAP_DEFINE (fifo_elem_pool ,
186186 FIFO_ELEM_MAX_SZ * CONFIG_USB_NRFX_EVT_QUEUE_SIZE );
187187
188- /**
189- * @brief Endpoint buffer pool
190- * Used for allocating buffers for the endpoints' data transfer
191- * Max pool size possible: 3072 Bytes (16 EP * 64B + 2 ISO * 1024B)
192- */
193188
194189/** Number of IN Endpoints configured (including control) */
195190#define CFG_EPIN_CNT (DT_INST_PROP(0, num_in_endpoints) + \
@@ -212,34 +207,20 @@ K_HEAP_DEFINE(fifo_elem_pool,
212207#define EP_BUF_MAX_SZ 64UL
213208#define ISO_EP_BUF_MAX_SZ 1024UL
214209
215- /** Minimum endpoint buffer size (minimum block size) */
216- #define EP_BUF_POOL_BLOCK_MIN_SZ EP_BUF_MAX_SZ
217-
218- /** Maximum endpoint buffer size (maximum block size) */
219- #if ( CFG_EP_ISOIN_CNT || CFG_EP_ISOOUT_CNT )
220- #define EP_BUF_POOL_BLOCK_MAX_SZ ISO_EP_BUF_MAX_SZ
221- #else
222- #define EP_BUF_POOL_BLOCK_MAX_SZ EP_BUF_MAX_SZ
223- #endif
210+ /**
211+ * @brief Output endpoint buffers
212+ * Used as buffers for the endpoints' data transfer
213+ * Max buffers size possible: 1536 Bytes (8 EP * 64B + 1 ISO * 1024B)
214+ */
215+ static uint8_t ep_out_bufs [ CFG_EPOUT_CNT ][ EP_BUF_MAX_SZ ]
216+ __aligned ( sizeof ( uint32_t ));
217+ static uint8_t ep_isoout_bufs [ CFG_EP_ISOOUT_CNT ][ ISO_EP_BUF_MAX_SZ ]
218+ __aligned ( sizeof ( uint32_t ));
224219
225220/** Total endpoints configured */
226221#define CFG_EP_CNT (CFG_EPIN_CNT + CFG_EP_ISOIN_CNT + \
227222 CFG_EPOUT_CNT + CFG_EP_ISOOUT_CNT)
228223
229- /** Total buffer size for all endpoints */
230- #define EP_BUF_TOTAL ((CFG_EPOUT_CNT * EP_BUF_MAX_SZ) + \
231- (CFG_EP_ISOOUT_CNT * ISO_EP_BUF_MAX_SZ))
232-
233- /** Total number of maximum sized buffers needed */
234- #define EP_BUF_POOL_BLOCK_COUNT ((EP_BUF_TOTAL / EP_BUF_POOL_BLOCK_MAX_SZ) + \
235- ((EP_BUF_TOTAL % EP_BUF_POOL_BLOCK_MAX_SZ) ? 1 : 0))
236-
237- /** 4 Byte Buffer alignment required by hardware */
238- #define EP_BUF_POOL_ALIGNMENT sizeof(unsigned int)
239-
240- K_HEAP_DEFINE (ep_buf_pool ,
241- EP_BUF_POOL_BLOCK_MAX_SZ * EP_BUF_POOL_BLOCK_COUNT );
242-
243224/**
244225 * @brief USBD control structure
245226 *
@@ -644,13 +625,7 @@ static int eps_ctx_init(void)
644625 __ASSERT_NO_MSG (ep_ctx );
645626
646627 if (!ep_ctx -> buf .block .data ) {
647- ep_ctx -> buf .block .data =
648- k_heap_alloc (& ep_buf_pool ,
649- EP_BUF_MAX_SZ , K_NO_WAIT );
650- if (ep_ctx -> buf .block .data == NULL ) {
651- LOG_ERR ("Buffer alloc failed for EP 0x%02x" , i );
652- return - ENOMEM ;
653- }
628+ ep_ctx -> buf .block .data = ep_out_bufs [i ];
654629 }
655630
656631 ep_ctx_reset (ep_ctx );
@@ -663,17 +638,13 @@ static int eps_ctx_init(void)
663638 }
664639
665640 if (CFG_EP_ISOOUT_CNT ) {
641+ BUILD_ASSERT (CFG_EP_ISOOUT_CNT <= 1 );
642+
666643 ep_ctx = out_endpoint_ctx (NRF_USBD_EPOUT (8 ));
667644 __ASSERT_NO_MSG (ep_ctx );
668645
669646 if (!ep_ctx -> buf .block .data ) {
670- ep_ctx -> buf .block .data = k_heap_alloc (& ep_buf_pool ,
671- ISO_EP_BUF_MAX_SZ ,
672- K_NO_WAIT );
673- if (ep_ctx -> buf .block .data == NULL ) {
674- LOG_ERR ("EP buffer alloc failed for ISOOUT" );
675- return - ENOMEM ;
676- }
647+ ep_ctx -> buf .block .data = ep_isoout_bufs [0 ];
677648 }
678649
679650 ep_ctx_reset (ep_ctx );
@@ -696,7 +667,6 @@ static void eps_ctx_uninit(void)
696667 for (i = 0U ; i < CFG_EPOUT_CNT ; i ++ ) {
697668 ep_ctx = out_endpoint_ctx (i );
698669 __ASSERT_NO_MSG (ep_ctx );
699- k_heap_free (& ep_buf_pool , ep_ctx -> buf .block .data );
700670 memset (ep_ctx , 0 , sizeof (* ep_ctx ));
701671 }
702672
@@ -709,7 +679,6 @@ static void eps_ctx_uninit(void)
709679 if (CFG_EP_ISOOUT_CNT ) {
710680 ep_ctx = out_endpoint_ctx (NRF_USBD_EPOUT (8 ));
711681 __ASSERT_NO_MSG (ep_ctx );
712- k_heap_free (& ep_buf_pool , ep_ctx -> buf .block .data );
713682 memset (ep_ctx , 0 , sizeof (* ep_ctx ));
714683 }
715684}
0 commit comments