FreeRTOS xQueueCreate breaks USB CDC Echo example

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have create an Atmel Start project from my ATSAMD21G18A board (Arduino zero, with bootloader) and run the "USB CDC Echo" example with succes. Al what was needed was setting up the clock simular to the Arduinoe Zero platform and skip the bootloader in the flash loader.
FreeRTOS is also included in my project but as soon as I create a queue, with xQueueCreate() the CDC USB doesn't react anymore.
Since I do nothing with the Queue I assume it is a (dynamic) memory allocation problem. I did search for quite a bit but can't find how the memory allocation breaks the application.
 

#include <atmel_start.h>
#include <FreeRTOS.h>
#include <queue.h>

static xQueueHandle readQ;

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();

	//Uncommenting the line below breaks the USB echo functionality
    //readQ = xQueueCreate(1, 1);

    cdcd_acm_example();
}

 

I hope someone can point me in the right direction.

 

Attached the Atmel Start configuration.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have an ICE? The first thought is that it never returns from the call to xQueueCreate() so it never gets to cdcd_acm_example(). A breakpoint on that last function call would prove this. You'd also be able to step in to xQueueCreate() and see if it is blocking on something.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the quick reaction!

 

I haven't solved it yet but managed to track it down, without ICE but with hours of led blinking, to the FreeRTOS implementation of dynamic memory allocation. It disables the interrupts when memory is allocated by xQueueCreate() and doesn't enable the interrupts when the scheduler is not running. This is not a bug but an implementation choice. I have to rethink how to start the USB/CDC subsystems.

 

Jeroen

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup, sadly without an ICE this kind of things comes down to LED blinking or printf()s or similar.

 

For programming "complex" systems I would highly recommend an ICE (talking of which the Atmel-ICE is currently half price - until the end of the month)

Last Edited: Mon. Feb 5, 2018 - 05:26 PM