GPIO example in FreeRTOS and Linux


I’ve a test program running well in FreeRTOS using GPIO and SPI, but without linux running on the A7 cores.
I need to run also Linux on the two A7 cores, but in the FreeRTOS program I’ve used GPIO02_22 (SODIMM 127) and GPIO02_IO26 (SODIMM 133).
To avoid linux blocking, I need to disable the entire GPIO2 bank in the linux device tree.

But in the DT we have:

  &iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio1 &pinctrl_gpio2 &pinctrl_gpio3 &pinctrl_gpio4
		     &pinctrl_gpio5 &pinctrl_gpio6 &pinctrl_gpio7>;

	pinctrl_gpio1: gpio1-grp {
		fsl,pins = <
			MX7D_PAD_SAI1_RX_SYNC__GPIO6_IO16	0x14 /* SODIMM 77 */
			MX7D_PAD_EPDC_DATA09__GPIO2_IO9		0x14 /* SODIMM 89 */
			MX7D_PAD_EPDC_DATA08__GPIO2_IO8		0x74 /* SODIMM 91 */
			MX7D_PAD_LCD_RESET__GPIO3_IO4		0x14 /* SODIMM 93 */
			MX7D_PAD_EPDC_DATA13__GPIO2_IO13	0x14 /* SODIMM 95 */
			MX7D_PAD_ENET1_RGMII_TXC__GPIO7_IO11	0x14 /* SODIMM 99 */
			MX7D_PAD_EPDC_DATA10__GPIO2_IO10	0x74 /* SODIMM 105 */
			MX7D_PAD_EPDC_DATA00__GPIO2_IO0		0x14 /* SODIMM 111 */
			MX7D_PAD_EPDC_DATA01__GPIO2_IO1		0x14 /* SODIMM 113 */
			MX7D_PAD_EPDC_DATA02__GPIO2_IO2		0x14 /* SODIMM 115 */
			MX7D_PAD_EPDC_DATA03__GPIO2_IO3		0x14 /* SODIMM 117 */
			MX7D_PAD_EPDC_DATA04__GPIO2_IO4		0x14 /* SODIMM 119 */
			MX7D_PAD_EPDC_DATA05__GPIO2_IO5		0x14 /* SODIMM 121 */
			MX7D_PAD_EPDC_DATA06__GPIO2_IO6		0x14 /* SODIMM 123 */
			MX7D_PAD_EPDC_DATA07__GPIO2_IO7		0x14 /* SODIMM 125 */
			MX7D_PAD_EPDC_SDCE2__GPIO2_IO22		0x14 /* SODIMM 127 */
			MX7D_PAD_UART3_RTS_B__GPIO4_IO6		0x14 /* SODIMM 131 */
			MX7D_PAD_EPDC_GDRL__GPIO2_IO26		0x14 /* SODIMM 133 */
			MX7D_PAD_SAI1_RX_DATA__GPIO6_IO12	0x14 /* SODIMM 169 */
			MX7D_PAD_SAI1_RX_BCLK__GPIO6_IO17	0x14 /* SODIMM 24 */
			MX7D_PAD_SD2_DATA2__GPIO5_IO16		0x14 /* SODIMM 100 */
			MX7D_PAD_SD2_DATA3__GPIO5_IO17		0x14 /* SODIMM 102 */
			MX7D_PAD_EPDC_GDSP__GPIO2_IO27		0x14 /* SODIMM 104 */
			MX7D_PAD_EPDC_BDR1__GPIO2_IO29		0x14 /* SODIMM 110 */
			MX7D_PAD_EPDC_PWR_COM__GPIO2_IO30	0x14 /* SODIMM 112 */
			MX7D_PAD_EPDC_SDCLK__GPIO2_IO16		0x14 /* SODIMM 114 */
			MX7D_PAD_EPDC_SDLE__GPIO2_IO17		0x14 /* SODIMM 116 */
			MX7D_PAD_EPDC_SDOE__GPIO2_IO18		0x14 /* SODIMM 118 */
			MX7D_PAD_EPDC_SDSHR__GPIO2_IO19		0x14 /* SODIMM 120 */
			MX7D_PAD_EPDC_SDCE0__GPIO2_IO20		0x14 /* SODIMM 122 */
			MX7D_PAD_EPDC_SDCE1__GPIO2_IO21		0x14 /* SODIMM 124 */
			MX7D_PAD_EPDC_DATA14__GPIO2_IO14	0x14 /* SODIMM 126 */
			MX7D_PAD_EPDC_PWR_STAT__GPIO2_IO31	0x14 /* SODIMM 128 */
			MX7D_PAD_EPDC_SDCE3__GPIO2_IO23		0x14 /* SODIMM 130 */
			MX7D_PAD_EPDC_GDCLK__GPIO2_IO24		0x14 /* SODIMM 132 */
			MX7D_PAD_EPDC_GDOE__GPIO2_IO25		0x14 /* SODIMM 134 */
			MX7D_PAD_EPDC_DATA12__GPIO2_IO12	0x14 /* SODIMM 150 */
			MX7D_PAD_EPDC_DATA11__GPIO2_IO11	0x14 /* SODIMM 152 */
			MX7D_PAD_SD2_CLK__GPIO5_IO12		0x14 /* SODIMM 184 */
			MX7D_PAD_SD2_CMD__GPIO5_IO13		0x14 /* SODIMM 186 */

I suppose the kernel doesn’t work well without this gpio …

Do you have some suggestion to solve the conflict? (like using other gpio?
SPDIF, audio and input camera are not used in my applications).

Thank you

Hi @Mane

Did you already try to run your application on the M4 while running a Linux on the other cores? What do you expect by disabling the GPIOs needed by your software on the M4 or what is your goal on that? At the end it depends what you are running in Linux, whether the values on the address of your GPIOs will be overwritten or not. If you don’t touch the GPIOs in Linux, they should not be blocked.

Anyway, if you want to disable the GPIO2 in Linux, you are free to do that. I tested it myself and added following entry to the imx7d-colibri-emmc-eval-v3.dts file:

&gpio2 {
        status = "disabled";

Did this help, or did I not get your question properly?

Best regards, Diego

Hi @diego_b.tx ,
Yes, I need to run my application on M4 core while Linux running on the other cores.
When I run the application and Linux toghether, I obtain a kernel panic from Linux.

By the way, I had read in this older post it is mandatory to disable the entire gpio bank in the DT if one or more gpios of that bank is used by M4, because disabling a single gpio is not possible.

The the GPIO2 bank seems be used by EPDC from Linux side, as I read from Colibri iMX7 datasheet, but now the electrophoretic display controller isn’t used.

Hi @Mane

Did you actually try to disable a bank in the device tree, run your M4 application and the Linux beside? Do you still run into some kind of problems? The most effective way is just to try it out I think.

It’s up to you, if you want to disable the full bank or not. If think this article is referenced to and there it’s stated that this is important if you are using interrupts:

Note: The interrupt part of the demo only works as long as Linux is not running. The reason for that is that Linux uses the same GPIO bank too, and reconfigures interrupts. The easiest way to use GPIO in interrupt mode on FreeRTOS while using Linux is to assign a complete GPIO bank to FreeRTOS and disabling the GPIO bank in Linux’ device tree.

Where did you find this information about the EPDC on the Colibri iMX7? In the datasheet of the Colibri iMX7 in chapter 5.5.6, it’s stated that the module does not support the EDPC interface.

Best regards, Diego

Hi @diego_b.tx ,

The easiest way to use GPIO in interrupt mode on
FreeRTOS while using Linux is to assign a complete GPIO bank to
FreeRTOS and disabling the GPIO bank in Linux’ device tree.

Yes, I am in this situation. I use GPIO and ecspi from FreeRTOS.
The problem is: which bank of GPIO I need to assign to FreeRTOS ?

I’ve found the EPDC in the Colibri iMx7 Datasheet pages 21, 22, 23 Chapter 4.4 in
the list of i.MX7pins. See, for example, the X1 pin 107: EPDC_D15 → gpio2.IO[15].
And yes, the EPDC isn’t available on iMX7S, but I have an iMX7D.

Thank you.

hi @Mane

The problem is: which bank of GPIO I need to assign to FreeRTOS ?
You don’t need to assign a Gpio Bank to RTOS, you just need to disable them in Linux (device tree). Then you can use them in M4. Since your pins are on GPIO2 Bank, you can disable the GPIO2 (don’t do the muxing and don’t add it to a device node).

Best regards, Jaski

Hi boys!

I’ve solved. Disabling gpio2 from the DT.

The kernel panic disappear, but the M4 program was freezing when Linux starting, and also Linux was blocked after a while.
The issue is a timer made upon GPT, but this is another story…

Without the timer, Linux and FreeRTOS running well together.

Perfect that it works. Thanks for the feedback.