cancel
Showing results for 
Search instead for 
Did you mean: 

Need to runtime execution times when running FreeRTOS on F446

Harvey White
Senior III
Posted on May 14, 2018 at 00:10

I have a relatively complex FreeRTOS application running.  I need to see run time information more detailed than the 'by task' that I've gotten working.  It's on a Nucleo 64 board, Atollic TS latest.

From what I've read, SWV, and SWD and so on will do the job if I insert printf to the SWO port instructions.  Been through about 4 hours of 'it's really easy, just click, click, and then you're fine' youtube videos which make certain assumptions.

First question.  I have SWV enabled, loads the program and debugs it. 

Did NOT use TMS and TCK for anything.  DID use SW0 (PB3) for another function.  Since that goes to a CPLD, I can swap a pin or so and get PB3 back to the SWO function.  What other pins do I need to get the more detailed tracing running?  I thiink no extra ones are needed.  I'm using the built in ST-LINK debugger.

I've gotten the code macros put in for at least one monitor point    

ITM_SendChar( 33 );   //  Send ASCII code 65 = ’A’

for example.  But recording doesn't get anything, which would make sense if the SWO pin has been borrowed.  Saw a bunch of things about enabling the functions in Cube32, but not everything matches the blogs/videos.  SYS is set up to enable serial wire debugging, but both of the system wakeup events are disabled.

So is switching out the one line going to work?  It's still going to be connected to the CPLD, but that's going to be an input/ignored/weak-pullup at worst.

I did not see a 'how to' with specific mention of 'you need these pins, etc....

Any thoughts?

6 REPLIES 6
Posted on May 14, 2018 at 00:29

SWD uses PA13/PA14 (SWDIO/SWCLK), SWV uses PB3 (SWO), not possible to reassign these pins.

Debug info can be output via USART. Run times can be observed by moving any GPIO high/low, and have that on a scope or analyzer. Timing can be done either by using the processors instruction counter (DWT_CYCCNT) or a free running TIM (TIM2/5 32-bit on F4) clock a 1MHz, or 1KHz, so you can read TIM2->CNT at entry and exit points and delta the computation/processing time.

Strongly recommend reviewing the Reference Manuals for the STM32F4 and the Cortex-M4, Joseph Yiu's Essential Cortex-M3/M4 spins the ARM TRM with a different perspective. ST also has a Programming Manual that is distinct from the Data Sheet and Reference Manual. If you don't want to read, at least skim so you know where to find info when you need it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 14, 2018 at 00:38

OK, thanks for the info on PB3.  I don't use PA13 and PA14.  I can move the functionality of PB3 to another pin on the processor.  Will that be sufficient?

The reason I'm trying to work through TrueStudio is that this application is *extremely* pin limited, and I've got no extra pins to bob up and down.  I've got a UART available, but I want specific timing data to compute routine time occurances and statistics.  Seems to me that the stuff in TS is likely easiest to use.  I've done the bits with pins (and a logic analyzer), but pins are lacking.  UARTS aren't going to give me the timing accuracy I need, not that I can see. 

Looked through the reference documents, but since I was looking for a specific 'to enable this useful feature in TS, you need to make sure that your processor has the appropriate setups.'  That was lacking.  Did all the workarounds on an Xmega.  Don't want to have to do that again.

Thanks

Posted on May 14, 2018 at 02:16

PA13/PA14 are the primary debugger interface, Like I said it is not possible to reassign these or PB3. Review Data Sheet, no alternates listed.

http://www.st.com/content/ccc/resource/technical/document/datasheet/65/cb/75/50/53/d6/48/24/DM00141306.pdf/files/DM00141306.pdf/jcr:content/translations/en.DM00141306.pdf

 

The DWT CYCCNT is trivially easy to use. At 72 MHz the wrap time of the 32-bit counter is around a minute. Measure stuff, output statistics.

volatile unsigned int *DWT_CYCCNT   = (volatile unsigned int *)0xE0001004; //address of the register

volatile unsigned int *DWT_CONTROL  = (volatile unsigned int *)0xE0001000; //address of the register

volatile unsigned int *DWT_LAR      = (volatile unsigned int *)0xE0001FB0; //address of the register

volatile unsigned int *SCB_DEMCR    = (volatile unsigned int *)0xE000EDFC; //address of the register

  *DWT_LAR = 0xC5ACCE55; // unlock (Cortex-M7)

  *SCB_DEMCR |= 0x01000000;

  *DWT_CYCCNT = 0; // reset the counter

  *DWT_CONTROL |= 1 ; // enable the counter

StartTime = *DWT_CYCCNT;

...

FinishTime = *DWT_CYCCNT;

ElapsedTime = FinishTime - StartTime; // In units of processor ticks, 5.556ns for 180 MHz F446

Sorry, not using TrueStudio. They have a forum and support.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 14, 2018 at 02:40

Thanks for your input.  Cube32MX, however, disagrees with you.  Clicking on it allows me to reassign PB3, PA13, and PA14.  Because of the names on PA13 and PA14 I had decided not to use them for anything.  The logic analyzer shows considerable activity on those pins.  (I have a debug fixture that allows me to take all the pins directly to a logic analyzer).

Since I use both Cube32 (despite the difficulties, I do not wish to go that deeply into the hardware, did that on the AVR series and had enough of that), and TrueStudio (tried AC6, and it doesn't have the higher end support that I want, specifically the built in FreeRTOS and (potentially) the trace capabilities in SWD/SWO), I'll stay here for the time.

I understand the counter, and thanks for the code.  If I need it, it will save a bit of time.  I'd rather concentrate on the higher level software with what I'm doing rather than go down into the hardware and argue with it.

You'll note that this was a hardware pin issue rather than TrueStudio issue, at least, to me.  Once I free up that pin, THEN it becomes a TrueStudio issue if it doesn't work.  However, it seems that I need only three pins, two of which I deliberately do not use, and one of which I can reassign (I drop out a reset line, reset in software.  Gotta love CPLD's).

Posted on May 14, 2018 at 04:17

To clarify: while I can assign other functions to PB3, and there's no problem with that, SWO has no pin it can be present on *other* than PB3 in this chip.  Ditto, I assume for the others.

Still working on the problem, but the CPLD pin has been reassigned.

Harvey White
Senior III
Posted on May 16, 2018 at 02:26

OK, in case anyone wants to do what I asked a question about, here's the original intention:

1) using Cube32 and Atollic True Studio and using a Nucleo 64 board, I wanted to have the same capability as FreeRTOS tools to monitor the program routines, not just the tasks.  While FreeRTOS allows you to look at tasks, the statistical analysis in TrueStudio allows you to look at routines.  I tried a number of things, and it was not happening.

2) Firstly, you must configure the hardware properly.  SWV can be used to program the chip and debug it.  On the F446 you need to absolutely avoid PC13 and PC14.  These are designated TMS and TCK.  In addition, you will need an additional pin PB3, designated SYS-JTDO SWO.  This is the output pin needed.  NOTE: you CANNOT use these pins in your design.  They are connected where they need to be on the N64 boards.

3) to configure the hardware, do not use the three pins above.  In Cube32, under SYS, select the TRACE ASYNCHRONOUS SW option rather than the SERIAL WIRE option.  If you do not see this option, then go through and disable (and select) some of the other JTAG pins and reserve them to JTAG.  It ought to show up.  This may be a problem in Cube32.  Once you have that option available, select it and then you can disable (unless you want to use them) all of the JTAG pins other than the SWO pin.  You must have that.

4) In True studio, select SWV debugging under the debugging tab (RUN/DEBUGGING CONFIGURATIONS/EMBEDDED C/C++ applications.  Under the same tab, set the clock to the highest value under the clock configuration in Cube32.  This is likely the only place to set that.  The default value for the F446 is 96 Mhz, which is the proper setting here.  If you change the speed of the CPU clock, this needs to be set AND the application needs to be recompiled and reloaded (it generates code!).

5) in TrueStudio, you must be halted.  Then select the debug configuration and under the swv console (lower right) you need to insert (at least, I think so) the following line of code somewhere.  You can take a time difference between two messages, but I was looking for percentage use, not indvidual routines.  Most of the tutorials do individual routines.  The line of code needed to be inserted is:    ITM_SendChar( 66 );   //  Send ASCII code 65 = ’A’ 

This apparently needs to be in at least one location.  It works only on debug channel 0 (it's a dedicated macro).  The argument can be changed for each insertion.

6).  In the SWV console configuration, enable channel 0 (a checkmark) and enable PC tagging.  You may have to be in active debugging mode to do this.

7) pause debugging

😎 in the SWV window, enable recording (little red button gets gray background)

9) RUN.

10 After a bit, you should see (likely) some data in the SWV console.  It will be whatever the characters were you told the ITM macro to print.

11) Pause the execution.  You should (hopefully) see some routine profiling at the STATISTICAL PROFILING tab.  If you haven't enabled it, it's gotten to by the VIEW/SWV from the main menu.

I may have left out something moderately important, but the details are in the youtube tutorials EXCEPT for the hardware setups and the requirement of what pins MUST be free and unused.  Please note (again) that this specific example for pinouts is for the F446 processor in an N64 environment running STlink.