Run Command during Pre-Initialization (early chance to disable UART1)

Windows 11, WSL2, NCS2, VSCode

Hi, I believe there's some way to run code during pre-initiliazation, I think by tagging certain .text areas in the code with pre-processors.  Is that how Zephyr does it for some BLE stuff for example?

Ultimately I am trying to avoid a parasitic draw on the serial TX line by a component who is powered off during startup.  Meaning, I have my nRF52840, and its UART1 TX is connected to another device's UART RX, and that device is powered off.  However, the device seems to be drawing 10mA+ of power through that serial connection.

I want to avoid that power draw by having the UART1 device powered off at startup.

Here is a scope of what the nRF52840's RX and TX lines look like in this condition.

If I set the devicetree UART1 to status="disabled" this completely breaks my code, I'm seemingly no longer able to operate UART1.

I am perfectly capable of enabling/disabling UART1 in software during runtime using the UARTE1 registers, and that works fine.

My specific concern is the span of time between the startup of the module and when my code runs.  Given some debugging statements of lower-level Zephyr libs, this can take quite a while, leaving my system in a state of power being drawn from the UART1 TX pin for nearly a second.

Here is a scope of the startup condition.

I want to avoid that long condition by running code as early as possible in the startup sequence, before many Zephyr libraries if possible.

What are my options?

Thanks.

Parents
  • Hi Douglas

    It seems odd that it would take as much as a second for the system to boot, but anyway this should not happen too often in most applications. 

    In order to run code during the boot sequence you can use the SYS_INIT(..) macro, described here

    With this macro you can define the level at which the function should be run, which determines where in the boot sequence your code gets executed. 

    If you set the level to PRE_KERNEL_1 it should be called very early in the process. 

    Best regards
    Torbjørn

  • Ah thanks, I'm looking into that.

    Ran into another question while doing so, maybe you can help.

    I'm trying to toggle a pin at certain points to know when my code is executing.

    Unfortunately, I see no signal, just a constant HIGH logic level, I think QSPI.  I'm using the pin that QSPI (P1.00/TRACEDATA0) would be on if in use, but I didn't think it was.

    Can you tell me what to look for?  I looked and I see CONFIG_NRFX_QSPI defaults to n in my configuration.  I tried setting

    CONFIG_FLASH_SHELL=n
    CONFIG_FLASH=n

    But that didn't do it.

    Thanks!

Reply
  • Ah thanks, I'm looking into that.

    Ran into another question while doing so, maybe you can help.

    I'm trying to toggle a pin at certain points to know when my code is executing.

    Unfortunately, I see no signal, just a constant HIGH logic level, I think QSPI.  I'm using the pin that QSPI (P1.00/TRACEDATA0) would be on if in use, but I didn't think it was.

    Can you tell me what to look for?  I looked and I see CONFIG_NRFX_QSPI defaults to n in my configuration.  I tried setting

    CONFIG_FLASH_SHELL=n
    CONFIG_FLASH=n

    But that didn't do it.

    Thanks!

Children
Related