Skip to content

Commit

Permalink
Fix bootup code for 035
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Apr 19, 2024
1 parent 094dc33 commit cd36df3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions ch32v003fun/ch32v003fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ void SystemInit()
#define BASE_CFGR0 RCC_HPRE_DIV1 | RCC_PPRE2_DIV1 | RCC_PPRE1_DIV2 | PLL_MULTIPLICATION
#endif
#else
#if defined(CH32V003)
#if defined(CH32V003) || defined(CH32X03x)
#define BASE_CFGR0 RCC_HPRE_DIV1 // HCLK = SYSCLK = APB1 And, no pll.
#else
#define BASE_CFGR0 RCC_HPRE_DIV1 | RCC_PPRE2_DIV1 | RCC_PPRE1_DIV1
Expand All @@ -1515,6 +1515,17 @@ void SystemInit()
#define BASE_CTLR (((FUNCONF_HSITRIM) << 3) | RCC_HSION | HSEBYP | RCC_CSS)
//#define BASE_CTLR (((FUNCONF_HSITRIM) << 3) | HSEBYP | RCC_CSS) // disable HSI in HSE modes

// CH32V003 flash latency
#if defined(CH32X03x)
FLASH->ACTLR = FLASH_ACTLR_LATENCY_2; // +2 Cycle Latency (Recommended per TRM)
#elif defined(CH32V003)
#if FUNCONF_SYSTEM_CORE_CLOCK > 25000000
FLASH->ACTLR = FLASH_ACTLR_LATENCY_1; // +1 Cycle Latency
#else
FLASH->ACTLR = FLASH_ACTLR_LATENCY_0; // +0 Cycle Latency
#endif
#endif

#if defined(FUNCONF_USE_HSI) && FUNCONF_USE_HSI
#if defined(CH32V30x) || defined(CH32V20x) || defined(CH32V10x)
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
Expand Down Expand Up @@ -1557,15 +1568,6 @@ void SystemInit()
FLASH->ACTLR |= FLASH_ACTLR_PRFTBE;
#endif

// CH32V003 flash latency
#if defined(CH32V003)
#if FUNCONF_SYSTEM_CORE_CLOCK > 25000000
FLASH->ACTLR = FLASH_ACTLR_LATENCY_1; // +1 Cycle Latency
#else
FLASH->ACTLR = FLASH_ACTLR_LATENCY_0; // +0 Cycle Latency
#endif
#endif

// CH32V10x flash latency
#if defined(CH32V10x)
#if defined(FUNCONF_USE_HSE) && FUNCONF_USE_HSE
Expand Down
2 changes: 1 addition & 1 deletion ch32v003fun/ch32v003fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -4466,7 +4466,7 @@ typedef struct
/* FLASH and Option Bytes Registers */
/******************************************************************************/

#if defined(CH32V003) || defined(CH32V10x)
#if defined(CH32V003) || defined(CH32V10x) || defined(CH32X03x)
/******************* Bit definition for FLASH_ACTLR register ******************/
#define FLASH_ACTLR_LATENCY ((uint8_t)0x03) /* LATENCY[2:0] bits (Latency) */
#define FLASH_ACTLR_LATENCY_0 ((uint8_t)0x00) /* Bit 0 */
Expand Down
2 changes: 1 addition & 1 deletion examples_x035/blink/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

int main()
{
//SystemInit();
SystemInit();

funGpioInitAll();

Expand Down

0 comments on commit cd36df3

Please sign in to comment.