This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NEW on Cortex-M3 STM32F103B IAR

Note: This was originally posted on 29th January 2010 at http://forums.arm.com

Hi everyone,

I recently got an Arm cortex m3 microcontroller (stm32f103B). I'm interested in programming in C. I received some software with the kit I bought (IAR workbench kickstart) but i find all of these a little confusing to use. Reading the book "the definitive guide to arm cortex m3",
i found that's describing assembly instructions,

I ask, if there is an other guide wich describes C instructions?
  • Note: This was originally posted on 29th January 2010 at http://forums.arm.com

    Hi ,

    thanks a lot Joseph.

    I'm working, benchmarking of real-time performance of the present SOC, (tail chaing, Systick, context switch and other performance to specify after)

    1- how can I show the importance of latency and jitter in C coding (systick with GPIO?!)  (refering to this document: rtos-comparison-EN.pdf ).
    2- hwo can show me, a code in C that details a cotext switch.
    3- DMA multilayering communication between interfaces and memories is the default configuration in cortex-M3; how can i show the importance of this feature, in benchmarking.

    Note: benchmarking with oscilloscope on GPIO of STM32F103B IAR.
  • Note: This was originally posted on 31st January 2010 at http://forums.arm.com

    Hi there, some of your qustions are not exactly clear. Hope my answers/suggestions would help.

    1- how can I show the importance of latency and jitter in C coding (systick with GPIO?!)  (refering to this document: rtos-comparison-EN.pdf ).
    The minimum latency and jitter depends on the waitstate of the system as well as interrupt latency of the processor. For best testing result you should try to run the system with a clock configuration with minimum wait state. I think for STM32 it is 24MHz for zero wait state on flash.  The Cortex-M3 can give you 12 cycle interrupt latency for zero wait state.  But access to peripherals via bus bridge might result in waitstate and hence increase the interrupt latency slight.

    The idea of measuring interrupt latency using GPIO is possible, but don't forget that your access to the GPIO inside the interrupt handler will result in extra clock cycles.  For a fair comparison you should try to carry out a measurement of I/O access time.  The I/O access latency is dependent on the microcontroller product design, C compiler, and clocksstem settings in the microcontroller.

    The importance of latency and jitter depends on your applications.  For simple applications a bit of interrupt latency and jitter does not matter.  But in some non-linear control applications a large jitter can result in failure in the control algorithm.  That is why Cortex-M3 is good for control applications: Exclusing the cases where interrupt is blocked by a higher priority interrupts or interrupt masking register, the interrupt latency is 12 cycles plus extra cycles results from wait states, which is usually a very small number.  Cortex-M0 even have a zero jitter feature - not sure if NXP LPC111x include this feature.
    Most other archtectures usually have non-deterministic interrupt latency.



    2- hwo can show me, a code in C that details a cotext switch.

    Context switching is unlikely to be implemented in C.  In context switching you would want to have total control on individual register read/write. This need to be done in assembly.
    There are a number of open source OS available for Cortex-M3, please look at their code to try to understand the implementation.

    3- DMA multilayering communication between interfaces and memories is the default configuration in cortex-M3; how can i show the importance of this feature, in benchmarking.

    The Cortex-M3 itself does not have DMA feature.  The DMA feature is added by individual microcontroller vendor in their design. There are various performance points you can focus on, depending on your applications, for example:
    - maximum bandwidth of the DMA operation,
    - maximum performance penalty of the procesor while DMA is running at a fixed rate in the background,
    - impact to interrupt latency jitter when DMA is running at a fixed rate in the back ground,
    - improvement of application peformance by using DMA,
    - comparison of DMA features between different Cortex-M3 microcontrollers, etc.

    Depending the target of your benchmark report, you might want to look at one or more of these areas.
    Is it an academic research paper you are preparing?


    thanks a lot Joseph,

    yes, I'm preparing an academic research paper intitled "Real-Time Performmance two RTOS running on STM32 (ARM cortex-M3 Archtecture): FreeRTOS and µc/osII"

    I'm using the STM32F103B-Eval Board from IAR systems with its IAR workbench IDE.
    within i'm trying to do an application containig two configuration:

    1- FreeRTOS config: OS_lib+STM32 Lib+ cortexm3 lib+ main(interrept latency with systick+ function using DMA+ other real-time fucntions not fixed yet)

    2- µc/osII configuration:  OS_lib+ BSP lib+ STM32 Lib+ cortexm3 lib+ main(interrept latency with systick+ function using DMA+ other real-time fucntions not fixed yet).

    Best regards,
    Slim
  • Note: This was originally posted on 11th March 2010 at http://forums.arm.com

    Hi Slim,

    Thanks for the update.

    The measurement you have done is interesting.

    There are a few things you might need to look at:
    - Are the two tests carried out in the same setup?
      (same clock frequency, same peripheral clock frequency,
      same wait state configuration, same OS tick frequency).
    - I guess you measured the duration of the pulse in the GPIO.
      Since both rising and falling edge of the pulse can be affected by jitter, the result might not be accurate.
      Ideally you should use a constant timing source which is synchronous to the processor clock
      and divided to the same test loop frequency to drive the trigger input of the oscilloscope.
      I know that might not be possible with the current setup, but it might worth mention in your paper.
      Using on chip timer measurment is one good way to solve this problem.
    - Other jitter source - e.g. Potential jitter from on chip PLL

    Regarding measurement of context switching time:
    Develop two tasks, one toggle a GPIO pin and the other task toggle another pin.
    You can then see the gap between the activities of the two tasks with an oscilloscope.
    Of course, there could be some timing inaccuracy because it depends on the length of the toggling loop, the access time of the GPIO registers, and which instruction it stop at most often during context switching.

    Unfortunately I don't have any STM32 board so can't develop test code for it.
    You can try post your question on this to STM32 forum
    [url="https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/AllItems.aspx"]my.st.com/.../url]
    Maybe someone will be able help you there.

    regards,
    Joseph





    1- For each OS we have to do:
    two tests (on-chip timer and GPIO probes on osciloscope)
    the two tests are carried out in the same setup

    (the clock frequency of stm32F103B is 72Mhz, so we work with 2 waitstates,
    the same os tick frequency).

    2- I have measured the pulse in GPIO (170,7 ns at max) with 100Mhz MTX3352 oscilloscope
    so we will substract the GPIO pulse time in pair (set/reset)
    from the latency duration (170,2 * 2), isn't it?

    3-  I don't undestand the following item:

    "Ideally you should use a constant timing source which is synchronous to the processor clock
    and divided to the same test loop frequency to drive the trigger input of the oscilloscope.
    I know that might not be possible with the current setup, but it might worth mention in your paper."

    ---> you can explain with pseudo code or diagram for example.


    4- I'm developping some charts to do a benchmark tool for both freertos and µcos2 seperatly (view attached file) /* comment*/

    Slim
  • Note: This was originally posted on 5th April 2010 at http://forums.arm.com

    Hi Joseph,

    1- How we can configure the NVIC parameters for context switching between tasks (C or Assemby code). can you explain the context switch mechanism in the NVIC hardware.
  • Note: This was originally posted on 7th April 2010 at http://forums.arm.com

    Thanks Joseph,

    yes, I'll try it and verify registers status.

    SVC handlnig problem: all tasks are created correctly. when we debug SVC instruction, we find this "message: attempt to use coprocessor instruction" in infinite loop, what's wrong?

    best regards

    Slim
  • Note: This was originally posted on 11th March 2010 at http://forums.arm.com

    Hi Slim,

    Thanks for the update.

    The measurement you have done is interesting.

    There are a few things you might need to look at:
    - Are the two tests carried out in the same setup?
      (same clock frequency, same peripheral clock frequency,
      same wait state configuration, same OS tick frequency).
    - I guess you measured the duration of the pulse in the GPIO.
      Since both rising and falling edge of the pulse can be affected by jitter, the result might not be accurate.
      Ideally you should use a constant timing source which is synchronous to the processor clock
      and divided to the same test loop frequency to drive the trigger input of the oscilloscope.
      I know that might not be possible with the current setup, but it might worth mention in your paper.
      Using on chip timer measurment is one good way to solve this problem.
    - Other jitter source - e.g. Potential jitter from on chip PLL

    Regarding measurement of context switching time:
    Develop two tasks, one toggle a GPIO pin and the other task toggle another pin.
    You can then see the gap between the activities of the two tasks with an oscilloscope.
    Of course, there could be some timing inaccuracy because it depends on the length of the toggling loop, the access time of the GPIO registers, and which instruction it stop at most often during context switching.

    Unfortunately I don't have any STM32 board so can't develop test code for it.
    You can try post your question on this to STM32 forum
    [url="https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/AllItems.aspx"]https://my.st.com/public/STe2ecommunities/m...2/AllItems.aspx[/url]
    Maybe someone will be able help you there.

    regards,
    Joseph
  • Note: This was originally posted on 11th March 2010 at http://forums.arm.com

    Hi Slim,

    By using the GPIO signal itself as trigger for oscilloscope, depending on how you define the jitter, you can see the jitter as:
    Rising edge time = reference time + jitter_1;
    Falling edge time = reference time + 10 ms + jitter_2;

    The range of pulse width you measure is then 10 ms + (jitter_2 - jitter_1)

    If value of jitter_2 is often same as jitter_1, you can get very small measured jitter value. But in fact both jitter values e can be big but not shown in the oscilloscope because the tigger source contains the common mode jitter.

    Using a separated timing source for timing reference (e.g. a timer) can avoid this issue.

    regards,
    Joseph
  • Note: This was originally posted on 6th April 2010 at http://forums.arm.com

    Context switching is not done by NVIC.  NVIC provide the exception mechanism for the software but the context switching is done by software.

    For example,
    - Task A running, and a SysTick timer tick trigger.
    - Register R0-R3, R12, LR, PC and xPSR are saved onto stacked with PSP
    - OS kernel determine that context switching is needed and set the PendSV exception pending status
    - Systick exception exit
    - PendSV get execute if no other exception is running
    - PendSV handler save the remaining registers (R4-R11), and current PSP value to a data structure for Task A.
    - PendSV handle load the register R4-R11, and PSP values from another data structure for Task B.
    - PendSV carry out exception return
    - The stack frame for task B is used for unstacking, and continue running task B.

    I don't have actual code to show you (I don't want to spend lots of time to prepare such example while you can try reading the source code or some open source OS). Even if I produce such example it might not match up what you see in the OS you are using.
  • Note: This was originally posted on 8th April 2010 at http://forums.arm.com

    Hi Slim,

    I'm afraid you need to ask IAR support for this one :-)

    Joseph
  • Note: This was originally posted on 29th January 2010 at http://forums.arm.com

    I guess you have the first edition of the book.  The second edition of the book got a lot more C examples:
    [url="http://www.amazon.com/Definitive-Guide-ARM-Cortex-M3-Second/dp/185617963X"]amazon US[/url], [url="http://www.amazon.co.uk/gp/product/185617963X"]amazon UK[/url]

    With the first edition, you can find a number of C examples in chapter 20.
    That's is based on the Keil Microcontroller Development Kit for ARM,
    but the programming examples there should help.

    For STM32, Hitex also have a free [url="http://www.st.com/mcdfiles/1221142709.pdf"]ebook[/url] on ST web site.

    Hope this helps.
    regards,
    Joseph
  • Note: This was originally posted on 31st January 2010 at http://forums.arm.com

    Hi there, some of your qustions are not exactly clear. Hope my answers/suggestions would help.

    1- how can I show the importance of latency and jitter in C coding (systick with GPIO?!)  (refering to this document: rtos-comparison-EN.pdf ).
    The minimum latency and jitter depends on the waitstate of the system as well as interrupt latency of the processor. For best testing result you should try to run the system with a clock configuration with minimum wait state. I think for STM32 it is 24MHz for zero wait state on flash.  The Cortex-M3 can give you 12 cycle interrupt latency for zero wait state.  But access to peripherals via bus bridge might result in waitstate and hence increase the interrupt latency slight.

    The idea of measuring interrupt latency using GPIO is possible, but don't forget that your access to the GPIO inside the interrupt handler will result in extra clock cycles.  For a fair comparison you should try to carry out a measurement of I/O access time.  The I/O access latency is dependent on the microcontroller product design, C compiler, and clocksstem settings in the microcontroller.

    The importance of latency and jitter depends on your applications.  For simple applications a bit of interrupt latency and jitter does not matter.  But in some non-linear control applications a large jitter can result in failure in the control algorithm.  That is why Cortex-M3 is good for control applications: Exclusing the cases where interrupt is blocked by a higher priority interrupts or interrupt masking register, the interrupt latency is 12 cycles plus extra cycles results from wait states, which is usually a very small number.  Cortex-M0 even have a zero jitter feature - not sure if NXP LPC111x include this feature.
    Most other archtectures usually have non-deterministic interrupt latency.



    2- hwo can show me, a code in C that details a cotext switch.

    Context switching is unlikely to be implemented in C.  In context switching you would want to have total control on individual register read/write. This need to be done in assembly.
    There are a number of open source OS available for Cortex-M3, please look at their code to try to understand the implementation.

    3- DMA multilayering communication between interfaces and memories is the default configuration in cortex-M3; how can i show the importance of this feature, in benchmarking.

    The Cortex-M3 itself does not have DMA feature.  The DMA feature is added by individual microcontroller vendor in their design. There are various performance points you can focus on, depending on your applications, for example:
    - maximum bandwidth of the DMA operation,
    - maximum performance penalty of the procesor while DMA is running at a fixed rate in the background,
    - impact to interrupt latency jitter when DMA is running at a fixed rate in the back ground,
    - improvement of application peformance by using DMA,
    - comparison of DMA features between different Cortex-M3 microcontrollers, etc.

    Depending the target of your benchmark report, you might want to look at one or more of these areas.
    Is it an academic research paper you are preparing?
  • Note: This was originally posted on 1st February 2010 at http://forums.arm.com

    thanks a lot Joseph,

    yes, I'm preparing an academic research paper intitled "Real-Time Performmance two RTOS running on STM32 (ARM cortex-M3 Archtecture): FreeRTOS and µc/osII"

    I'm using the STM32F103B-Eval Board from IAR systems with its IAR workbench IDE.
    within i'm trying to do an application containig two configuration:

    1- FreeRTOS config: OS_lib+STM32 Lib+ cortexm3 lib+ main(interrept latency with systick+ function using DMA+ other real-time fucntions not fixed yet)

    2- µc/osII configuration:  OS_lib+ BSP lib+ STM32 Lib+ cortexm3 lib+ main(interrept latency with systick+ function using DMA+ other real-time fucntions not fixed yet).

    Best regards,
    Slim


    Hi Slim,
    Sounds like an interesting project. Would be nice to know how you are progressing,
    and let us know if you further help.
    Joseph