STM32F0 and others: Hardware Modbus support

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
Ilfirin
Posts: 6
Joined: Mon Jun 20, 2016 1:41 pm
Has thanked: 2 times

STM32F0 and others: Hardware Modbus support

Post by Ilfirin »

Greetings,

I was implementing hardware modbus support on STM32F072 because somehow I messed Virtual Timers (for idle detection) beyond point of return.

I succeded, but run into some obstackles:

1) No API for setting RTOR register, workarounded by

Code: Select all

UARTD2.usart->RTOR |= MODBUS_15SPACE_BITS;

2) No IRQ handling in uart_lld. Workarounded by adding it into errors (couldn't found better place)

Code: Select all

#define UART_REC_IDLE_DETECTED  128 /**< @brief Reciever timeout detected.  */

static uartflags_t translate_errors(uint32_t isr) {
  uartflags_t sts = 0;

  if (isr & USART_ISR_ORE)
    sts |= UART_OVERRUN_ERROR;
  if (isr & USART_ISR_PE)
    sts |= UART_PARITY_ERROR;
  if (isr & USART_ISR_FE)
    sts |= UART_FRAMING_ERROR;
  if (isr & USART_ISR_NE)
    sts |= UART_NOISE_ERROR;
  if (isr & USART_ISR_LBDF)
    sts |= UART_BREAK_DETECTED;
  if (isr & USART_ISR_RTOF)
    sts |= UART_REC_IDLE_DETECTED;
  return sts;
}
and added to static void serve_usart_irq(UARTDriver *uartp) as an error

Just wanted to ask, if is planned better support in future, or is better way to do it?

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

Re: STM32F0 and others: Hardware Modbus support

Post by Giovanni »

Hi,

The driver would need a small update in order to support that, the ISR and one more field in the configuration structure.

Giovanni
cipher
Posts: 24
Joined: Tue May 31, 2016 10:05 pm
Has thanked: 2 times
Been thanked: 2 times

Re: STM32F0 and others: Hardware Modbus support

Post by cipher »

Hi Giovanni
Any plans to add this functionality in the near future?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F0 and others: Hardware Modbus support

Post by Giovanni »

Hi,

It has already been implemented in the trunk code (by barthess), it is not handled as an error, there is a specific callback for timeout handling.

Giovanni
cipher
Posts: 24
Joined: Tue May 31, 2016 10:05 pm
Has thanked: 2 times
Been thanked: 2 times

Re: STM32F0 and others: Hardware Modbus support

Post by cipher »

Ohh this is great
Thank you for the info, i will get the code from the TRUNK
Post Reply