MCUSEL write ignored

Code is on APP processor. It is in secure mode, verified using this method: https://community.arm.com/support-forums/f/architectures-and-processors-forum/13548/for-armv8-m-is-there-a-system-register-indicating-the-security-state-of-the-core

So i try to set a pin to peripheral mode, it is ignored...

	NRF_P1_S->PIN_CNF[8] = t = (NRF_P1_S->PIN_CNF[8] &~ (GPIO_PIN_CNF_MCUSEL_Msk | GPIO_PIN_CNF_PULL_Msk | GPIO_PIN_CNF_DRIVE_Msk | GPIO_PIN_CNF_INPUT_Msk | GPIO_PIN_CNF_DIR_Msk)) |
		(GPIO_PIN_CNF_MCUSEL_Peripheral << GPIO_PIN_CNF_MCUSEL_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
		(GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
	
	printf("CNF=0x%08x, wrote 0x%08x\n", NRF_P1_S->PIN_CNF[8], t);

result is 

CNF=0x00000003, wrote 0x30000003

Docs say that to write this, i need ot be in secure mode, which i am. my code is on the app processor, to which the pin is indeed assigned. what is going on?

Parents
  • Hi!

    I was not able to reproduce the behavior you describe

    Using zephyr\samples\hello_world, with this main.c,

    /*
     * Copyright (c) 2012-2014 Wind River Systems, Inc.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/init.h>
    #include <nrf.h>
    #include <nrfx.h>
    
    int main(void)
    {
    	printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
    
    	uint32_t t = 0;
    
    		NRF_P1_S->PIN_CNF[8] = t= (NRF_P1_S->PIN_CNF[8] &~ (GPIO_PIN_CNF_MCUSEL_Msk | GPIO_PIN_CNF_PULL_Msk | GPIO_PIN_CNF_DRIVE_Msk | GPIO_PIN_CNF_INPUT_Msk | GPIO_PIN_CNF_DIR_Msk)) |
    		(GPIO_PIN_CNF_MCUSEL_Peripheral << GPIO_PIN_CNF_MCUSEL_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
    		(GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
    	
    	printf("CNF=0x%08x, wrote 0x%08x\n", NRF_P1_S->PIN_CNF[8],t);
    
    
    
    	return 0;
    }
    

    Build it like this: west build -b nrf5340dk/nrf5340/cpuapp

    Flashed it: west flash --recover

    Output:

  • please note that you did in fact to reproduce my problem. Look at the readback value from CNF register. Note that the top bits you read back are zero and do not show that you assigned to peripheral mode.  The value you wrote contained a three there, and the readback contains a zero

    this is precisely issue, and you precisely reproduced it

  • Hi!

    Yes, you are right. I had a new look at this, and it seems you can only set the mcusel to "Peripheral" on certain dedicated pins. This includes dedicated pins that are used for e.g. QSPI, SPIM4, TRACE and LFXO pins. Setting mcusel to "Peripheral" for a pin that is not associated to any special Peripheral will not do anything.

Reply Children
Related