This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use I2C0 instead of UART0 (nRF5340)

Hello,

 

I work with the nRF5340 and want to use I2C0 (1-3 is reserved for other sensors in my project ). I already use I2C2 for a sensor and this works fine.

To use the I2C0, I must deactivate the UART0 because you can only use one of them. I deactivated UART0 to use I2C0. Because UART0 is necessary for the terminal output (printk-functions) I switched to RTT instead.

The problem is, when I run the program in debug mode, it won’t reach the main function. When I use “step over” the program works and the program reaches the main-function. Also the function “device_get_binding(“I2C_0”)” is successful.

 

This is my prj.conf:

CONFIG_PRINTK=y
CONFIG_CONSOLE=y

CONFIG_SERIAL=n     #disable logging (serial)
CONFIG_STDOUT_CONSOLE=y

CONFIG_UART_CONSOLE=n
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y

CONFIG_DEBUG_OPTIMIZATIONS=y

#Buttons and LEDs configuration
CONFIG_DK_LIBRARY=y

#I2C
CONFIG_I2C=y
CONFIG_NRFX_TWIM=y

 

This is my overlay file:

&uart0 {
                status = "disabled";
};

&i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        sda-pin = < 0x0D >;
        scl-pin = < 0x0E >;
};

 

 Below I listed some functions that are called when I run the program. The functions are always the same.

nrfx_twim_0_irq_handler
twim_irq_handler
z_impl_k_sem_give
z_unpend_first_thread

Why is there a difference between running the program and only use “step-over”?

Thank you very much for your help!

Parents
  • Hello,

    The problem is, when I run the program in debug mode, it won’t reach the main function.

    what happens when it doesn't reach main? Does it just hang, or does the code crash somewhere? Where in the code does this happen? Are there any error codes?

  • Hello Hakon,

    there are no reported errors.

    I think the code crashes somewhere else. If I pause the session the code calls always the following function:

    static int init_twim(const struct device *dev)
    
    static void twim_irq_handler(NRF_TWIM_Type * p_twim, twim_control_block_t * p_cb)
    
    static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
    
    void z_impl_k_sem_give(struct k_sem *sem)

  • Have you tried putting a breakpoint in one of these functions to see exactly how far it gets?

  • The problem seems to be in this function

    void spm_jump(void)

    The program reaches a breakpoint in line 1 (reset_ns=...). When I click "Step Over", the programm jumps to line 15 (spm_config_peripheral(uart_id, 0). Now the program will reach the main, if I run the program.

    reset_ns = TZ_NONSECURE_FUNC_PTR_CREATE(vtor_ns[1]);
    
    	if (TZ_NONSECURE_FUNC_PTR_IS_NS(reset_ns)) {
    		PRINT("SPM: prepare to jump to Non-Secure image.\n");
    
    		/* Note: Move UARTE0 before jumping, if it is
    		 * to be used on the Non-Secure domain.
    		 */
    
    		/* Configure UARTE0 as non-secure */
    		uint8_t uart_id = NRFX_PERIPHERAL_ID_GET(NRF_UARTE0);
    
    		IS_ENABLED(CONFIG_SPM_SHARE_CONSOLE_UART) ?
    			spm_config_unlocked_peripheral(uart_id, 0) :
    			spm_config_peripheral(uart_id, 0);
    

  • Can you try also disabling logging for SPM?

    child_image/spm.conf -> CONFIG_SERIAL=n

  • Hello Hakon, it worked. Thank you very much!!!

Reply Children
No Data
Related