Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Stopping the scheduler from switching a task

Posted by dibosco on April 14, 2016

Folks,

I have a really bizarre problem that I've been trying to track down for well over a day. It looks to me like some other thread may be hijacking my UART's DMA and cuasing havoc.

Maybe. I'm not convinced of that just yet.

Anyway, I thought that I'd solved it temporarily with a cludge by doing this rather than using the DMA:

vTaskSuspendAll();
for (i=0;i<RDMMessageSize;i++)
    {
        while ((USART1->SR & 0x80) == 0);// Make sure we're free to send
    USART1->DR = *RDMOutPtr++; //  DummyPacket[i];
    } 
while ((USART1->SR & 0x40) == 0); // Wait until all bytes have finished transmitting before turning RS485 line around
xTaskResumeAll();

That did seem to send all the bytes out at one point, but it's since gone back to either not sending anything out or sending two bytes (when there should be twenty-odd.

Is this vTaskSuspendAll(); and xTaskResumeAll(); what I need so that the part of the program sending out the data cannot be interrupted by anything else at all? Errrr, interrupts aside of course. Although, maybe being able to disable all interrupts would also be a good idea. I'm not sure whether there's a FreeRTOS method for that or whether I should just set the global disable bit on this STM32F107.

Thanks!

Rob


Stopping the scheduler from switching a task

Posted by rtel on April 15, 2016

The suspend/resume all functions, as you imply, will prevent a switch to another task, but will not prevent interrupts. Whether that is ok in your case or not depends on how long it takes for your for() loop to execute (which in turn will depend on the length of the message being sent and the baud rate). It could be quite a long time to have nothing running but what is effectively a polling loop.

If this simple code is still erring then I suspect your problem is not FreeRTOS related. Are you sure the uart does not have interrupts enabled?


Stopping the scheduler from switching a task

Posted by heinbali01 on April 16, 2016

Hi Rob,

Does your application access USART1->DR or the WE-bit of the RS485 bus from more than one task?

Why would it help to use a critical section or disable the scheduler while sending data?

Does RDMOutPtr point to fast internal RAM, or maybe to (slower) external (S)DRAM? That may cause problems. Some peripherals will allow it but perform badly.

Otherwise I would find it strange if DMA doesn't work properly.

Have you checked the RS485 signal with a scope? Isn't there a hardware problem? When no device is lowering the WE bit, do you see good, well-defined levels? Your USART must see a high in this 'resting position', if not the first start-bit may not be understood.

Do you wait long enough between setting WE and writing the first byte? As a test, you can try to wait more than 10 bits between lowering WE and sending the first byte.

Regards.


Stopping the scheduler from switching a task

Posted by dibosco on April 19, 2016

Thanks Richard and Hein and apologies for not replying earlier. I never get notifications over email of when someone posts a reply for some reaosn.

Anyway, it turns out it was, indeed, an interrupt going off and disabling the UART itself.

It seemed so obvious when I eventually it down!

I had spent ages looking at the signals with scope, Hein, yes. :) This was partly why it was driving me nuts. I have a fabulous Agilent scope that has all sorts of amazing serial decoding built in that helps so much with issues like this and it was showing a perfect reply (when I was single stepping anyway).


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists