{"action":"created","issue":{"url":"https://api.github.com/repos/espressif/esp-idf/issues/2756","repository_url":"https://api.github.com/repos/espressif/esp-idf","labels_url":"https://api.github.com/repos/espressif/esp-idf/issues/2756/labels{/name}","comments_url":"https://api.github.com/repos/espressif/esp-idf/issues/2756/comments","events_url":"https://api.github.com/repos/espressif/esp-idf/issues/2756/events","html_url":"https://github.com/espressif/esp-idf/issues/2756","id":385191231,"node_id":"MDU6SXNzdWUzODUxOTEyMzE=","number":2756,"title":"[TW#27664] esp_restart fails to work properly if hardware timers are used","user":{"login":"X-Ryl669","id":3277165,"node_id":"MDQ6VXNlcjMyNzcxNjU=","avatar_url":"https://avatars2.githubusercontent.com/u/3277165?v=4","gravatar_id":"","url":"https://api.github.com/users/X-Ryl669","html_url":"https://github.com/X-Ryl669","followers_url":"https://api.github.com/users/X-Ryl669/followers","following_url":"https://api.github.com/users/X-Ryl669/following{/other_user}","gists_url":"https://api.github.com/users/X-Ryl669/gists{/gist_id}","starred_url":"https://api.github.com/users/X-Ryl669/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/X-Ryl669/subscriptions","organizations_url":"https://api.github.com/users/X-Ryl669/orgs","repos_url":"https://api.github.com/users/X-Ryl669/repos","events_url":"https://api.github.com/users/X-Ryl669/events{/privacy}","received_events_url":"https://api.github.com/users/X-Ryl669/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-11-28T10:07:43Z","updated_at":"2018-11-29T11:43:49Z","closed_at":null,"author_association":"NONE","body":"Using lastest master as of writing, whenever I've started a timer with an installed interruption (in fact, I'm using 3 HW timers as I need precise ~90µs wake up) and call `esp_restart`, the system crash upon restart.\r\n\r\nThe callstack contains my timer's ISR routine, and it crashes when it's trying to send an event to a FreeRTOS queue within ISR. \r\nIt seems the timer fired after the restart but before FreeRTOS was started correctly.\r\n\r\nI've tried to disable all the timer's interrupt (via `timer_disable_intr`) and this does not make any change (and reading `esp_restart_noos` code, that's what you're doing anyway). \r\nI wonder if, when the system is starting, if timer interrupt are re-enabled before the RTOS is correctly initialized, this would explain the behavior ?\r\n\r\nIf I pause all the timer before restarting, it restarts correctly for few seconds, but crash later on in `double exception vector`, (located in FreeRTOS's assembly, without a backtrace in that case).\r\n\r\nRestarting via the serial link always work correctly, so I wonder if there is a way to restart the complete CPU correctly (both core at the same time, with clean state), instead of having to deal with both core independently, and with left over peripherals messing things up ?\r\n\r\nBTW, my code is too big now to isolate a working example. \r\n"},"comment":{"url":"https://api.github.com/repos/espressif/esp-idf/issues/comments/442804262","html_url":"https://github.com/espressif/esp-idf/issues/2756#issuecomment-442804262","issue_url":"https://api.github.com/repos/espressif/esp-idf/issues/2756","id":442804262,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjgwNDI2Mg==","user":{"login":"igrr","id":4349050,"node_id":"MDQ6VXNlcjQzNDkwNTA=","avatar_url":"https://avatars2.githubusercontent.com/u/4349050?v=4","gravatar_id":"","url":"https://api.github.com/users/igrr","html_url":"https://github.com/igrr","followers_url":"https://api.github.com/users/igrr/followers","following_url":"https://api.github.com/users/igrr/following{/other_user}","gists_url":"https://api.github.com/users/igrr/gists{/gist_id}","starred_url":"https://api.github.com/users/igrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igrr/subscriptions","organizations_url":"https://api.github.com/users/igrr/orgs","repos_url":"https://api.github.com/users/igrr/repos","events_url":"https://api.github.com/users/igrr/events{/privacy}","received_events_url":"https://api.github.com/users/igrr/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T11:43:49Z","updated_at":"2018-11-29T11:43:49Z","author_association":"MEMBER","body":"> Can you guarantee nothing is touching the HW timer registers during startup (or while the bootloader is running) ? Is there something that would re-enable the timer's ISR in the startup code (since esp_restart_noos does disable them) ?\r\n\r\n`esp_restart_noos` does not touch the timer (at least, \"timer group 0/1\" timers), so the timer keeps running while the CPUs are starting up. And it probably sets its interrupt flag while the CPUs are starting up.\r\n\r\nHowever this (theoretically) should not matter, since the CPU interrupt input for respective interrupt is only unmasked when `esp_intr_alloc` is called. So if you only initialize the timers in app_main, esp_intr_alloc should not be called until app_main.\r\n\r\nThere is a way to check this, though. First, set log level to \"Debug\" in menuconfig. Note the message similar to `Connected src %d to int %d (cpu %d)`, where `src` will be 14/15 for TG0 or 18/19 for TG1. Then add something like\r\n```\r\nif (esp_reset_reason() == ESP_RST_SW && source == <value you have seen>) { abort(); }\r\n```\r\nat the start of esp_intr_alloc.\r\nThis should generate a panic when `esp_intr_alloc` is called for this interrupt source, after restart. Then we will see the backtrace and will see where this calls is coming from."}}
{"actor":{"display_login":"igrr"}}