Skip to content

Commit 0ecf88a

Browse files
committed
Update to latest clock settings.
1 parent e2c5e8b commit 0ecf88a

File tree

6 files changed

+39
-26
lines changed

6 files changed

+39
-26
lines changed

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/icsp_inhibit.mc3

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/mcc_generated_files/system/clock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
@brief This macro is used to read the System clock (FOSC) Frequency configured in
4848
the MCC Melody User Interface
4949
*/
50-
#define CLOCK_SystemFrequencyGet() (8000000UL)
50+
#define CLOCK_SystemFrequencyGet() (200000000UL)
5151

5252
/**
5353
@ingroup clockdriver

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/mcc_generated_files/system/src/clock.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,25 @@ void CLOCK_Initialize(void)
4444
{
4545
/*
4646
Input frequency : 8.00 MHz
47-
Clock source : FRC Oscillator
48-
System frequency (Fosc) : 8.00 MHz
49-
Clock switching enabled : false
47+
Clock source : External Oscillator with PLL
48+
System frequency (Fosc) : 200.00 MHz [(8.00 MHz / 1) * 50 / 1 / 2 = 200.00 MHz]
49+
PLL VCO frequency (Fvco) : 400.00 MHz [(8.00 MHz / 1) * 50 = 400.00 MHz]
50+
PLL output frequency (Fpllo) : 400.00 MHz [(8.00 MHz / 1) * 50 / 1 = 400.00 MHz]
51+
PLL VCO divider frequency (Fvcodiv) : 100.00 MHz [400.00 MHz / 4 = 100.00 MHz]
52+
Clock switching enabled : true
53+
Clock source when device boots : FRC Oscillator
5054
Auxiliary clock source : FRC Oscillator
5155
Auxiliary clock input frequency : 8.00 MHz
5256
Auxiliary clock PLL output frequency (AFpllo) : 8.00 MHz
5357
*/
5458
// RCDIV FRC/1; PLLPRE 1:1; DOZE 1:8; DOZEN disabled; ROI disabled;
5559
CLKDIV = 0x3001;
56-
// PLLDIV 150;
57-
PLLFBD = 0x96;
60+
// PLLDIV 50;
61+
PLLFBD = 0x32;
5862
// TUN Center frequency;
5963
OSCTUN = 0x0;
60-
// PLLPOST 1:4; VCODIV FVCO/4; POST2DIV 1:1;
61-
PLLDIV = 0x41;
64+
// PLLPOST 1:1; VCODIV FVCO/4; POST2DIV 1:1;
65+
PLLDIV = 0x11;
6266
// ENAPLL disabled; FRCSEL FRC Oscillator; APLLPRE 1:1;
6367
ACLKCON1 = 0x101;
6468
// APLLFBDIV 150;
@@ -91,9 +95,12 @@ void CLOCK_Initialize(void)
9195
PMD7 = 0x0;
9296
// DMTMD enabled; CLC3MD enabled; OPAMPMD enabled; BIASMD enabled; CLC4MD enabled; SENT1MD enabled; CLC1MD enabled; CLC2MD enabled; SENT2MD enabled;
9397
PMD8 = 0x0;
94-
// CF no clock failure; NOSC FRC; CLKLOCK unlocked; OSWEN Switch is Complete;
95-
__builtin_write_OSCCONH((uint8_t) (0x00));
96-
__builtin_write_OSCCONL((uint8_t) (0x00));
98+
// CF no clock failure; NOSC PRIPLL; CLKLOCK unlocked; OSWEN Switch is Complete;
99+
__builtin_write_OSCCONH((uint8_t) (0x03));
100+
__builtin_write_OSCCONL((uint8_t) (0x01));
101+
// Wait for Clock switch to occur
102+
while (OSCCONbits.OSWEN != 0);
103+
while (OSCCONbits.LOCK != 1);
97104
}
98105

99106
bool CLOCK_AuxPllLockStatusGet(void)

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/mcc_generated_files/system/src/config_bits.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
#pragma config IESO = OFF //Two-speed Oscillator Start-up Enable bit->Start up with user-selected oscillator source
5656

5757
// FOSC
58-
#pragma config POSCMD = NONE //Primary Oscillator Mode Select bits->Primary Oscillator disabled
58+
#pragma config POSCMD = EC //Primary Oscillator Mode Select bits->EC (External Clock) Mode
5959
#pragma config OSCIOFNC = ON //OSC2 Pin Function bit->OSC2 is general purpose digital I/O pin
60-
#pragma config FCKSM = CSDCMD //Clock Switching Mode bits->Both Clock switching and Fail-safe Clock Monitor are disabled
60+
#pragma config FCKSM = CSECMD //Clock Switching Mode bits->Clock switching is enabled,Fail-safe Clock Monitor is disabled
6161
#pragma config PLLKEN = ON //PLL Lock Status Control->PLL lock signal will be used to disable PLL clock output if lock is lost
6262
#pragma config XTCFG = G3 //XT Config->24-32 MHz crystals
6363
#pragma config XTBST = ENABLE //XT Boost->Boost the kick-start

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/mcc_generated_files/system/src/pins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void PINS_Initialize(void)
9898
* Setting the Analog/Digital Configuration SFR(s)
9999
***************************************************************************/
100100
ANSELA = 0x001F;
101-
ANSELB = 0x009F;
101+
ANSELB = 0x009E;
102102
ANSELC = 0x00CF;
103103
ANSELD = 0x2C00;
104104
ANSELE = 0x000F;

secure_boot_and_secure_firmware_upgrade_over_canfd/icsp_inhibit.X/mcc_generated_files/uart/src/uart1.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
#include "../uart1.h"
4444

4545
// Section: Macro Definitions
46-
#define UART1_CLOCK 4000000U
46+
#define UART1_CLOCK 100000000U
4747
#define UART1_BAUD_TO_BRG_WITH_FRACTIONAL(x) (UART1_CLOCK/(x))
4848
#define UART1_BAUD_TO_BRG_WITH_BRGH_1(x) (UART1_CLOCK/(4U*(x))-1U)
4949
#define UART1_BAUD_TO_BRG_WITH_BRGH_0(x) (UART1_CLOCK/(16U*(x))-1U)
5050
#define UART1_BRG_TO_BAUD_WITH_FRACTIONAL(x) (UART1_CLOCK/(x))
5151
#define UART1_BRG_TO_BAUD_WITH_BRGH_1(x) (UART1_CLOCK/(4U*((x)+1U)))
5252
#define UART1_BRG_TO_BAUD_WITH_BRGH_0(x) (UART1_CLOCK/(16U*((x)+1U)))
5353

54-
#define UART1_MIN_ACHIEVABLE_BAUD_WITH_FRACTIONAL 4U
55-
#define UART1_MIN_ACHIEVABLE_BAUD_WITH_BRGH_1 1U
54+
#define UART1_MIN_ACHIEVABLE_BAUD_WITH_FRACTIONAL 95U
55+
#define UART1_MIN_ACHIEVABLE_BAUD_WITH_BRGH_1 24U
5656

5757
// Section: Driver Interface
5858

@@ -113,8 +113,8 @@ void UART1_Initialize(void)
113113
U1STA = 0x80;
114114
// URXISEL ; UTXBE ; UTXISEL ; URXBE ; STPMD ; TXWRE ;
115115
U1STAH = 0x2E;
116-
// BaudRate 9592.33; Frequency 4000000 Hz; BRG 417;
117-
U1BRG = 0x1A1;
116+
// BaudRate 9599.69; Frequency 100000000 Hz; BRG 10417;
117+
U1BRG = 0x28B1;
118118
// BRG 0;
119119
U1BRGH = 0x0;
120120

@@ -256,12 +256,18 @@ void UART1_BaudRateSet(uint32_t baudRate)
256256
U1MODEbits.BRGH = 0;
257257
brgValue = UART1_BAUD_TO_BRG_WITH_FRACTIONAL(baudRate);
258258
}
259-
else
259+
else if(baudRate >= UART1_MIN_ACHIEVABLE_BAUD_WITH_BRGH_1)
260260
{
261261
U1MODEHbits.BCLKMOD = 0;
262262
U1MODEbits.BRGH = 1;
263263
brgValue = UART1_BAUD_TO_BRG_WITH_BRGH_1(baudRate);
264264
}
265+
else
266+
{
267+
U1MODEHbits.BCLKMOD = 0;
268+
U1MODEbits.BRGH = 0;
269+
brgValue = UART1_BAUD_TO_BRG_WITH_BRGH_0(baudRate);
270+
}
265271
U1BRG = brgValue & 0xFFFFU;
266272
U1BRGH = (brgValue >>16U) & 0x000FU;
267273
}

0 commit comments

Comments
 (0)