can't get ASF USB driver to work

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

Hi, I'm using SAMD21 Xplained Pro board and am new to Studio and ASF but have experience with other IDEs and embedded platforms.

 

I'm trying to get a basic USB CDC echo program working, but as soon as I enable the driver nothing else works. I've followed the start guides and the examples but still not luck.

 

using ASF wizard I have the following

- Generic board support (automatically added when created project)

- PORT-GPIO pin control driver (automatically added when created project) 

- SYSTEM - Core system driver (automatically added when created project) 

- Delay routines (service) (systick) - I've added

- USB Device service (CDC) - I've added

 

To start with I created a heartbeat signal on LED 0, by checking for systick events - all worked ok

Then I added the USB. I modified the conf_usb and conf_clocks as per examples, except I haven't included all the optional event callbacks. If I leave the udc_start() function call in, the heartbeat stops and Windows reports that USB device not recognized.

If I comment out the udc_start call then heartbeat starts working again. 

 

Is there some interaction between USB and systick drivers?

The ASF stuff is supposed to just work, isn't it?

 

In the ASF example the code uses the sleep manager, however the start guide and api reference state this is optional so I haven't included. 

 

my main.c

#include <asf.h>

#define MS_TICK 10
#define MSEC(_x) (_x / MS_TICK)
#define SYS_TICK (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)

int main (void)
{
	int timer = 0;
	char ch;

	// ASF init routines
	irq_initialize_vectors();
	cpu_irq_enable();

	system_init();

	delay_init();

	udc_start(); 

	// application setup code here, after the board has been initialized

	// setup system timer for base interval
	SysTick->LOAD = (system_gclk_gen_get_hz(0) / 1000) * MS_TICK;
	SysTick->VAL = 0;

	while (1) {
		if(SYS_TICK) {
			if(timer) --timer;
		}

		// heartbeat
		if(!timer) {
			timer = MSEC(500);
			port_pin_toggle_output_level(LED_0_PIN);
		}

		if(udi_cdc_is_rx_ready()) {
			ch = udi_cdc_getc();
			udi_cdc_putc(ch);
		}

		// Is button pressed? if yes LED on, else led off
	/*	if (port_pin_get_input_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
			port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
		} else {
			port_pin_set_output_level(LED_0_PIN, !LED_0_ACTIVE);
		} */
	}
}

 

 

This is getting really frustrating, as ASF is supposed to make things easier to get the application going, but I've now spent several days banging my head against the wall trying to get this going.

 

PS. If I load one of the ASF CDC examples "as-is" the USB device enumerates in Windows OK, so hardware is all good, however I don't want to use the sleep manager so have tried copying the example rather than modify

 

Thanks in advance

Andrew

Last Edited: Wed. Oct 26, 2016 - 10:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

If there is some strange interaction with your heartbeat and USB (which is very heavy with interrupting) then try if helps with it (the full heartbeat section of the code or parts of it) inside

	    system_interrupt_enter_critical_section();

	    system_interrupt_leave_critical_section(); 

/Lars

 

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

Andrewjfox, have you had any luck with this? I'm working with a SAMS70 but am having similar problems with USB ASF.

 

The device never recognizes, it just says failed to get descriptors in the windows device manager.

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

Me too having issues with SAM E70.

Am trying to get the USB Host working. But sadly it isn't working.

Silly beans are always silly
:)

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

Have you modified the clocks_config to run at 48mhz? To use the USB as a target, there are a few settings needed. See http://www.atmel.com/images/atmel-42352-sam-d21-xpro-usb-host-msc-bootloader_training-manual_an8185.pdf

For details

 

"When all else fails, read the directions"

Last Edited: Wed. Dec 7, 2016 - 07:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you.
I'll respond after going through the doc.

yes

Silly beans are always silly
:)

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

On my ATSAME70Q21 I have it working, not sure if this is applicable for you, but for me there is an issue where the cache can't be enabled when doing USB. I do have my caches enabled, but have used the MPU to mark my SRAM sharable and now the USB is working and I still get cache benefits when accessing Flash. Maybe this can be improved more by relocating all USB memory into a single spot and only mark that sharable.

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

I finally got the USB Device mode to enumerate with the SAMS70Q21 but I had to move away from ASF and use the samv71_softpack_1.5 libraries instead. There were some timing issues. If my processor was running at 240MHz I couldn't get it to enumerate unless I stepped through certain parts of the initialization code. If I changed it to 120MHz everything worked fine.

 

I got it to enumerate properly with 240MHz if I put a 10 microsecond delay after the UTMI clock is unfrozen:

 

__STATIC_INLINE void USBHS_UnFreezeClock(Usbhs *pUsbhs)
{
	pUsbhs->USBHS_CTRL &= ~((uint32_t)USBHS_CTRL_FRZCLK);
	delay_us(10);
}

I tried to monitor the status register to hold it until the clock was usable but it only works if I add this delay in. 

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

Ok, I'll try disabling the cache memory.

 

Silly beans are always silly
:)

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

That is a good news, but unfortunately almost 40% of the actual firmware has been developed using ASF.

So, moving out of ASF would spell disaster.

But I'll try that frequency modification technique of yours.

 

Lets see it it works...

Silly beans are always silly
:)

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

Is it possible for you to share a sample code for that.

Because we are really running out of time here.

 

We are close to the deadline, lots of work needs to be done.

ASF is really bothering me.

sad

Silly beans are always silly
:)

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

I could detect the USB device connected but am unable to mount the device.

sad

Silly beans are always silly
:)

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

I am still using ASF for the majority of my code as well. I only imported about 12-15 USB files from the samv71_softpack_1.5 libraries. Again I'm only using USB in device mode so I don't think my code is going to help in your situation, it's essentially code straight from the examples in the samv71_softpack_1.5 libraries. There are a lot more examples in the pack.

 

Go download the package for Atmel studio:  http://www.atmel.com/tools/samv7...

 

The libraries and example projects by default install into C:/Temp/samv71_softpack.......

 

Open one of the host examples and look at the specific files they imported. You'll have to remove the chip.h and board.h include statements in the files you import and find equivalent files and definitions in the ASF files. They are almost identical, but you may need to add a couple of definitions to the compiler.h and same70xxx.h chip file in your project. It took a couple of hours for me to get it to compile but it's completely doable.

 

Good luck!

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

Hi,

Thanks a lot.

It seems promising, let me try it out.

 

I really appreciate your help. Lets hope this works.

 

I wonder why Atmel Support is not bothering at all.

I tried contacting everybody in my reach, but nobody is responding.

sad

It seems like opting SAM E70 for our project was a big mistake. It is simply killing my time.

crying

Silly beans are always silly
:)

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

Oh nooo....

Atmel Website is under maintenance.

Am unable to download any file from their website.

Its a total mess.

Silly beans are always silly
:)

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

lourensr wrote:

On my ATSAME70Q21 I have it working, not sure if this is applicable for you, but for me there is an issue where the cache can't be enabled when doing USB. I do have my caches enabled, but have used the MPU to mark my SRAM sharable and now the USB is working and I still get cache benefits when accessing Flash. Maybe this can be improved more by relocating all USB memory into a single spot and only mark that sharable.

 

Hi Lourensr,

 

Even I have issues with getting my USB drivers to work properly for my same70q21. I wanted to try "marking my SRAM shareable". Can you tell me how you did that? I looked up online but couldn't find much information. I did find this(http://atmel.force.com/support/s...) document though.  But I am so new to this I couldn't understand.

 

Thank for your help! :) 

 

 

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

Any Luck guys? 

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

Note the date of the last post in this thread ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was recently (in Dec 2017) able to get the USB CDC echo working with the SAMG55 eval board and then on my custom board also.  I too used the newer Atmel START/ASF4.  So it is possible to get working.  Clocking is an issue that is sensitive.  There is an app note describing crystal-less USB clocking on the G55 but I was not able to get that to work and resorted to adding a 32KHz clock source that is then used to drive the PLL to generate the 48MHz USB clock.

 

Some problems I found with the eval board example:

- Change the MCU clock rate; in the G55 the default was 8MHz which was too slow for USB.  Changing it to 24MHz helps. This was under the clocks tab for the main clock.

- Change the  default bulk out endpoint number to 3 or higher; under the USB_DEVICE_INSTANCE settings.  The example needs EP83 and it only limits it to EP82 here.

 

(FWIW: Here is a link to the other thread https://www.avrfreaks.net/forum/u...)

 

 

Last Edited: Wed. Jan 10, 2018 - 02:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey tarribred Thanks a billion for your reply. I checked the link you redirected there you say

 The ASF3 example works easily but the ASF4/START solution does not

I am using ASF3.32.0 for SAM E70-XPLD USB example. So its okay if I stick to ASF3? My PC never detects USB device. Going to check clock etc.

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

tarribred Thanks for the clue about ASF4, I have got CDC Echo running succesfully on SAME70-XPLD. But I want to configure the board as USB vendor class. No such example project found for the board.

If someone has a clue about where to found such example code please share.

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

Finally i got USB Vendor class device detected successfully on PC I created new project in ASF4/START. now trying to modify code not to loopback just transmit only.

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

Hello all, I am transmitting data over USB (Project created in ASF4/START) I am unable to fine endpoint size please help me fine this or any documentation that can help me understanding the code?

Here is my code not to loopback just transmit data assuming 1024 packet size.

void vendor_example(void)

{

/* usb stack init */

usbdc_init(ctrl_buffer);

enum usb_xfer_code rc;

/* usbdc_register_funcion inside */

vendordf_init();

usbdc_start(single_desc);

usbdc_attach();

while (!vendordf_is_enabled()) {

// wait vendor application to be installed

};

while(1)

{

uint16_t c=0;

for (c=0; c<1024; c++)

{

main_buf_loopback[c]=0xFF;

}

vendordf_write(USB_EP_TYPE_BULK, main_buf_loopback, 1024);

}

}

No data appearing on analyzer.

P.S: Web is not allowing me to decorate code using < >.

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

sidk wrote:
Web is not allowing me to decorate code using < >.

This is a long-standing bug - Microchip must know of it by now.

 

Please send a PM to users mt_nor and  Jacob ("Site Admin") 

 

In the meantime, a workaround is described here: https://www.avrfreaks.net/forum/make-code-editor-work-edge-and-chrome

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My code stucks at vendordf_is_enabled(); figured out using GPIO toggle. Anybody can please help?

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

sidk wrote:
My code stucks at vendordf_is_enabled();

So use your debugger to step into that code, and see what it's waiting for, then!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe this thread will help you...

 

https://community.atmel.com/forum...

 

 

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

Thanks tarribred, Code attached there is designed using ASF3, whereas I have now shifted to ASF4/START the code is totally different. No help is available on internet.

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

Tracing the code revealed, vendordf_write() is returning error code -19 i.e. ERR_OVERFLOW. Following is the snapshot of USBLyzer 

 

How to overcome this overflow error? Any documentation or Clue plzzzz

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

I have issue with SAME70 board.

 uint8_t input;

while (true) {
		//sleepmgr_enter_sleep();
	if (udi_cdc_is_rx_ready())
	{
		input = udi_cdc_getc();
		udi_cdc_putc(input);

	}
	}

output :what's wrong with is this? why it's not sending all of the char back

Last Edited: Fri. Feb 8, 2019 - 10:50 AM