Page 1 of 2
STM32F4Discovery USART3 problem
Posted: Sun Mar 04, 2012 11:41 pm
by carnecro
I have the following issue when testing ChibiOS 2.4.0 and and USART driver on STM32F4-Discovery board:
1. sending data via uartStartSend() ends in STM32_UART_DMA_ERROR_HOOK handler
2. revceiving data does not work, rxerr callback is called with strange error flags (for example 0x52, no idea what the bit 1 means)
3. uartStartReceive() raises unhandled exception when chSysUnlock() is called
I am using modified ChibiOS USART example, USART3 is routed to PD8(TX)/PD9(RX) or PC10(TX)/PC10(RX), same issue with both configurations. Same program routed to USART2 PA2(TX)/PA3(RX) works without any problems! Any idea?
Robert
Re: STM32F4Discovery USART3 problem
Posted: Mon Mar 05, 2012 9:06 am
by Giovanni
Hi Robert,
I need to make some tests about this, it is possible there is an USART3-related bug (DMA setting, clock setting etc). In the meanwhile could you enable the debug options in chconf.h and, if the system halts, verify the error using the debug plugin?
The bits definitions are in uart.h:
Code: Select all
#define UART_NO_ERROR 0 /**< @brief No pending conditions. */
#define UART_PARITY_ERROR 4 /**< @brief Parity error happened. */
#define UART_FRAMING_ERROR 8 /**< @brief Framing error happened. */
#define UART_OVERRUN_ERROR 16 /**< @brief Overflow happened. */
#define UART_NOISE_ERROR 32 /**< @brief Noise on the line. */
#define UART_BREAK_DETECTED 64 /**< @brief Break detected. */
I quite don't understand the 0x2, it should not be used in the uart driver, are you sure 0x52 is the actual value?
Giovanni
Re: STM32F4Discovery USART3 problem
Posted: Mon Mar 05, 2012 12:19 pm
by Giovanni
I found an error, in the file ./os/hal/platforms/STM32F4xx/hal_lld.h at line 401 change
#define STM32_USART3_RX_DMA_CHN 0x00400400
with
#define STM32_USART3_RX_DMA_CHN 0x00000040
Basically the wrong DMA channel was selected, could you confirm?
Giovanni
Re: STM32F4Discovery USART3 problem
Posted: Tue Mar 06, 2012 9:05 pm
by carnecro
Giovani,
I changed the define but I still have issues, although other when using wrong DMA channel definition. Whenever I try to send or receive anything via USART3, the unhanded exception is raised and I land in the handler endless loop.
Is this definition in ./os/hal/platforms/STM32F4xx/hal_lld.h ok?
#define STM32_USART3_TX_DMA_CHN 0x00074040
IMO it should be
#define STM32_USART3_TX_DMA_CHN 0x00044000
however both definitions do not work. I cannot use debug plugin, I am using Rowley's CrossWorks.
Robert
Re: STM32F4Discovery USART3 problem
Posted: Tue Mar 06, 2012 9:28 pm
by Giovanni
Hi,
That constant should be:
#define STM32_USART3_TX_DMA_CHN 0x00074000
because the USART3 TX on the stream 4 is mapped on channel 7, it is already fixed on the repository but I think this is not the cause of the problem you are experiencing.
Is your program going in _unhandled_exception or in STM32_UART_DMA_ERROR_HOOK? because the two things are very different as possible causes.
Giovanni
Re: STM32F4Discovery USART3 problem
Posted: Wed Mar 07, 2012 1:21 am
by carnecro
Error occurs when calling uartStartSend() in main.c. I defined breakpoints in the callbacks routines an I see differences between CrossWorks and Atollic Studio!
In Atollic Studio before the program stops in port_halt() the callbacks txend2() and restart() are called, in this order. Callback txend1 is not called! Stack trace(row numbers are from 2.4.0)
5 port_halt() chcore.c:48 0x080003a2
4 uart_lld_serve_tx_end_irq() uart_lld.c:248 0x0800136c
3 Vector78() stm32_dma.c:201 0x08000ca8
In CrossWorks the callback txend1() is called immediately followed with _unhandled_exception. The stack trace is empty.
Robert
Re: STM32F4Discovery USART3 problem
Posted: Wed Mar 07, 2012 2:19 pm
by Giovanni
That stack trace means that the system stops into the DMA hook. The hook is called when the DMA accesses an invalid location, are you sure the buffer pointer passed to the UART driver is a valid pointer?
Anyway I will write a specific test case in the evening and then will report here.
Giovanni
Re: STM32F4Discovery USART3 problem
Posted: Wed Mar 07, 2012 2:45 pm
by carnecro
Giovani,
I am pretty sure the pointer is ok. When I change the deeclaration of USART from UARTD3 to UARTD2 (of course additionaly I have to change the I/O pins and to define the alternate function for the new pins), everything works ok. Note that I am testing only TX direction.
However maybe I am doing anything totally wrong, my last active work on embeded system goes back to Z80 assembler, about 30 years ago. Now, when we have such nice high level tools like ChibiOS, I reinvented the embedded world and try to learn more as hobbyist. Thank you for your perfect job and for your support!
Robert
Re: STM32F4Discovery USART3 problem
Posted: Wed Mar 07, 2012 2:57 pm
by Giovanni
I started with the Z80 too

Anyway, I will be back home in the evening and will be able to test this issue myself.
Giovanni
Re: STM32F4Discovery USART3 problem
Posted: Wed Mar 07, 2012 7:27 pm
by Giovanni
OK, found the problem, it is not in the code.
USART3_TX DMA stream conflicts with SPI2 streams (3 and 4). The problem is not in the software but in the dumb mapping of DMA streams. See table 20 in the STM32F4xx RM, sadly, for some unknown reason, SPI2 does not have any alternate channels choice.
If you disable SPI2 then the USART3 will work correctly.
The conflict would have been caught by running with debug options enabled because conflicts are trapped by an assertion.
Giovanni