Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerEach Cortex-M core integrates a SysTick module, as this module is an essential (timer) function for microcontroller projects.Whether it is the latest Cortex-M85 core or the classic Cortex-M3 microcontroller, the SysTick module is integrated.

cm3.h and cm85.h

Microcontroller developers are most familiar with the core_cm3.h (core_cm85.h) files, which define most of the content related to the core, and the interfaces we call most often are also from here.Let’s compare these two source files:Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

By comparing the source code, you will intuitively find that cm85 has significantly more lines of code than cm3, with 1943 lines and 4672 lines respectively. Of course, with so many more lines, the left side has more red (differences).

Although there are more “red” sections on the left, most of them are just additional lines and macro definitions. Upon closer comparison, many are actually the same, such as the commonly used system reset function:Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void){  __DSB();                                                          /* Ensure all outstanding memory accesses included                                                                       buffered write are completed before reset */  SCB->AIRCR  = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos)    |                           (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |                            SCB_AIRCR_SYSRESETREQ_Msk    );         /* Keep priority group unchanged */  __DSB();                                                          /* Ensure completion of memory access */  for(;;)                                                           /* wait until reset */  {    __NOP();  }

For example, the system Tick configuration function:

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks){  if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)  {    return (1UL);                                                   /* Reload value impossible */  }  SysTick->LOAD  = (uint32_t)(ticks - 1UL);                         /* set reload register */  NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */  SysTick->VAL   = 0UL;                                             /* Load the SysTick Counter Value */  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |                   SysTick_CTRL_TICKINT_Msk   |                   SysTick_CTRL_ENABLE_Msk;                         /* Enable SysTick IRQ and SysTick Timer */  return (0UL);                                                     /* Function successful */}

In fact, you will find that the commonly used function interfaces on the Cortex-M3 microcontroller are basically the same as those on the CM85, which also indicates that CM85 is mostly backward compatible with CM3.

Description of SysTick Usage in RA8 Microcontroller

Here, I will explain the usage of SysTick and describe its source code in conjunction with the Renesas RA8D1 (Cortex-M85 core) microcontroller.

Using e2 studio and FSP software package

The software package provided by the tool is actually the most practical. Here, I will take IO toggling and SysTick delay as an example to guide you step by step in creating a project and demonstrating the effect.

1

Open e2 studio to create a microcontroller project

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerWe named the project: RA8D1_SysTickTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerSelect the corresponding chip model: R7FA8D1BECTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Basically, you just need to click a few buttons, and a complete project will be created.

2

Configure the project

Here, we configure some basic information, using an IO (PA01) to test the SysTick delay time.

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Configure the clock tree:

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerConfigure the output Hex file:Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

3

Demonstration

This is just a simple demo. We add an IO toggle to test the SysTick delay time.

while(1){    R_PORT10->PODR ^= 1<<(BSP_IO_PORT_10_PIN_01 & 0xFF);     //PA01 toggle    R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);    //SysTick delay}

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerThis is a 1ms toggle, and the SysTick delay error is relatively small, which can be ignored compared to 1ms (sampling frequency 100KHz shows no error).Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerWith a sampling frequency of 100MHz, some error can still be observed. Of course, this error is influenced by various factors such as the crystal oscillator and software. Additionally, us-level errors can be ignored compared to ms.Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

If we change to a 1us toggle, the error becomes relatively more noticeable.

4

Source Code Description

Experienced engineers should be able to understand this. Here, I will briefly explain for beginners.

R_PORT10->PODR ^= 1<<(BSP_IO_PORT_10_PIN_01 & 0xFF);

To reduce software-induced errors, we directly manipulate the register for IO toggling.

R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);

R_BSP_SoftwareDelay: A blocking delay function, which is a built-in function interface of the FSP software package.BSP_DELAY_UNITS_MILLISECONDS: Macro definition for delay units (milliseconds).The system defines three macros:

typedef enum{    BSP_DELAY_UNITS_SECONDS      = 1000000, ///< Requested delay amount is in seconds    BSP_DELAY_UNITS_MILLISECONDS = 1000,    ///< Requested delay amount is in milliseconds    BSP_DELAY_UNITS_MICROSECONDS = 1        ///< Requested delay amount is in microseconds} bsp_delay_units_t;

R_BSP_SoftwareDelay: This actually utilizes SysTick for delay.Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerBy analyzing the source code, you will find that the SysTick of the Cortex-M85 core is backward compatible with that of the Cortex-M3, and the commonly used interfaces are the same.Finally, the SysTick of the microcontroller core is quite simple. I hope this description helps you understand SysTick better.

1

END

1

To be continued

Recommended Reading

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Renesas RA8 Series Tutorial | Setting up the Renesas RA8 Development Environment and Lighting Up an LED

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Renesas RA8 Series Tutorial | Serial Output Configuration Based on e2s

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Renesas RA8 Series Tutorial | Introduction to the RA8 Series Microcontrollers

Tutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 MicrocontrollerTutorial on Renesas RA8 Series | Description of SysTick Usage in RA8 Microcontroller

Leave a Comment