Skip to main content
Visitor II
April 13, 2011
Question

STM8L GPIO initialization slow?

  • April 13, 2011
  • 4 replies
  • 1149 views
Posted on April 13, 2011 at 19:30

STM8L GPIO initialization slow?

    This topic has been closed for replies.

    4 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:12

    Hi Marc,

    I can suggest to write directly in GPIO control registers. You need to set the GPIOx->CR1 CR2 DDR ...

    The best way is to analyze the function and check the setted bits and write directly in the GPIO control registers.

    The driver functions are generic and test the different cases.

    In you case you know your pin configuration --> do it, without the different cases.

    I test it with a code someting like that quickly the  results seems interesting:

    // GPIO_Init(OW_PORT, OW_PIN, GPIO_Mode_Out_PP_Low_Fast); //define as output 

    GPIOE->ODR = 0;

    GPIOE->DDR =0x80; // pin 7 output

    GPIOE->CR1 =0x80; // PUSH PULL

    GPIOE->CR2 =0x00; // SLOW FAST

     // GPIO_ResetBits(OW_PORT, OW_PIN); //set low

    GPIOE->ODR = 0x80; // set GPIOE pin7 to 1

    _delay_us(5); 

    // GPIO_Init(OW_PORT, OW_PIN, GPIO_Mode_In_PU_No_IT) //define as input

    GPIOE->ODR = 0;

    GPIO-GPIOE->CR2 = 0; // no interrupt

    GPIOE->DDR = 0; // PIN7 INPUT

    GPIOE->CR1 =0x80; // PIN 7 PULL UP

    _delay_us(5);

    }

    I think that this example reply to your request, let me know.

    Rgds

    Phil

    d2snapAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:12

    Hi Phil,

    thank you. I've tested it. It's faster, but still not fast enough. The high / low signals are now 18 microseconds. Do you have other suggestions?

    Thanks

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:12

    Hi Marc,

    Quickly,

    I haven't your complete application context; I give to you only some tips.

    Peharps you can optimize the loop; by put outside the loop the registers CR1 and CR2.

    Other important point in this example I force the other GPIO bits (pin0 to 6) peharps in your case you need to do mask with OR and AND instructions !!!

    Last point, I don't understand why you don't reduve the delay?

    Rgds

    Philippe

    Example (something like that....):

    GPIOE->ODR = 0;

    GPIOE->CR2 =0x0;

    GPIOE->CR1 =0x80;

    while(1){

     

    GPIOE->DDR =0x80; // pin 7 output

    _delay_us(5);

    GPIOE->DDR = 0; // PIN7 INPUT

    _delay_us(5);

    }

    Visitor II
    November 3, 2014
    Posted on November 03, 2014 at 16:04

    Hi Phil, Hi Marc,

    Is the problem identified with the GPIO response times.?

    I used the functions GPIO_Init with GPIO_MODE_OUT_PP_LOW_FAST for o/p & 

    GPIO_MODE_IN_FL_IT

    for i/p

    which is supposed to 10Mhz, and the GPIO_WriteHigh & GPIO_WriteLow as well as

    GPIO_ReadInputPin.

    Each of these functions are directly writing to the registers GPIOX->ODR.

    But the response time is painfully slow.

    I have configured my clock as 16Mhz & using HSI oscillator.

    In a while loop when i light an led depending on the state of a GPIO pin configured as i/p, there seems to be a distinct lag of around 1-2secs, which is surprising

    It's the same even when i light the led in an interrupt service routine

    Do you any idea as to why this could be happening

    I am using STM8S-Discovery board & SDCC compiler & STVP flash tool