LUFA - Problem detecting RTS changes

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

Hi all!

Firt post here.

 

Ive compiled mocoLufa (which is based on LUFA-100807) and loaded to an atmega16u2. Trough a python script, using pyserial, i can toogle the DTR and RTS lines from the script. DTR toogling works ok, but RTS isnt.

 

Ive modified this section from mocolufa in dualMoco.c from this

/** Event handler for the CDC Class driver Host-to-Device Line Encoding Changed event.
 *
 *  \param[in] CDCInterfaceInfo  Pointer to the CDC class interface configuration structure being referenced
 */
void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) {
  bool CurrentDTRState = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR);

  if (CurrentDTRState)
    AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK;
  else
    AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK;
}

to this

 

/** Event handler for the CDC Class driver Host-to-Device Line Encoding Changed event.
 *
 *  \param[in] CDCInterfaceInfo  Pointer to the CDC class interface configuration structure being referenced
 */
void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) {
  bool CurrentDTRState = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR);
  bool CurrentRTSState = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_RTS);

  if (CurrentDTRState)
    AVR_RESET_LINE_PORT &= ~AVR_RESET_LINE_MASK;
  else
    AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK;

  if (CurrentRTSState)
    AVR_RESET_LINE_PORT &= ~AVR_RTS_LINE_MASK;
  else
    AVR_RESET_LINE_PORT |= AVR_RTS_LINE_MASK;
}

and as i said, it doesnt detect the RTS changes.

 

I think the problem relies on EVENT_CDC_Device_ControLineStateChanged() not being called by a RTS change. With a DTR change it works ok.

 

On windows: if, from the python script, i first make a change on DTR, then instantly on RTS, the change on RTS is outputed by the mega16u2  because, the function EVENT_CDC_Device_ControLineStateChanged()  gets called (because of the DTR change) and "bool CurrentRTSState = ..." is evaluated accordingly.

 

On mac: RTS signal never respond to any change.

 

 

I think this https://github.com/urjaman/fast-usbserial/issues/2 is kinda related,

especially this line:

"...I debuged, and found that, function Endpoint_IsSETUPReceived return false when I set RTS, but return true when I set DTR

 

static inline bool Endpoint_IsSETUPReceived(void)
{
    return ((UEINTX & (1 << RXSTPI)) ? true : false);
}

..."

 

Am i doing something wrong?

 

Any help is greatly appreciated

Last Edited: Sun. Mar 22, 2020 - 02:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, ive made some little advancement here, though i couldnt detect the problem.

Ive navigate/debugged trough the code and end up in USBInterrupt.c.

There is an ISR that is called each time there is a DTR change:
 

#if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
ISR(USB_COM_vect, ISR_BLOCK)
{
	uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint(); 

	Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
	USB_INT_Disable(USB_INT_RXSTPI);

	NONATOMIC_BLOCK(NONATOMIC_FORCEOFF)
	{
		USB_Device_ProcessControlRequest();
	}

	Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
	USB_INT_Enable(USB_INT_RXSTPI);
	Endpoint_SelectEndpoint(PrevSelectedEndpoint);
}
#endif

 

So i guess, this ISR is no being fired by a RST toggle. Though i must say that is entering once, the first time the script is run, but then when i change again the RST state it doesnt respond anymore. It is always held on low state.

I dont know what may be causing this problem.

 

Another thing that i did was to modify the VID and PID of the uC.
Previously it had the ones from mocoLufa and those where the ones of an Arduino Uno.
Then, added LUFA CDC-ACM.inf to c:\windows\inf and changed the PID/VID to match the ones on the firmware.
This was done in order to try to use the windows default drivers.
It still doesnt works.

 

Im not sure if i should be using  LUFA_VirtualSerial.inf  instead. As i understand, mocoLufa is a CDC device, but im not exactly sure.

I guess i need to start from scracth with some LUFA demo project, and see if there is already one that uses the RTS signal.
As i said, DTR signal is no problem and i can control it fine.

Last Edited: Wed. Mar 25, 2020 - 04:46 PM