Skip to content

Commit 45e8bee

Browse files
committed
Add PIC18F45K50 config and init
1 parent 9796655 commit 45e8bee

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

apps/common/hardware.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,49 @@ _CONFIG3(WPFP_WPFP255 & SOSCSEL_SOSC & WUTSEL_LEG & ALTPMP_ALPMPDIS & WPDIS_WPDI
4949
#pragma config IOL1WAY = OFF
5050
#pragma config WPDIS = OFF /* This pragma seems backwards */
5151

52+
#elif _18F24K50 || _18F25K50 || _18F45K50
53+
#pragma config PLLSEL = PLL3X // PLL Selection (3x clock multiplier)
54+
#pragma config CFGPLLEN = OFF // PLL Enable Configuration bit (PLL Disabled (firmware controlled))
55+
#pragma config CPUDIV = NOCLKDIV // CPU System Clock Postscaler (CPU uses system clock (no divide))
56+
#pragma config LS48MHZ = SYS48X8 // Low Speed USB mode with 48 MHz system clock (System clock at 48 MHz, USB clock divider is set to 8)
57+
#pragma config FOSC = INTOSCIO // Oscillator Selection (Internal oscillator)
58+
#pragma config PCLKEN = OFF // Primary Oscillator Shutdown (Primary oscillator shutdown firmware controlled)
59+
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor (Fail-Safe Clock Monitor disabled)
60+
#pragma config IESO = OFF // Internal/External Oscillator Switchover (Oscillator Switchover mode disabled)
61+
#pragma config nPWRTEN = OFF // Power-up Timer Enable (Power up timer disabled)
62+
#pragma config BOREN = SBORDIS // Brown-out Reset Enable (BOR enabled in hardware (SBOREN is ignored))
63+
#pragma config BORV = 190 // Brown-out Reset Voltage (BOR set to 1.9V nominal)
64+
#pragma config nLPBOR = ON // Low-Power Brown-out Reset (Low-Power Brown-out Reset enabled)
65+
#pragma config WDTEN = SWON // Watchdog Timer Enable bits (WDT controlled by firmware (SWDTEN enabled))
66+
#pragma config WDTPS = 32768 // Watchdog Timer Postscaler (1:32768)
67+
#pragma config CCP2MX = RC1 // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
68+
#pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset)
69+
#pragma config T3CMX = RC0 // Timer3 Clock Input MUX bit (T3CKI function is on RC0)
70+
#pragma config SDOMX = RC7 // SDO Output MUX bit (SDO function is on RC7)
71+
#pragma config MCLRE = ON // Master Clear Reset Pin Enable (MCLR pin enabled; RE3 input disabled)
72+
#pragma config STVREN = ON // Stack Full/Underflow Reset (Stack full/underflow will cause Reset)
73+
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
74+
#pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming Port Enable (ICPORT disabled)
75+
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled)
76+
#pragma config CP0 = OFF // Block 0 Code Protect (Block 0 is not code-protected)
77+
#pragma config CP1 = OFF // Block 1 Code Protect (Block 1 is not code-protected)
78+
#pragma config CP2 = OFF // Block 2 Code Protect (Block 2 is not code-protected)
79+
#pragma config CP3 = OFF // Block 3 Code Protect (Block 3 is not code-protected)
80+
#pragma config CPB = OFF // Boot Block Code Protect (Boot block is not code-protected)
81+
#pragma config CPD = OFF // Data EEPROM Code Protect (Data EEPROM is not code-protected)
82+
#pragma config WRT0 = OFF // Block 0 Write Protect (Block 0 (0800-1FFFh) is not write-protected)
83+
#pragma config WRT1 = OFF // Block 1 Write Protect (Block 1 (2000-3FFFh) is not write-protected)
84+
#pragma config WRT2 = OFF // Block 2 Write Protect (Block 2 (04000-5FFFh) is not write-protected)
85+
#pragma config WRT3 = OFF // Block 3 Write Protect (Block 3 (06000-7FFFh) is not write-protected)
86+
#pragma config WRTC = OFF // Configuration Registers Write Protect (Configuration registers (300000-3000FFh) are not write-protected)
87+
#pragma config WRTB = OFF // Boot Block Write Protect (Boot block (0000-7FFh) is not write-protected)
88+
#pragma config WRTD = OFF // Data EEPROM Write Protect (Data EEPROM is not write-protected)
89+
#pragma config EBTR0 = OFF // Block 0 Table Read Protect (Block 0 is not protected from table reads executed in other blocks)
90+
#pragma config EBTR1 = OFF // Block 1 Table Read Protect (Block 1 is not protected from table reads executed in other blocks)
91+
#pragma config EBTR2 = OFF // Block 2 Table Read Protect (Block 2 is not protected from table reads executed in other blocks)
92+
#pragma config EBTR3 = OFF // Block 3 Table Read Protect (Block 3 is not protected from table reads executed in other blocks)
93+
#pragma config EBTRB = OFF // Boot Block Table Read Protect (Boot block is not protected from table reads executed in other blocks)
94+
5295
#elif _16F1459 || _16F1454
5396
#pragma config FOSC = INTOSC
5497
#pragma config WDTE = OFF
@@ -208,8 +251,15 @@ void hardware_init(void)
208251
#elif _18F46J50
209252
unsigned int pll_startup = 600;
210253
OSCTUNEbits.PLLEN = 1;
211-
while (pll_startup--)
212-
;
254+
while (pll_startup--);
255+
256+
#elif _18F24K50 || _18F25K50 || _18F45K50
257+
OSCTUNE = 0x80; //3X PLL ratio mode selected
258+
OSCCON = 0x70; //Switch to 16MHz HFINTOSC
259+
OSCCON2 = 0x10; //Enable PLL, SOSC, PRI OSC drivers turned off
260+
while(OSCCON2bits.PLLRDY != 1); //Wait for PLL lock
261+
ACTCON = 0x90; //Enable active clock tuning for USB operation
262+
213263
#elif _16F1459 || _16F1454
214264
OSCCONbits.IRCF = 0b1111; /* 0b1111 = 16MHz HFINTOSC postscalar */
215265

usb/src/usb_hal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ struct buffer_descriptor {
186186
#define SFR_USB_STALL_IF UIRbits.STALLIF
187187
#define SFR_USB_TOKEN_IF UIRbits.TRNIF
188188
#define SFR_USB_SOF_IF UIRbits.SOFIF
189-
#define SFR_USB_IF PIR2bits.USBIF
189+
#define SFR_USB_IF USBIF
190190

191191
#define SFR_USB_INTERRUPT_EN UIE
192192
#define SFR_TRANSFER_IE UIEbits.TRNIE
193193
#define SFR_STALL_IE UIEbits.STALLIE
194194
#define SFR_RESET_IE UIEbits.URSTIE
195195
#define SFR_SOF_IE UIEbits.SOFIE
196-
#define SFR_USB_IE PIE2bits.USBIE
196+
#define SFR_USB_IE USBIE
197197

198198
#define SFR_USB_EXTENDED_INTERRUPT_EN UEIE
199199

@@ -285,7 +285,7 @@ struct buffer_descriptor {
285285
#define BDN_LENGTH(REG) (REG.BDnCNT)
286286
#endif
287287

288-
#ifdef _18F46J50
288+
#if _18F46J50 || _18F45K50
289289
#define BD_ADDR 0x400
290290
//#undef BUFFER_ADDR
291291
#else

0 commit comments

Comments
 (0)