|
|
View previous topic :: View next topic |
Author |
Message |
Oli Guest
|
PIC24 with USB / Isolated problem - what is happening? |
Posted: Fri May 22, 2009 7:50 am |
|
|
Hi All
I have finally created a simple reasonably isolated example of the problem I have been experiencing with USB on PIC24 using PCD 4.092 and 4.093.
The below program does not work - USB is established although no data is sent over USB.... However, any one of the following things fixes the problem (and it behaves as expected):
- if you comment out the first line (sprintf)
- change the sprintf to strcpy
- remove the empty function setup_pic_peripherals
- moving the interrupts to below the usb_cdc.h include
I have included the .SYM of the compiled program below. I don't understand how re-ordering those interrupts could make a difference. Or removing an empty function that is never called making a difference! I would really appreciate it if somebody could help explain what I am experiencing.
Many thanks
EDIT: Also, this warning is given when compiling.
"usb_endpoint_control_registers needs to be positioned at the start of a 512 byte boundry"
drilling to the code (that was given in the example for the same processor I'm using) gives #locate usb_endpoint_control_registers=0xA00
Why have they used this specific location? (2560, 5 x 512) it seems quite an arbitrary position?
Code: | #include <24FJ256GB110.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP1 //ICD uses PGC1/PGD1 pins
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES XT
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES WPEND_LOW
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES WPFP0
#FUSES PR_PLL //Enable PLL for primary oscillator?
#FUSES PLL3 //Divide By 3(12MHz oscillator input)
#FUSES RESERVED //Used to set the reserved FUSE bits
#FUSES DISUVREG
#use delay(clock=32000000)
#include <string.h>
#include <stdlib.h>
#use rs232(baud=9600,parity=N,xmit=PIN_D2,rcv=PIN_D1,bits=8,FORCE_SW,stream=GPS)
#use rs232(baud=9600,parity=N,bits=8,UART1,DISABLE_INTS,stream=GSM)
#use i2c(Master,fast,sda=PIN_A15,scl=PIN_A14)
// Memory / Buffer size definitions
#word U1OTGCON = 0x0486 // USB on the go reg
#bit OTGEN = U1OTGCON.2 // enable bit for OTG
#bit DPPULUP = U1OTGCON.7 // pull ups on USB
BYTE device_fw[21]; // firmware version of the device
// DEFINE GLOBAL VARIABLES FOR SERIAL COMMS
BYTE main_buffer[255]; // initial buffer where everything is dumped, also used for sending txts
BYTE next_in = 0;
BYTE next_out = 0;
#int_timer1 // Triggered by timer1 interrupt
void timer1_isr(void) // occurs every (12000000 / 4) / 32768 / 8 = 11.44 / sec or 0.0873 seconds / interrupt
{
}
#int_timer2
void timer2_isr(void)
{
}
//BYTE debug_getc(void);
#int_rda
void serial_isr() {
int8 t;
main_buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % 255;
if(next_in==next_out)
next_in=t; // Buffer full !!
}
#include <usb_cdc.h> // USB
void setup_pic_peripherals (void)
{
}
void main(void)
{
sprintf(device_fw, "Test String Copy");
setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_uart(TRUE, GSM);
clear_interrupt(INT_RDA);
enable_interrupts(int_rda);
enable_interrupts(intr_global);
usb_attach();
usb_init_cs();
OTGEN = 1; // needed
DPPULUP = 1; // needed
usb_task();
do
{
//local_config_mode();
printf(usb_cdc_putc, "Really long test sentence! please please please work!\r\n");
delay_ms(200);
} while (TRUE);
} |
.SYM:
Code: | [size=7][/size]W0 @SCRATCH
W0L _RETURN_
W0 -W1 @DIVS3232A.P1
W0 -W1 @READ_ROM_MEMORY.P2
W0 -W1 @MULS3232.P3
W0 -W3 @MULFF64.P4
W0 -W3 @I64TOF64.P5
W0 -W3 @DIVFF64.P6
W0 -W3 @I64TOF48.P7
W0 -W3 @ADDFF64.P8
W0 -W1 @MULFF.P9
W0 -W2 @ADDFF48.P10
W0 -W1 @ADDFF.P11
W0 @delay_ms1.P12
W0 @delay_us1.P13
W0 -W1 @DIVFF.P14
W0 -W2 @MULFF48.P15
W0L @SPRINTF.P16
W0 -W2 @DIVFF48.P17
W0 @ITOF.P18
W0 -W1 @MUL3232.P19
W1 @SCRATCH
W1L @I2C_WRITE_1.P1
W1L @I2C_READ_1.P2
W2 @SCRATCH
W2 @READ_ROM_MEMORY.P1
W2 -W3 @ADDFF.P2
W2 -W3 @DIVS3232A.P3
W2 -W3 @MULFF.P4
W2 -W3 @MUL3232.P5
W2 -W3 @MULS3232.P6
W2 -W3 @DIVFF.P7
W3 -W5 @MULFF48.P1
W3 -W5 @ADDFF48.P2
W3 -W5 @DIVFF48.P3
W3 @READ_ROM_MEMORY.P4
W4 -W7 @DIVFF64.P1
W4 -W7 @ADDFF64.P2
W4 -W7 @MULFF64.P3
042 SR
480 UOTGIR
480.4 UOTGIR_ACTV
482 UOTGIE
482.4 UOTGIE_ACTV
486 U1OTGCON
486 UOTGCON
486.2 OTGEN
486.7 DPPULUP
488.0 UPWRC_USBPWR
488 UPWRC
488.1 UPWRC_SUSPND
48A UIR
48A.0 UIR_URST
48A.1 UIR_UERR
48A.2 UIR_SOF
48A.3 UIR_TRN
48A.4 UIR_IDLE
48A.7 UIR_STALL
48C.0 UIE_URST
48C UIE
48C.1 UIE_UERR
48C.2 UIE_SOF
48C.3 UIE_TRN
48C.4 UIE_IDLE
48C.7 UIE_STALL
48E UEIR
490 UEIE
492 USTAT
494 UCON
494.0 UCON_USBEN
494.1 UCON_PPBRST
494.2 UCON_RESUME
494.5 UCON_PKTDIS
494.6 UCON_SE0
496 UADDR
498 UBDTP1
49A UFRML
49C UFRMH
4A6 UCFG1
4A8 UCFG2
4AA-4C9 UEP_SFR
800-801 strtok.save
802-805 _Randseed
806-807 rs232_errors
808-81C device_fw
81D next_in
81E-91C main_buffer
91D next_out
91E-924 USB_stack_status
925 usb_state
926-928 USB_STRING_DESC_OFFSET
929 __setup_0_tx_size
92A USB_address_pending
92B usb_getdesc_ptr
92C usb_getdesc_len
92D usb_cdc_put_buffer_nextin
92E-92F USB_Interface
930-936 usb_cdc_line_coding
937.0 usb_cdc_got_set_line_coding
938-939 usb_cdc_break
93A-941 usb_cdc_encapsulated_cmd
942-980 usb_cdc_put_buffer
981 usb_cdc_carrier
982-984 usb_cdc_get_buffer_status
985 g_LastCDCDataPacketSize
986 __usb_cdc_state
988-989 @sprintf_string
A00-A17 usb_endpoint_control_registers
A18-B1F g_USBDataBuffer
B20 usb_cdc_putc.c
B22 usb_cdc_putc_fast.c
B24-B25 usb_cdc_putc_fast.oldSR
B38 serial_isr.t
B38 usb_isr.TRNAttempts
B3C usb_isr_tok_dne.en
B3C-B3D usb_clear_isr_reg.sfr
B3E-B3F usb_token_reset.i
B3E-B3F pidKey
B44 usb_unstall_ep.endpoint
B44 usb_endpoint_stalled.endpoint
B45.0 usb_endpoint_stalled.direction
B45.0 usb_unstall_ep.direction
B46-B47 usb_clear_isr_flag.sfr
B46-B47 usb_endpoint_stalled.st
B48 usb_clear_isr_flag.BIT
B48 usb_stall_ep.endpoint
B49.0 usb_stall_ep.direction
B4A usb_isr_tok_out_dne.endpoint
B50 usb_set_configured.config
B51 usb_set_configured.en
B52-B53 usb_set_configured.addy
B52 usb_endpoint_is_valid.endpoint
B52 usb_isr_tok_in_dne.endpoint
B53.0 usb_endpoint_is_valid.direction
B54 usb_flush_out.endpoint
B54 usb_set_configured.new_uep
B55 usb_flush_out.tgl
B56-B57 usb_flush_out.oldBD
B56-B57 usb_set_configured.len
B58-B59 usb_set_configured.newBD
B58-B59 usb_flush_out.newBD
B58 usb_isr_tkn_setup_StandardInterface.curr_config
B5A-B5B usb_flush_out.len
B5A usb_rx_packet_size.endpoint
B5C usb_set_address.address
B5E usb_put_packet.endpoint
B5F usb_put_packet.tgl
B60-B61 usb_put_packet.ptr
B62-B63 usb_put_packet.len
B64-B65 usb_put_packet.buff_add
B66-B67 usb_init_ep0_setup.newBD
B66-B67 usb_copy_desc_seg_to_ep.i
B68 usb_copy_desc_seg_to_ep.c
B6C usb_request_send_response.len
B76 usb_disable_endpoints.i
B7A usb_flush_in.endpoint
B7B usb_flush_in.tgl
B7C-B7D usb_flush_in.len
B7C usb_disable_endpoint.en
B7E-B7F usb_flush_in.oldBD
B80-B81 usb_flush_in.newBD
B8A usb_tbe.en
4780-47FF Stack
ROM Allocation:
0011A6 @delay_ms1
0003DE @GETCH_1_
0003A6 timer1_isr
0003C2 timer2_isr
000404 serial_isr
000200 usb_ep_tx_type
00021C usb_ep_rx_type
000238 usb_ep_tx_size
000262 usb_ep_rx_size
00028C USB_CONFIG_DESC
0002D6 USB_NUM_INTERFACES
0002E4 USB_CLASS_DESCRIPTORS
0002F8 USB_DEVICE_DESC
000316 USB_STRING_DESC
000C30 usb_tbe
001098 usb_detach
0010EA usb_init_cs
001074 usb_attach
0010F0 usb_task
000C6C usb_flush_in
000DCE usb_put_packet
000B9C usb_flush_out
000D64 usb_rx_packet_size
0009B6 usb_stall_ep
000978 usb_unstall_ep
0009F4 usb_endpoint_stalled
000DA8 usb_set_address
0006F4 usb_set_configured
000566 usb_clear_trn
000FD0 usb_isr
0005C6 usb_isr_sof
00050E usb_disable_endpoint
00054C usb_disable_endpoints
000578 usb_isr_rst
00047A usb_init_ep0_setup
0004B6 usb_isr_uerr
0005B6 usb_isr_uidle
000468 usb_isr_activity
000492 usb_isr_stall
000E70 usb_isr_tok_dne
0005D4 usb_request_send_response
000ABE usb_request_get_data
0005DA usb_request_stall
000456 usb_clear_isr_flag
0004AA usb_clear_isr_reg
0004E6 usb_token_reset
000932 usb_endpoint_is_valid
000E44 usb_isr_tok_in_dne
000D90 usb_isr_tok_out_dne
000B58 usb_isr_tok_setup_dne
0007E8 usb_isr_tkn_setup_StandardDevice
0008A6 usb_isr_tkn_setup_StandardInterface
000A52 usb_isr_tkn_setup_StandardEndpoint
00065E usb_Get_Descriptor
000DC0 usb_finish_set_address
0005E0 usb_copy_desc_seg_to_ep
000D22 usb_isr_tok_out_cdc_control_dne
000AC4 usb_isr_tkn_cdc
000D80 usb_isr_tok_out_cdc_data_dne
000E3A usb_isr_tok_in_cdc_data_dne
000E1C usb_cdc_flush_out_buffer
0004CC usb_cdc_init
001126 usb_cdc_putc_fast
001172 usb_cdc_putc
0011B6 MAIN
000346 @const693
001066 @SPRINTF
000364 @const697
0011B6 @cinit
0136 StrtoulGO
0136 StrtolGO |
|
|
|
Oli Guest
|
Anybody have any pointers? |
Posted: Sun May 24, 2009 6:39 am |
|
|
Hi again
Does anybody have any ideas about the above? I'm at a point where I have to identify what is going on before I make any more progress. Can anybody offer any advice on tracking down the problem?
Many thanks |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu May 28, 2009 1:27 am |
|
|
As a late comment:
I don't see the changes, e.g. omitting dead code or changing function placing directly related to the reported application failure. E.g. omitting setup_pic_peripherals(), that isn't called at all, moves some variable allocations by a small amount. (Although the reason isn't exactly understandable, I don't see a problem in this modification).
So the most likely explanation is, that this modification brings on a latent application code or PCD bug. If so, application failure is more or less accidental and it won't get you much further to analyze the code differences. Instead, you have to trace the code failure directly.
Unfortunately, I didn't yet use a PIC24FJxxGB chip and have no option to trace your code in operation. I'm planning another project with PIC24FJxxGB, so may be, I'll face the problem soon. Generally, I'm used to reveal some PCD bugs with each new complex piece of code.
Yesterday, I e.g. dared to use an array argument inside a SPI built-in function. (For a reason, discussed elsewhere, spi_read() must be used to send data).
Code: | spi_read(ProgBuf[i]); |
But it failed, because PCD preferred to push and pop SPI1BUF within the code as if it would be a RAM variable. PCD don't like it that complex, you have to think more basic:
Code: | b = ProgBuf[i];
spi_read(b); | Everything is O.K. then.
Regarding the said warning
Quote: | "usb_endpoint_control_registers needs to be positioned at the start of a 512 byte boundry" |
It's issued unconditionally by the library code and isn't more specific then telling "Thank you for choosing CCS C".
Best regards,
Frank |
|
|
Guest
|
Re: PIC24 with USB / Isolated problem - what is happening? |
Posted: Tue Jun 02, 2009 9:52 am |
|
|
Oli wrote: | EDIT: Also, this warning is given when compiling.
"usb_endpoint_control_registers needs to be positioned at the start of a 512 byte boundry"
drilling to the code (that was given in the example for the same processor I'm using) gives #locate usb_endpoint_control_registers=0xA00
Why have they used this specific location? (2560, 5 x 512) it seems quite an arbitrary position?
|
Read the datasheet of the PIC, it's a limitation of the USB engine hardware. The endpoint descriptor table has to start on a 512 byte boundry. |
|
|
Oli Guest
|
if you are using explorer16 board |
Posted: Mon Jun 08, 2009 8:21 am |
|
|
An update:
I have since purchased an explorer16 board with USB pictail and the PIC24FJ256GB110 PIM
To replicate the above anomolies on this board, you just need to swap the '#fuses' and '#use delay' lines for:
Code: |
#fuses HS,PR_PLL,NOWDT,DISUVREG,ICSP2
#use delay(clock=32M) //8MHz clock is 4x because of PLL
#fuses PLL2 //Divide 8MHz by 2 to get the 4MHz required for USB
|
The same thing happens, so this rules out a problem with my hardware. |
|
|
Oli Guest
|
Solution! |
Posted: Fri Jun 26, 2009 3:48 am |
|
|
Hi all.
After contacting CCS support, it turns out it was a bug in the USB drivers somewhere. They have sent me the new versions and the above example now works as expected, so expect it in the next compiler revision (current is 4.093)
Oliver |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|