GPIO to I2C kernel driver (opposite of i2c-gpio) - linux-device-driver

My Zynq board has SPI, I2C but does not have kernel level GPIO (The GPIO on the MIO is sent to a bunch of other things) so I can't get it from the headers. Believe me when I say this.
I need some kernel level GPIO so I can drive a touch screen interface. I need to map some GPIO to the stmpe610 touch screen driver (Device Tree compatible = "st,stmpe610"). This is all well and good. So what I want to do is somehow map the I2C to GPIO (which will be connected to the display), and pipe the driver to interface through I2C. This way I can access the GPIO pins of my i2c expander from kernel space.
I looked at the i2c-gpio driver, but it does the opposite of what I want (http://lwn.net/Articles/230571/). It takes GPIO and makes it I2C by bit-banging.
I have an i2c expander mini-board that will take I2C and spit out GPIO. So if I have a gpio-i2C that would be great.
Maybe I have wandered too afar and off the beaten path. Does the stmpe610 have an i2c driver? This would also alleviate my issue.
<<

If I have understood you correctly, you have a GPIO expansion board that you can connect to your Zync main board.
If the above assumption is correct, what you have to do is find the correct driver for your GPIO extension board. What model do you have ? What chip is there on it ? Maybe there is already a driver for it in the kernel. If so, you then just have to declare it under your I2C base controller node in your device tree so that its GPIOs can then be referenced in your device tree for your stmpe610 touchscreen node.
If the chip does not have a driver yet, you then will have to write a GPIO driver for the chip. One good example to start with is the GPIO driver for the MAX 7300, that is connected via I2C as well. Have a look at gpio-max7300.c and gpio-max730x.c

Related

DFRO316 MCP3424 and STM32

I am trying to know the status of MCP3424, either it is connected or not to the master STM32 with defined address 0x68. The ADC module gets connected with the Arduino in same address but using STM32, I am not able to get connected with the following code:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if((HAL_I2C_IsDeviceReady(&hi2c1, 0x68 << 1, 100, 1000))==HAL_OK){
HAL_UART_Transmit(&huart2, "device connected\r\n", 10, 10);
}
else{
HAL_UART_Transmit(&huart2, "no device\r\n", 100, 10);
}
}
Is there any mistake that I have done in this code by chance or any other way there is to deal with MCP3424 ADC module specifically? Please suggest me.
I believe your problem lies with voltage levels: your STM32 functions with 3.3V, while MCP3424 is powered from 5V. Let's open the datasheet of the MCP3424, page 6:
High level input voltage is 0.7Vdd, which is 0.7V*5V=3.5V, which means your A/D can't detect "1" on the line. It sees the line as always "0", even when STM32 MCU outputs HIGH (3.3V).
Possible solutions:
Logic level conversion (various ways). A circuit between A/D IC and MCU to convert 3.3V levels into 5V levels. There are dedicated chips for that, there are also other approaches using resistors and mosfets. Something you may want to explore on electrical engineering stackexchange.
Check the datasheet of the MCU, find GPIO properties. It's very likely those I2C pins are in fact 5V-tolerant, meaning you can pull up I2C lines to 5V and still drive them with 3.3V STM32, and it will be within the spec of STM32 MCU. If that's the case, no extra circuit will be necessary.

Can I directly connect a GPIO OUTPUT and INPUT

Can I directly connect a GPIO OUTPUT and INPUT of a raspberry pi? I heard that this would be dangerous in case that both GPIOs are accidentally set as outputs and that it is better to put a resistor of at least 220 ohm in between (not to ground?). Is this really necesarry?

How to establish 3 UART and 2 I2C interface at a same time in STM32F103C8T6?

I am a newbie to STM32 and CubeMX. I need to create 3 UART interface and 2 I2C interface in STM32F103C8T6. I tried to, but there is a common port for both i2c and uart communication and it allows me to create only (2 uart and 2 i2c) or (3 uart and 1 i2c ) and I couldn't create as I needed . how can I establish 3 UART and 2 I2C interface at a same time in STM32F103C8T6 ?
Thanks in advance...
You can't. There's an unresolvable pin conflict.
The I2C2 peripheral must use pins PB10 and PB11 for SDA and SCL -- there are no remappings for this peripheral.
The USART3 peripheral uses those pins for TX and RX. On higher pin-count STM32F1 parts, it can be remapped to pins PC10/PC11 or PD8/PD9; however, the STM32F103C8 doesn't have those pins.
There are only two I2C and three USART peripherals on the STM32F103, so there are no alternate I2C or USART peripherals available.
use hardware I2C and as many as possible hardware UARTS. For the additional ones write the software implementation. You have an example here: https://www.st.com/resource/en/application_note/dm00110292.pdf or take stm32F103 with more pins

Hardware NSS signal conficts with PA15 mapped with GPIO output

I'm having a Chinese development board of STM32F103RCT6 STM32_Mini_Pro where a winbond SPI flash is attached with SPI3. The Chip Select is attached with PA15 pin.
While configuring SPI in STM32 cubeMX, I assign Chip Select i.e. PA15 as GPIO output for software NSS.
But while assigning it i get an error like this
This is my assignment in Cube MX
What is the reason for this problem and how to rectify it?
Thank you
There is no problem. Cube shows you that you can not assign slave select signal to PA15 (yes, it's rigth, you already mapped this pin as GPIO).
Hardware slave select it STM32 micros has the meaning only if you use MCU as slave device.

Access GPIO Hog input value

I'm trying to have some GPIO pins on my SoC board available by default at boot. I've run across the gpio-hog property in the device tree documentation here, and I have my 'hogged' pin visible in userspace. How can I see the value of that pin? It's configured as an input.