IC:

Introduction

This chapter mainly introduces various configuration files that require special attention and modification during the development process.​

ameba_bootcfg

This section introduces the boot-related configurations including SoC clock switch and boot log.

github source code

The KM4 boots at 200MHz at the BootRom Stage, and switches to a higher frequency during the bootloader Stage.

There are some limitations when changing the SoC clock:

Clock

Frequency

Core voltage

PLL

300MHz ~ 688.128MHz

KM0

≤105MHz

0.9V

KM0

≤115MHz

1.0V

KM4

≤262MHz

0.9V

KM4

≤345MHz

1.0V

Note

  • By default, the SDK assumes the Flash is powered at 3.3V. And during initialization, it will automatically switch the Flash to the highest speed rate that does not exceed the 104MHz limit.

  • For wide voltage range ICs, the maximum operating frequency of the Flash should comply with the speed limitations in the 1.65V to 2.3V power supply range. You can refer to ameba_flashcfg to reduce the speed or contact Realtek for assistance.

SoC & PSRAM Clock Set Flow

  1. Check the value of Boot_SocClk_Info_Idx and SocClk_Info[] in ameba_bootcfg.c.

     1// for km4, max 345MHz under 1.0v, max 262MHz under 0.9v
     2// for km0, max 115MHz under 1.0v, max 105MHz under 0.9v
     3// PLL can be 300MHz~688.128MHz
     4// KM4_CKD range is [1, 8], KM0_CKD range is [1, 16] or USEXTAL
     5const SocClk_Info_TypeDef SocClk_Info[] = {
     6   /* PLL_CLK,     Vol_Type,      KM4_CKD,    KM0_CKD,    PSRAMC_CKD*/
     7   /* This group is to reduce the impact of PSRAM on RF, the frequency is specially selected */
     8   {PLL_524M,      CORE_VOL_0P9,  CLKDIV(2),  CLKDIV(5),  CLKDIV(2)},  // For SiP Psram
     9   {PLL_392M,      CORE_VOL_0P9,  CLKDIV(2),  CLKDIV(4),  CLKDIV(1)},  // For SiP Psram
    10   {PLL_334M,      CORE_VOL_1P0,  CLKDIV(1),  CLKDIV(3),  CLKDIV(1)},  // For SiP Psram
    11   /* This group is to reduce the impact of Flash on RF, the frequency is specially selected.
    12      Single die use the same settings. */
    13   {PLL_512M,      CORE_VOL_0P9,  CLKDIV(2),  CLKDIV(5),  CLKDIV(2)},  // For SiP Flash or single die (No Psram)
    14   {PLL_400M,      CORE_VOL_0P9,  CLKDIV(2),  CLKDIV(4),  CLKDIV(1)},  // For SiP Flash or single die (No Psram)
    15   {PLL_334M,      CORE_VOL_1P0,  CLKDIV(1),  CLKDIV(3),  CLKDIV(1)},  // For SiP Flash or single die (No Psram)
    16   /* The following frequency settings are not adjustable */
    17   {PLL_480M,      CORE_VOL_0P9,  CLKDIV(2),  CLKDIV(5),  CLKDIV(2)},  // 48M for usb, both For SiP Psram / SiP Flash / single die
    18   {PLL_677P376M,  CORE_VOL_1P0,  CLKDIV(2),  CLKDIV(6),  CLKDIV(2)},  // Audio
    19   {PLL_688P128M,  CORE_VOL_1P0,  CLKDIV(2),  CLKDIV(6),  CLKDIV(2)},  // Audio
    20};
    21
    22/**
    23* @brif  SocClk_Info select. One of Valid_Boot_Idx_for_SiP_Psram or Valid_Boot_Idx_for_No_Psram depend on different chip types
    24* Boot_SocClk_Info_Idx is [0, sizeof(SocClk_Info)), Soc will set socclk by SocClk_Info[Boot_SocClk_Info_Idx]
    25*/
    26#ifdef CONFIG_USB_DEVICE_EN
    27u8 Boot_SocClk_Info_Idx = 6; /* Make sure the PLL_CLK for USB is an integer multiple of 48MHz */
    28#else
    29u8 Boot_SocClk_Info_Idx = 6; /* 480M has an acceptable impact on the RF performance of SiP Psram and SiP Flash */
    30#endif
    
  2. Due to certain frequencies of PSRAM or Flash interfering with RF, the BOOT_ChipInfo_ClkInfoIdx() function in the bootloaderbootloader_km4.c file only allows indices represented by Boot_SocClk_Info_Idx within the SocClk_Info array.”

    Note

    It is not recommended to modify SocClk_Info. If frequency combinations outside of SocClk_Info are needed, it is necessary to confirm whether such configurations would affect RF performance.

    u32 BOOT_ChipInfo_ClkInfoIdx(void)
    {
       /* PSRAM die is wb955 which can run up to 200MHz */
       ...
       return Boot_SocClk_Info_Idx;
    }
    

    The Bootloader will configure the SoC voltage and clock according to the definition of SocClk_Info[Boot_SocClk_Info_Idx]. The PSRAMC (twice the PSRAM clock) rate will also be adjusted synchronously with the SoC clock. The clock speeds for other modules will be automatically set to reasonable values by the software based on their maximum operating speeds. The cases where the value of Boot_SocClk_Info_Idx is 0 and 4 serve as examples:

    PSRAM type

    PSRAM speed

    SocClk_Info[x]

    Clock Info

    No PSRAM

    SocClk_Info[4]

    • PLL: 400MHz

    • KM4: PLL/2

    • KM0: PLL/4

    With PSRAM

    ≤200MHz

    SocClk_Info[0]

    • PLL: 524MHz

    • KM4: PLL/2

    • KM0: PLL/5

    • PSRAMC: PLL/2

  3. Refer to one of the following methods to change the SoC clock if needed.

    • Modify Boot_SocClk_Info_Idx to a value within the range of [0, sizeof(SocClk_Info)], then customize the clock configuration information in SocClk_Info [Boot_SocClk_Info_Idx].

    Note

    Consider the limitations of the hardware and do not set the clock info illogically.

  4. Rebuild the project and download the new image again.

Boot_Agg_En

The Boot_Agg_En is used with Trace Tool to sort out boot logs from different cores. It can be enabled through Boot_Agg_En.

/**
* @brif  Loguart AGG enable or disable
*    FALSE: disable
*    TRUE: enable
*/
u8 Boot_Agg_En = FALSE;

Note

Refer to Chapter Trace Tool for more information.

ameba_flashcfg

This section introduces the Flash-related configurations including speed, read mode, layout and protect mode.

github source code

Flash_Speed

The frequency of the SPIC controller is set to XTAL (40MHz) during the BootRom stage, and switches to a higher frequency during the Bootloader stage. The Flash runs at half the speed of the SPIC controller. By default, the SPIC controller’s speed is derived from the PLL divider, but it must remain below SPIC_CLK_LIMIT (208MHz).

If the Flash needs to run slower, modify the value of Flash_Speed (for SPIC0) or Data_Flash_Speed (for SPIC1), which is the PLL division factor.

const u16 Flash_Speed = CLKDIV(2);
const u16 Data_Flash_Speed = CLKDIV(2);

Note

  • Refer to ameba_bootcfg for details about the Frequency of PLL.

  • The maximum clock of Flash is SPIC_CLK_LIMIT/2. The initial flow will automatically check whether the configured speed is higher than the maximun one or not.

  • Flash has already been set to optimal performance during initialization, so it is not recommended to modify Flash_Speed and Flash_ReadMode, or Data_Flash_Speed and Data_Flash_ReadMode.

Flash_ReadMode

During the BootRom stage, the SPIC operates in 1IO mode, and switches to the mode specified by Flash_ReadMode (default is 4IO) during the Bootloader stage. If the currently configured read mode is not supported, the system will automatically try other modes until a compatible mode is found.

Flash_Layout

The default Flash layout in the SDK are illustrated in Chapter Flash Layout. If you want to modify the Flash layout, refer to Section Flash Layout Modification Guide.

Flash Protect Enable

For more information about this function, refer to Section Flash Protection Mechanism .

ameba_boot_trustzonecfg

This section introduces TrustZone-related configurations, focusing primarily on the configuration of the MPC and SAU in chips that support Secure features. If the chip does not support the Secure feature, this configuration profile will be ignored.

github source code

sau_config

Users can configure the security attributes of KM4 by modifying the values in sau_config. Within the specified interval [Start, End], users can set NSC to 0 or 1 to designate whether the area is non-secure.

  • If NSC is set to 1, the area will be treated as secure code, i.e., Non-secure Callable (NSC);

  • If NSC is set to 0, the area will be treated as non-secure code, and Non-secure KM4 will be able to access this area.

  • Areas that are not set will be treated as secure code, accessible by Secure KM4.

mpc1_config

Users can configure the security attributes of certain SRAM intervals by modifying the values in mpc1_config:

  • Within the specified interval [Start, End], Non-secure Master can access this area;

  • Areas that are not set can only be accessed by Secure Master.

mpc2_config

Users can configure the security attributes of certain PSRAM intervals by modifying the values in mpc2_config:

  • Within the specified interval [Start, End], Non-secure Master can access this area;

  • Areas that are not set can only be accessed by Secure Master.

Note

ameba_intfcfg

This section introduces peripheral pin assignment, which refers to mapping the physical pins of the chip to various peripheral functions.

github source code

sdio_config

sdio_config is mainly used to configure the relevant interfaces of the SDIO Device, refer to Section :ref:`sdio_config`.

ameba_pinmapcfg

This section introduces the pull-up and pull-down status of each pin configged by pinmap_init() during the initialization phase.

github source code

pmap_func

The pmap_func array is mainly used to configure the pull-up and pull-down status of each pin:

  • The Func PU/PD controls the default pull-up and pull-down states of pins when the SOC is Active. In main() or subsequent tasks, the pull-up and pull-down states of pins need to be set according to the specific IP requirements when the SOC is Active.

  • The Slp PU/PD controls the pull-up and pull-down states when the SOC is in Sleep mode. If not set correctly, leakage current may occur on that pin during sleep, Please modify according to the hardware status.

const PMAP_TypeDef pmap_func[] = {
     //Pin Name              Func PU/PD                              Slp PU/PD
     {_PA_0,                 GPIO_PuPd_UP,                   GPIO_PuPd_UP},
     {_PA_1,                 GPIO_PuPd_UP,                   GPIO_PuPd_UP},
     {_PA_2,                 GPIO_PuPd_KEEP,         GPIO_PuPd_UP},
   ...
};

ameba_sleepcfg

github source code

Wakeup Mask Setup

For sleep mode, only one CPU is required to wake up to execute the program in some situations. The wakeup mask module is designed to implement this function. In general, in addition to configuring the wakeup mask, it is also necessary to register the wakeup source interrupt so that the specific CPU can handle it upon wakeup.

By setting a wakeup mask, you can choose to wake up only one CPU core. If KM4 is chosen, KM0 will be waked up first and then KM0 will resume KM4.

Users can set the wakeup attribute in sleep_wevent_config[] in ameba_sleepcfg.c to choose which CPU you want to wake up. The wakeup attribute of each wakeup source can be set to WAKEUP_KM4 or WAKEUP_KM0 or WAKEUP_NULL, respectively indicating that this wakeup source is only to wake up KM4, or wake up KM0, or not used as a wakeup source.

/* Wakeup entry can be set to WAKEUP_NULL/WAKEUP_KM4/WAKEUP_KM0 */
WakeEvent_TypeDef sleep_wevent_config[] = {
   //   Module              Wakeup
   {WAKE_SRC_SDIO,          WAKEUP_NULL},
   {WAKE_SRC_AON_WAKEPIN,      WAKEUP_NULL},
   {WAKE_SRC_AON_TIM,        WAKEUP_NULL},
   {WAKE_SRC_Keyscan,        WAKEUP_NULL},
   {WAKE_SRC_PWR_DOWN,        WAKEUP_NULL},
   {WAKE_SRC_BOR,          WAKEUP_NULL},
   {WAKE_SRC_ADC,          WAKEUP_NULL},
   {WAKE_SRC_RTC,          WAKEUP_NULL},
   {WAKE_SRC_CTOUCH,        WAKEUP_NULL},
   {WAKE_SRC_I2C1,          WAKEUP_NULL},
   {WAKE_SRC_I2C0,          WAKEUP_NULL},
   {WAKE_SRC_GPIOB,        WAKEUP_NULL},
   {WAKE_SRC_GPIOA,        WAKEUP_NULL},
   {WAKE_SRC_UART_LOG,        WAKEUP_NULL},
   {WAKE_SRC_UART2_BT,        WAKEUP_NULL},
   {WAKE_SRC_UART1,        WAKEUP_NULL},
   {WAKE_SRC_UART0,        WAKEUP_NULL},
   {WAKE_SRC_pmc_timer1,      WAKEUP_KM0},  /* Internal use, do not change it*/
   {WAKE_SRC_pmc_timer0,      WAKEUP_KM4},  /* Internal use, do not change it*/
   {WAKE_SRC_Timer7,        WAKEUP_NULL},
   {WAKE_SRC_Timer6,        WAKEUP_NULL},
   {WAKE_SRC_Timer5,        WAKEUP_NULL},
   {WAKE_SRC_Timer4,        WAKEUP_NULL},
   {WAKE_SRC_IPC_KM4,        WAKEUP_KM4},  /* IPC can only wake up KM4, do not change it*/
   {WAKE_SRC_BT_WAKE_HOST,      WAKEUP_NULL},
   {WAKE_SRC_KM4_WAKE_IRQ,      WAKEUP_KM0},  /* Internal use, do not change it*/
   {WAKE_SRC_WIFI_FTSR_MAILBOX,  WAKEUP_KM0},  /* Wi-Fi wakeup, do not change it*/
   {WAKE_SRC_WIFI_FISR_FESR_IRQ,  WAKEUP_KM0},  /* Wi-Fi wakeup, do not change it*/
   {0xFFFFFFFF,          WAKEUP_NULL},
};

AON Wakepin Configuration

AON wakepin is one of the peripherals that can be set as a wakeup source. SoC has two AON wakepins (PB30 and PB31), which can be configured in sleep_wakepin_config[] in ameba_sleepcfg.c. The config attribute can be set to DISABLE_WAKEPIN or HIGH_LEVEL_WAKEUP or LOW_LEVEL_WAKEUP, meaning not wake up, or GPIO level high will wake up, or GPIO level low will wake up respectively.

/* can be used by sleep mode & deep sleep mode */
/* config can be set to DISABLE_WAKEPIN/HIGH_LEVEL_WAKEUP/LOW_LEVEL_WAKEUP */
WAKEPIN_TypeDef sleep_wakepin_config[] = {
   //   wakepin      config
   {WAKEPIN_0,    DISABLE_WAKEPIN},  /* WAKEPIN_0 corresponding to _PB_30 */
   {WAKEPIN_1,    DISABLE_WAKEPIN},  /* WAKEPIN_1 corresponding to _PB_31 */
   {0xFFFFFFFF,  DISABLE_WAKEPIN},
};

Note

  • By default, AON_WAKEPIN_IRQ will not be enabled in sleep_wakepin_config[], and users need to enable it by themselves.

  • The wakeup mask will not be set in sleep_wakepin_config[]. If wakepin is used for sleep mode, WAKE_SRC_AON_WAKEPIN entry needs to be set in sleep_wevent_config[].

Clock and Voltage Configuration

The XTAL, OSC4M state, and sleep mode voltage are configurable in ps_config[] in ameba_sleepcfg.c. Users can use this configuration for peripherals that need XTAL or OSC4M on in sleep mode.

PSCFG_TypeDef ps_config = {
   .keep_OSC4M_on = FALSE,        /* Keep OSC4M on or off for sleep */
   .xtal_mode_in_sleep = XTAL_OFF,    /* Set XTAL mode during sleep mode, see enum xtal_mode_sleep for details */
   .sleep_to_08V = FALSE,        /* Default sleep to 0.7V, setting this option to TRUE will sleep to 0.8V */
};

Sleep mode Configuration

  • Application software can set sleep mode to CG or PG by calling pmu_set_sleep_type(uint32_t type)().

  • Users can get CPU’s sleep mode by calling pmu_get_sleep_type().

Note

  • KM0 and KM4 are in the same power domain, so they will have the same sleep type, thus pmu_set_sleep_type() should be set to KM4, and KM0 will follow KM4’s sleep mode type.

  • Sleep mode is set to PG by default. If users want to change the sleep type, pmu_set_sleep_type() needs to be called before sleep.

ameba_wificfg

wifi_user_conf