Can't subscribe SPI bus after use as GPIO

I’m trying to use SPI1 on a Q2686; R7.2a; Open-AT v6.11.

To hold the pins in a known state before starting to use them as an SPI bus, I subscribe them as “ordinary” GPIOs.

When I’m ready to use them as an SPI bus, I unsubscribe the GPIO handle before making the adl_busSubscribe call.

The GPIO unsubscribe returns OK, but the adl_busSubscribe call fails with ADL_RET_ERR_BAD_HDL (-7); which means, “a GPIO required by the bus is currently subscribed”:

But I just unsubscribed them all! :angry:

Doing an adl_ioGetCapabilitiesList confirms that none of the GPIOs associated with either SPI bus is in use:

7811.866	Trace	ADL	5	   pIo_defs[ 0]=00603023: Num=35 Type=3 Dir=0 Stat=0 
7811.866	Trace	ADL	5	   pIo_defs[ 1]=00603022: Num=34 Type=3 Dir=0 Stat=0 
7811.866	Trace	ADL	5	   pIo_defs[ 2]=00603021: Num=33 Type=3 Dir=0 Stat=0 
7811.866	Trace	ADL	5	   pIo_defs[ 3]=00603020: Num=32 Type=3 Dir=0 Stat=0 
7811.866	Trace	ADL	5	   pIo_defs[ 4]=0060301F: Num=31 Type=3 Dir=0 Stat=0 
7811.866	Trace	ADL	5	   pIo_defs[ 5]=0060301E: Num=30 Type=3 Dir=0 Stat=0 
7811.866	Trace	ADL	5	   pIo_defs[ 6]=0060301D: Num=29 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[ 7]=0060301C: Num=28 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[ 8]=0060301B: Num=27 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[ 9]=0060301A: Num=26 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[10]=00603019: Num=25 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[11]=00603018: Num=24 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[12]=00603017: Num=23 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[13]=00603016: Num=22 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[14]=00603015: Num=21 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[15]=00603014: Num=20 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[16]=00603013: Num=19 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[17]=0060300D: Num=13 Type=3 Dir=0 Stat=0 
7811.951	Trace	ADL	5	   pIo_defs[18]=0060300C: Num=12 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[19]=0060300B: Num=11 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[20]=0060300A: Num=10 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[21]=00603009: Num= 9 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[22]=00603008: Num= 8 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[23]=00603007: Num= 7 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[24]=00683006: Num= 6 Type=3 Dir=0 Stat=1 
7812.036	Trace	ADL	5	   pIo_defs[25]=00603005: Num= 5 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[26]=00603004: Num= 4 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[27]=00603003: Num= 3 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[28]=00603002: Num= 2 Type=3 Dir=0 Stat=0 
7812.036	Trace	ADL	5	   pIo_defs[29]=00603001: Num= 1 Type=3 Dir=0 Stat=0 
7812.131	Trace	ADL	5	   pIo_defs[30]=00603000: Num= 0 Type=3 Dir=0 Stat=0 
7812.131	Trace	IOB	1	bsp_spi_OpenAll: ERROR! some SPI lines are not available
7812.131	Trace	ADL	5	  SPI Subs:  -7

Is there some trick required after the GPIO unsubscribe to make the pins really free for SPI use?

As far as I see the GPIO #24 has a status of 1. Which is supposed to show that the pin is used by the task. So it is wrong that none of SPI1 pins is in use - system regards the GPIO #24 as used.

Are you looking at this:

The 24 there is the index in the table created by adl_ioGetCapabilitiesList, not the GPIO number. The GPIO number is 6

So it is GPIO6 that is the only one in use - not GPIO24.

So all the SPI pins are clear.

Sorry not to have made that clear. :blush:

Have you found the solution? One of our customer reports similar problems switching multiplexed SPI1 pins from SPI to GPIO and back.

No - I didn’t, I’m afraid.