nRF5340 Audio application - moving button5 to gpio1 instead of gpio0

Hello!

Using SDK v2.6.1 and the nRF5340 Audio application, I want to use an external button as button5 instead of the one that is on the board.

I noticed that if i change the device tree to use an unused pin on gpio1, it does not seem to work. 

In src/bluetooth/bt_management/bt_mgmt.c, I added a print in the bonding_clear_check() function to see the value of BUTTON_5. When I run the application with the original device tree (gpio0 5), i see that the value is 5. If I change the device tree (gpio1 5 instead), it still shows at 5. This leads me to believe that it is not accessing the correct GPIO since I would expect it to be 37 (5 + 32).

Looking more closely, in src/modules/button_assignments.h, I see the button list which is giving BUTTON_5 its value. 

`BUTTON_5 = DT_GPIO_PIN(DT_ALIAS(sw4), gpios)`
I tried doing + 32 here directly as suggested in this post, but then I get "Unsupported pin" error. 
Note: I've tested with other gpio0 pins and it works fine.
Could you explain what needs to be changed in order to move button5 to gpio1?
 
Cheers.
  • Hi,

    I tried doing + 32 here directly as suggested in this post, but then I get "Unsupported pin" error. 

    What is the API that gives this error? Maybe you can step into that function call using a debugger and see in the code exactly where in the libraries or driver you get this error. That will give you more context on why this is happening.

  • Hello Susheel,

    Thanks for the reply.

    What is the API that gives this error?

    The error originates from the ASSERT in `zephyr/include/zephyr/drivers/gpio.h` at line 1001.

    	__ASSERT((cfg->port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U,
    		 "Unsupported pin");

    I have no issues with gpios that are outputs on gpio1. But trying to set an input button on gpio1 with the nRF5340 Audio app is causing problems. If i switch to another pin on gpio0, its fine and works fine. Any insights?

  • It is either the pin is reserved in the device tree or there is some conflict that we are unable to see. Can you attach your project here so that I can quickly flash and see why we see this error. Trying to use sw4 button_4 in nrf53_audio dk gives me some errors. So it is best if I use exact same setup as you are using to test this.

  • Hello Susheel,

    My apologies for the delay. Here is the project i am using. It is basically the SDK v2.6.1 nRF5340 Audio application with a modification in the project CMake to use the included overlay. The overlay is used to re-route P1.07 that is usually used for UART to button5. and i just used a "random" gpio for the UART. I chose P1.07 specifically because it shows the issue. 
    Unzip and flash Headset Left. 
    Usually, Headset Left has a BLUE color, but you'll notice that it's Magenta. This is because RGB LED1 RED is being triggered. While I asked for P1.07 to be used for button5, it is using P0.07 instead which is RGB LED1 RED, hence the magenta instead of blue. 

    In the original app, when we press and release button5, the audio will mute. If you flash a gateway as well and pair them, you can test this. Then, flash with my code. You will see that button5 no longer works, so i know the overlay is working as intended. If you bring ground to P1.07 by the header, nothing will happen. But, if you bring ground to P0.07, the audio will mute at the Headset. 

    Please let me know if your findings are the same and what can be done to fix this. 

    Cheers.

    3173.nrf5340_audio.zip

  • Hi Daniel,

    Susheel is away and I will be communicating with you regarding this ticket.

    I have gone through the sample, your changes, and building / programming on the DK.

    I could see what you are getting. I could exactly see the same behavior and the error / logs.

    However, upon searching about the issue and looking more into the code, we could see that the audio-application button-handler module indeed uses only the gpio0.

    That was also the finding of this case, and probably you would need to make changes at your own if you want to use another gpio port.

    Best regards,

    Naeem

Related