Skip to content

Commit 9bfe37a

Browse files
authored
Merge pull request #779 from unicab369/Ch32x30x_mco_test
Ch32v30x MCO clock test.
2 parents c04a7b3 + c8a0b0d commit 9bfe37a

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all : flash
2+
3+
TARGET:=mco_clock_output
4+
TARGET_MCU:=CH32V303
5+
TARGET_MCU_PACKAGE:=CH32V303
6+
7+
include ../../ch32fun/ch32fun.mk
8+
9+
flash : cv_flash
10+
clean : cv_clean
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _FUNCONFIG_H
2+
#define _FUNCONFIG_H
3+
4+
#define FUNCONF_SYSTICK_USE_HCLK 1
5+
#define FUNCONF_USE_HSI 1
6+
#define FUNCONF_USE_PLL 0
7+
#define FUNCONF_PLL_MULTIPLIER 2
8+
9+
#define FUNCONF_USE_DEBUGPRINTF 1
10+
#define FUNCONF_SYSTEM_CORE_CLOCK 8 * 1000 * 1000
11+
12+
#endif
13+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// copied from the mco_clock_output example in the ch32fun example
2+
// This allows the device to output one of four internal
3+
// clock signals to the PC8 pin. It cycles through no signal and
4+
// each of the four different clock signals. Each
5+
// signal is output for five seconds before moving on to the next.
6+
// The serial output displays the signals as they are selected.
7+
8+
// The different signals are:
9+
// 0) Nothing
10+
// 1) SYSCLK (48MHz)
11+
// 2) HSI (24MHz)
12+
// 3) HSE (depends on external XTAL)
13+
// 4) PLL clock output (48MHz)
14+
15+
#include "ch32fun.h"
16+
#include <stdio.h>
17+
18+
int main() {
19+
SystemInit();
20+
Delay_Ms(100);
21+
printf("\n~ MCO Clock Test ~\n");
22+
23+
funGpioInitAll();
24+
funPinMode(PA8, GPIO_CFGLR_OUT_50Mhz_AF_PP);
25+
26+
// uncomment this for the HSE clock source if you have an external crystal
27+
// // turn the HSE on
28+
// RCC->CTLR |= RCC_HSE_ON;
29+
// // Wait till HSE is ready
30+
// while(!(RCC->CTLR & RCC_HSERDY));
31+
32+
int count = 0;
33+
int regtemp;
34+
35+
while(1) {
36+
regtemp = (RCC->CFGR0 & ~RCC_CFGR0_MCO);
37+
38+
switch(count) {
39+
case 0:
40+
printf("\r\nNo signal on MCO\r\n");
41+
printf("CFGR0 going from %08lX to %08lX\r\n", RCC->CFGR0, regtemp);
42+
RCC->CFGR0 = regtemp;
43+
count++;
44+
break;
45+
case 1:
46+
printf("\r\nSYSCLK signal on MCO\r\n");
47+
regtemp |= RCC_CFGR0_MCO_SYSCLK;
48+
printf("CFGR0 going from %08lX to %08lX\r\n", RCC->CFGR0, regtemp);
49+
RCC->CFGR0 = regtemp;
50+
count++;
51+
break;
52+
case 2:
53+
printf("\r\nHSI signal on MCO\r\n");
54+
regtemp |= RCC_CFGR0_MCO_HSI;
55+
printf("CFGR0 going from %08lX to %08lX\r\n", RCC->CFGR0, regtemp);
56+
RCC->CFGR0 = regtemp;
57+
count++;
58+
break;
59+
case 3:
60+
printf("\r\nHSE signal on MCO\r\n");
61+
regtemp |= RCC_CFGR0_MCO_HSE;
62+
printf("CFGR0 going from %08lX to %08lX\r\n", RCC->CFGR0, regtemp);
63+
RCC->CFGR0 = regtemp;
64+
count++;
65+
break;
66+
case 4:
67+
printf("\r\nPLLCLK signal on MCO\r\n");
68+
regtemp |= RCC_CFGR0_MCO_PLL;
69+
printf("CFGR0 going from %08lX to %08lX\r\n", RCC->CFGR0, regtemp);
70+
RCC->CFGR0 = regtemp;
71+
count=0;
72+
break;
73+
}
74+
Delay_Ms(5000);
75+
}
76+
}

0 commit comments

Comments
 (0)