@defragster: Oh indeed -
@Luni, sorry, seems not to work.
apart from the typo here:
constexpr IntervalTimer() {
CCM_CSCMR1 &= ~CCM_CSCMR1_PERCLK_CLK_SEL;
...
ITcnt=500003 loop() ii=13635
ITcnt=499984 loop() ii=14107
ITcnt=500197 loop() ii=14098
ITcnt=501055 loop() ii=16832
Set i.MX RT1050 IPG clock frequency to 150 MHz, and updated the results. It was set to 300 MHz before which is not allowed.
Looks like more things are unexpectedly slow on the T4
takes 119 cycles...Code:start = ARM_DWT_CYCCNT; digitalWriteFast(LED_BUILTIN,!digitalReadFast(LED_BUILTIN)); end = ARM_DWT_CYCCNT; Serial.println(end - start);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
uint32_t start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
uint32_t end = ARM_DWT_CYCCNT;
Serial.println(end - start);
delay(1000);
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
uint32_t start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, HIGH);
uint32_t end = ARM_DWT_CYCCNT;
Serial.println(end - start);
delay(1000);
digitalWriteFast(LED_BUILTIN, LOW);
delay(1000);
}
...
@defragster - is that the only change you made to your test sketch.
Looks like digitalReadFast() is much of the problem. It's only 2 cycles with this:
Has anybody gone over the NXP App Note on Measuring interrupt latency, https://www.nxp.com/docs/en/application-note/AN12078.pdf. Or does this not apply.
GPT1_COMPARE1 GPIO_EMC_35 ALT2
GPT1_COMPARE2 GPIO_EMC_36 ALT2
GPT1_COMPARE3 GPIO_EMC_37 ALT2
GPT2_COMPARE1 GPIO_AD_B0_06 ALT1
GPT2_COMPARE2 GPIO_AD_B0_07 ALT1
GPT2_COMPARE3 GPIO_AD_B0_08 ALT1
have you tried with and without the SION bit for reading the pin? perhaps the SION uses more cycles as oposed to reading an input pin without it?
CCM_CCOSR = CCM_CCOSR_CLKO1_EN | CCM_CCOSR_CLKO1_DIV(1) |
CCM_CCOSR_CLKO1_SEL(12);
IOMUXC_SW_MUX_CTL_PAD_GPIO_SD_B0_04 = 6;
Too bad we can't reproduce the example in that pdf. None of the (6) GPT output pins are available on Teensy 4.
Code:GPT1_COMPARE1 GPIO_EMC_35 ALT2 GPT1_COMPARE2 GPIO_EMC_36 ALT2 GPT1_COMPARE3 GPIO_EMC_37 ALT2 GPT2_COMPARE1 GPIO_AD_B0_06 ALT1 GPT2_COMPARE2 GPIO_AD_B0_07 ALT1 GPT2_COMPARE3 GPIO_AD_B0_08 ALT1
#define DiWr digitalWriteFast
//#define DiWr digitalWrite
uint32_t PinVar = LED_BUILTIN;
#define PIN_NUM LED_BUILTIN
//#define PIN_NUM PinVar
void setup() {
pinMode(PIN_NUM, OUTPUT);
}
bool Gflip = false;
void loop() {
bool flip = Gflip;
uint32_t start, end;
delay(1000);
start = ARM_DWT_CYCCNT;
DiWr(PIN_NUM, flip);
flip = !flip;
DiWr(PIN_NUM, flip);
flip = !flip;
DiWr(PIN_NUM, flip);
flip = !flip;
end = ARM_DWT_CYCCNT;
Serial.print("flipped write >");
Serial.println(end - start);
delay(1000);
start = ARM_DWT_CYCCNT;
DiWr(PIN_NUM, Gflip);
DiWr(PIN_NUM, !Gflip);
DiWr(PIN_NUM, Gflip);
end = ARM_DWT_CYCCNT;
Serial.print("Global ! flip write >");
Serial.println(end - start);
delay(1000);
start = ARM_DWT_CYCCNT;
DiWr(PIN_NUM, HIGH);
DiWr(PIN_NUM, LOW);
DiWr(PIN_NUM, HIGH);
end = ARM_DWT_CYCCNT;
Serial.print("H L H write >");
Serial.println(end - start);
delay(1000);
start = ARM_DWT_CYCCNT;
DiWr(PIN_NUM, LOW);
DiWr(PIN_NUM, HIGH);
DiWr(PIN_NUM, LOW);
end = ARM_DWT_CYCCNT;
Serial.print("L H L write >");
Serial.println(end - start);
delay(1000);
start = ARM_DWT_CYCCNT;
DiWr(PIN_NUM, flip);
DiWr(PIN_NUM, !flip);
DiWr(PIN_NUM, flip);
end = ARM_DWT_CYCCNT;
Serial.print("! flip write >");
Serial.println(end - start);
Serial.println();
delay(1000);
Gflip = flip;
}
Yeah and there is not other pins with those available as alternates. But take a look at section 5.3. GPIO interrupt latency. For those measurements you don't need a "compare".
The other thing I am wondering is if using pin 13 (LED) is impacting the timing?
uint32_t PinVar = LED_BUILTIN;
[B]#define NO_LED 12
#define PIN_NUM NO_LED
[/B]//#define PIN_NUM LED_BUILTIN
//#define PIN_NUM PinVar
Can't reproduce 119 cycles.
First: 135
Second: 52
loop: 44
loop: 50
loop: 40
loop: 50
loop: 40
#include "Arduino.h"
unsigned start, end;
void setup()
{
delay(500);
pinMode(LED_BUILTIN, OUTPUT);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
end = ARM_DWT_CYCCNT;
Serial.printf("First: %d\n", end - start);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
end = ARM_DWT_CYCCNT;
Serial.printf("Second: %d\n", end - start);
}
void loop()
{
uint32_t start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
uint32_t end = ARM_DWT_CYCCNT;
Serial.printf("loop: %d\n",end - start);
delay(1000);
}
Can it be that there is some caching/buffering active there?
First: cycles 20
1 write: cycles 4
2 writes: total 5, mean:2
6 writes: total 101, mean:16
20 writes: total 549, mean:27
#include "Arduino.h"
unsigned start, end;
void setup()
{
delay(500);
pinMode(LED_BUILTIN, OUTPUT);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, HIGH);
end = ARM_DWT_CYCCNT;
Serial.printf("First: cycles %d\n", end - start);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, LOW);
end = ARM_DWT_CYCCNT;
Serial.printf("1 write: cycles %d\n", end - start);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
end = ARM_DWT_CYCCNT;
Serial.printf("2 writes: total %d, mean:%d\n", end - start, (end - start) / 2);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
end = ARM_DWT_CYCCNT;
Serial.printf("6 writes: total %d, mean:%d\n", end - start, (end - start) / 6);
start = ARM_DWT_CYCCNT;
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
digitalWriteFast(LED_BUILTIN, HIGH);
digitalWriteFast(LED_BUILTIN, LOW);
end = ARM_DWT_CYCCNT;
Serial.printf("20 writes: total %d, mean:%d\n", end - start, (end - start) / 20);
}
void loop()
{
}
flipped write >16
Global ! flip write >17
H L H 'const' write >5
H H H var write >5
L L L var write >5
L H L 'const' write >5
! flip write >24
flipped write >7
Global ! flip write >8
H L H 'const' write >5
H H H var write >5
L L L var write >5
L H L 'const' write >5
! flip write >19
flipped write >16
Hm, seems to be a Nerd-Processor, highly intelligent inside but reluctant to communicate with the outside worldThe ARM core is running much faster now - but not all peripherals
or screwed up?highly intelligent inside
It would be interesting now how long it really takes to write. Unfortunately my scope and LA are too slow to reasonable measure this. Maybe somebody with better equipment can have a quick look?
__attribute__((weak))
void HardFault_HandlerC(unsigned int *hardfault_args) {
Fault irq 3
stacked_r0 :: 20000988
stacked_r1 :: 0000016E
stacked_r2 :: 00000000
stacked_r3 :: FFFFFE92
stacked_r12 :: 2E4F70BA
stacked_lr :: 00001BD7
stacked_pc :: 00000A90
stacked_psr :: 01000000
_CFSR :: 00000400
_HFSR :: 40000000
_DFSR :: 00000000
_AFSR :: 00000000
_BFAR :: 00000000
_MMAR :: 00000000
need to switch to alternate clock during reconfigure of ARM PLL
USB PLL is running, so we can use 120 MHz
Freq: 12 MHz * 75 / 3 / 1
ARM PLL=80002064
ARM PLL needs reconfigure
ARM PLL=8000204B
New Frequency: ARM=300000000, IPG=150000000
Decreasing voltage to 1150 mV
HELP: looking for easy ways to fault the T4 - post or PM would be welcome - just to make sure they all perform the same.
void setup() {
delay(1000);
Serial.begin(9600);
Serial.print(*((uint16_t*)0));
}
void loop() {}
in Sketch ... Fault irq 3
stacked_r0 :: 20000c10
stacked_r1 :: 2bb
stacked_r2 :: 3e8
stacked_r3 :: 0
stacked_r12 :: 72459fc7
stacked_lr :: 9600000
stacked_pc :: 260
stacked_psr :: 61000000
_CFSR :: 10000
_HFSR :: 40000000
#include <FlexIO_t4.h>
#include <FlexSPI.h>
FlexSPI SPIFLEX(2, 3, 4, 5); // Setup on (int mosiPin, int sckPin, int misoPin, int csPin=-1) :
void setup() {
pinMode(13, OUTPUT);
while (!Serial && millis() < 4000);
Serial.begin(115200);
delay(500);
SPIFLEX.begin();
Serial.println("End Setup");
}
uint8_t buf[] = "abcdefghijklmnopqrstuvwxyz";
uint16_t ret_buf[256];
uint8_t ch_out = 0;
void loop() {
for (uint8_t ch_out = 0; ch_out < 64; ch_out++) {
ret_buf[ch_out] = SPIFLEX.transfer(ch_out);
}
// Serial.println();
delay(25);
uint8_t index = 0;
for (uint16_t ch_out = 0; ch_out < 500; ch_out+=25) {
ret_buf[ch_out] = SPIFLEX.transfer16(ch_out);
}
delay(25);
SPIFLEX.transfer(buf, NULL, sizeof(buf));
delay(500);
}