Bus fault on just enabling CONFIG_I2C=y on nrf5340dk

Hi,

I am writing a custom i2c driver for an evaluation, when I ran the same i was getting exception:

[00:00:00.422,149] <err> os: ***** BUS FAULT *****
[00:00:00.422,180] <err> os:   Precise data bus error
[00:00:00.422,180] <err> os:   BFAR Address: 0x0
[00:00:00.422,180] <err> os: r0/a1:  0x00010734  r1/a2:  0x0001073c  r2/a3:  0x00000000
[00:00:00.422,210] <err> os: r3/a4:  0x0000000c r12/ip:  0x00000042 r14/lr:  0x0000f911
[00:00:00.422,210] <err> os:  xpsr:  0x81000000
[00:00:00.422,210] <err> os: Faulting instruction address (r15/pc): 0x0000b372
[00:00:00.422,241] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0
[00:00:00.422,271] <err> os: Current thread: 0x20008720 (unknown)
[00:00:00.494,689] <err> os: Halting system

during troubleshooting i scraped the entire custom driver and found that the issue was still persistent.
Then I just disabled CONFIG_I2C=n and the issue disappeared.

Now somehow even blinky sample program throws the very same exception when i enable CONFIG_I2C=y.

I fail to understand what is happening here.
Kindly suggest.

  • Hi,

     

    This looks like a problem with the pins for the specific i2c instance.

    Have you set the pinctrl entry, and remembered to name the pinctrl definitions?

    Here's an example:

    &pinctrl {
        my_custom_pinctrl: my_custom_pinctrl {
            group1 {
                psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
                        <NRF_PSEL(TWIM_SCL, 0, 27)>;
            };
        };
    
        my_custom_pinctrl_sleep: my_custom_pinctrl_sleep {
            group1 {
                psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
                        <NRF_PSEL(TWIM_SCL, 0, 27)>;
                low-power-enable;
            };
        };
    };
    
    &i2c2 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        pinctrl-0 = <&my_custom_pinctrl>;
        pinctrl-1 = <&my_custom_pinctrl_sleep>;
        pinctrl-names = "default", "sleep";
    };

     

    Kind regards,

    Håkon

  • Hello  ,

    Found the issue, seems i wasn't at fault.
    You too can recreate at your end.

    Just use a blinky sample.

    1. Add CONFIG_I2C=y in prj.conf of blinky sample, enable 

    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=4
    Build for nrf5340dk/nrf5340/cpuapp

    Runs fine, observe logs on serial terminal.

    2. Add CONFIG_I2C=y in prj.conf of blinky sample, enable 

    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=4
    Build for nrf5340dk/nrf5340/cpuapp/ns

    observe logs on serial terminal, it throws a bus fault exception.
    [00:00:00.422,149] <err> os: ***** BUS FAULT *****
    [00:00:00.422,180] <err> os:   Precise data bus error
    [00:00:00.422,180] <err> os:   BFAR Address: 0x0
    [00:00:00.422,180] <err> os: r0/a1:  0x00010734  r1/a2:  0x0001073c  r2/a3:  0x00000000
    [00:00:00.422,210] <err> os: r3/a4:  0x0000000c r12/ip:  0x00000042 r14/lr:  0x0000f911
    [00:00:00.422,210] <err> os:  xpsr:  0x81000000
    [00:00:00.422,210] <err> os: Faulting instruction address (r15/pc): 0x0000b372
    [00:00:00.422,241] <err> os: >>> ZEPHYR FATAL ERROR 25: Unknown error on CPU 0
    [00:00:00.422,271] <err> os: Current thread: 0x20008720 (unknown)
    [00:00:00.494,689] <err> os: Halting system

    Is this a bug in SDK.?
    Thanks,
  • Hi,

     

    When using TFM, the default setting is that it uses uart1 for logging.

    By setting I2C=y, you are trying to use i2c1 for the application. This creates a conflict and thus a secure fault when trying to access the peripheral.

    Try disabling TFM logs:

    CONFIG_TFM_SECURE_UART=n
    CONFIG_TFM_LOG_LEVEL_SILENCE=y

     

    Kind regards,

    Håkon

Related