SerialDriver event on Stm32F4Discovery board

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
zamek
Posts: 14
Joined: Sat Mar 23, 2013 6:39 pm

SerialDriver event on Stm32F4Discovery board

Post by zamek »

Hello All,

I would like to use serial driver on an stm32f4 discovery board.
I use SD1 in PB6 and PB7 bits. SerialDriver config is:

Code: Select all

static const SerialConfig serial_config ={
   921600,
   0,
   USART_CR2_STOP1_BITS | USART_CR2_LINEN,
   0
};


Init code is:

Code: Select all

  
  palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOB, 7, PAL_MODE_INPUT_PULLUP);

I would like to use event driven option with:

Code: Select all

    
   sdStart(&SD1, &serial_config);
    event_listener_t serial_listener;
    chEvtRegisterMaskWithFlags(chnGetEventSource(&SD_DRIVER),
                                 &serial_listener,
                                 EVENT_MASK(1),
                                 CHN_INPUT_AVAILABLE);
    while(TRUE) {
        palSetPad(GPIOD, GPIOD_LED5);
       eventmask_t evt = chEvtWaitAny(ALL_EVENTS);
       if (evt & EVENT_MASK(1)) {
            palTogglePad(GPIOD, GPIOD_LED5);
          eventflags_t flags = chEvtGetAndClearFlags(&serial_listener);
          if (flags&CHN_INPUT_AVAILABLE)
             handle_serial_data(motorola);
       }
       chThdSleepMicroseconds(SERIAL_SLEEP_TIME_US);
    }


I can send data to the serial port (I checked it with an oscilloscope), but I cannot get events on receive.
It enters chEvtWaitAny(ALL_EVENTS); and it cannot returns from it. I see the input in PB7.
Documentation said there is no need to init SerialDriver. Maybe I forgot to init anything?
Is there an example for event driven serial driver usage?

thx
Zamek
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SerialDriver event on Stm32F4Discovery board

Post by Giovanni »

Hi,

It is possible there is a problem with the baud rate, the frames are discarded because errors. Enable assertions and see if something is caught, you may also try a much lower baud rate for a test.

Giovanni
zamek
Posts: 14
Joined: Sat Mar 23, 2013 6:39 pm

Re: SerialDriver event on Stm32F4Discovery board

Post by zamek »

Hi Giovanni,

thx, for your replay, I try to set all event flags like this:

Code: Select all

 chEvtRegisterMaskWithFlags(chnGetEventSource(&SD1), &serial_listener,
                                 EVENT_MASK(1),
                         CHN_INPUT_AVAILABLE|SD_PARITY_ERROR|SD_FRAMING_ERROR|SD_OVERRUN_ERROR|SD_NOISE_ERROR|SD_BREAK_DETECTED);


but unfortunately it doesn't helps:(

thx,
Zamek
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SerialDriver event on Stm32F4Discovery board

Post by Giovanni »

Make sure that USART1 is ONLY assigned to the pins you are using, mapping it on multiple pins causes it to not get routed correctly.

Giovanni
zamek
Posts: 14
Joined: Sat Mar 23, 2013 6:39 pm

Re: SerialDriver event on Stm32F4Discovery board

Post by zamek »

Hi Giovanni,

I made a test environment which has two discovery board connected to each other. First board is sending frames as a transmitter and second is the receiver. I checked it with oscilloscope. Transmitted data is on transmitter PB6 which is connected to receiver PB7.
I'm sure that, the trnsmitted data is connected to PB7 on receiver.

Maybe I need to set any constants in SerialConfig? I tried to set USART_CR1_RE|USART_CR1_TE on CR1 register, but it didn't helps.

thx
Zamek
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SerialDriver event on Stm32F4Discovery board

Post by Giovanni »

Hi,

You need to answer to my previous advice, assertions, pins assignment duplication etc.

Seen the signal on the pin does not mean that it reaches the USART.

Giovanni
zamek
Posts: 14
Joined: Sat Mar 23, 2013 6:39 pm

Re: SerialDriver event on Stm32F4Discovery board

Post by zamek »

Hi,
>>You need to answer to my previous advice, assertions, pins assignment duplication etc.
You are right, because it was an unnecessary palSetPadMode(GPIOB, 7, PAL_MODE_INPUT_PULLUP); after palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(7));

That was the reason why rx didn't works.

thx a lot,
Zamek
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: SerialDriver event on Stm32F4Discovery board

Post by rew »

Giovanni wrote:Make sure that USART1 is ONLY assigned to the pins you are using, mapping it on multiple pins causes it to not get routed correctly.
Wait! Are you saying that when I set the alternate function of two "TX" pins both to the same USART then things get messed up? Of course two inputs will not work, but two outputs. Weird situation, agreed, but it should work, shouldn't it?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SerialDriver event on Stm32F4Discovery board

Post by Giovanni »

rew wrote:
Giovanni wrote:Make sure that USART1 is ONLY assigned to the pins you are using, mapping it on multiple pins causes it to not get routed correctly.
Wait! Are you saying that when I set the alternate function of two "TX" pins both to the same USART then things get messed up? Of course two inputs will not work, but two outputs. Weird situation, agreed, but it should work, shouldn't it?


I am not sure it works.

Giovanni
Post Reply