Skip to content

us_ticker_read() return a 0xFFFF less value for STM32F103RB. #816

Closed
@leibin2014

Description

@leibin2014

I use the following code to simulate a 500us/2000us software PWM on PB_0 :

 #include "mbed.h"

DigitalOut out0(PB_0);

Timeout t;

extern void pin_off_callback();
void pin_on_callback()
{
    out0 = 1;
    t.attach_us(&pin_off_callback, 500);
}
void pin_off_callback()
{
    out0 = 0;
    t.attach_us(&pin_on_callback, 2000-500);
}

int main()
{
    out0 = 1;
    t.attach_us(&pin_off_callback, 500);
        while(1)
      {

      }
}

No problem is found when it run on STM32F100RB, but found a problem when run it on STM32F103RB. I found some 65ms continuous high(1) or low(0) level voltage on PB_0 each about 10 seconds.

After digging into thIS problem, I found this is due to in us_ticker.c of STM32F103RB it uses the same IRQ function for update and compare interrupts. So if us_ticker_read() is called in us_ticker_irq_handler(), and at the same time if a update interrupt happens, the variable SlaveCounter has no chance to increase 1. SlaveCounter will be just updated in the next calling of IRQ function. So the function us_ticker_read() will return a 0xFFFF less value in current IRQ function, then cause the 65ms blank area problem.

If running the previous code is easily to reproduce this problem on STM32F103RB. This problem can't be reproduced on STM32F100R since STM32F100RB uses different IRQ fucntions for update and compare interrupts with different priorities.

I know the cause, but don't have good idea about how to fix it. Could any one help to have a check and help to fix it?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions