renesas / fsp

Flexible Software Package (FSP) for Renesas RA MCU Family
https://renesas.github.io/fsp/
Other
192 stars 82 forks source link

RM_COMMS_I2C semaphore/mutex not initialised #350

Open KoviRobi opened 5 months ago

KoviRobi commented 5 months ago

Hi,

If I add an I2C shared bus/device (rm_comms_i2c) via the e2studio, it creates the g_comms_i2c_bus<busname>_recursive_mutex_handle and g_comms_i2c_bus<busname>_blocking_semaphore_handle in ra_gen/common_data.c, but it is never initialised. I might expect it to be initialised in the RM_COMMS_I2C_Open:

https://github.com/renesas/fsp/blob/ba7104eb99475f0217595123d4972852c22b89bc/ra/fsp/src/rm_comms_i2c/rm_comms_i2c.c#L88-L132

If you contrast this with the UART CDC (rm_comms_uart), then it has a mutex in ra_gen/hal_data.c, which is initialised in RM_COMMS_UART_Open

https://github.com/renesas/fsp/blob/ba7104eb99475f0217595123d4972852c22b89bc/ra/fsp/src/rm_comms_uart/rm_comms_uart.c#L73-L139

Possibly I didn't set some configuration setting, but I would expect the I2C mutex/semaphore to be initialised like this too. I couldn't find a different function to initialise it either. Especially since the actual mutex isn't declared in the header, so it seems like it shouldn't be user visible (which makes sense, it is internal to RM_COMMS_I2C). But without initialising the mutex/semaphore, I cannot use the I2C shared bus.

For now I've worked around this, by initialising it in src/hal_entry.c which isn't autogenerated:

        extern SemaphoreHandle_t g_comms_i2c_bus<busname>_recursive_mutex_handle;
        extern StaticSemaphore_t g_comms_i2c_bus<busname>_recursive_mutex_memory;
        extern SemaphoreHandle_t g_comms_i2c_bus<busname>_blocking_semaphore_handle;
        extern StaticSemaphore_t g_comms_i2c_bus<busname>_blocking_semaphore_memory;

        g_comms_i2c_bus<busname>_recursive_mutex_handle =
            xSemaphoreCreateRecursiveMutexStatic(&g_comms_i2c_bus<busname>_recursive_mutex_memory);

        g_comms_i2c_bus<busname>_blocking_semaphore_handle = xSemaphoreCreateCountingStatic(
            (UBaseType_t)1,
            (UBaseType_t)0,
            &g_comms_i2c_bus<busname>_blocking_semaphore_memory);

(Also as an aside, the UART uses the abstracted type rm_comms_mutex_t/rm_comms_semaphore_t from ra/fsp/src/rm_comms_lock/rm_comms_lock.h whereas the I2C just uses the TX_MUTEX/SemaphoreHandle_t)

renesas-austin-hansen commented 5 months ago

This issue is being internally tracked under FSPRA-2948.