Debugging a signle register with JTAG

xrCyhxcPN
Posts: 6
Joined: Sun Jul 23, 2017 8:43 am

Debugging a signle register with JTAG

Postby xrCyhxcPN » Sun Jul 23, 2017 8:54 am

Hi all,

I have the TUMPA JTAG v2 board, connected to the ESP32 DevKitC board.
The connection works fine and OpenOCD and gdb is properly setup.

In my main.c, I am using the following function:

Code: Select all

#define RAND_REGCOUNT       32 // * 4 bytes = 1kByte

uint32_t IRAM_ATTR esp_random_custom(void) {
    uint32_t retval; // in order to print the variable using GDB
    retval = REG_READ(WDEV_RND_REG);
    return retval;
}

static void rnd_task(void *pvParameter)
{
    for(;;){
        printf("Sampling...");
        //uint32_t* randNumbers = pvPortMallocCaps(RAND_REGCOUNT*4, MALLOC_CAP_32BIT);
        uint32_t* randNumbers = pvPortMallocCaps(RAND_REGCOUNT*4, MALLOC_CAP_8BIT);

        for(int i=0; i<RAND_REGCOUNT; i++){
            randNumbers[i] = esp_random_custom();
        }
 
        for(int i=0; i<RAND_REGCOUNT; i++) {
            if ( i>0 && i%8 == 0 ) printf("\n"); // pretty print
            printf("[%02d] %08x ", i, randNumbers[i]);
        }
        printf("\n");
        free(randNumbers);
        vTaskDelay(10000 / portTICK_PERIOD_MS);
     }
}

void app_main()
{
    xTaskCreate(&rnd_task, "rnd_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
I have no explanation why the variable

Code: Select all

retval
returns different values although I am calling this function every ABP_CLK (in the for loop). The expected behaviour, according to the documentation, would be the same value twice as the register changes every ABP_CLK/2.
Am I debugging correctly here?

Code: Select all

(gdb) break esp_random_custom
Breakpoint 1 at 0x400828fc: file /home/patrick/Nextcloud/thesis/esp32dev/003-optimizedOversampling/main/./main.c, line 48.
(gdb) c
Continuing.
Target halted. PRO_CPU: PC=0x400828FC             APP_CPU: PC=0x00000000 (active)
[New Thread 1073413360]
[New Thread 1073427136]
[New Thread 1073425404]
[New Thread 1073408876]

Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 1073413740]
0x00000000 in ?? ()
(gdb) i threads
[New Remote target]
  Id   Target Id         Frame 
  6    Remote target     0x00000000 in ?? ()
  5    Thread 1073408876 (ipc0) xQueueGenericReceive (xQueue=0x3ffae5d0, pvBuffer=0x0, 
    xTicksToWait=1644638200, xJustPeeking=0)
    at /home/patrick/Nextcloud/thesis/software/esp-idf/components/freertos/./queue.c:1452
  4    Thread 1073425404 (Tmr Svc) prvTimerTask (pvParameters=0x0)
    at /home/patrick/Nextcloud/thesis/software/esp-idf/components/freertos/./timers.c:445
  3    Thread 1073427136 (rnd_task : Running) esp_random_custom ()
    at /home/patrick/Nextcloud/thesis/esp32dev/003-optimizedOversampling/main/./main.c:48
  2    Thread 1073413360 (main) 0x4000bff0 in ?? ()
* 1    Thread 1073413740 (IDLE) 0x00000000 in ?? ()
(gdb) thread 3
[Switching to thread 3 (Thread 1073427136)]
#0  esp_random_custom ()
    at /home/patrick/Nextcloud/thesis/esp32dev/003-optimizedOversampling/main/./main.c:48
48	uint32_t IRAM_ATTR esp_random_custom(void) {
(gdb) s
Target halted. PRO_CPU: PC=0x400828FF (active)    APP_CPU: PC=0x00000000 
50	    retval = REG_READ(WDEV_RND_REG);
(gdb) n
Target halted. PRO_CPU: PC=0x40082902 (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x40082905 (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x40082907 (active)    APP_CPU: PC=0x00000000 
52	}
(gdb) p retval
$1 = 71946031
(gdb) c
Continuing.
Target halted. PRO_CPU: PC=0x400828FC (active)    APP_CPU: PC=0x00000000 

Breakpoint 1, esp_random_custom ()
    at /home/patrick/Nextcloud/thesis/esp32dev/003-optimizedOversampling/main/./main.c:48
48	uint32_t IRAM_ATTR esp_random_custom(void) {
(gdb) s
Target halted. PRO_CPU: PC=0x400828FF (active)    APP_CPU: PC=0x00000000 
50	    retval = REG_READ(WDEV_RND_REG);
(gdb) n
Target halted. PRO_CPU: PC=0x40082902 (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x40082905 (active)    APP_CPU: PC=0x00000000 
Target halted. PRO_CPU: PC=0x40082907 (active)    APP_CPU: PC=0x00000000 
52	}
(gdb) p retval
$2 = 2011269021
(gdb)
thanks and best regards
Patrick

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Debugging a signle register with JTAG

Postby ESP_igrr » Sun Jul 23, 2017 1:18 pm

Random register changes every time it is read, but entropy is only added on every APB clock cycle. Even if WiFI/BT are disabled (and therefore no entropy is added), you will still get a new pseudorandom value each time you read the register.

xrCyhxcPN
Posts: 6
Joined: Sun Jul 23, 2017 8:43 am

Re: Debugging a signle register with JTAG

Postby xrCyhxcPN » Sun Oct 01, 2017 12:55 pm

Thanks ESP_igrr
Why is the SDK always using WDEV_RND_REG, which is pointing to 0x60035144, instead of 0x3ff75144 as mentioned in the technical reference manual?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Debugging a signle register with JTAG

Postby ESP_Sprite » Sun Oct 01, 2017 3:39 pm

Different bus, but same physical register. Not sure why the TRM and the SDK differ, but it doesn't make much difference here.

xrCyhxcPN
Posts: 6
Joined: Sun Jul 23, 2017 8:43 am

Re: Debugging a signle register with JTAG

Postby xrCyhxcPN » Mon Oct 02, 2017 10:50 am

Which buses are involved here? How is the WDEV_RND_REG linked to the address given in the TRM (0x3ff75144)?

User avatar
ESP_krzychb
Posts: 394
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: Debugging a signle register with JTAG

Postby ESP_krzychb » Mon Oct 02, 2017 1:54 pm

xrCyhxcPN wrote:Which buses are involved here?
APB and DPORT
xrCyhxcPN wrote:How is the WDEV_RND_REG linked to the address given in the TRM (0x3ff75144)?
See viewtopic.php?f=2&t=3033&p=14227&hilit=APB+DPORT#p14227

Who is online

Users browsing this forum: Bing [Bot], biterror, spenderIng and 162 guests