Closed lyusupov closed 2 months ago
Allright, I think I found the cause. For the V003, the code seems only compiled for I2C1_BASE. Appearantly V30x also has I2C2_BASE defined. That undeclared "handle" is declared a few lines higher. For I2C1_BASE this code is used:
void I2C1_EV_IRQHandler(void)
{
#if OPT_I2C_SLAVE
I2C_HandleTypeDef *handle = i2c_handles[I2C1_INDEX]; // MMOLE: was commented
// MMOLE: I2C1_EV_IRQHandler is the event handler, handle is an I2C_HandleTypeDef struct containing parameters and pointer to the registers
static int _nCounterEV1=1;
_nCounterEV1++;
i2c_slave_process(get_i2c_obj(handle)); // process I2C transmissions, for now only events, not errors
#endif
}
Guess what... for I2C2_BASE the code is almost identical:
void I2C2_EV_IRQHandler(void)
{
#if OPT_I2C_SLAVE
//I2C_HandleTypeDef *handle = i2c_handles[I2C2_INDEX]; // MMOLE: was commented
// MMOLE: I2C2_EV_IRQHandler is the event handler, handle is an I2C_HandleTypeDef struct containing parameters and pointer to the registers
static int _nCounterEV2=1;
_nCounterEV2++;
i2c_slave_process(get_i2c_obj(handle)); // process I2C transmissions, for now only events, not errors
// MMOLLE: tested only using I2C1
#endif
}
As you can read in that final comment, I only tested using I2C1. Never compiled for V30x. When looking at the definition of "handle", you can see it is still commented for that I2C2_BASE. It only needs to be uncommented to make the code compilable. Just remove the first slashes from this line:
//I2C_HandleTypeDef *handle = i2c_handles[I2C2_INDEX]; // MMOLE: was commented
I just did it for my local copy and used the i2cMinimalSlave example to see if it compiles. Before if gave the same error you quoted. Now it properly compiles for the CH32V30x board. Mind you, I still don't have any V30x hardware to test this.
If you don't need I2C slave functionality I suggest you to switch the slave option off. Then all related code should be disabled and make the code compile as well:
#define OPT_I2C_SLAVE 0
@lyusupov - If I can find some more time I will make the fix in a new PR. Perhaps in the mean time you can make your own local change and see if that i2cMinimalSlave example actually works for the CH32V30x? Thanks for your testing and good luck compiling!
I can confirm V30x build fix after this commit https://github.com/maxint-rd/arduino_core_ch32/commit/b9fa7d8f7503c3e449b15d86bbcaaff0d2ea2724
Thank you!
Build platform
Linux
Core version
current 'main' branch
Target
CH32V30x_EVT
To reproduce
Root cause
The PR #108 had set
in twi.h: https://github.com/openwch/arduino_core_ch32/blob/main/libraries/Wire/src/utility/twi.h#L53-L56
This change works for CH32V00x_EVT target build but it breaks CH32V30x_EVT one !!!