Previously, we were able to run the DigitalOut and Serial classes of Mbed.
This time, we will try to run the Ticker class.
Here is the development environment at the time of submission.
PC: Windows 10 OS
IDE: STM32CubeIDE Version1.6.0
Configurator: STM32CubeMX Version6.2.1
Board: STM32Nucleo-F401RE
What is the Ticker class in Mbed?
You can get an overview by looking at here.
You can call a function periodically, like an interval timer used for interrupts.
The function can also be a member function of a specific object.
Trying to code
Ticker code should be written after SystemClock_Config() in the initialization process of the clock system.
/* USER CODE BEGIN 0 */
DigitalOut led(LED1);
void led_ticker();
void led_ticker()
{
led = !led;
}
/* USER CODE END 0 */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
Ticker tick;
tick.attach(&led_ticker, 1);
/* USER CODE END SysInit */
Let’s build and run it
Now let’s try to build and run it once.
Here we can see the LED-blinkey.
How was it in your environment?
Attaching a class member function
Here is another example of the attach_us code.
/* USER CODE BEGIN 0 */
class LedTicker
{
public:
LedTicker(PinName pin) : led(pin)
{
led = 0;
}
void toggle()
{
led = !led;
}
private:
DigitalOut led;
};
LedTicker l(LED1);
/* USER CODE END 0 */
Ticker t;
t.attach_us(callback(&l, &LedTicker::toggle), 500000.0); // 500msec
while (1)
This is an example of attaching a class member function.
The constructor and attach_us() should be written after SystemClock_Config().
Build and run the code, and you have successfully confirmed the LED-Blinkey.





