cancel
Showing results for 
Search instead for 
Did you mean: 

timing if statement stm32

stijn2
Associate
Posted on February 09, 2016 at 10:37

I'm working on a porject where I need to communicate with an USB PHY chip. I am using a STM32 microcontoller. (stm32f446ret6,

http://www.st.com/web/en/resource/technical/document/datasheet/DM00141306.pdf

)

To communicate with the USB PHY chip, I need to use the ULPI interface. This is an parallel communication. This interface has a clockfrequenty of 60MHz.

The frequency of my STM32-controller is 180MHz(his maximum, I checked this twice). So for every clock pulse of the ULPI interface, the microcontroller had 3 clockpulses.

To communicate with the USB-PHY chip, I need first to let the device know, witch register I want to adjust. When the USB-PHY chip received this command good, he will set the NXT line high.

http://i.stack.imgur.com/wsGg2.jpg

I think this is my problem. I need to check or this is high (offcourse with an if-statement). And that is where my problem is, I think. Is it possible that the if-statement takes to many clock-cycles? Is there a way to fix this problem?

My code:

bool UPLI_setRegister_FunctionControl(void)

{

    if( (GPIOA -> IDR & 0x01)) {//check if the dir is high

        return false;

    } else {

        GPIOB -> ODR = 4;

        //int j =0;

        if((GPIOA -> IDR & (uint16_t)0x0020)) { // wait until the nxt control line is high

            GPIOB -> ODR = 0b0000000001000000;

            /*

            Register settings

            LMP enable -> 0

            SuspendM -> 1

            Reset -> 0

            Opmode -> 00

            TermSelect -> 0

            XcrvSelect -> 00

            */

            if(GPIOA -> IDR & (uint16_t)0x0020) {

                //NXT still high

                GPIOA ->ODR |= 0x0002; //stp high

                for(int i =0; i==1; i++); //waste some time

                //set outputs back to 0;

                GPIOB -> ODR = 0x0000;

                GPIOA ->ODR = 0x0000;

                return true;

            } else {

                GPIOA ->ODR |= 0x0002; //stp high

                for(int i =0; i==1; i++); //waste some time

                GPIOB -> ODR = 0x0000000;

                GPIOA ->ODR = 0x000000;

                return false;

            }

        }

        else {

            GPIOA ->ODR |= 0x0002; //stp high

            for(int i =0; i==1; i++); //waste some time

            GPIOB -> ODR = 0x0000000;

            GPIOA ->ODR = 0x000000;

            return false;

        }

    }

}

#timing-stm32
2 REPLIES 2
Radosław
Senior II
Posted on February 09, 2016 at 12:36

for(int i =0; i==1; i++); //waste some time

this is not true.

On which optimization you working?

Your pin driving looks very strange

Posted on February 09, 2016 at 16:49

This isn't VHDL or assembler, all your instructions are going to take several cycles. If you want some semblance of control use assembler, and review the BSRR port of the GPIO peripheral.

Perhaps you can use a CPLD/FPGA to clock hardware at these speeds?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..