Hspahr_89north

Minimal code/ram config for 52212 MQX CDC

Discussion created by Hspahr_89north on Nov 14, 2012

Freescale lists that the MQX RTOS with USB stack requires 10K of RAM and 32K of code.  Unfortunately the 52212 only has 8K of RAM.  Because of this, the vanilla off the shelf 3.8.0 MQX stack will not work.  Here are the required changes to get the stack to comfortably fit within the 52212 footprint.  Note:  This has been tested on version 3.8.0 of the MQX stack using CodeWarrior 7.2.

 

Base your build off the 52223evb.cw project in the MQX folder.

 

In MQX 3.8/mqx/source/psp/coldfire/int_unx.c:

Add #if _DEBUG around printf statements.  New code should look as follows:

 

#if _DEBUG

   printf( "\n*** UNHANDLED INTERRUPT ***\n");

   printf( "Vector #: %d  0x%x\n\r",vector,vector);

   printf( "Offset  : %d  0x%x\n\r",offset,offset);

   printf( "Task Id: 0x%0x Td_ptr 0x%x Stack Frame: 0x%x\n\r",

      td_ptr->TASK_ID, td_ptr, basic_frame_ptr);

   printf( "Interrupt_nesting level: %d   PC: 0x%08x   SR: 0x%04x\n\r",

      kernel_data->IN_ISR,

      basic_frame_ptr->FRAME.RETURN_ADDRESS,

      basic_frame_ptr->FRAME.STATUS_REGISTER );

#endif


In MQX 3.8/usb/device/source/include/usbfs/usbprv_fs.h:

Add #if PSP_MQX_MIN_USB to reduce number of endpoints.  New code should look as follows:

 

#if PSP_MQX_MIN_USB

     #define USB_MAX_ENDPOINTS          (4)

     #define MAX_XDS_FOR_TR_CALLS     (4)

#elif PSP_MQX_CPU_IS_MCF51JM

     #define USB_MAX_ENDPOINTS          (4)

     #define MAX_XDS_FOR_TR_CALLS     (8)

#else

     #define USB_MAX_ENDPOINTS          (16)

     #define MAX_XDS_FOR_TR_CALLS     (32)

#endif

 

In MQX 3.8/usb/device/source/classes/include/usb_stack_config.h:

Change IMPLEMENT_QUEUING to 0.

 

In MQX 3.8/usb/device/source/classes/include/usb_cdc.h:

Add #if IMPLEMENT_QUEUING to USB_CLASS_CDC_ENDPOINT.  The above file is also copied into MQX 3.8/lib/m52223evb.cw/usb/device/usb_cdc.h.  New code should look as follows:

 

/* USB class cdc endpoint data */

typedef struct _usb_class_cdc_endpoint

{

     uint_8 endpoint;     /* endpoint num */

     uint_8 type;          /* type of endpoint (interrupt, bulk or isochronous) */

     #if IMPLEMENT_QUEUING

          uint_8 bin_consumer;     /* the num of queued elements */

          uint_8 bin_producer;     /* the num of de-queued elements */

     #endif

}USB_CLASS_CDC_ENDPOINT;

 

In MQX 3.8/source/bsp/m52223evb/gpio_init.c:

Change USB_USBCTRL_CLKSRC_OSCCLK to USB_USBCTRL_CLKSRC_SYSCLK.  Note:  This change is because I don't have an external oscillator on my board, and need to use the internal relaxation oscillator.  New code should look as follows:

 

/* Set clock source from internal PLL oscillator */

reg_ptr->USBOTG.USBCTRL &= ~USB_USBCTRL_CLKSRC_MASK;

reg_ptr->USBOTG.USBCTRL |= USB_USBCTRL_CLKSRC_SYSCLK;

 

In MQX 3.8/config/m52223evb/user_config.h:

Change BSPCFG_ENABLE_TTYA to 0.  Add BSPCFG_RX_RING_LEN, BSPCFG_TX_RING_LEN, and BSPCFG_ENABLE_IO_SUBSYSTEM to 0.  Change MQX_HAS_TIME_SLICE to 0, and MQX_ROM_VECTORS to 1.  Add MQX_USE_PARTITIONS to 1, MQX_USE_MUTEXES to 1, MQX_USE_LWEVENTS to 1, MQX_USE_LWMSGQ to 1, MQX_SPARSE_ISR_TABLE to 1, MQX_SPARSE_ISR_SHIFT to 7, MQX_USE_IO to 0, and PSP_MQX_MIN_USB to 1.  Change MQX_TASK_DESTRUCTION to 0.  Change include of "small_ram_config.h" to "smallest_config.h".  I've included the user_config.h file for reference.

 

With these changes, adding code that contains three tasks, multiple interrupts, a bootloader (which takes 8K codespace), and bunch of other stuff, I get 42.8K for code, and 6.8K for RAM.  This leaves me plenty more space for the application.

 

These are the minimal changes that I could find without heavily modifying the internals of the RTOS/USB stack.  That would save a lot more code/RAM, but it would make it much more difficult to upgrade to a newer version of the operating system if necessary.  While it does look like a lot of changes, each change is really only a line or two, and very easy to make.  These changes have been verified to connect properly on Windows XP, Windows 7, (both 32 and 64 bit versions), and Linux.

Original Attachment has been moved to: user_config.h.zip

Outcomes