• AVR Freaks

Hot!Best advice for making a USB to serial converter

Page: < 123 Showing page 3 of 3
Author
NorthGuy
Super Member
  • Total Posts : 5810
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 10:33:39 (permalink)
0
(removing blinks again)
#41
swmcl
Super Member
  • Total Posts : 271
  • Reward points : 0
  • Joined: 2014/05/10 13:54:42
  • Location: Queensland
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 13:09:40 (permalink)
0
I thought I'd take a look at things in MPLABX (5.25) xc8 (2.05) ...
So I started a new project with the said chip, added a few modules with the Microchip Code Configurator (MCC) and configured the oscillator.  Absolutely nothing else has been added.

I replicate the 'MCC_generated_files' folder and copy it to a folder called 'user_generated_files' but they are the same thing.  I do this so that I can change settings in the MCC without those changes affecting my code just to see what they affect.  I also 'exclude from compilation' all the files in the 'mcc_generated_files' folder of course.
 
I'm thinking this would be a good way to build a project in that an amount of possibly helpful code is in place and maybe I can just tweak it.  Am I wrong ?  At least this is what happens to me when I ask for help at Microchip.  They encourage you to start a new project with them...
 
The whole MPLABX project is attached (by hook or by crook ...)
 
Under the MLA USB device lite module there is an option 'endpoint 0 size'.  Apparently the option allows 8 (bytes), 16, 32 and 64.  See line #32 in usb_device_config.h.

When I try to compile selecting the 64-byte option it throws this error: 'error: (1250) could not find space (64 bytes) for variable _CtrlTrfData'.  It is probably an error in the MCC generated code right ?
 
At 32 bytes the memory usage is: data 38%, program 44%.
At 16 bytes the memory usage is: data 36%, program 44%.
 
Rgds,
 

Attachment(s)

Attachments are not available: Download requirements not met
#42
swmcl
Super Member
  • Total Posts : 271
  • Reward points : 0
  • Joined: 2014/05/10 13:54:42
  • Location: Queensland
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 13:28:39 (permalink)
0
When a device is enumerated the USB data packet size is set ... yes ?

This means that unless you re-enumerate each time you send a USB packet, all packets must be the same length ... which means USB comms is not suited to variable packet-length frames ... yes ?

This would explain the need to pad out the last frame at the end of a large byte string. 

( All very obvious I know but it takes me some time OK ! )
#43
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 14:59:50 (permalink)
0
I was able to download and build the project, but I had to relocate most of the files because they were absolute addresses that used "C:\users\administrators". I also saw the error when I changed the USB_EP0_BUFF_SIZE to 64:
#define USB_EP0_BUFF_SIZE        32    // Valid Options: 8, 16, 32, or 64 bytes.
                                // Using larger options take more SRAM, but
                                // does not provide much advantage in most types
                                // of applications.  Exceptions to this, are applications
                                // that use EP0 IN or OUT for sending large amounts of
                                // application related data.

There is also the following:
/** ENDPOINTS ALLOCATION *******************************************/
/* CDC */
#define CDC_COMM_INTF_ID        0x0
#define CDC_COMM_EP              1
#define CDC_COMM_IN_EP_SIZE      10

#define CDC_DATA_INTF_ID        0x01
#define CDC_DATA_EP             2
#define CDC_DATA_OUT_EP_SIZE    64
#define CDC_DATA_IN_EP_SIZE     64

The problem may be related to the following in fixed_access_memory.h
#define FIXED_ADDRESS_MEMORY

#if(__XC8_VERSION < 2000)
    #define IN_DATA_BUFFER_ADDRESS_TAG      @0x2080
    #define OUT_DATA_BUFFER_ADDRESS_TAG     @0x20C0
    #define CONTROL_BUFFER_ADDRESS_TAG      @0x2100
    #define DRIVER_DATA_ADDRESS_TAG         @0x2140
#else
    #define IN_DATA_BUFFER_ADDRESS_TAG      __at(0x2080)
    #define OUT_DATA_BUFFER_ADDRESS_TAG     __at(0x20C0)
    #define CONTROL_BUFFER_ADDRESS_TAG      __at(0x2100)
    #define DRIVER_DATA_ADDRESS_TAG         __at(0x2140)
#endif

Perhaps those addresses can be changed to accommodate the 64 bits, although it appears that they have 64 bytes in each section.
 
The PIC16F1455 has dual access RAM at locations 2000-204F, 2050-209F, ..., 2190-21DF, and 21E0-21EF.

 
#44
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 15:24:59 (permalink)
0
I was able to build the project with the following changes:
#define USB_EP0_BUFF_SIZE        64    // Valid Options: 8, 16, 32, or 64 bytes.
                                // Using larger options take more SRAM, but
                                // does not provide much advantage in most types
                                // of applications.  Exceptions to this, are applications
                                // that use EP0 IN or OUT for sending large amounts of
                                // application related data.
                                    
#define USB_MAX_NUM_INT         2   //Set this number to match the maximum interface number used in the descriptors for this firmware project

#define USB_MAX_EP_NUMBER        1   //Was 2 Set this number to match the maximum endpoint number used in the descriptors for this firmware project
    #define IN_DATA_BUFFER_ADDRESS_TAG      __at(0x2050) // was 2080
    #define OUT_DATA_BUFFER_ADDRESS_TAG     __at(0x20A0) // was 20C0
    #define CONTROL_BUFFER_ADDRESS_TAG      __at(0x20F0) // was 2100
    #define DRIVER_DATA_ADDRESS_TAG         __at(0x2140)

You might be able to fiddle with these #defines. I don't know if it needs more than one endpoint.
 
 

 
#45
swmcl
Super Member
  • Total Posts : 271
  • Reward points : 0
  • Joined: 2014/05/10 13:54:42
  • Location: Queensland
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 17:37:11 (permalink)
0
Hi Paul,

Thank you for your help.  It is great.
 
I concur.  I have compiled also with the same changes:
 
In fixed_address_memory.h,
 

    #define IN_DATA_BUFFER_ADDRESS_TAG      @0x2050 // was 2080
    #define OUT_DATA_BUFFER_ADDRESS_TAG     @0x20A0 // was 20C0
    #define CONTROL_BUFFER_ADDRESS_TAG      @0x20F0 // was 2100

 
In usb_device_config.h,



    #define USB_EP0_BUFF_SIZE        64
    #define USB_MAX_EP_NUMBER        1

 
Now to try to understand how it works ...
post edited by swmcl - 2019/10/20 17:43:09
#46
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/20 18:02:03 (permalink)
0
It also builds with the original tags. The main fix is setting USB_MAX_EP_NUMBER to 1.
 
The problem seems to arise from:
#define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG
 
 
 
#if (USB_PING_PONG_MODE == USB_PING_PONG__NO_PING_PONG)
    #define BDT_NUM_ENTRIES      ((USB_MAX_EP_NUMBER + 1) * 2)
#elif (USB_PING_PONG_MODE == USB_PING_PONG__EP0_OUT_ONLY)
    #define BDT_NUM_ENTRIES      (((USB_MAX_EP_NUMBER + 1) * 2)+1)
#elif (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG)
    #define BDT_NUM_ENTRIES      ((USB_MAX_EP_NUMBER + 1) * 4)
#elif (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0)
    #define BDT_NUM_ENTRIES      (((USB_MAX_EP_NUMBER + 1) * 4)-2)
#else
    #error "No ping pong mode defined."
#endif
 
#define CTRL_TRF_SETUP_ADDR     BDT_BASE_ADDR + (BDT_ENTRY_SIZE * BDT_NUM_ENTRIES)
#define CTRL_TRF_DATA_ADDR      CTRL_TRF_SETUP_ADDR + USB_EP0_BUFF_SIZE

#if(__XC8_VERSION < 2000)
    #define CTRL_TRF_SETUP_ADDR_TAG @ CTRL_TRF_SETUP_ADDR
    #define CTRL_TRF_DATA_ADDR_TAG  @ CTRL_TRF_DATA_ADDR
#else
    #define CTRL_TRF_SETUP_ADDR_TAG __at(CTRL_TRF_SETUP_ADDR)
    #define CTRL_TRF_DATA_ADDR_TAG  __at(CTRL_TRF_DATA_ADDR)
#endif

 
Since full ping pong mode is defined and if MAX_EP_NUMBER is 2, BDT_NUM_ENTRIES is 12.
volatile BDT_ENTRY BDT[BDT_NUM_ENTRIES] BDT_BASE_ADDR_TAG;

/********************************************************************
 * EP0 Buffer Space
 *******************************************************************/
volatile CTRL_TRF_SETUP SetupPkt CTRL_TRF_SETUP_ADDR_TAG;
volatile uint8_t CtrlTrfData[USB_EP0_BUFF_SIZE] CTRL_TRF_DATA_ADDR_TAG;

The problem is somewhere in that mess ;)

 
#47
swmcl
Super Member
  • Total Posts : 271
  • Reward points : 0
  • Joined: 2014/05/10 13:54:42
  • Location: Queensland
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/21 17:23:56 (permalink)
0
Mess it is !  I'm not a greatly experienced programmer but this is horrible to wade through.
#48
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/21 20:31:03 (permalink)
0
My only other experience with USB was a project using a PIC18F2455 and a circuit based on the Microchip PICdem FSUSB demo module. Originally I used the original PICdem USB board that used a PIC16C745  and PIC16C765. I attended a seminar where I was given the newer development board, which enabled me to use the MLA USB stack to develop my project. It is called the "Ortmaster", which has hardware and software to read millivolts on a 1000A shunt for current and time measurements of AC current pulses from 5 amps to 10,000 amps as encountered in Oil Recloser Testing (hence ORT). I have a patent on the test set, ORT-15 and ORT-560, awarded 1979. The original design used all analog and TTL/CMOS components, but around 1994 I developed the first Ortmaster, ORTM-1 which used MSDOS software and the parallel port to read current and time more accurately. After MSDOS and parallel ports were superseded with Windows and USB, around 1994, I developed the ORTM-4 which is currently in production.
 
The heart of the ORTM-4 is a 4"x6" PCB with a USB-Serial interface between the computer and a second circuit on the board that uses a PIC18F2420 and various analog and digital components for current measurement.
 

 


 
#49
NorthGuy
Super Member
  • Total Posts : 5810
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/21 20:38:48 (permalink)
+1 (1)
swmcl

 
    #define USB_EP0_BUFF_SIZE        64
 

 
EP0 is for control transfers which are rare. It is used mostly during enumeration.
post edited by NorthGuy - 2019/10/22 07:13:54
#50
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/21 23:49:53 (permalink)
0
I programmed my PIC16F1455 prototype with the PIC16F1455_USB_to_Serial code, and it fails enumeration. My Demo_PIC16F1455 enumerates as a COM port. There are some differences in the code, such as:
#elif defined(_16F1459) || defined(_16LF1459) || defined(_16F1454) || defined(_16LF1454) || defined(_16F1455) || defined(_16LF1455)
        #define IN_DATA_BUFFER_ADDRESS 0x2140
        #define OUT_DATA_BUFFER_ADDRESS 0x2190
        #define LINE_CODING_ADDRESS 0x20A0
        #define NOTICE_ADDRESS (LINE_CODING_ADDRESS + LINE_CODING_LENGTH)

        #define IN_DATA_BUFFER_ADDRESS_TAG  @IN_DATA_BUFFER_ADDRESS
        #define OUT_DATA_BUFFER_ADDRESS_TAG @OUT_DATA_BUFFER_ADDRESS
        #define LINE_CODING_ADDRESS_TAG     @LINE_CODING_ADDRESS
        #define NOTICE_ADDRESS_TAG          @NOTICE_ADDRESS

 I also discovered that the PIC16F1455 has ICSPCLK and ICSPDAT on pins 9 and 10 instead of the more usual 12 and 13, which are used for the USB D- and D+. Apparently they can be used for LVP for legacy PIC18Fxx50 devices, but did not work for HV programming.
post edited by PStechPaul - 2019/10/22 02:24:30

 
#51
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/22 14:29:52 (permalink)
0
I found an old post that addressed the problem of the relocated programming pins: https://www.microchip.com/forums/m983458.aspx?high=PIC16F1455
 
I also discovered that my Demo_PIC16F1455 project is a simple USB serial device and not a USB-serial converter. I added a header to TxD and RxD and found that there was no signal on the pins, but when connected to TeraTerm every character I typed was echoed with it incremented by one.
    if(USBUSARTIsTxTrfReady())
    {
        numBytesRead = getsUSBUSART(USB_Out_Buffer,64);
        if(numBytesRead != 0)
        {
            BYTE i;
            
            for(i=0;i<numBytesRead;i++)
            {
                switch(USB_Out_Buffer[i])
                {
                    case 0x0A:
                    case 0x0D:
                        USB_In_Buffer[i] = USB_Out_Buffer[i];
                        break;
                    default:
                        USB_In_Buffer[i] = USB_Out_Buffer[i] + 1;
                        break;
                }

            }

            putUSBUSART(USB_In_Buffer,numBytesRead);
        }
    }


 
#52
PStechPaul
Super Member
  • Total Posts : 2443
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: Best advice for making a USB to serial converter 2019/10/22 16:03:03 (permalink)
0
I was able to make a new project which now functions as a USB to serial emulator. I had to add a 10k pullup to the RxD pin to keep it from reading the signal from the TxD pin. Now I have to connect them together to see the sent characters returned.
 
I tried to upload the zipped project to the forum - stupid Access Denied again. I'll upload it to my web server:
http://enginuitysystems.c...55_Serial_Emulator.zip

 
#53
Page: < 123 Showing page 3 of 3
Jump to:
© 2019 APG vNext Commercial Version 4.5