Why does USBHostInit() functions returns false?
Hi everyone,
I'm trying to make working the usb host hid mouse of the mla on a PIC24FJ64GB002 on a breadboard. So I've adapted the code of the example because I don't have all the required HW (LCD for example) and I adapted it to output some states on LEDs.
If I'm posting here, it means I have not made it working yet.
Actually, I'm stucked at the very beggining of the program. The USBHostInit() function actually returns false, which means that memory could not be allocated to the endpoint0 of the host, according to the code and the mla usb documentation.
Has someone been through this problem before?
As I'm new to PIC programming, I'm not aware of every subtility that exist in this field. However I understood that Oscillator configuration seems to be a pretty big deal for USB management.
As I don't own crystal oscillator, I've decided to cofnigure internal oscillator, as described on PIC24FJGB004 family reference manual.
The configuration bits are below. I think it's a good configuration. I get 32MHz oscillator from FRC oscillator aided with PLL, which means FCY is 16MHz.
// CONFIG4
#pragma config DSWDTPS = DSWDTPS3 // DSWDT Postscale Select (1:128 (132 ms))
#pragma config DSWDTOSC = LPRC // Deep Sleep Watchdog Timer Oscillator Select (DSWDT uses Low Power RC Oscillator (LPRC))
#pragma config RTCOSC = LPRC // RTCC Reference Oscillator Select (RTCC uses Low Power RC Oscillator (LPRC))
#pragma config DSBOREN = OFF // Deep Sleep BOR Enable bit (BOR disabled in Deep Sleep)
#pragma config DSWDTEN = OFF // Deep Sleep Watchdog Timer (DSWDT disabled)
// CONFIG3
#pragma config WPFP = WPFP0 // Write Protection Flash Page Segment Boundary (Page 0 (0x0))
#pragma config SOSCSEL = SOSC // Secondary Oscillator Pin Mode Select (SOSC pins in Default (high drive-strength) Oscillator Mode)
#pragma config WUTSEL = LEG // Voltage Regulator Wake-up Time Select (Default regulator start-up time used)
#pragma config WPDIS = WPDIS // Segment Write Protection Disable (Segmented code protection disabled)
#pragma config WPCFG = WPCFGDIS // Write Protect Configuration Page Select (Last page and Flash Configuration words are unprotected)
#pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory)
// CONFIG2
#pragma config POSCMOD = NONE // Primary Oscillator Select (Primary Oscillator disabled)
#pragma config I2C1SEL = PRI // I2C1 Pin Select bit (Use default SCL1/SDA1 pins for I2C1 )
#pragma config IOL1WAY = OFF // IOLOCK One-Way Set Enable (The IOLOCK bit can be set and cleared using the unlock sequence)
#pragma config OSCIOFNC = OFF // OSCO Pin Configuration (OSCO pin functions as clock output (CLKO))
#pragma config FCKSM = CSDCMD // Clock Switching and Fail-Safe Clock Monitor (Sw Disabled, Mon Disabled)
#pragma config FNOSC = FRCPLL // Initial Oscillator Select (Fast RC Oscillator with Postscaler and PLL module (FRCPLL))
#pragma config PLL96MHZ = ON // 96MHz PLL Startup Select (96 MHz PLL Startup is enabled automatically on start-up)
#pragma config PLLDIV = NODIV // USB 96 MHz PLL Prescaler Select (Oscillator input used directly (4 MHz input))
#pragma config IESO = OFF // Internal External Switchover (IESO mode (Two-Speed Start-up) disabled)
// CONFIG1
#pragma config WDTPS = PS1 // Watchdog Timer Postscaler (1:1)
#pragma config FWPSA = PR32 // WDT Prescaler (Prescaler ratio of 1:32)
#pragma config WINDIS = OFF // Windowed WDT (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF // Watchdog Timer (Watchdog Timer is disabled)
#pragma config ICS = PGx1 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC1/PGED1)
#pragma config GWRP = ON // General Segment Write Protect (Writes to program memory are disabled)
#pragma config GCP = OFF // General Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
Moreover, my power management seems to be OK too:
- wiring respected for Vdd (3.3V) and Vss (GND)
- Vbus is 5V and Vusb is 3.3V
Any idea what's going on ?
post edited by aurelienalbert - 2020/11/21 05:42:39