STM32F3 port bit problem

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
Toley
Posts: 922
Joined: 03 Sep 2008 16:17

STM32F3 port bit problem

#1 Post by Toley » 24 May 2013 01:04

I am testing the new version of the compiler "3.3.5" with my STM32F3Discovery board, and I think I found a bug.
When I use the complete port (GPIOE_ODR) all the leds are blinking correctly.

Code: Select all

void main()
{
    GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_HIGH); // PIN8-15 LEDs

    while(1)
    {
        GPIOE_ODR = 0x0000;
        delay_ms(500);
        GPIOE_ODR = 0xFF00;
        delay_ms(500);
    }
}
But if I use a bit field (GPIOE_ODRbits.ODRx) to blink only one led, nothing happen.

Code: Select all

void main()
{
    GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_HIGH); // PIN8-15 LEDs

    while(1)
    {
        GPIOE_ODRbits.ODR15 = 0;
        delay_ms(500);
        GPIOE_ODRbits.ODR15 = 1;
        delay_ms(500);
    }
}
Serge T.
Learning is an endeless process but it must start somewhere!

prakob
Posts: 187
Joined: 24 Nov 2012 07:05
Location: Thailand

Re: STM32F3 port bit problem

#2 Post by prakob » 24 May 2013 02:21

Hi, Toley

I have tested your code. It's not work like you but when i change alias of bit variable from GPIOE_ODRbits.ODR15 to ODR15_GPIOE_ODR_bit then it's work. Led's blinking now.

Code: Select all

{

  GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_ALL); // PIN8-15 LEDs
  while(1)
  {
    while(1)
    {
        ODR15_GPIOE_ODR_bit = 0;
        delay_ms(500);
        ODR15_GPIOE_ODR_bit = 1;
        delay_ms(500);

    }
  }
}
I think there may be a problem with bit variable declaration so i take a look at file STM32F303VC.C and i think that i found the problem.

bit variable declaration that worked

Code: Select all

sfr far unsigned long   volatile GPIOE_ODR            absolute 0x48001014;
    sbit  ODR15_GPIOE_ODR_bit at GPIOE_ODR.B15;
    sbit  ODR14_GPIOE_ODR_bit at GPIOE_ODR.B14;
    sbit  ODR13_GPIOE_ODR_bit at GPIOE_ODR.B13;
    sbit  ODR12_GPIOE_ODR_bit at GPIOE_ODR.B12;
    sbit  ODR11_GPIOE_ODR_bit at GPIOE_ODR.B11;
    sbit  ODR10_GPIOE_ODR_bit at GPIOE_ODR.B10;
    sbit  ODR9_GPIOE_ODR_bit at GPIOE_ODR.B9;
    sbit  ODR8_GPIOE_ODR_bit at GPIOE_ODR.B8;
    sbit  ODR7_GPIOE_ODR_bit at GPIOE_ODR.B7;
    sbit  ODR6_GPIOE_ODR_bit at GPIOE_ODR.B6;
    sbit  ODR5_GPIOE_ODR_bit at GPIOE_ODR.B5;
    sbit  ODR4_GPIOE_ODR_bit at GPIOE_ODR.B4;
    sbit  ODR3_GPIOE_ODR_bit at GPIOE_ODR.B3;
    sbit  ODR2_GPIOE_ODR_bit at GPIOE_ODR.B2;
    sbit  ODR1_GPIOE_ODR_bit at GPIOE_ODR.B1;
    sbit  ODR0_GPIOE_ODR_bit at GPIOE_ODR.B0;
bit variable declaration that not worked

Code: Select all

typedef struct tagGPIOE_ODRBITS {
  union {
    struct {
      unsigned ODR0 : 1;
      unsigned ODR1 : 1;
      unsigned ODR2 : 1;
      unsigned ODR3 : 1;
      unsigned ODR4 : 1;
      unsigned ODR5 : 1;
      unsigned ODR6 : 1;
      unsigned ODR7 : 1;
      unsigned ODR8 : 1;
      unsigned ODR9 : 1;
      unsigned ODR10 : 1;
      unsigned ODR11 : 1;
      unsigned ODR12 : 1;
      unsigned ODR13 : 1;
      unsigned ODR14 : 1;
      unsigned ODR15 : 1;
      unsigned : 16;
    };
  };
} typeGPIOE_ODRBITS;
sfr volatile typeGPIOE_ODRBITS GPIOE_ODRbits absolute 0x48001014;
I can see one thing differences. In the SFR declaration of GPIOE_ODRbits don't have far typy qualifier.
when change

Code: Select all

sfr volatile typeGPIOE_ODRBITS GPIOE_ODRbits absolute 0x48001014;
to

Code: Select all

sfr far volatile typeGPIOE_ODRBITS GPIOE_ODRbits absolute 0x48001014;
now it works.

Best regard.

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: STM32F3 port bit problem

#3 Post by Toley » 24 May 2013 02:40

Hi prakob, thanks for your time. You are probably right the far qualifier is missing, but it seems to be missing in every port declaration and probably in other files also. So I will wait for mikroe to make the changes.

I didn't know those defines exist ODR15_GPIOE_ODR_bit :o
Serge T.
Learning is an endeless process but it must start somewhere!

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: STM32F3 port bit problem

#4 Post by janko.kaljevic » 24 May 2013 09:01

Hello,

Thanks for reporting this.
I confirm that far identifier is needed for port bitfilelds on STM32F3xx controllers.
Workaround would be as prakob suggested.

We will correct this and provide solution via live update as soon as possible.

Best regards.

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: STM32F3 port bit problem

#5 Post by Toley » 17 Jul 2013 14:31

janko.kaljevic wrote:We will correct this and provide solution via live update as soon as possible.
Any news about this ?
Serge T.
Learning is an endeless process but it must start somewhere!

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: STM32F3 port bit problem

#6 Post by janko.kaljevic » 18 Jul 2013 09:01

Hello,

Compiler version v3.3.5 is the latest and this problem still exists.
But we are currently preparing new compiler release which will be very soon and this fix will be implemented.

At the moment you can use bit definitions instead of bit fields.
For example:
ODR15_GPIOE_ODR_bit

Best regards.

Post Reply

Return to “mikroC PRO for ARM General”