/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / a strange Problem with USART in OS 4.1

Username:     
Password:     
             

Forum

# 1   2010-11-04 13:15:38 a strange Problem with USART in OS 4.1

xuwa0800
Member
From: Sweden
Registered: 2010-05-20
Posts: 27

a strange Problem with USART in OS 4.1

I have a strange problem with the usart2 in os4.1.

my project can be sucessfully built and downloaded to the primer2 in debug mode, and the usart works quite fine while i debug, and when i stop debug (without shutdown), it still works quite fine.

But!!!!! when i shut down the kit, and restart it, the usart part will not work, can not communicate with sensor (i have not checked which part does not working, clock, ini or something else)!

and when i debug it again(reload the code when debug), it works.


why it would be like this? Some things should have changed in some register when i shutdown  and restart.

1. about debug, is it possible to debug without downloading the code again. then i will be able to see some registers when the usart is not working.

2. about baudrate of usart. it seems that the baudrate configuration function is not working probably( by "USART2_InitStructure.USART_BaudRate = 9600"),   i should write ''USART2->BRR = 0x753;'' in order to get baudrate in 9600 correctly according to the clock settings in os.

3. then i change the primer2_Circle.elf to the default elf file(OS 3.8 in the default os folder), then there will be no such problem! (problem still exists in os 3.7). Does that mean, for different ride7 version, one should use the related os version. (in the latest version ride7, the default os would be os 4.1, right?)

right now, the software used is :
ride 7 version: 7.24.09.0251
rkit-arm for ride7 version: 1.22.09.0251


please give some hint...

Last edited by xuwa0800 (2010-11-04 13:18:07)


/Wang

Offline

 

# 2   2010-11-05 09:04:59 a strange Problem with USART in OS 4.1

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: a strange Problem with USART in OS 4.1

Hi,

At first, your versions are effectively not up to date !

1 : Concerning debug without downloading, it is not yet possible. We are thinking about it.

2 : Concerning the UART baud rate, we already were facing with this problem due to ST library. Do you use the precompiled ST library, or did you put the source files into your project . The problem is that the ST library expected a 8 MHz external crystal, and the Primer 2 is equiped with 12 MHz crystal.   

3 : Normally there is no relation between CirckeOS version and Ride7 version.

Concerning the different behavior in debug mode and depending on the CircleOS version, I don't understand. May be it is a problem of timing during initialization.
Did you execute the program in debug mode step by step, or did you try to do a run command at the begining of the main ?

Yves

Offline

 

# 3   2010-11-09 19:11:45 a strange Problem with USART in OS 4.1

xuwa0800
Member
From: Sweden
Registered: 2010-05-20
Posts: 27

Re: a strange Problem with USART in OS 4.1

1. I do hope we can have such a function in debug. In IAR workbench, they have option of debug with download and debug without download, maybe we can have a similar function in Ride7.

2. I'm using the precompilied library, and when set the baudrate to 6400, and it is also working. i will keep that in mind.

3.

since the communication with sensor has a time limitation, so i do run command at the begining of the main, but of course i ran it step by step at first when i use the sensor for the first time.


today i have retried OS 3.7 which was working(a mistake up), but sometimes, when i shut down and restart, it will not be able to communicate, then i should restart it (unplug the jump for battery first), and then it works. as long as i keep power on, and it will working probably, even i quite to the main menu.

the code for communicating with sensor is verified( i have written the code without using OS, everything turns out to be quite fine). And now the problem turns out to be something related with power on or off.

are there something changed in OS when power is off? especially the clock source.

BTW, i also change the memory in cycle_app.ld:
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
                             .
FLASH (rx) : ORIGIN = 0x8006000, LENGTH = 256K-0x6000
                             .
                             .
_eflash = 0x8006000 + 256K -1;

because the size exceeded


/Wang

Offline

 

# 4   2010-11-10 14:42:48 a strange Problem with USART in OS 4.1

xuwa0800
Member
From: Sweden
Registered: 2010-05-20
Posts: 27

Re: a strange Problem with USART in OS 4.1

Hasn't anyone had such similar problem before????????????

Last edited by xuwa0800 (2010-11-10 22:15:56)


/Wang

Offline

 

# 5   2010-12-13 10:54:09 a strange Problem with USART in OS 4.1

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: a strange Problem with USART in OS 4.1

Just a remark about baudrate.
As written in another topic, the precompiled ST library expects a 8MHz CPU quartz as HSE. The Primer uses a 12 MHz HSE, and the baudrate calculation is then bad.

Offline

 

# 6   2010-12-28 02:15:25 a strange Problem with USART in OS 4.1

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: a strange Problem with USART in OS 4.1

I just encountered the same problem. I made a simple USART test project in CurcleOS 4.1 for the EvoPrimer.
When I debug the project, everything works fine, USART can send and receive. When I terminate the debug session the program still works fine, as long as CircleOS is running you can start and stop the program and it will work. But as soon as you shut down the EvoPrimer and restart and then run the app again, only receive works, transmit does not work anymore.
I tested this by just connecting the Rx and Tx pins on the extension connector and also by using Hyperterminal - same result - Receiving data works but transmitting data does not.
It seems that the Debug mode sets some registers/peripherals on the STM32 differently than when the CircleOS starts up. I am not sure what could be different.
Since I cannot attach the project file here in the forum, I have it uploaded here: http://lts.cr/CbH.

Anyone have any idea what could be causing this? Has anyone successfully used USART Tx in CircleOS 4.1?
Thanks,
Mike

Offline

 

# 7   2010-12-28 05:37:49 a strange Problem with USART in OS 4.1

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: a strange Problem with USART in OS 4.1

Ok, so I got this to work by resetting the TIM2 as suggested in other posts here.
Basically I added the following before the USART_Init call:

Code:

TIM_DeInit(TIM2);

That basically resets the Timer 2. That also means that after you exit the app, the MEMS will no longer work.
I put the following in my app cleanup, which seems to enable the MEMS again

Code:

    // set TIM2 functionality back to "normal"
    /* Enable TIM2 */
    RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2, ENABLE );
    /* TIM2 enable counter */
    TIM_Cmd( TIM2, ENABLE );
    /* Enable TIM2 Update interrupt */
    TIM_ITConfig( TIM2, TIM_IT_Update, ENABLE );

Not sure if that is the best/right way to do it but it seems to work.
Now I still have the following questions:
- why does it work in Debug mode without the TIM_DeInit(TIM2) ?
- what has changed in CircleOS re: the TIM2 initialization, since xuwa0800 said this was working in earlier version of CircleOS?

Anyway, I thought I'd share my findings here. If anyone has any input as t how to set TIM2 back to it's regular state and do a proper cleanup when leaving the app, that would be great.
I could probably copy the same code as in CircleOS init_spe.c, but maybe there is an easier way?
Latest code is here: http://lts.cr/CeZ
Mike

Last edited by mikepo (2010-12-28 05:39:33)

Offline

 

# 8   2010-12-29 10:55:22 a strange Problem with USART in OS 4.1

xuwa0800
Member
From: Sweden
Registered: 2010-05-20
Posts: 27

Re: a strange Problem with USART in OS 4.1

i just test my primer2, as suggested by mike, it works now! Very nice!

for the reason, hopefully yrt can answer!


/Wang

Offline

 

# 9   2011-01-03 11:02:53 a strange Problem with USART in OS 4.1

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: a strange Problem with USART in OS 4.1

Sorry, I don't understand yet these behaviours :
- the TIM2 configuration has not changed between v3.7 and v4.1,
- I don't see where the debug mode could change the behavior of USART or TIM2

Offline

 

# 10   2011-01-03 15:10:00 a strange Problem with USART in OS 4.1

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: a strange Problem with USART in OS 4.1

Hi Yves,
I added the example project in the "Projects" section
(http://www.stm32circle.com/projects/project.php?id=133).
If you comment out lines 379 - 382 in application.c

Code:

     TIM_DeInit(TIM2);

You can hopefully reproduce the behavior we saw:
If you load the project on the EvoPrimer/Primer2 and then terminate debugging and then RESTART the Primer, the Rx portion still works .. but the Tx does not work anymore.

I have not looked at the differences between CircleOS 3.7 and 4.1, but it seems from another post that it was already not working in version 3.8:
http://www.stm32circle.com/forum/viewtopic.php?id=1180

Regards,
Mike

Last edited by mikepo (2011-01-03 15:13:06)

Offline

 

# 11   2011-01-04 07:36:33 a strange Problem with USART in OS 4.1

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: a strange Problem with USART in OS 4.1

Hi Mike,

Thanks for posting the project.
One first remark about the baudrate. The function "USART_Init" calculates the parameters depending on the CPU clock, thanks to the "RCC_GetClocksFreq" function. This one depends on the HSE_Value (external crystal value). The ST library set this value to 8 MHz by default. So to get the right value (9600bds) you have to modify the line :

Code:

#define HSE_Value    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */

in the "stm32f10x.h" file.

I cannot reproduce the behavior : when I power off then on the EvoPrimer, the application runs properly (display of the joystick used).
I also tried with a Primer2 with no problem (just change the project properties (define PRIMER2, FAT.elf and Primer2.elf, linker script, display locations...)

I will take a look at the TIM2 / debug issues when I get time.

Yves

Last edited by yrt (2011-01-04 08:06:30)

Offline

 

# 12   2011-01-04 13:28:20 a strange Problem with USART in OS 4.1

mikepo
Member
From: USA
Registered: 2010-12-03
Posts: 36

Re: a strange Problem with USART in OS 4.1

Hello Yves,
thank you for the tip about the HSE_Value!
I will change that in the next iteration of the project.
Mike

Offline

 

Board footer