|
1 | 1 | /* This file supports the CH32V00X and CH32M00X family of chips
|
2 | 2 | */
|
3 | 3 |
|
4 |
| -#ifndef TODO_HARDWARE_H |
5 |
| -#define TODO_HARDWARE_H |
| 4 | +#ifndef TODO_CH32X00X_H |
| 5 | +#define TODO_CH32X00X_H |
6 | 6 |
|
7 | 7 | #include "ch32fun.h"
|
8 | 8 |
|
@@ -117,13 +117,19 @@ typedef struct
|
117 | 117 | #define HSE_Value HSE_VALUE
|
118 | 118 | #define HSEStartUp_TimeOut HSE_STARTUP_TIMEOUT
|
119 | 119 |
|
| 120 | +// Datasheet recommends HSE of 24M |
| 121 | +#ifndef HSE_VALUE |
| 122 | +#define HSE_VALUE 24000000 |
| 123 | +#endif |
| 124 | + |
120 | 125 | #ifndef __ASSEMBLER__
|
121 | 126 | /* Analog to Digital Converter */
|
122 | 127 | typedef struct
|
123 | 128 | {
|
124 | 129 | __IO uint32_t STATR;
|
125 | 130 | __IO uint32_t CTLR1;
|
126 | 131 | __IO uint32_t CTLR2;
|
| 132 | + __IO uint32_t SAMPTR1; |
127 | 133 | __IO uint32_t SAMPTR2;
|
128 | 134 | __IO uint32_t IOFR1;
|
129 | 135 | __IO uint32_t IOFR2;
|
@@ -235,6 +241,21 @@ typedef enum
|
235 | 241 | GPIO_CFGLR_OUT_OD = 0b0101,
|
236 | 242 | GPIO_CFGLR_OUT_AF_PP = 0b1001,
|
237 | 243 | GPIO_CFGLR_OUT_AF_OD = 0b1101,
|
| 244 | + |
| 245 | + |
| 246 | + // For intercompatibility with 003 legacy code. |
| 247 | + GPIO_CFGLR_OUT_10Mhz_PP = 0b0001, |
| 248 | + GPIO_CFGLR_OUT_2Mhz_PP = 0b0001, |
| 249 | + GPIO_CFGLR_OUT_50Mhz_PP = 0b0001, |
| 250 | + GPIO_CFGLR_OUT_10Mhz_OD = 0b0101, |
| 251 | + GPIO_CFGLR_OUT_2Mhz_OD = 0b0101, |
| 252 | + GPIO_CFGLR_OUT_50Mhz_OD = 0b0101, |
| 253 | + GPIO_CFGLR_OUT_10Mhz_AF_PP = 0b1001, |
| 254 | + GPIO_CFGLR_OUT_2Mhz_AF_PP = 0b1001, |
| 255 | + GPIO_CFGLR_OUT_50Mhz_AF_PP = 0b1001, |
| 256 | + GPIO_CFGLR_OUT_10Mhz_AF_OD = 0b1101, |
| 257 | + GPIO_CFGLR_OUT_2Mhz_AF_OD = 0b1101, |
| 258 | + GPIO_CFGLR_OUT_50Mhz_AF_OD = 0b1101, |
238 | 259 | } GPIO_CFGLR_PIN_MODE_Typedef;
|
239 | 260 |
|
240 | 261 | /* This was correct in the 003, but the 00X have 0b0010 as a reserved bit in this field. The above enum never sets this bit as directed by the RM. But it's included in the following structure as a 4 bit field becaus changing it to two disjoint bit fields would make life too painful. */
|
@@ -403,11 +424,23 @@ typedef struct
|
403 | 424 | __IO uint32_t CTLR;
|
404 | 425 | __IO uint32_t CFGR0;
|
405 | 426 | __IO uint32_t INTR;
|
406 |
| - __IO uint32_t PB2PRSTR; |
| 427 | + union |
| 428 | + { |
| 429 | + __IO uint32_t PB2PRSTR; |
| 430 | + __IO uint32_t APB2PRSTR; // For 003 compatibility |
| 431 | + }; |
407 | 432 | __IO uint32_t PB1PRSTR;
|
408 | 433 | __IO uint32_t HBPCENR;
|
409 |
| - __IO uint32_t PB2PCENR; |
410 |
| - __IO uint32_t PB1PCENR; |
| 434 | + union |
| 435 | + { |
| 436 | + __IO uint32_t PB2PCENR; |
| 437 | + __IO uint32_t APB2PCENR; // For 003 compatibility |
| 438 | + }; |
| 439 | + union |
| 440 | + { |
| 441 | + __IO uint32_t PB1PCENR; |
| 442 | + __IO uint32_t APB1PCENR; // For 003 compatibility |
| 443 | + }; |
411 | 444 | __IO uint32_t RESERVED0;
|
412 | 445 | __IO uint32_t RSTSCKR;
|
413 | 446 | } RCC_TypeDef;
|
@@ -1893,6 +1926,10 @@ typedef struct
|
1893 | 1926 |
|
1894 | 1927 | #define RCC_PLLSRC ((uint32_t)0x00010000) /* PLL entry clock source */
|
1895 | 1928 |
|
| 1929 | +//For compatibility with the v003 |
| 1930 | +#define RCC_PLLSRC_HSI_Mul2 ((uint32_t)0x00000000) /* HSI clock*2 selected as PLL entry clock source */ |
| 1931 | +#define RCC_PLLSRC_HSE_Mul2 ((uint32_t)0x00010000) /* HSE clock*2 selected as PLL entry clock source */ |
| 1932 | + |
1896 | 1933 | #define RCC_CFGR0_MCO ((uint32_t)0x07000000) /* MCO[2:0] bits (Microcontroller Clock Output) */
|
1897 | 1934 | #define RCC_MCO_0 ((uint32_t)0x01000000) /* Bit 0 */
|
1898 | 1935 | #define RCC_MCO_1 ((uint32_t)0x02000000) /* Bit 1 */
|
|
0 commit comments