legacy USB library and PIC32MX450F128H

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

legacy USB library and PIC32MX450F128H

#1 Post by phil31 » 27 May 2015 15:03

Hi all, team

i try to use the legacy USB HID device on a PIC32MX450F128H.
i try the "HID_Read_Write" example (interrupt mode)

i just modify the OSC settings to be compliant with my board :
16MHz external oscillator ==>
  • PLL input divider = 4
    PLL multiplier = 24 (define a 96MHz MCU clock)
    USB PLL input divider = 4
    USB PLL Enable
the CPU run right (i use an UART to putout some readable text and registers values)

but anyway, can't to have an right enumeration of a HID device : Windows 7 X64 complain about the device !

this is the first time i use this lib on PIC32, but i use it many many time on PIC18F.
it seem that the DMA3 channel is used in this lib version (IPC11 : DMA3 interrupt priority bits are set)
but when i check the DMACON registers, the DMA module is OFF !

here it is the code ( pretty same as the original ME example )

Code: Select all

' 
' * Project name:
'     HID_Read_Write (USB HID Read & Write Test)
' * Copyright:
'     (c) Mikroelektronika, 2012.
' * Revision History:
'     20120810:
'       - initial release (FJ);
' * Description:
'     This example establishes connection with the HID terminal that is active
'     on the PC. Upon connection establishment, the HID Device Name will appear
'     in the respective window. The character that user sends to PIC from the HID
'     terminal will be re-sent back to user.
' * Test configuration:
'     MCU:             P32MX795F512L
'                      http://ww1.microchip.com/downloads/en/DeviceDoc/61156F.pdf
'     Dev.Board:       EasyPIC Fusion v7 - ac:USB
'                      http://www.mikroe.com/easypic-fusion/
'     Oscillator:      XT-PLL, 80.000MHz
'     Ext. Modules:    None.
'     SW:              mikroBasic PRO for PIC32
'                      http://www.mikroe.com/mikrobasic/pic32/
' * NOTES:  
'     - None.
' *

program HID_Read_Write

dim cnt as byte
dim readbuff as byte[64]
dim writebuff as byte[64]

sub procedure USB1Interrupt() iv IVT_USB_1 ilevel 7 ics ICS_SRS
  USB_Interrupt_Proc()
end sub

sub procedure DebugString_UART(dim byref str as string)
   UART3_Write_Text(str)
   UART3_Write(0x0D)
end sub

sub procedure DebugStringLWord_UART(dim byref str as string, dim value as longword)
dim txt_buffer as string[8]
   UART3_Write_Text(str)
   LongWordToHex(value, txt_buffer)                      ' convertir le longword en HEX ASCII
   UART3_Write_Text(txt_buffer)
   UART3_Write(0x0D)
end sub

main:
   JTAGEN_bit = 0

   'AD1PCFG    = 0xFFFF
   ANSELB     = 0  ' IMPORTANT !! ALL IO's as DIGITAL pins
   ANSELC     = 0  ' IMPORTANT !!
   ANSELD     = 0  ' IMPORTANT !!
   ANSELE     = 0  ' IMPORTANT !!
   ANSELF     = 0  ' IMPORTANT !!
   ANSELG     = 0  ' IMPORTANT !!

   TRISF.B1   = 0  ' DBG_TX
   TRISF.B0   = 1  ' DBG_RX

   TRISF.B3   = 1  ' USBID
   
    Unlock_IOLOCK()
       PPS_Mapping_NoLock(_RPF1, _OUTPUT, _U3TX)  ' Sets pin PORTF.B1  to be Output and maps UART3 Transmit to it
       PPS_Mapping_NoLock(_RPF0, _INPUT,  _U3RX)  ' Sets pin PORTF.B0  to be Input  and maps UART3 Receive to it
    Lock_IOLOCK()
    UART3_Init_Advanced(512000, 96000, _UART_HIGH_SPEED, _UART_8BIT_NOPARITY, _UART_ONE_STOPBIT)  ' to DBG terminal


  DebugString_UART("START : ")
  DebugStringLWord_UART("OSCCON : ", OSCCON)
  
  USBIE_bit = 0
  IPC11SET = 7 << 10      ' Inerrupt priority 7
  
  EnableInterrupts()


  delay_ms(1000)
  HID_Enable(@readbuff,@writebuff)


  delay_ms(1000)
  DebugStringLWord_UART("OSCCON  : ", OSCCON)
  DebugStringLWord_UART("DMACON  : ", DMACON)
  DebugStringLWord_UART("DMASTAT : ", DMASTAT)
  
  while TRUE
    while(HID_Read() = 0)
    wend
    for cnt=0 to 63
      writebuff[cnt] = readbuff[cnt]
    next cnt
    while(HID_Write(@writebuff,64) = 0)
    wend
  wend
end.
my debug terminal show me

Code: Select all

OSCCON : 01673320<CR>
OSCCON  : 01673360<CR>
DMACON  : 00000000<CR>
DMASTAT : 00000000<CR>
please any advice, remarks, tips ?? .. what i'm missing ?


thanks, regards
Phil

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: legacy USB library and PIC32MX450F128H

#2 Post by darko.minic » 28 May 2015 09:12

Hi Phil,

I believe I have answered you on following topic:
http://www.mikroe.com/forum/viewtopic.p ... 46#p257746

Best regards,

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: legacy USB library and PIC32MX450F128H

#3 Post by phil31 » 28 May 2015 09:45

Hi Darko

i believe you don't read carefully this topic !
in that case i want to use the ORIGINAL lib .. which is available for this CPU target !

thanks

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: legacy USB library and PIC32MX450F128H

#4 Post by darko.minic » 28 May 2015 09:58

Hi Phil,

Did you ensure that your USB clock is 48MHz?
According to datasheet 48 MHz USB clock is required for proper USB operation.

Regards,
Darko

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: legacy USB library and PIC32MX450F128H

#5 Post by phil31 » 28 May 2015 15:16

well PLL settings is right for the SYSCLOCK ( as my UART work as expected )
i suppose yes the 48MHz for USB is right too ! but can't measure it so i provide my settings to see if anybody find something wrong ..?
the OSCCON register value seem right too

is it normal that the DMACON read is 0x0 ?

regards
phil

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: legacy USB library and PIC32MX450F128H

#6 Post by darko.minic » 29 May 2015 09:36

Hi Phil,

As I can see from datasheet your clock settings should be OK.

You should first divide your OSC with UPLLIDIV and get UFIN = 4MHz.
Your OSC is 16MHz and UPLLIDIV is 4, that's OK.

After that you multiply UFIN with PLL which is 24, so you get 96MHz, that's also OK.

Finally 96MHz is divided by 2, and you get 48MHz, so clock settings is OK.

Also i tried to go through debug with my PIC32MX795F512L to see is DMACON always 0 and as I see it is always 0, so this is OK also.

Can you tell me which legacy library did you use?
Is PIC32MX450F128H supported by legacy library?

Regards,
Darko

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: legacy USB library and PIC32MX450F128H

#7 Post by phil31 » 01 Jun 2015 14:33

Darko,



thanks for confirmation about DMACON.

"Can you tell me which legacy library did you use?
Is PIC32MX450F128H supported by legacy library?"

i speak about the USB HID device lib that is provided with mikroBASIC PRO PIC32 compiler v3.5.0.
NOT the libstock one.
and 32MX450F128H is supported by this compiler version, so i expect the library work on this device !..
can't found any advice about that .. do you ?!

can you do some tests on this target please ?

thanks, regards

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: legacy USB library and PIC32MX450F128H

#8 Post by darko.minic » 02 Jun 2015 10:31

Hi Phil,

Please try example from attachment which is adjusted for your MCU.
Windows should recognize device as USB HID Device, and device should be recognized in HID terminal as well.

Regards,
Darko
Attachments
HID_Read_Write_Interrupt.zip
(130.42 KiB) Downloaded 145 times

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: legacy USB library and PIC32MX450F128H

#9 Post by phil31 » 02 Jun 2015 10:45

hello Darko,

thanks for your try. like that, yes it's working.

but i prefer to not use the pooling method !
i can't garanty a 100us pooling time in my application.

what is wrong with the interrupt version please ?

regards
Phil

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: legacy USB library and PIC32MX450F128H

#10 Post by darko.minic » 02 Jun 2015 11:22

Hi Phil,

Please try example which you can find in attachment.

Problem was in following line of code:

Code: Select all

IPC11SET = 7 << 10
IPC11 register is related to DMA interrupt priority on PIC32MX450F128H, not to USB interrupt priority as is on PIC32MX795F512L.
So you should change it to:

Code: Select all

IPC7SET = 7 << 10
On PIC32MX450F128H IPC7 register is related to USB interrupt priority.

Regards,
Darko
Attachments
HID_Read_Write_Interrupt.zip
(130.37 KiB) Downloaded 140 times

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: legacy USB library and PIC32MX450F128H

#11 Post by phil31 » 02 Jun 2015 11:38

using IPC7, it's WORKING as expected !
so no DMA are involving using this library.


thanks for the support, regards

Post Reply

Return to “mikroBasic PRO for PIC32 General”