Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add I2C support for whole STM32 family #101

Closed
strongly-typed opened this issue Oct 14, 2018 · 17 comments
Closed

Add I2C support for whole STM32 family #101

strongly-typed opened this issue Oct 14, 2018 · 17 comments

Comments

@strongly-typed
Copy link
Collaborator

There has been some work done in roboterclubaachen/xpcc#350 by @rleh

The STM32L4 driver (which is an ugly name, blame @strongly-typed), seems to be suitable also for F0, F3 and F7. I discussed with @chris-durand on Friday. I have F3 hardware here to test this.

There is the distinction between

How integrate this to modm?

@chris-durand
Copy link
Member

I looked at the reference manuals yesterday. stm32-extended and stm32l4 are in fact the same implementation. The memory maps and features seem to be completely identical except for the WUPEN bit (Wakeup from Stop mode enable) in I2C_CR1 that is missing on some controllers (some F0, F7 ?).

I would suggest to rename the L4 I2C to stm32-extended and enable it for all the other controllers. That would need some changes in the L4 I2C driver and device file generator. The name stm32-extended is problably ok because it supports more features than the other I2C IP (Fast Mode Plus support).

@chris-durand
Copy link
Member

chris-durand commented Oct 14, 2018

It's not that easy, thank you ST:
image

I hope this is somewhere in the CubeMX data…
However, we do not support any of these optional features right now.

@rleh
Copy link
Member

rleh commented Oct 14, 2018

STM32F0 reference manual: I2C register CR1
The WUPEN bit is not used by the modm anyway, so we can simply ignore it.

I remember that the digital noise filter DNF is not available on all controllers.

@chris-durand
Copy link
Member

I remember that the digital noise filter DNF is not available on all controllers.

I think this is only true for the other IP. If I didn't overlook anything the DNF bits are available in all controllers that have the extended IP.

@chris-durand
Copy link
Member

@rleh Are you currently working on this? It wouldn't be very efficient if we end up with 2 PRs implementing the same thing.

@rleh

This comment has been minimized.

@rleh
Copy link
Member

rleh commented Oct 14, 2018

CubeMX has data about e.g. FastModePlus:

<RefParameter Name="GPIO_FM6" Comment="Fast Mode" Type="list" DefaultValue="__NULL">
	<PossibleValue Value="__NULL" Comment="Disable"/>
	<PossibleValue Value="I2C_FASTMODEPLUS_PB6" Comment="Enable"/>
</RefParameter>
<RefParameter Comment="I2C Speed Mode " DefaultValue="I2C_Standard" Group="Timing configuration" Name="I2C_Speed_Mode" Type="list">
	<PossibleValue Comment="Standard Mode" Value="I2C_Standard"/>
	<PossibleValue Comment="Fast Mode" Value="I2C_Fast"/>
	<PossibleValue Comment="Fast Mode Plus" Semaphore="$IpInstance_FastMP" Value="I2C_Fast_Plus"/> 
</RefParameter>

But I don't know where $IpInstance_FastMP is defined 😒

@rleh
Copy link
Member

rleh commented Oct 14, 2018

Are you currently working on this? It wouldn't be very efficient if we end up with 2 PRs implementing the same thing.

No.

@chris-durand
Copy link
Member

This data is available because for FastModePlus the io pin has to be configured in SYSCFG_CFGR1 to a special mode that can drive the I2C bus with 20mA.

@chris-durand
Copy link
Member

According to CubeMX every device with the stm32-extended IP supports FM+ except I2C instance 2 on devices that match STM32F030C8Tx|STM32F030R8Tx|STM32F051R8Tx|STM32F051C8Tx|STM32F051R8Ux|STM32F051C8Ux|STM32F0x0_Value_Line.

All instances of stm32-extended support SMBus except I2C2 on F0/L0.

This data is somehow contradictory to the reference manuals. STM32F05xxx have no FM+ but I can configure it in CubeMX for STM32F058x8. The correct rule according to the reference manual is that every instance supports FM+ except for I2C2 on F03x, F05x and F070xB devices.

@strongly-typed
Copy link
Collaborator Author

Is there a way in lbuild to see if there are multiple instances of the peripheral?

in module.lb:

properties["aid"] = "2" if self.instance == 4 else "1"

but ST sometimes leaves out the postfix 1 if there is only one peripheral.

Or should I just create an alias between APB1RSTR and APB1RSTR1?

@salkinium
Copy link
Member

Is there a way in lbuild to see if there are multiple instances of the peripheral?

You mean like this?

has_instances = "instance" in device.get_driver("i2c")

This is just a dictionary, so you can always use the get(key, default) function: device.get_driver("i2c").get("instance", []).

@salkinium
Copy link
Member

The above is an issue in the CAN drivers, where there's CAN or CAN1 and/or CAN2. We follow the reference manual naming here, since we don't want to rename stuff (that gets you into trouble).

@chris-durand
Copy link
Member

in module.lb:

properties["aid"] = "2" if self.instance == 4 else "1"

but ST sometimes leaves out the postfix 1 if there is only one peripheral.

Or should I just create an alias between APB1RSTR and APB1RSTR1?

This is probably not the right solution to this problem. This relation only holds for some L4. For instance, STM32F745 has 4 I2Cs but no APB1RSTR1.

@chris-durand
Copy link
Member

Or should I just create an alias between APB1RSTR and APB1RSTR1?

L4 controllers have APB1RSTR1/APB1RSTR2, all the others APB1RSTR. That should be manageable.

@strongly-typed
Copy link
Collaborator Author

There is a little FIXME we/I need to fix. Blame me :-O

The timing blob was taken from the CubeMX. Does anybody know how to calculate these settings? Is a LUT with a bunch of common frequencies an intermediate solution?

@salkinium
Copy link
Member

Closed in #118.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants