添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi,

I am getting warning as build output as below.

phaseBegin and phaseEnd is of type uint16_t. But, I typecast it as pointer variable to point uint8_t, because HAL_I2C_Mem_Read expects that argument to be pointer to uint8_t data.

My code is here.

Could you please help me resolve ?

22:02:55 **** Incremental Build of configuration Debug for project PCA9685 ****
make -j8 all 
arm-none-eabi-gcc "../Core/Src/PCA9685.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F407xx -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/PCA9685.d" -MT"Core/Src/PCA9685.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/PCA9685.o"
In file included from ../Core/Src/PCA9685.c:9:
../Core/Inc/PCA9685.h:26:9: note: '#pragma message: i2c buffer length not defined - using default value of 32, which may not be correct for your microcontroller. Check stm32f4xx_hal_i2c.h (or similar) for your hardware and manually define BUFFER_LENGTH or I2C_BUFFER_LENGTH to remove this warning.'
   26 | #pragma message( "i2c buffer length not defined - using default value of 32, which may not be correct for your microcontroller. Check stm32f4xx_hal_i2c.h (or similar) for your hardware and manually define BUFFER_LENGTH or I2C_BUFFER_LENGTH to remove this warning.")
      |         ^~~~~~~
../Core/Src/PCA9685.c: In function 'getChannelPWM':
../Core/Src/PCA9685.c:516:74: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  516 |     HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)phaseBegin, 2, HAL_MAX_DELAY);
      |                                                                          ^
../Core/Src/PCA9685.c:517:74: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  517 |     HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)phaseEnd, 2, HAL_MAX_DELAY);
      |                                                                          ^
../Core/Src/PCA9685.c: In function 'i2cWire_begin_end_write_Transmission':
../Core/Src/PCA9685.c:862:79: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  862 |    HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)addr, (uint8_t*)data, sizeof(data), HAL_MAX_DELAY);
      |                                                                               ^
../Core/Src/PCA9685.c: In function 'i2cWire_requestFrom_read':
../Core/Src/PCA9685.c:894:12: warning: 'status' is used uninitialized [-Wuninitialized]
  894 |     return status;
      |            ^~~~~~
arm-none-eabi-gcc -o "PCA9685.elf" @"objects.list"   -mcpu=cortex-m4 -T"C:\Users\bjvyhb\OneDrive - PHINIA\Desktop\MCU\Workspace\RTOS_Workspace\PCA9685\STM32F407VGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="PCA9685.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
Finished building target: PCA9685.elf
arm-none-eabi-size  PCA9685.elf 
arm-none-eabi-objdump -h -S PCA9685.elf  > "PCA9685.list"
   text	   data	    bss	    dec	    hex	filename
  22748	    112	   2152	  25012	   61b4	PCA9685.elf
Finished building: default.size.stdout
Finished building: PCA9685.list
22:02:57 Build Finished. 0 errors, 4 warnings. (took 2s.162ms)
						

Ok, you can't cast the content of a variable to a pointer, you need to use the ADDRESS of the variable, as that's what a POINTER is

https://github.com/c-demir/PCA9685/blob/master/Core/Src/PCA9685.c#L516

HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)&phaseBegin, 2, HAL_MAX_DELAY);
HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)&phaseEnd, 2, HAL_MAX_DELAY);

You'd perhaps want to double check the endian ordering of the bytes, looks to be small endian, which should work fine.

Alternatively you might want

uint8_t temp[2];

HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)temp, sizeof(temp), HAL_MAX_DELAY);

phaseBegin = (uint16_t)temp[0];
phaseBegin |= (uint16_t)temp[1] << 8;

 

Ok, you can't cast the content of a variable to a pointer, you need to use the ADDRESS of the variable, as that's what a POINTER is

https://github.com/c-demir/PCA9685/blob/master/Core/Src/PCA9685.c#L516

HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)&phaseBegin, 2, HAL_MAX_DELAY);
HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)&phaseEnd, 2, HAL_MAX_DELAY);

You'd perhaps want to double check the endian ordering of the bytes, looks to be small endian, which should work fine.

Alternatively you might want

uint8_t temp[2];

HAL_I2C_Mem_Read(&hi2c1,_i2cAddress,regAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*)temp, sizeof(temp), HAL_MAX_DELAY);

phaseBegin = (uint16_t)temp[0];
phaseBegin |= (uint16_t)temp[1] << 8;

 

'undefined reference to..' error, after defining in main.h and creating a function. in STM32CubeIDE (MCUs) STM32U0_OTA mode in STM32CubeIDE (MCUs) NUCLEO-L4R5ZI-P Printing gibberish on Serial in STM32CubeIDE (MCUs) Actual Include paths do not correspond to Include Paths in the settings in STM32CubeIDE (MCUs)