I have tried to compare the performance when a function is called from flash and then when its called from the IRAM. The idea was to set a pin high before the function call and then resetting to zero once the function is entered. The pulse width should approximately reveal the time, needed to load the function.
The code is as following:
Code: Select all
void IRAM_ATTR test_iram(void)
{
gpio_set_level(TEST_IRAM_PIN, 0);
int a = 0;
do{
a++;
}while(a<5000);
do{
a--;
}while(a>0);
}
void test_flash(void)
{
gpio_set_level(TEST_FLASH_PIN, 0);
int a = 0;
do{
a++;
}while(a<5000);
do{
a--;
}while(a>0);
}
void app_main(void)
{
gpio_set_direction(TEST_IRAM_PIN, GPIO_MODE_OUTPUT);
gpio_set_direction(TEST_FLASH_PIN, GPIO_MODE_OUTPUT);
while(1){
for(int i=0; i < 10; i++){
gpio_set_level(TEST_IRAM_PIN, 1);
test_iram();
}
for(int i=0; i < 10; i++){
gpio_set_level(TEST_FLASH_PIN, 1);
test_flash();
}
vTaskDelay(pdMS_TO_TICKS(10));
}
}
The function in the flash first takes time after boot t_flash_first_exe=2.26us, after this the execution lowers to t_flash_normal=0.34us. I guess the reason is that since there are no other function its still in the cache and therefore needs from then on lower execution time? The IRAM function takes after first boot t_iram_first_exe=3.28us, after this the execution lowers to t_iram_normal=0.56us.
First, why the flash function takes always less time then the one called out of iram? Its because its after the first call already in the cache and the iram function is always called from the IRAM? Second, why then there is even a difference in the execution time of the IRAM function if it should be already be stored in the IRAM at boot. Is it because there are also used the gpio functions which are not stored in the iram(i guess), but why then anyway the time is still higher at boot compared to the flash function?
regards