-
Notifications
You must be signed in to change notification settings - Fork 0
Micropy 66 i2c target implementation #25
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
base: MICROPY-57-enable-i2c-module-for-psoc-edge
Are you sure you want to change the base?
Micropy 66 i2c target implementation #25
Conversation
Signed-off-by: zhanglinjing <Linjing.Zhang@infineon.com>
Signed-off-by: zhanglinjing <Linjing.Zhang@infineon.com>
Signed-off-by: zhanglinjing <Linjing.Zhang@infineon.com>
Signed-off-by: zhanglinjing <Linjing.Zhang@infineon.com>
Signed-off-by: zhanglinjing <Linjing.Zhang@infineon.com>
jaenrig-ifx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a lot of progress :) Well done, looks quite good as far as I can judge.
Some questions and minor discussion or things we can polish before merging to main.
|
|
||
| LDFLAGS += -Wl,-Map,$(BUILD)/$(MPY_APP_NAME).map | ||
|
|
||
| # Ensure assembly file is compiled with correct flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this contribution regarding the assembler flags?
| #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "KIT_PSE84_AI" | ||
|
|
||
| #define MICROPY_GC_HEAP_SIZE (315 * 1024) // 315 KB | ||
| #define MICROPY_GC_HEAP_SIZE (32 * 1024) // TODO: 315 was too big for non-secure RAM? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this relates to the I2C ?
| return 0; | ||
| } | ||
|
|
||
| #if MICROPY_ENABLE_GC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this enablement of the garbage collector?
| #define MICROPY_PY_BUILTINS_SLICE (1) | ||
|
|
||
| // Disable optional modules, only use bytearray | ||
| #define MICROPY_PY_ARRAY (0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are all these macros related to the I2C enablement?
Please remove all the defines that are not related to what you are working on, and you are not aware of what they control.
Usually by default, they have default values in "py/mpconfig.h" which should be consciously overwritten.
|
|
||
| // Forward declare MAX_I2C from mpconfigboard.h | ||
| #ifndef MAX_I2C | ||
| #define MAX_I2C MICROPY_HW_MAX_I2C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no default definition of MICROPY_HW_MAX_I2C or? If not MAX_I2C is defined this will not compile.
In file included from ../../extmod/machine_i2c_target.c:240:
../../ports/psoc-edge/machine_i2c_target.c:59:17: error: 'MICROPY_HW_MAX_I2C' undeclared here (not in a function); did you mean 'MICROPY_HW_MCU_NAME'?
59 | #define MAX_I2C MICROPY_HW_MAX_I2C
| ^~~~~~~~~~~~~~~~~~
../../ports/psoc-edge/machine_i2c_target.c:62:56: note: in expansion of macro 'MAX_I2C'
62 | static machine_i2c_target_obj_t machine_i2c_target_obj[MAX_I2C];
| ^~~~~~~
../../ports/psoc-edge/machine_i2c_target.c:62:33: error: 'machine_i2c_target_obj' defined but not used [-Werror=unused-variable]
62 | static machine_i2c_target_obj_t machine_i2c_target_obj[MAX_I2C];
| ^~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [../../py/mkrules.mk:101: build-KIT_PSE84_AI/extmod/machine_i2c_target.o] Error 1
| .useRxFifo = false, // PDL recommends false for slave to avoid side effects | ||
| .useTxFifo = true, | ||
| .slaveAddress = addr, | ||
| .slaveAddressMask = (addrsize == 7) ? 0xFEU : 0xFCU, // Mask for 7-bit or 10-bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm is that mask right? if addrsize is 7 the mask is 0b11111110 and if not 0b11111100. How does this work?
| } | ||
|
|
||
| static void mp_machine_i2c_target_irq_config(machine_i2c_target_obj_t *self, unsigned int trigger) { | ||
| // IRQ configuration already handled in init |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not needed? How is the passed trigger by the user updated in the pdl interrupt handler?
Summary
Implement i2c target (slave) based on mpy extmod.momachine
Only 0 address is supported!
TODO:
8 bit/16 bit Memory Access mode:
https://jirard.intra.infineon.com/browse/MICROPY-82
Explore mpy ROM level feature
https://jirard.intra.infineon.com/browse/MICROPY-83
Testing
Using example in micropython doc:
Target - PSoC edge:
Controller - PSoC 6:
Verify with logic analyzer:

Trade-offs and Alternatives
I've added a few modules/functions, but these are the minimum I need to use extmod I2CTarget.