Skip to main content

Messages

This section allows you to view all Messages made by this member. Note that you can only see Messages made in areas you currently have access to.

Messages - JTR

316
Open source USB stack / Re: Re: Honken USB stack cdc test app
A few notes.

Yes there are errors relating to the USTAT differences for the PIC24 in various places in the stack. I have previously posted in this thread some further details but I do not claim that I have found and related all of them.

I cannot find any reference anywhere as to why the COSC is set to FRCDIV at this point. I am still looking per chance that I missed something. However the data sheet and the oscillator reference manual don't seem to be shedding any light. Nor is there anything in the latest (2.8) microchip stack that alludes to anything being required. It may well be that the COSC bits are N/A as we select HS_PLL as a start-up oscillator and do not enable clock switch over. I am not sure.
317
Open source USB stack / Re: Re: Honken USB stack cdc test app
While you are looking at that also check the USB_USTAT2BD(X) for the PIC24. They are the same for the PIC18 in the stack version I have here but that cannot be correct as the USTAT SPRs are different on each.

Sorry to be so brief right now I have other duties.
318
Open source USB stack / Re: Honken USB stack cdc test app
[quote author="rebeccapalmer"][
To define PIC_24F or PIC_18F for every processor I use:
[code]#if defined __PIC24F__ || defined __PIC24FK__ //we don't care about 24H/30/33 because they don't have USB anyway
[/quote]

Best I can tell none of the PIC24FK series have USB either.
319
Open source USB stack / Re: Re: Honken USB stack cdc test app
[quote author="rebeccapalmer"]After further thought, I decided that rather than having to separately set USB_BDT_ADDRESS, USB_DATA_ADDRESS, USB_CDCDATA_ADDRESS (and more if we later add other device classes; #define USB_DATA_ADDRESS USB_BDT_ADDRESS+8*USB_NUM_ENDPOINTS doesn't work because arithmetic is not done inside #pragma directives), it made more sense to have one section for everything that needs to be in USB memory: only one USB_BDT_ADDRESS that must be set for each processor, no linker script required.

usb_stack.c:
Code: [Select]
/* Allocate buffers for buffer description table and the actual buffers */
#if USB_PP_BUF_MODE == 0

#if defined(PIC_18F)
#pragma udata usb_bdt=USB_BDT_ADDRESS
volatile BDentry usb_bdt[2*USB_NUM_ENDPOINTS];
#elif defined(PIC_24F)
volatile BDentry usb_bdt[2*USB_NUM_ENDPOINTS] __attribute__((aligned(512)));
#endif
/*If you get the linker error "section 'usb_bdt' can not fit the absolute section",
 * your buffers are too large for one 256-byte bank.  Use additional banks
 * (if your device has them) with #pragma udata usb_data1=USB_DATA1_ADDRESS, etc

/* Only claim buffer for ep 0 */
unsigned char usb_ep0_out_buf[USB_EP0_BUFFER_SIZE];
unsigned char usb_ep0_in_buf[USB_EP0_BUFFER_SIZE];
#ifdef CDC_BUFFER_SIZE //are we a CDC class device?
unsigned char cdc_acm_out_buffer[CDC_BUFFER_SIZE];
unsigned char cdc_acm_in_buffer[CDC_BUFFER_SIZE];
unsigned char cdc_rx_buffer[CDC_BUFFER_SIZE];
unsigned char cdc_tx_buffer[CDC_BUFFER_SIZE];
#endif
#else
#error "Ping pong buffer not implemented yet!"
#endif

#pragma udata
cdc.c:
Code: [Select]
extern unsigned char cdc_acm_out_buffer[CDC_BUFFER_SIZE];
extern unsigned char cdc_acm_in_buffer[CDC_BUFFER_SIZE];
extern unsigned char cdc_rx_buffer[CDC_BUFFER_SIZE];
extern unsigned char cdc_tx_buffer[CDC_BUFFER_SIZE];
If there is too much for one bank (over 256 bytes; we currently use 72 bytes) it needs to be manually divided into banks with #pragma udata usb_data1=USB_DATA1_ADDRESS (0x500 on an 18F4550) etc (not doing so will cause a linker error), but this is also true of the linker script method.
[/quote]

For certain something like this should be used. There is no point juggling linker scripts when there is no need to.  Microchip have a system like this in their stack.

[quote author="rebeccapalmer"]
[quote author="JTR"]As you can see in the last two there is no code generated for the runtime variable trn_status while there is for my proposed correction. ???[/quote]
If ping-pong is off (the default), trn_status isn't supposed to do anything at this point, hence its absence from the compiled code.
[quote author="JTR"]The runtime variable isn't just inside an array index, it is also inside a compile time macro.[/quote]
Macros in C are text substitutions, not compile-time calculations as such (constant folding, where calculations that can be done at compile time are, is a separate process and occurs whether or not the constants are part of a macro), so the parameters can be run-time variables.[/quote]

Yes, thanks... I have worked it all out. I see how the C macros are work now. Funny thing is that I  learn a lot about C on code that is not even required or used. :)
320
Open source USB stack / Re: Honken USB stack cdc test app
[quote author="ian"]

I noticed that in my debugging, the interrupt never fires.
[/quote]

Oh but it did, just the wrong interrupt. :)  EDIT: Vector that is.

[quote author="ian"]

It looks like there are a lot of good updates and findings. I can apply any patches and fixes mentioned in this thread to SVN. Is there a general consensus about which should be applied now?
[/quote]

I have taken the view that there needs to be a reshuffle of how and where things are defined in the header files and even what header files are required. The stack I am working on is bit of a departure from the way it is organized now. My intent is to apply myself to getting this in order and then I will send you a zip file.

Where or not people agree with me doesn't really matter. I will not be offended if people see things differently or have better ideas. You don't have to use anything I have changed. However, I do have the experience of having done this before and knowing what works and why. When I have something tested and operational I will hand it over and explain the rational for the reorganization.

I am noting the comments posted here and if there is any correction or good idea then I will incorporate that into my work.

Meantime any further work done on the CDC side of things can easily be added to what I have done.
321
Open source USB stack / Re: Re: Honken USB stack cdc test app
Thanks for the heads up Rebecca and Honken. Here are some disassemblies
Code: [Select]
703:                 		bd = &usb_bdt[USB_CALC_BD(0, USB_DIR_IN, 0x01) ^ ((trn_status & 0x02)>>1)];
  13E8    0E02    MOVLW 0x2
  13EA    15D0    ANDWF 0xd0, W, BANKED
  13EC    40E8    RRNCF 0xfe8, W, ACCESS
  13EE    0B7F    ANDLW 0x7f
  13F0    0A01    XORLW 0x1
  13F2    0D04    MULLW 0x4
  13F4    CFF3    MOVFF 0xff3, 0x14
  13F6    F014    NOP
  13F8    CFF4    MOVFF 0xff4, 0x15
  13FA    F015    NOP
  13FC    0E00    MOVLW 0
  13FE    2614    ADDWF 0x14, F, ACCESS
  1400    0E02    MOVLW 0x2
  1402    2215    ADDWFC 0x15, F, ACCESS
  1404    0E02    MOVLW 0x2
  1406    C014    MOVFF 0x14, 0xfdb
  1408    FFDB    NOP
  140A    0E03    MOVLW 0x3
  140C    C015    MOVFF 0x15, 0xfdb
  140E    FFDB    NOP

// JTR righthand side of calculation removed.
704:              bd = &usb_bdt[USB_CALC_BD(0, USB_DIR_IN, 0x01)];  //^ ((trn_status & USTAT_ODD_EVEN)>>USTAT_ODD_EVEN_SHIFT)];    //((trn_status & 0x02)>>1))];
  13E8    50D9    MOVF 0xfd9, W, ACCESS
  13EA    0F02    ADDLW 0x2
  13EC    6EE9    MOVWF 0xfe9, ACCESS
  13EE    CFDA    MOVFF 0xfda, 0xfea
  13F0    FFEA    NOP
  13F2    0E04    MOVLW 0x4
  13F4    6EEE    MOVWF 0xfee, ACCESS
  13F6    0E02    MOVLW 0x2
  13F8    6EED    MOVWF 0xfed, ACCESS

// JTR righthand side of calculation restored to what it was. 
704:              bd = &usb_bdt[USB_CALC_BD(0, USB_DIR_IN, 0x01 ^ ((trn_status & USTAT_ODD_EVEN)>>USTAT_ODD_EVEN_SHIFT))];    //((trn_status & 0x02)>>1))];
  13E8    50D9    MOVF 0xfd9, W, ACCESS
  13EA    0F02    ADDLW 0x2
  13EC    6EE9    MOVWF 0xfe9, ACCESS
  13EE    CFDA    MOVFF 0xfda, 0xfea
  13F0    FFEA    NOP
  13F2    0E04    MOVLW 0x4
  13F4    6EEE    MOVWF 0xfee, ACCESS
  13F6    0E02    MOVLW 0x2
  13F8    6EED    MOVWF 0xfed, ACCESS

As you can see in the last two there is no code generated for the runtime variable trn_status while there is for my proposed correction. ???

The runtime variable isn't just inside an array index, it is also inside a compile time macro.

However! As rebecca suggests I have to agree that bd is not used at all and the whole thing is moot. Looks to me that the code can be removed. It does nothing.  I wished I had of looked closer at that. Would of saved an hours work. :(

Any differing view points on this?
322
Open source USB stack / Re: Re: Honken USB stack cdc test app
Attention C programming experts. Please confirm this for me.

In usb_stack.c this line:

        bd = &usb_bdt[USB_CALC_BD(0, USB_DIR_IN, 0x01 ^ ((trn_status & 0x02)>>1))];

Is meant to be:

        bd = &usb_bdt[USB_CALC_BD(0, USB_DIR_IN, 0x01) ^ ((trn_status & 0x02)>>1)];

Otherwise, well as it appears to me, you are trying to XOR a compile time variable to unknown run time variable to create the index to the usb_bdt.

I looked at the dissassembly and the code for the first case just is not doing anything like what is required.

Right now, because we are not using ping-pong buffering it does not make a difference to the operation of the code. However if ping-pong is added it surely will.

As it is, even with my correction, the code is not correct for the PIC24 parts and will need to be:

bd = &usb_bdt[USB_CALC_BD(0, USB_DIR_IN, 0x01) ^ ((trn_status & USTAT_ODD_EVEN)>>USTAT_ODD_EVEN_SHIFT)];

Where USTAT_ODD_EVEN and USTAT_ODD_EVEN_SHIFT are defined uniquely for the PIC18 and PIC24 devices.

I am near certain I am right but some confirmation wouldn't go astray.
323
Open source USB stack / Re: Re: Honken USB stack cdc test app
A very timely post Rebecca! I am just looking at all this now and formulating the best, most flexible approach. I have already done all this with my assembler stack and have a good template to work with.

I missed the shorthand way of determining a PIC24. Way to go!

Yes the issue of the number of endpoints needs to be addressed in a few places. Already I have done something similar to what you did however I labeled the max number of endpoint on the chip as MAX_CHIP_ENDPOINT as USB_MAX_ENDPOINTS is already used in a different way in several other existing  stacks.

Re the configuation bits and hardware init. This is not really an issue. These belong not to the stack but to the hardware. They are implementation specific and except for the PLL settings they are always going to be highly variable and user defined.
324
Open source USB stack / Re: Re: Honken USB stack cdc test app
Yeah, there are a few holes in the stack like this. The header files need to be reorganized somewhat so that a project written say for the 18F24J50 with very easily port to say the 18F47J53. This should be a cinch with no hidden gotchas hiding deep within the stack proper or other unintuitive or undocumented headers.

It is a work in progress but we will get there.
325
Open source USB stack / Re: Re: Honken USB stack cdc test app
Near on 6AM here in Oz and I have just finished a 12 hour straight debug session. Happy to say that I got the basic stack working with all the changes. It turned out to be a big job. How, what, why  and when the stack worked previously is something I am puzzled by as I found a real show stopper with the interrupts. Basically priority interrupts where being used but I could not find anywhere in the code how they were enabled. By default the legacy mode is enabled and this was not changed by setting bit-7 in the RCON register.

Re the PIC24 support. There are some bit differences from the PIC18 pics that have not been addressed. Please double check these corrections in the usb_p24f.h header.
Code: [Select]
/* USTAT */
typedef unsigned char usb_status_t;
#define GetUsbTransaction()                                    (U1STAT)
#define USB_STAT2EP(x)                                          ((x>>4)&0x0F) //((x>>3)&0x0F)  JTR corrections
#define USB_STAT2DIR(x)                                        ((x>>3)&0x01) //((x>>2)&0x01)  ""
#define USB_STAT2ADDR(x)                                        ((x>>2)&0x1F) //((x>>2)&0x1F)  ""
#define USB_STAT2PPI(x)                                        ((x>>2 &0x01) //((x>>1)&0x01)  ""

I may have found other bugs too but right now I am too sleepy to go looking.

More soon.
326
Open source USB stack / Re: Re: Honken USB stack cdc test app
While I an waiting on my hardware to arrive I should be able to zip up the corrections I have made and so we can see how they go. I have addressed a few PIC24 specific bugs and also brought my USB knowledge to address a few TODO things that were marked with a "?" and some other errors that trace back to the original source this effort was inspired by.

Design wise, I stayed with the principle of keeping the core USB stack (I.E. CHP9 specs and house keeping) in the one module. Already the stack was pretty much like this and it that is well done.  You will see the wisdom of this when you discover how easy it will be in future to use the stack for a HID keyboard and anything else you want. The core of the stack does not need to be altered. and can even be a object file that you simply link in.

I am at the point where I will start testing the updates on a PIC18F14K50 and a PIC18F2550. Other bits and pieces are in the mail.
327
Open source USB stack / Re: Re: Honken USB stack cdc test app
After a day of poking around C documentation and trying things I have managed to bring myself further up to speed with programming in C and have been able to alter the code in the way I know well it needed to be. I didn't particularly want to do this as I felt my expertise was better directed at the function of the USB stack and not trying to learn C on the fly. However, in the long run it was probably better that I took that extra step.

Hope to give the stack a good hit out over the weekend.
328
Open source USB stack / Re: Re: Honken USB stack cdc test app
Yeah, this debate stemming from the well constructed ambiguity of the data sheets has been debated on the microchip forums. It is very ambiguous.

Anyway. Back to the real task at hand. I need HELP! I am not pretending to be a C coder and there are somethings that need to be fixed up that is out of my league. What is required immediately are:

1) Either global variables or a macro/function that conveys the current USB CONFIGURED STATE. That is we need to be able to test the USB CONFIGURED STATE from within main.c. It will also be required in cdc.c
Code: [Select]
#if defined(PIC_18F)
void main( void )
#elif defined(PIC_24F)
void _USB1Interrupt(void);
int main(void)
#endif
{ unsigned char c;
init();
InitCDC();

while(1)
{

//usb_handler();
if (USB_configured() !=0)  // JTR addition function/macro or global variable required here.
{

if(DataRdyCDC())
{ c=getcCDC();
putcCDC(c);
}
}
}
}
2) A CALLBACK system for when the device enters the CONFIGURED STATE.
Code: [Select]
	case USB_REQUEST_SET_CONFIGURATION:
if (USB_NUM_CONFIGURATIONS >= packet[USB_wValue]) {
// TODO: Support multiple configurations
/* Configure endpoints (USB_UEPn - registers) */
usb_configured = packet[USB_wValue];
if (usb_configured !=0)    // JTR addition
                        {
user_configured_init();  //JTR addtion, USB Function endpoints set up done via CALLBACK .
// Note I have this working but what is preferred is for the callback to go to a separate device function module and not be handled in the CHP9 module.
}
rbdp->BDCNT = 0;
rbdp->BDSTAT = UOWN + DTS + DTSEN;
DPRINTF("DEV Set_Config 0x%02Xn", packet[USB_wValue]);
} else
usb_RequestError();
break;
In my assembler stack I just define global variables and use the extern directive etc. However as this is a C program there is a C way of doing things and the last thing I want to do is hack the code in a most unlike C way.

Without these two additions the stack is will be locked into a shaky path and not be very workable in the long run.

So is there any skilled C coder who can help out here. Of course you realize that it requires some resolution on what you want the stack to be. If you just want a CDC stack then why not stick everything into one file. If you want something flexible then judicious organization is required starting now. IMHO that is where the stack development is at. Currently it does not even test for the CONFIGURED STATE before trying to perform CDC functions. Also, if say you wanted to create a generic bulk device again you would have to alter the CHP9 code. This is not a desirable thing from my point of view.

The bottom line I have come to is that even if I can find and fix the logical errors (and I have found some) the fix-ups cannot really be tested until there is a workable way of testing for the  CONFIGURED STATE. I do not plan to try to fudge the C code in this way. Someone, anyone?
329
Open source USB stack / Re: Re: Honken USB stack cdc test app
@ rsdio. Yes, you are right. The internal oscillator for the "GB" series is not really good for USB. The "DA" series does however spec the internal oscillator for USB and this is where I got confused. It is interesting to note though that both series have the same maximum and minimum tolerances.  ???
330
Open source USB stack / Re: Re: Honken USB stack cdc test app
Yes it can Ian. A very nice feature indeed.

Note to all: I am adding a whole heap of new defines and header info to the existing stack. My aim is to have it portable across ALL PIC18 and PIC24 USB devices.  That is - ready to work out of the box and not have to be rewritten to add device support. All device/hardware/project support can be defined in a single header file and the core of the stack will remain unchanged.

There are some corrections to the PIC24 support to come.  Do not expect it to work for the PIC24 as is.

There will be some heavy lifting required to mature the stack. This is going to need some proficient C coders and that counts me out. However I can show what needs to be added and where and why as I have done all this in assembler.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01632460128session_write_close ( )...(null):0
20.01672591752ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01672592528Database_MySQL->query( ).../DatabaseHandler.php:119
40.06172731288Database_MySQL->error( ).../Db-mysql.class.php:273