generated from hulk/gd32e23x_template_cmake_vscode
detect MCU flash size and config usart
This commit is contained in:
77
Src/mcu_config.c
Normal file
77
Src/mcu_config.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*!
|
||||
\file mcu_config.c
|
||||
\brief MCU type detection and dynamic configuration
|
||||
|
||||
\version 2025-08-20, V1.0.0, MCU detection for GD32E23x
|
||||
*/
|
||||
|
||||
#include "gd32e23x.h"
|
||||
#include "board_config.h"
|
||||
|
||||
#define FLASH_SIZE_ADDR (*(const uint16_t *)0x1FFFF7E0)
|
||||
|
||||
/* Global variables for dynamic configuration */
|
||||
uint8_t g_mcu_type = 0;
|
||||
usart_config_t g_usart_config = {0};
|
||||
|
||||
/*!
|
||||
\brief detect MCU type and configure USART accordingly
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void mcu_detect_and_config(void)
|
||||
{
|
||||
uint16_t flash_kb = FLASH_SIZE_ADDR;
|
||||
uint8_t size = (flash_kb >> 8) & 0xFF;
|
||||
|
||||
/* Detect MCU type based on flash size */
|
||||
switch (size) {
|
||||
case GD32E23XF4:
|
||||
g_mcu_type = GD32E23XF4;
|
||||
/* Configure for USART0 (GD32E23XF4) */
|
||||
g_usart_config.rcu_usart = RCU_USART0;
|
||||
g_usart_config.usart_periph = USART0;
|
||||
g_usart_config.gpio_af = GPIO_AF_1;
|
||||
g_usart_config.irq_type = USART0_IRQn;
|
||||
break;
|
||||
|
||||
case GD32E23XF6:
|
||||
g_mcu_type = GD32E23XF6;
|
||||
/* Configure for USART1 (GD32E23XF6) */
|
||||
g_usart_config.rcu_usart = RCU_USART1;
|
||||
g_usart_config.usart_periph = USART1;
|
||||
g_usart_config.gpio_af = GPIO_AF_1;
|
||||
g_usart_config.irq_type = USART1_IRQn;
|
||||
break;
|
||||
|
||||
case GD32E23XF8:
|
||||
g_mcu_type = GD32E23XF8;
|
||||
/* Configure for USART1 (GD32E23XF8) */
|
||||
g_usart_config.rcu_usart = RCU_USART1;
|
||||
g_usart_config.usart_periph = USART1;
|
||||
g_usart_config.gpio_af = GPIO_AF_1;
|
||||
g_usart_config.irq_type = USART1_IRQn;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Default to GD32E23XF8 configuration */
|
||||
g_mcu_type = GD32E23XF8;
|
||||
g_usart_config.rcu_usart = RCU_USART1;
|
||||
g_usart_config.usart_periph = USART1;
|
||||
g_usart_config.gpio_af = GPIO_AF_1;
|
||||
g_usart_config.irq_type = USART1_IRQn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief get current MCU type
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval MCU type (GD32E23XF4, GD32E23XF6, or GD32E23XF8)
|
||||
*/
|
||||
uint8_t get_mcu_type(void)
|
||||
{
|
||||
return g_mcu_type;
|
||||
}
|
Reference in New Issue
Block a user