RZG Flexible Software Package Documentation
Release v2.1.0
|
|
Functions | |
fsp_err_t | R_FSP_VersionGet (fsp_pack_version_t *const p_version) |
void | Reset_Handler_NS (void) |
void | Default_Handler (void) |
void | NMI_Handler_NS (void) |
void | SVC_Handler_NS (void) |
SVC Handler. | |
void | PendSV_Handler_NS (void) |
PendSV Exception handler. | |
void | Reset_Handler_S (void) |
void | Default_Handler_S (void) |
void | NMI_Handler_S (void) |
void | SecureFault_Handler (void) |
void | SystemInit (void) |
void | R_BSP_WarmStart (bsp_warm_start_event_t event) |
void | R_BSP_SecurityInit (void) |
void | SystemInit_S (void) |
__attribute__ ((naked)) | |
uint32_t | R_FSP_SystemClockHzGet (fsp_priv_clock_t clock) |
void | R_FSP_SystemClockHzSet (fsp_priv_clock_t clock, uint32_t clock_sel, uint32_t clock_div) |
fsp_err_t | R_BSP_VersionGet (fsp_version_t *p_version) |
__STATIC_INLINE IRQn_Type | R_FSP_CurrentIrqGet (void) |
__STATIC_INLINE bsp_unique_id_t const * | R_BSP_UniqueIdGet () |
void | R_BSP_SoftwareDelay (uint32_t delay, bsp_delay_units_t units) |
fsp_err_t | R_BSP_GroupIrqWrite (bsp_grp_irq_t irq, void(*p_callback)(bsp_grp_irq_t irq)) |
void | R_BSP_NonSecureEnter (void) |
The BSP is responsible for getting the MCU from reset to the user's application. Before reaching the user's application, the BSP sets up the stacks, heap, clocks, interrupts, and C runtime environment.
All system clocks are set up during BSP initialization based on the settings in bsp_clock_cfg.h. These settings are derived from clock configuration information provided from the Configuration editor Clocks tab.
As RZ MPUs are based on the Cortex-M ARM architecture, the NVIC Nested Vectored Interrupt Controller (NVIC) handles exceptions and interrupt configuration, prioritization and interrupt masking. In the ARM architecture, the NVIC handles exceptions. Some exceptions are known as System Exceptions. System exceptions are statically located at the "top" of the vector table and occupy vector numbers 1 to 15. Vector zero is reserved for the MSP Main Stack Pointer (MSP). The remaining 15 system exceptions are shown below:
NMI and Hard Fault exceptions are enabled out of reset and have fixed priorities. Other exceptions have configurable priorities and some can be disabled.
Note1: In RZ MPU, NMI occurs as an external interrupt (SPI No.0) instead of Coretex-M Core's System Interrupt. Note2: RZ MPU does not support MPU (Memory Protection Unit).
Group Interrupts are not supported in this device.
RZ MPU supports 480 interrupts by NVIC, and any factor can be registered in the vector table from the Interrupts tab of the Configuration editor.
You might wonder how the BSP is able to place ISR addresses in the NVIC table without the user having explicitly defined one. All that is required by the BSP is that the interrupt event be given a priority.
This is accomplished through the use of the 'weak' attribute. The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. A weak symbol is one that can be overridden by an accompanying strong reference with the same name. When the BSP declares a function as weak, user code can define the same function and it will be used in place of the BSP function. By defining all possible interrupt sources as weak, the vector table can be built at compile time and any user declarations (strong references) will be used at runtime.
Weak symbols are supported for ELF targets and also for a.out targets when using the GNU assembler and linker.
Note that in CMSIS system.c
, there is also a weak definition (and a function body) for the Warm Start callback function R_BSP_WarmStart(). Because this function is defined in the same file as the weak declaration, it will be called as the 'default' implementation. The function may be overridden by the user by copying the body into their user application and modifying it as necessary. The linker identifies this as the 'strong' reference and uses it.
As the BSP is in the process of bringing up the board out of reset, there are three points where the user can request a callback. These are defined as the 'Pre Clock Init', 'Post Clock Init' and 'Post C' warm start callbacks.
As described above, this function is already weakly defined as R_BSP_WarmStart(), so it is a simple matter of redefining the function or copying the existing body from CMSIS system.c into the application code to get a callback. R_BSP_WarmStart() takes an event parameter of type bsp_warm_start_event_t
which describes the type of warm start callback being made.
This function is not enabled/disabled and is always called for both events as part of the BSP startup. Therefore it needs a function body, which will not be called if the user is overriding it. The function body is located in system.c. To use this function just copy this function into your own code and modify it to meet your needs.
This BSP configuration allows the user to skip the FSP C runtime initialization code by setting the "C Runtime Initialization" to "Disabled" on the BSP tab of the Configuration editor. Disabling this option is useful in cases where a non-standard linker script is being used or other modifications to the runtime initialization are desired. If this macro is disabled, the user must use the 'Post Clock Init' event from the warm start (described above) to run their own runtime initialization code.
The relatively low amount of on-chip SRAM available and lack of memory protection in an MPU means that heap use must be very carefully controlled to avoid memory leaks, overruns and attempted overallocation. Further, many RTOSes provide their own dynamic memory allocation system. For these reasons the default heap size is set at 0 bytes, effectively disabling dynamic memory. If it is required for an application setting a positive value to the "Heap size (bytes)" option in the Common configurations on the BSP tab will allocate a heap.
When error logging is enabled, the error logging function can be redefined on the command line by defining FSP_ERROR_LOG(err) to the desired function call. The default function implementation is FSP_ERROR_LOG(err)=fsp_error_log(err, FILE, LINE). This implementation uses the predefined macros FILE and LINE to help identify the location where the error occurred. Removing the line from the function call can reduce code size when error logging is enabled. Some compilers may support other predefined macros like FUNCTION, which could be helpful for customizing the error logger.
This feature is not supported on this device.
This feature is not supported on this device.
Implements a blocking software delay. A delay can be specified in microseconds, milliseconds or seconds. The delay is implemented based on the system clock rate.
Implements a critical section. Some MPUs (MPUs with the BASEPRI register) support allowing high priority interrupts to execute during critical sections. On these MPUs, interrupts with priority less than or equal to BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION are not serviced in critical sections. Interrupts with higher priority than BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION still execute in critical sections.
This feature is not supported on this device.
The BSP will call the board's initialization function (bsp_init) which can initialize board specific features.
The BSP is heavily data driven with most features and functionality being configured based on the content from configuration files. Configuration files represent the settings specified by the user and are generated when the project is built and/or when the Generate Project Content button is clicked in the Configuration editor.
Configuration | Options | Default | Description |
---|---|---|---|
Secure stack size (bytes) | Value must be an integer multiple of 8 and between 8 and 0xFFFFFFFF | 0x200 | Set the size of the secure program stack. NOTE: This entry is for the secure stack. |
Main stack size (bytes) | Value must be an integer multiple of 8 and between 8 and 0xFFFFFFFF | 0x400 | Set the size of the main program stack. NOTE: This entry is for the main stack. When using an RTOS, thread stacks can be configured in the properties for each thread. |
Heap size (bytes) | Value must be 0 or an integer multiple of 8 between 8 and 0xFFFFFFFF. | 0 | The main heap is disabled by default. Set the heap size to a positive integer divisible by 8 to enable it. A minimum of 4K (0x1000) is recommended if standard library functions are to be used. |
MCU Vcc (mV) | Value must between 0 and 5500 (5.5V) | 3300 | Some peripherals require different settings based on the supplied voltage. Entering Vcc here (in mV) allows the relevant driver modules to configure the associated peripherals accordingly. |
Parameter checking |
| Disabled | When enabled, parameter checking for the BSP is turned on. In addition, any modules whose parameter checking configuration is set to 'Default (BSP)' will perform parameter checking as well. |
Assert Failures |
| Return FSP_ERR_ASSERTION | Define the behavior of the FSP_ASSERT() macro. |
Error Log |
| No Error Log | Specify error logging behavior. |
PFS Protect |
| Enabled | Keep the PFS registers locked when they are not being modified. If disabled they will be unlocked during startup. |
C Runtime Initialization |
| Enabled | Select if the C runtime initialization in the BSP is to be used. If disabled, use the BSP_WARM_START_POST_CLOCK event to run user defined equivalent. |
Modules | |
RZG2L | |
RZG2UL | |
RZG3S | |
Macros | |
#define | R_BSP_MODULE_START(ip, ch) |
#define | R_BSP_MODULE_STOP(ip, ch) |
#define | BSP_IRQ_DISABLED |
#define | FSP_RETURN(err) |
#define | FSP_ERROR_LOG(err) |
#define | FSP_ASSERT(a) |
#define | FSP_ERROR_RETURN(a, err) |
#define | FSP_CRITICAL_SECTION_ENTER |
#define | FSP_CRITICAL_SECTION_EXIT |
#define | FSP_INVALID_VECTOR |
#define | BSP_CFG_HANDLE_UNRECOVERABLE_ERROR(x) |
#define | BSP_STACK_ALIGNMENT |
#define | R_BSP_MSTP_START(ip, channel) |
#define | R_BSP_MSTP_STOP(ip, channel) |
Enumerations | |
enum | fsp_ip_t |
enum | bsp_warm_start_event_t |
enum | bsp_delay_units_t |
enum | bsp_grp_irq_t |
Variables | |
uint32_t | SystemCoreClock |
const fsp_version_t | g_bsp_version |
Default initialization function. More... | |
#define R_BSP_MODULE_START | ( | ip, | |
ch | |||
) |
Cancels the module stop state.
ip | fsp_ip_t enum value for the module to be started |
ch | The channel. Use channel 0 for modules without channels. |
#define R_BSP_MODULE_STOP | ( | ip, | |
ch | |||
) |
Enables the module stop state.
ip | fsp_ip_t enum value for the module to be stopped |
ch | The channel. Use channel 0 for modules without channels. |
#define BSP_IRQ_DISABLED |
Used to signify that an interrupt factor is not available.
#define FSP_RETURN | ( | err | ) |
Macro to log and return error without an assertion.
#define FSP_ERROR_LOG | ( | err | ) |
This function is called before returning an error code. To stop on a runtime error, define fsp_error_log in user code and do required debugging (breakpoints, stack dump, etc) in this function.
#define FSP_ASSERT | ( | a | ) |
Default assertion calls FSP_ERROR_RETURN if condition "a" is false. Used to identify incorrect use of API's in FSP functions.
#define FSP_ERROR_RETURN | ( | a, | |
err | |||
) |
All FSP error codes are returned using this macro. Calls FSP_ERROR_LOG function if condition "a" is false. Used to identify runtime errors in FSP functions.
#define FSP_CRITICAL_SECTION_ENTER |
This macro temporarily saves the current interrupt state and disables interrupts.
#define FSP_CRITICAL_SECTION_EXIT |
This macro restores the previously saved interrupt state, reenabling interrupts.
#define FSP_INVALID_VECTOR |
Used to signify that the requested IRQ vector is not defined in this system.
#define BSP_CFG_HANDLE_UNRECOVERABLE_ERROR | ( | x | ) |
In the event of an unrecoverable error the BSP will by default call the __BKPT() intrinsic function which will alert the user of the error. The user can override this default behavior by defining their own BSP_CFG_HANDLE_UNRECOVERABLE_ERROR macro.
#define BSP_STACK_ALIGNMENT |
Stacks (and heap) must be sized and aligned to an integer multiple of this number.
#define R_BSP_MSTP_START | ( | ip, | |
channel | |||
) |
Cancels the module stop state.
ip | fsp_ip_t enum value for the module to be started. |
channel | The channel. Use ch 0 for modules without channels. |
#define R_BSP_MSTP_STOP | ( | ip, | |
channel | |||
) |
Enables the module stop state.
ip | fsp_ip_t enum value for the module to be stopped. |
channel | The channel. Use ch 0 for modules without channels. |
enum fsp_ip_t |
Available modules.
Different warm start entry locations in the BSP.
enum bsp_delay_units_t |
Available delay units for R_BSP_SoftwareDelay(). These are ultimately used to calculate a total # of microseconds
enum bsp_grp_irq_t |
fsp_err_t R_FSP_VersionGet | ( | fsp_pack_version_t *const | p_version | ) |
Get the FSP version based on compile time macros.
[out] | p_version | Memory address to return version information to. |
FSP_SUCCESS | Version information stored. |
FSP_ERR_ASSERTION | The parameter p_version is NULL. |
void Reset_Handler_NS | ( | void | ) |
MPU starts executing here out of reset. Main stack pointer is set up already.
void Default_Handler | ( | void | ) |
Default exception handler.
void NMI_Handler_NS | ( | void | ) |
Non-maskable interrupt handler.
void Reset_Handler_S | ( | void | ) |
MPU starts executing here out of reset. Main stack pointer is set up already.
void Default_Handler_S | ( | void | ) |
Default exception handler.
void NMI_Handler_S | ( | void | ) |
Non-maskable interrupt handler.
void SecureFault_Handler | ( | void | ) |
SecureFault_Handler
void SystemInit | ( | void | ) |
Initialize the MPU and the runtime environment.
void R_BSP_WarmStart | ( | bsp_warm_start_event_t | event | ) |
This function is called at various points during the startup process. This function is declared as a weak symbol higher up in this file because it is meant to be overridden by a user implemented version. One of the main uses for this function is to call functional safety code during the startup process. To use this function just copy this function into your own code and modify it to meet your needs.
[in] | event | Where the code currently is in the start up process |
void R_BSP_SecurityInit | ( | void | ) |
Initialize security features for TrustZone.
This function initializes ARM security register for secure projects.
void SystemInit_S | ( | void | ) |
Initialize the MPU and the runtime environment.
__attribute__ | ( | (naked) | ) |
In the Cortex-M33 CPU core of this device, the secure vector address must be set to SYS_CM33_CFG2 before WarmReset is executed. Also, the non-secure vector address must be set to SYS_CM33_CFG3 before WarmReset is executed. The Cortex-M33's program works on the assumption that the appropriate vector address values have been set in SYS_CM33_CFG2 and SYS_CM33_CFG3 in the Cortex-A55 program.
Entry function when debugging RAM load using a debugger
Same function as Warm_Reset_S. Used as an entry function at XSPI boot.
uint32_t R_FSP_SystemClockHzGet | ( | fsp_priv_clock_t | clock | ) |
Get the system clock frequency.
[in] | clock | Element number of the array that defines the frequency of the bus clock. |
g_clock_freq[clock] | System clock frequency. |
void R_FSP_SystemClockHzSet | ( | fsp_priv_clock_t | clock, |
uint32_t | clock_sel, | ||
uint32_t | clock_div | ||
) |
Set a clock frequency.
[in] | clock | Element number of the array that defines the frequency of each clock. |
[in] | clock_sel | Value to set in Source Clock Setting register. |
[in] | clock_div | Value to set in Division Ratio Setting register. |
fsp_err_t R_BSP_VersionGet | ( | fsp_version_t * | p_version | ) |
Get the BSP version based on compile time macros.
[out] | p_version | Memory address to return version information to. |
FSP_SUCCESS | Version information stored. |
FSP_ERR_ASSERTION | The parameter p_version is NULL. |
__STATIC_INLINE IRQn_Type R_FSP_CurrentIrqGet | ( | void | ) |
Return active interrupt vector number value
__STATIC_INLINE bsp_unique_id_t const* R_BSP_UniqueIdGet | ( | ) |
Get unique ID is not supported in this device.
void R_BSP_SoftwareDelay | ( | uint32_t | delay, |
bsp_delay_units_t | units | ||
) |
Delay for at least the specified duration in units and return. This function shouldn't be used to generate an accurate delay time. A running time of the function is depending on the region of memory where the function is excuted on and a frequency of the CPU clock.
The funcion calls bsp_prv_software_delay_loop() which loops over the requested delay time. One loop time through bsp_prv_software_delay_loop() takes roughly 500ns. This value is based on the actual measured time in the condition that a frequency of the CPU clock is 200MHz and the code is excuted on DDR3L-1333 DRAM(133MHz). One loop running time of software_delay_loop() can be modified by redefining BSP_DELAY_LOOP_CYCLES.
[in] | delay | The number of 'units' to delay. |
[in] | units | The 'base' (bsp_delay_units_t) for the units specified. Valid values are: BSP_DELAY_UNITS_SECONDS, BSP_DELAY_UNITS_MILLISECONDS, BSP_DELAY_UNITS_MICROSECONDS. For example: One run through bsp_prv_software_delay_loop() takes roughly 500ns. A delay of 100 us therefore requires 100000ns/500ns -> 200 loops. |
The 'theoretical' maximum delay that may be obtained is determined by a full 32 bit loop count and the system clock rate. @200MHz: ((0xFFFFFFFF loops * 500ns) = 2147 seconds.
Note that requests for very large delays will be affected by rounding in the calculations and the actual delay achieved may be slightly off of a setting time.
Note also that if the calculations result in a loop_cnt of zero, the bsp_prv_software_delay_loop() function is not called at all. In this case the requested delay is too small (nanoseconds) to be carried out by the loop itself, and the overhead associated with executing the code to just get to this point has certainly satisfied the requested delay.
fsp_err_t R_BSP_GroupIrqWrite | ( | bsp_grp_irq_t | irq, |
void(*)(bsp_grp_irq_t irq) | p_callback | ||
) |
Register a callback function for supported interrupts. If NULL is passed for the callback argument then any previously registered callbacks are unregistered.
[in] | irq | Interrupt for which to register a callback. |
[in] | p_callback | Pointer to function to call when interrupt occurs. |
FSP_ERR_UNSUPPORTED | NMI Group IRQ are not supported in this device. |
void R_BSP_NonSecureEnter | ( | void | ) |
Enter the non-secure code environment.
This function configures the non-secure MSP and vector table then jumps to the non-secure project's Reset_Handler.
uint32_t SystemCoreClock |
System Clock Frequency (Core Clock)
const fsp_version_t g_bsp_version |
Default initialization function.
Version data structure used by error logger macro.