### Minimum Resource Consumption Source: https://github.com/armink/easyflash/blob/master/README.md Displays the minimum resource requirements for EasyFlash. This is a static value and does not require specific setup. ```text Minimum : ROM: 6K bytes RAM: 0.2K bytes ``` -------------------------------- ### Direct Peripheral Register Access Example Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Demonstrates how to access and modify peripheral registers using the defined access structures and base addresses. This example shows setting the SysTick control register to 0. ```c SysTick->CTRL = 0; ``` -------------------------------- ### Doxygen Function Comment Example Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm This is an example of Doxygen-formatted comments for a function, providing a brief overview, parameter explanation, return value details, and a comprehensive description. ```c /** * @brief Enable Interrupt in NVIC Interrupt Controller * @param IRQn interrupt number that specifies the interrupt * @return none. * Enable the specified interrupt in the NVIC Interrupt Controller. * Other settings of the interrupt such as priority are not affected. */ ``` -------------------------------- ### RTOS Kernel ITM Debug Example Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Example demonstrating the usage of ITM Channel 31 for RTOS kernel awareness debugging. It checks for debugger connection and ITM channel enablement before transmitting trace data. ```c // check if debugger connected and ITM channel enabled for tracing if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) && (ITM->TCR & ITM_TCR_ITMENA) && (ITM->TER & (1UL << 31))) { // transmit trace data while (ITM->PORT31_U32 == 0); ITM->PORT31_U32 = task_id; // id of next task while (ITM->PORT31_U32 == 0); ITM->PORT31_U32 = task_status; // status information } ``` -------------------------------- ### CMSIS Layer STM32F10x Example Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm A typical example of using the CMSIS layer in a user application on an STM32F10x device, demonstrating SysTick configuration, LED control, and delay functions. ```c #include "stm32f10x.h" volatile uint32_t msTicks; /* timeTicks counter */ void SysTick_Handler(void) { msTicks++; /* increment timeTicks counter */ } __INLINE static void Delay (uint32_t dlyTicks) { uint32_t curTicks = msTicks; while ((msTicks - curTicks) < dlyTicks); } __INLINE static void LED_Config(void) { ; /* Configure the LEDs */ } __INLINE static void LED_On (uint32_t led) { ; /* Turn On LED */ } __INLINE static void LED_Off (uint32_t led) { ; /* Turn Off LED */ } int main (void) { if (SysTick_Config (SystemCoreClock / 1000)) { /* Setup SysTick for 1 msec interrupts */ ; /* Handle Error */ while (1); } LED_Config(); /* configure the LEDs */ while(1) { LED_On (0x100); /* Turn on the LED */ Delay (100); /* delay 100 Msec */ LED_Off (0x100); /* Turn off the LED */ Delay (100); /* delay 100 Msec */ } } ``` -------------------------------- ### Copy downloaded firmware to application start address with ef_copy_app_from_bak Source: https://context7.com/armink/easyflash/llms.txt Copies a complete firmware image from the backup area to the user application's execute-in-place address. Must be called from a bootloader after erasing the user app area with ef_erase_user_app. ```c #include /* Run from bootloader ONLY */ void bootloader_apply_update(uint32_t app_addr, size_t app_size) { EfErrCode err; /* 1. erase the live application slot */ err = ef_erase_user_app(app_addr, app_size); if (err != EF_NO_ERR) { /* handle */ return; } /* 2. copy from backup area → application slot */ err = ef_copy_app_from_bak(app_addr, app_size); if (err != EF_NO_ERR) { /* handle */ return; } /* 3. boot new application */ typedef void (*AppEntry)(void); uint32_t sp = *(volatile uint32_t *)app_addr; uint32_t entry = *(volatile uint32_t *)(app_addr + 4); __set_MSP(sp); ((AppEntry)entry)(); } ``` -------------------------------- ### Doxygen Example for NVIC Enable Interrupt Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os_spi_flash/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm This is an example of Doxygen-formatted comments for a function that enables an interrupt in the NVIC. It details the function's purpose, parameters, and return values. ```c /** * @brief Enable Interrupt in NVIC Interrupt Controller * @param IRQn interrupt number that specifies the interrupt * @return none. * Enable the specified interrupt in the NVIC Interrupt Controller. * Other settings of the interrupt such as priority are not affected. */ ``` -------------------------------- ### ef_copy_bl_from_bak Source: https://github.com/armink/easyflash/blob/master/docs/zh/api.md Copies a bootloader from the backup region to the bootloader start address. The existing bootloader must be erased before copying. This function should not be called from within the bootloader itself. ```APIDOC ## ef_copy_bl_from_bak ### Description Copies a bootloader from the backup region to the bootloader start address. The existing bootloader must be erased before copying. This function should not be called from within the bootloader itself. ### Function Signature ```c EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size) ``` ### Parameters - **bl_addr** (uint32_t) - The starting address of the bootloader. - **bl_size** (size_t) - The size of the bootloader. ``` -------------------------------- ### RTOS Kernel ITM Debug Trace Example Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os_spi_flash/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm Example demonstrating the use of ITM Channel 31 for RTOS kernel awareness debugging. It checks for debugger connection and ITM channel enablement before transmitting trace data. ```c // check if debugger connected and ITM channel enabled for tracing if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) && (ITM->TCR & ITM_TCR_ITMENA) && (ITM->TER & (1UL << 31))) { // transmit trace data while (ITM->PORT31_U32 == 0); ITM->PORT[31].u8 = task_id; // id of next task while (ITM->PORT31_U32 == 0); ITM->PORT[31].u32 = task_status; // status information } ``` -------------------------------- ### RTOS Kernel ITM Channel 31 Example Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os_spi_flash/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Example demonstrating the usage of ITM Channel 31 for RTOS kernel tracing. It checks for debugger connection and ITM channel enablement before transmitting task ID and status. ```c // check if debugger connected and ITM channel enabled for tracing if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) && (ITM->TCR & ITM_TCR_ITMENA) && (ITM->TER & (1UL << 31))) { // transmit trace data while (ITM->PORT31_U32 == 0); ITM->PORT31.u8 = task_id; // id of next task while (ITM->PORT31.u32 == 0); ITM->PORT31.u32 = task_status; // status information } ``` -------------------------------- ### ef_copy_app_from_bak Source: https://github.com/armink/easyflash/blob/master/docs/zh/api.md Copies an application from the backup region to the user application start address. The existing application must be erased before copying. This function should not be called from within the application itself. ```APIDOC ## ef_copy_app_from_bak ### Description Copies an application from the backup region to the user application start address. The existing application must be erased before copying. This function should not be called from within the application itself. ### Function Signature ```c EfErrCode ef_copy_app_from_bak(uint32_t user_app_addr, size_t app_size) ``` ### Parameters - **user_app_addr** (uint32_t) - The starting address of the user application. - **app_size** (size_t) - The size of the user application. ``` -------------------------------- ### System Initialization and Clock Configuration Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Provides information on the SystemInit function for microcontroller system setup, SystemCoreClockUpdate for dynamic clock frequency updates, and the SystemCoreClock variable for current CPU clock speed. ```APIDOC ## SystemInit ### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. ### Function Signature ```c void SystemInit (void) ``` ### Called By SystemInit is called from startup_device file. ## SystemCoreClockUpdate ### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ### Function Signature ```c void SystemCoreClockUpdate (void) ``` ## SystemCoreClock Variable ### Description Contains the system core clock (which is the system clock frequency supplied to the SysTick timer and the processor core clock). This variable can be used by the user application to setup the SysTick timer or configure other parameters. It may also be used by debugger to query the frequency of the debug timer or configure the trace clock speed. ### Variable Definition ```c extern uint32_t SystemCoreClock ``` ### Initialization SystemCoreClock is initialized with a correct predefined value. ``` -------------------------------- ### Doxygen Example for CMSIS Function Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm This is an example of Doxygen-style comments used for CMSIS functions, providing a brief overview, parameter explanation, return value details, and a comprehensive function description. It is used to document functions within the Core Peripheral Access Layer. ```c /** * @brief Enable Interrupt in NVIC Interrupt Controller * @param IRQn interrupt number that specifies the interrupt * @return none. * Enable the specified interrupt in the NVIC Interrupt Controller. * Other settings of the interrupt such as priority are not affected. */ ``` -------------------------------- ### Copy Application from Backup Source: https://github.com/armink/easyflash/blob/master/docs/zh/api.md Copies a downloaded application from the backup area to the user application start address. The existing application must be erased before copying. Do not call this function from within the application itself. ```C EfErrCode ef_copy_app_from_bak(uint32_t user_app_addr, size_t app_size) ``` -------------------------------- ### Copy Bootloader from Backup Source: https://github.com/armink/easyflash/blob/master/docs/zh/api.md Copies a downloaded bootloader from the backup area to the bootloader start address. The existing bootloader must be erased before copying. Do not call this function from within the bootloader itself. ```C EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size) ``` -------------------------------- ### Configure SysTick Timer Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Sets up the SysTick timer to generate interrupts at a specified interval. Call this function to start the SysTick interrupt. ```c uint32_t SysTickConfig (uint32_t ticks) ``` -------------------------------- ### ef_copy_spec_app_from_bak Source: https://github.com/armink/easyflash/blob/master/docs/zh/api.md Copies an application from the backup region to the user application start address using a user-specified write operation. This is useful when the user application and backup region are not on the same Flash. It uses the `ef_port_write` function from the porting file for writing, otherwise, its functionality is identical to `ef_copy_app_from_bak`. ```APIDOC ## ef_copy_spec_app_from_bak ### Description Copies an application from the backup region to the user application start address using a user-specified write operation. This is useful when the user application and backup region are not on the same Flash. It uses the `ef_port_write` function from the porting file for writing, otherwise, its functionality is identical to `ef_copy_app_from_bak`. ### Function Signature ```c EfErrCode ef_copy_spec_app_from_bak(uint32_t user_app_addr, size_t app_size, EfErrCode (*app_write)(uint32_t addr, const uint32_t *buf, size_t size)) ``` ### Parameters - **user_app_addr** (uint32_t) - The starting address of the user application. - **app_size** (size_t) - The size of the user application. - **app_write** (EfErrCode (*)(uint32_t, const uint32_t *, size_t)) - A user-specified function for writing the application. ``` -------------------------------- ### Initialize EasyFlash Library Source: https://context7.com/armink/easyflash/llms.txt Must be called once at startup before any other EasyFlash API. Internally calls `ef_port_init` and initializes enabled modules. Writes default ENV values on first run. Returns `EF_NO_ERR` on success. ```c #define EF_USING_ENV #define EF_USING_IAP #define EF_USING_LOG #define EF_ERASE_MIN_SIZE 4096 /* NOR flash sector = 4 KB */ #define EF_WRITE_GRAN 1 /* NOR flash: 1-bit granularity */ #define EF_START_ADDR 0x08040000 /* backup area start in flash */ #define ENV_AREA_SIZE (8 * 4096) /* 32 KB for ENV */ #define LOG_AREA_SIZE (4 * 4096) /* 16 KB for log */ ``` ```c #include int main(void) { board_flash_init(); /* platform-specific flash hw init */ EfErrCode result = easyflash_init(); if (result == EF_NO_ERR) { /* Output: "EasyFlash V4.1.99 is initialize success." */ } else { /* Output: "EasyFlash V4.1.99 is initialize fail." */ while (1); /* halt on fatal error */ } app_run(); return 0; } ``` -------------------------------- ### Initialize Port Layer and Register Default ENV with `ef_port_init` Source: https://context7.com/armink/easyflash/llms.txt Implement `ef_port_init` to register the default environment set and its size. This function is called automatically by `easyflash_init`. ```c /* easyflash/port/ef_port.c */ #include static uint32_t s_boot_count = 0; static float s_cal_offset = 0.0f; static const ef_env default_env_set[] = { {"device_name", "sensor-node-01", 0}, /* string */ {"boot_count", &s_boot_count, sizeof(uint32_t)}, {"cal_offset", &s_cal_offset, sizeof(float)}, }; EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) { *default_env = default_env_set; *default_env_size = sizeof(default_env_set) / sizeof(default_env_set[0]); return EF_NO_ERR; } ``` -------------------------------- ### easyflash_init Source: https://context7.com/armink/easyflash/llms.txt Initializes the EasyFlash library and all enabled modules. Must be called once at startup before any other EasyFlash API is used. ```APIDOC ## easyflash_init ### Description Initializes the EasyFlash library and all enabled modules. Must be called once at startup before any other EasyFlash API is used. Internally calls `ef_port_init`, then initializes each enabled module (ENV, IAP, Log). On the first run it writes default ENV values from the port's `default_env_set[]` table to flash. Returns `EF_NO_ERR` on success. ### Function Signature ```c EfErrCode easyflash_init(void); ``` ### Parameters None ### Returns - `EF_NO_ERR`: Initialization successful. - Other error codes: Initialization failed. ### Example ```c /* ef_cfg.h — configure before building */ #define EF_USING_ENV #define EF_USING_IAP #define EF_USING_LOG #define EF_ERASE_MIN_SIZE 4096 /* NOR flash sector = 4 KB */ #define EF_WRITE_GRAN 1 /* NOR flash: 1-bit granularity */ #define EF_START_ADDR 0x08040000 /* backup area start in flash */ #define ENV_AREA_SIZE (8 * 4096) /* 32 KB for ENV */ #define LOG_AREA_SIZE (4 * 4096) /* 16 KB for log */ /* main.c */ #include int main(void) { board_flash_init(); /* platform-specific flash hw init */ EfErrCode result = easyflash_init(); if (result == EF_NO_ERR) { /* Output: "EasyFlash V4.1.99 is initialize success." */ } else { /* Output: "EasyFlash V4.1.99 is initialize fail." */ while (1); /* halt on fatal error */ } app_run(); return 0; } ``` ``` -------------------------------- ### Interrupt Number Definition Example (IRQn_Type) Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm An example enum typedef from _device.h defining interrupt request numbers (IRQn) for Cortex-M3 processor exceptions and STM32 specific interrupts. ```c typedef enum IRQn { /****** Cortex-M3 Processor Exceptions/Interrupt Numbers ************************************************************************/ NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ HardFault_IRQn = -13, /*!< 3 Cortex-M3 Hard Fault Interrupt */ MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ /****** STM32 specific Interrupt Numbers ******************************************************************************************/ WWDG_STM_IRQn = 0, /*!< Window WatchDog Interrupt */ PVD_STM_IRQn = 1, /*!< PVD through EXTI Line detection Interrupt */ : : } IRQn_Type; ``` -------------------------------- ### System Initialization Function Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm The SystemInit function must be provided to set up the microcontroller system, typically configuring the oscillator (PLL) and updating the SystemCoreClock variable if the clock speed is variable. It is called from the startup file. ```c void SystemInit (void) ``` -------------------------------- ### System Initialization Functions Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os_spi_flash/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm These functions are crucial for setting up the microcontroller system, including clock configuration and updating the system core clock. ```APIDOC ## SystemInit ### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. ### Function Signature ```c void SystemInit (void) ``` ### Called By SystemInit is called from startup_device file. ``` ```APIDOC ## SystemCoreClockUpdate ### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ### Function Signature ```c void SystemCoreClockUpdate (void) ``` ``` -------------------------------- ### System Initialization Functions Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/rtt/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Provides functions for system initialization and core clock updates. SystemInit configures the microcontroller system, and SystemCoreClockUpdate refreshes the SystemCoreClock variable. ```APIDOC ## void SystemInit (void) ### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. ### Called By Startup file (`startup_device.c`) ## void SystemCoreClockUpdate (void) ### Description Updates the variable `SystemCoreClock` and must be called whenever the core clock is changed during program execution. `SystemCoreClockUpdate()` evaluates the clock register settings and calculates the current core clock. ``` -------------------------------- ### NVIC Access Functions Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os_spi_flash/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm Provides helper functions to simplify the setup and configuration of the Nested Vectored Interrupt Controller (NVIC). ```APIDOC ## NVIC Access Functions The CMSIS provides access to the NVIC via the register interface structure and several helper functions that simplify the setup of the NVIC. The CMSIS HAL uses IRQ numbers (IRQn) to identify the interrupts. ### Core Exception IRQn Values | Core Exception Name | Core | IRQn Value | Description | |----------------------------|--------|------------|------------------------------------| | `NonMaskableInt_IRQn` | M0, M3 | -14 | Non Maskable Interrupt | | `HardFault_IRQn` | M0, M3 | -13 | Hard Fault Interrupt | | `MemoryManagement_IRQn` | M3 | -12 | Memory Management Interrupt | | `BusFault_IRQn` | M3 | -11 | Bus Fault Interrupt | | `UsageFault_IRQn` | M3 | -10 | Usage Fault Interrupt | | `SVCall_IRQn` | M0, M3 | -5 | SV Call Interrupt | | `DebugMonitor_IRQn` | M3 | -4 | Debug Monitor Interrupt | | `PendSV_IRQn` | M0, M3 | -2 | Pend SV Interrupt | | `SysTick_IRQn` | M0, M3 | -1 | System Tick Interrupt | ### NVIC Configuration Functions These functions are defined as **static inline**. #### `NVIC_SetPriorityGrouping(uint32_t PriorityGroup)` - **Description**: Set the Priority Grouping (Groups . Subgroups). - **Core**: M3 - **Parameter**: `PriorityGroup` - Priority Grouping Value #### `NVIC_GetPriorityGrouping(void)` - **Description**: Get the Priority Grouping (Groups . Subgroups). - **Core**: M3 - **Parameter**: `void` - **Returns**: Priority Grouping Value #### `NVIC_EnableIRQ(IRQn_Type IRQn)` - **Description**: Enable IRQn. - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number #### `NVIC_DisableIRQ(IRQn_Type IRQn)` - **Description**: Disable IRQn. - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number #### `NVIC_GetPendingIRQ(IRQn_Type IRQn)` - **Description**: Return 1 if IRQn is pending else 0. - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number - **Returns**: 1 if pending, 0 otherwise #### `NVIC_SetPendingIRQ(IRQn_Type IRQn)` - **Description**: Set IRQn Pending. - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number #### `NVIC_ClearPendingIRQ(IRQn_Type IRQn)` - **Description**: Clear IRQn Pending Status. - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number #### `NVIC_GetActive(IRQn_Type IRQn)` - **Description**: Return 1 if IRQn is active else 0. - **Core**: M3 - **Parameter**: `IRQn` - IRQ Number - **Returns**: 1 if active, 0 otherwise #### `NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)` - **Description**: Set Priority for IRQn. (Note: Not threadsafe for Cortex-M0). - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number, `priority` - Priority Value #### `NVIC_GetPriority(IRQn_Type IRQn)` - **Description**: Get Priority for IRQn. - **Core**: M0, M3 - **Parameter**: `IRQn` - IRQ Number - **Returns**: Priority Value #### `NVIC_EncodePriority(uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)` - **Description**: Encode priority for given group, preemptive and sub priority. - **Core**: M3 - **Parameter**: `PriorityGroup` - Priority Grouping Value, `PreemptPriority` - Preemptive Priority Value, `SubPriority` - Sub Priority Value - **Returns**: Encoded Priority Value #### `NVIC_DecodePriority(uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)` - **Description**: Decode given priority to group, preemptive and sub priority. - **Core**: M3 - **Parameter**: `Priority` - Encoded Priority Value, `PriorityGroup` - Priority Grouping Value, `pPreemptPriority` - Pointer to Preemptive Priority, `pSubPriority` - Pointer to Sub Priority #### `NVIC_SystemReset(void)` - **Description**: Resets the System. - **Core**: M0, M3 - **Parameter**: `void` **Notes**: * Processor exceptions have negative enum values. Device specific interrupts have positive enum values starting from 0. Values are defined in the `_device.h` file. * The values for `PreemptPriority` and `SubPriority` used in `NVIC_EncodePriority` and `NVIC_DecodePriority` depend on the available `__NVIC_PRIO_BITS` implemented in the NVIC. ``` -------------------------------- ### ef_port_init Source: https://context7.com/armink/easyflash/llms.txt Registers the default environment set and initializes the Hardware Abstraction Layer (HAL). This function is called automatically by `easyflash_init`. ```APIDOC ## ef_port_init ### Description Registers the default environment set and initializes the HAL. This function is called automatically by `easyflash_init`. The implementer must set `*default_env` to point to the static `default_env_set[]` array and set `*default_env_size` to its element count. ### Function Signature ```c EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size); ``` ### Parameters - `default_env` (ef_env const **): Pointer to a pointer that will be set to the default environment set. - `default_env_size` (size_t *): Pointer to a size_t that will be set to the number of elements in the default environment set. ### Return Value - `EF_NO_ERR`: Success. - Other error codes indicate failure. ``` -------------------------------- ### Copy downloaded bootloader from backup area with ef_copy_bl_from_bak Source: https://context7.com/armink/easyflash/llms.txt Copies a downloaded bootloader from the backup area to the bootloader flash region. Must be called from the application, never from the bootloader itself. Erase the bootloader area first with ef_erase_bl. ```c #include /* Called from running APPLICATION to self-update the bootloader */ void app_update_bootloader(uint32_t bl_addr, size_t bl_size) { EfErrCode err; err = ef_erase_bl(bl_addr, bl_size); if (err != EF_NO_ERR) return; err = ef_copy_bl_from_bak(bl_addr, bl_size); if (err == EF_NO_ERR) { NVIC_SystemReset(); /* reboot into new bootloader */ } } ``` -------------------------------- ### Get Used Log Size in Flash Source: https://github.com/armink/easyflash/blob/master/docs/zh/api.md Retrieves the total size of log data currently stored in flash memory. ```C size_t ef_log_get_used_size(void); ``` -------------------------------- ### Get Control Register Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the CONTROL register using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_CONTROL (void) ``` -------------------------------- ### NVIC Access Functions Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Helper functions to simplify the setup and management of the Nested Vectored Interrupt Controller (NVIC), using IRQ numbers. ```APIDOC ## NVIC Access Functions These functions simplify the setup of the NVIC. They are defined as `static inline`. ### `void NVIC_SetPriorityGrouping (uint32_t PriorityGroup)` * **Core:** M3 * **Parameter:** `PriorityGroup` - Priority Grouping Value * **Description:** Set the Priority Grouping (Groups . Subgroups). ### `uint32_t NVIC_GetPriorityGrouping (void)` * **Core:** M3 * **Parameter:** `(void)` * **Description:** Get the Priority Grouping (Groups . Subgroups). ### `void NVIC_EnableIRQ (IRQn_Type IRQn)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Enable IRQn. ### `void NVIC_DisableIRQ (IRQn_Type IRQn)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Disable IRQn. ### `uint32_t NVIC_GetPendingIRQ (IRQn_Type IRQn)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Return 1 if IRQn is pending else 0. ### `void NVIC_SetPendingIRQ (IRQn_Type IRQn)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Set IRQn Pending. ### `void NVIC_ClearPendingIRQ (IRQn_Type IRQn)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Clear IRQn Pending Status. ### `uint32_t NVIC_GetActive (IRQn_Type IRQn)` * **Core:** M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Return 1 if IRQn is active else 0. ### `void NVIC_SetPriority (IRQn_Type IRQn, uint32_t priority)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number, `priority` - Priority * **Description:** Set Priority for IRQn (not threadsafe for Cortex-M0). ### `uint32_t NVIC_GetPriority (IRQn_Type IRQn)` * **Core:** M0, M3 * **Parameter:** `IRQn` - IRQ Number * **Description:** Get Priority for IRQn. ### `uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)` * **Core:** M3 * **Parameter:** `PriorityGroup` - Priority Group, `PreemptPriority` - Preemptive Priority, `SubPriority` - Sub Priority * **Description:** Encode priority for given group, preemptive and sub priority. ### `NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)` * **Core:** M3 * **Parameter:** `Priority` - Priority, `PriorityGroup` - pointer to Priority Group, `pPreemptPriority` - pointer to Preemptive Priority, `pSubPriority` - pointer to Sub Priority * **Description:** Decode given priority to group, preemptive and sub priority. ### `void NVIC_SystemReset (void)` * **Core:** M0, M3 * **Parameter:** `(void)` * **Description:** Resets the System. **Note:** * The processor exceptions have negative enum values. Device specific interrupts have positive enum values and start with 0. The values are defined in `_device.h` file. * The values for `PreemptPriority` and `SubPriority` used in functions `NVIC_EncodePriority` and `NVIC_DecodePriority` depend on the available `__NVIC_PRIO_BITS` implemented in the NVIC. ``` -------------------------------- ### Get Base Priority Register Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Base Priority Register (BASEPRI) using the MRS instruction. Available for Cortex-M3. ```c uiuint32_t __get_BASEPRI (void) ``` -------------------------------- ### System Configuration Functions Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/rtt/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm These functions are essential for initializing the microcontroller system and managing the core clock frequency. ```APIDOC ## System Configuration ### void SystemInit (void) #### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. SystemInit is called from startup_device file. ### void SystemCoreClockUpdate (void) #### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ### uint32_t SystemCoreClock #### Description Contains the system core clock (which is the system clock frequency supplied to the SysTick timer and the processor core clock). This variable can be used by the user application to setup the SysTick timer or configure other parameters. It may also be used by debugger to query the frequency of the debug timer or configure the trace clock speed. SystemCoreClock is initialized with a correct predefined value. ``` -------------------------------- ### System Initialization and Core Clock Configuration Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os_spi_flash/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Provides essential functions for microcontroller system initialization and core clock updates, along with a variable to hold the system core clock frequency. ```APIDOC ## System Configuration Functions ### `void SystemInit (void)` #### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. SystemInit is called from startup_device file. ### `void SystemCoreClockUpdate (void)` #### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ## System Core Clock Variable ### `uint32_t SystemCoreClock` #### Description Contains the system core clock (which is the system clock frequency supplied to the SysTick timer and the processor core clock). This variable can be used by the user application to setup the SysTick timer or configure other parameters. It may also be used by debugger to query the frequency of the debug timer or configure the trace clock speed. SystemCoreClock is initialized with a correct predefined value. ``` -------------------------------- ### Get Fault Mask Register Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Fault Mask Register (FAULTMASK) using the MRS instruction. Available for Cortex-M3. ```c uint32_t __get_FAULTMASK (void) ``` -------------------------------- ### NVIC Active and Priority Management Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Functions to check if an interrupt is active and to set or get the priority of an interrupt. Note that setting priority is not thread-safe for Cortex-M0. ```c uint32_t NVIC_GetActive (IRQn_Type IRQn) ``` ```c void NVIC_SetPriority (IRQn_Type IRQn, uint32_t priority) ``` ```c uint32_t NVIC_GetPriority (IRQn_Type IRQn) ``` -------------------------------- ### ef_copy_app_from_bak Source: https://context7.com/armink/easyflash/llms.txt Copies a complete firmware image from the backup area to the user application's execute-in-place address. This function must be called from a bootloader after the backup area has been fully written and the user application area has been erased using `ef_erase_user_app`. ```APIDOC ## ef_copy_app_from_bak — Copy downloaded firmware to application start address ### Description After a complete firmware image has been written to the backup area, this function copies it to the user application's execute-in-place address. Call only from a **bootloader**, never from the application itself. Erase the user app area first with `ef_erase_user_app`. ### Function Signature ```c EfErrCode ef_copy_app_from_bak(uint32_t app_addr, size_t app_size) ``` ### Parameters - **app_addr** (*uint32_t*) - The starting address of the user application area. - **app_size** (*size_t*) - The size of the user application. ### Return Value - **EfErrCode**: Returns `EF_NO_ERR` on success, or an error code if the copy operation fails. ``` -------------------------------- ### Get Main Stack Pointer Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Main Stack Pointer (MSP) using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_MSP (void) ``` -------------------------------- ### Get Process Stack Pointer Source: https://github.com/armink/easyflash/blob/master/demo/env/stm32f10x/non_os/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Process Stack Pointer (PSP) using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_PSP (void) ``` -------------------------------- ### Minimum Resource Requirements Source: https://github.com/armink/easyflash/blob/master/README.md Specifies the minimum ROM and RAM required for EasyFlash. ```text Minimum requirement: ROM: 6K bytes RAM: 0.1K bytes ```