Ярлыки

_GetPixelIndex (1) _SetPixelIndex (1) 3-phase (1) 800x480 (1) АЦП (1) генератор (1) синхронный усилитель (2) структура (1) учебный курс (1) шаговый двигатель (1) ШИМ (2) accert (1) AD7608 (1) AD8429 (1) ADC (5) amplifer (1) arccos (1) arcsin (1) arctang (2) arctg (3) ARM (2) arm_sqrt_q15 (2) assembler (6) ASSERT (1) atan (2) bit (1) Bitband (1) boot (3) bootlloader (1) BUTTON (1) C (5) C# (1) CAN (2) CC2530 (5) CMSIS (4) command (1) Cordic (1) Core746I (1) CubeMX (4) DBGMCU (2) debug (2) debug.ini (1) delegate (1) Digital Potentiometers (1) DigitalPOT (1) Discovery (1) DMA (9) DMA2D (1) DSP (1) DSP library (1) DWT (1) EFM32 (5) EmWin (9) EXTI (1) FATFS (1) FMC (2) FreeRTOS (2) gl868-dual cmux (1) GPIO (4) GUI (2) GUIBuilder (1) GUIDRV_CompactColor_16 (1) HAL (3) HappyGecko (1) Hard Fault (2) heap (1) I2C (1) ID (1) ILI9320 (1) ILI9325 (1) Initialisation (1) InitLTDC (1) Instrumentithion (1) Interrupt (4) ITR (1) JTAG (1) Keil (5) LCDConf (2) lock-in (1) LTCD (1) LTDC (3) main (1) memory (1) MINI_STM32 Revision 01 (1) nBoot0 (1) NVIC (1) OnePulse (2) OSAL (4) pack (1) phase (1) printf (3) Pulse (1) PWM (12) RCC (2) RCR (1) Register (1) RESET (2) RS232 (3) RSS (1) RTC (3) RTOS-RTX (1) RTT (1) RTX-RTOS (1) SDCard (1) SDRAM (6) Segger (2) SPI (3) sqrt (3) SSD1298 (1) SSD1963 (1) Standart Peripherial Library (3) STANDBAY (1) startup (1) STemWin (8) stepper motor (1) STlink (2) STM32 (17) STM32429ZI (1) STM32Cube (1) STM32DBG.IN (1) STM32F (28) STM32F0 (4) STM32F1 (13) STM32F4 (10) STM32F4 Discovery (1) STM32F407ZG (1) STM32F429 (2) STM32F746 (1) STOP (1) string (1) struct (1) SWD (1) SWD JTAG (1) Synhronization (1) system_stm32f4xx.c (1) SystemInit (1) SysTick (1) task (4) telit (1) TIM (27) typedef (1) UART (1) USART (9) viewer (2) WM_PAINT (1) Z-stack (5) ZigBee (5)

пятница, 2 мая 2014 г.

DWT - Data Watchpoint and Trace unit

  В STM32 регистры, используя которые, можно достаточно просто осуществлять подсчет времени исполнения различных участков кода.
 Один из этих регистров – DWT_CYCCNT, расположенный по адресу 0xE0001004, представляет собой счетчик тактов микроконтроллера. Чтобы запустить его на счет, необходимо установить младший бит (CYCCNTENA) регистра DWT_CONTROL.

#define    DWT_CYCCNT       *(volatile unsigned long *)0xE0001004
#define    DWT_CONTROL   *(volatile unsigned long *)0xE0001000
#define    SCB_DEMCR         *(volatile unsigned long *)0xE000EDFC

  SCB_DEMCR |= 0x01000000;
  DWT_CONTROL|= 1; // enable the counter
  DWT_CYCCNT  = 0;
  for(i=0;i<1000;i++){};
  time=DWT_CYCCNT;


=======================================================

#define    DWT_CYCCNT       *(volatile uint32_t *)0xE0001004
#define    DWT_CONTROL     *(volatile uint32_t *)0xE0001000
#define    SCB_DEMCR         *(volatile uint32_t *)0xE000EDFC

static inline uint32_t DWT_Get(void)
{
    return DWT_CYCCNT;
}
void init_dwt()
{
    SCB_DEMCR  |= 0x01000000;
    DWT_CYCCNT  = 0;
    DWT_CONTROL|= 1;                    // enable the counter
}

int main(void)
{
init_dwt();
DWT_CYCCNT=0;                             // сброс счётчика цилов процессора
DoSome();
uint32_t cycles=DWT_CYCCNT;      // чтение количества циклов
}
===========================================================
организация  задержки

uint32_t DWT_Get(void)
{
&nbsp;&nbsp;&nbsp;&nbsp;return DWT_CYCCNT;
}
__inline
uint8_t DWT_Compare(int32_t tp)
{
&nbsp;&nbsp;&nbsp;&nbsp;return (((int32_t)DWT_Get() - tp) < 0);
}

void DWT_Delay(uint32_t us) // microseconds
{
&nbsp;&nbsp;&nbsp;&nbsp;int32_t tp = DWT_Get() + us * (SystemCoreClock/1000000);
&nbsp;&nbsp;&nbsp;&nbsp;while (DWT_Compare(tp));
}
==========================================================
uint32_t DWT_Get(void)
{
    return DWT_CYCCNT;
}
__inline
uint8_t DWT_Compare(int32_t tp)
{
    return (((int32_t)DWT_Get() - tp) < 0);
}

void DWT_Delay(uint32_t us) // microseconds
{
    int32_t tp = DWT_Get() + us * (SystemCoreClock/1000000));
    while (DWT_Compare(tp));

}


If your Cortex M microcontroller  have DWT  (Data Watchpoint and Trace) unit, you can use its register to count the number of cycles in which some code is executed. This could be useful for performance measuring. Simple cycle counter on ARM microcontroller  having DWT unit could be implemented like this:

#include <stdint.h>

volatile uint32_t count = 0;

// addresses of registers
volatile uint32_t *DWT_CONTROL = (uint32_t *)0xE0001000;
volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xE0001004; 
volatile uint32_t *DEMCR = (uint32_t *)0xE000EDFC; 

// enable the use DWT
*DEMCR = *DEMCR | 0x01000000;

// Reset cycle counter
*DWT_CYCCNT = 0; 

// enable cycle counter
*DWT_CONTROL = *DWT_CONTROL | 1 ; 

// some code here
// .....

// number of cycles stored in count variable
count = *DWT_CYCCNT;

The DWT is an optional debug unit that provides watchpoints, data tracing, and system profiling for the processor.A full DWT contains four comparators that you can configure as 
  • hardware watchpoint
  • an ETM trigger
  • a PC sampler event trigger
  • a data address sampler event trigger.

The first comparator, DWT_COMP0, can also compare against the clock cycle counter, CYCCNT. You can also use the second comparator, DWT_COMP1, as a data comparator. A reduced DWT contains one comparator that you can use as a watchpoint or as a trigger. It does not support data matching. The DWT if present contains counters for:

  • clock cycles (CYCCNT)
  • folded instructions
  • Load Store Unit (LSU) operations 
  • sleep cycles 
  • CPI, that is all instruction cycles except for the first cycle
  • interrupt overhead.

Note
An event is generated each time a counter overflows.
You can configure the DWT to generate PC samples at defined intervals, and to generate interrupt event information.
The DWT provides periodic requests for protocol synchronization to the ITM and the TPIU, if the your implementation includes the Cortex-M3 TPIU.

Lists the DWT registers. Depending on the implementation of your processor, some of these registers might not be present. Any register that is configured as not present reads as zero.


a. Possible reset values are:
0x40000000 if four comparators for watchpoints and triggers are present
0x4F000000 if four comparators for watchpoints only are present
0x10000000 if only one comparator is present
0x1F000000 if one comparator for watchpoints and not triggers is present
0x00000000 if DWT is not present.

DWT registers are described in the ARMv7M Architecture Reference Manual. Peripheral Identification. Component Identification registers are described in the ARM CoreSight Components Technical Reference Manual.

Note
• Cycle matching functionality is only available in comparator 0.
• Data matching functionality is only available in comparator 1.
• Data value is only sampled for accesses that do not produce an MPU or bus fault. The PC is sampled irrespective of any faults. The PC is only sampled for the first address of a burst.
• The FUNCTION field in the DWT_FUNCTION1 register is overridden for comparators given by DATAVADDR0 and DATAVADDR1 if DATAVMATCH is also set in DWT_FUNCTION1. The comparators given by DATAVADDR0 and DATAVADDR1 can then only perform address comparator matches for comparator 1 data matches.
• If the data matching functionality is not included during implementation it is not possible to set DATAVADDR0, DATAVADDR1, or DATAVMATCH in DWT_FUNCTION1. This means that the data matching functionality is not available in the implementation. Test the availability of data matching by writing and reading the DATAVMATCH bit in DWT_FUNCTION1. If this bit cannot be set then data matching is unavailable.
• PC match is not recommended for watchpoints because it stops after the instruction. It mainly guards and triggers the ETM.


1 комментарий: