Pc lint "-egrep" option

200 Views Asked by At

I'm trying to clean up my code from misra violations using Pc-lint.

One of them is the violation to rule 11.4 in this code.

GPIO_PinState level = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6);

the definition of GPIOB is

#define GPIOB               ((GPIO_TypeDef *) GPIOB_BASE)

The violation is the following: *[9078] conversion between object pointer type 'GPIO_TypeDef ' and integer type 'unsigned long' [MISRA 2012 Rule 11.4, advisory]

Since I can't modify this files (and is on memory mapped registers) I'm trying to use the Pc-lint command "egrep" to avoid this "warning".

I've tried to use

//lint -egrep(9078, "type 'GPIO_TypeDef *' and integer type 'unsigned long'")

but it doesn't work.

I don't want to use this command

//lint -e9078

because I want to exclude just this particular kind of violation.

Thanks in advance for the help.

1

There are 1 best solutions below

1
Sercan On

HAL drivers released by STMicroelectronics contain hundreds of blocked lines of code; there is no rule that HAL drivers will not be interfered with; I have witnessed many times in the industry that HAL drivers are interfered with.

You can solve this problem using pointer arithmetic. Similar case study is shared in Keil RTOS v2 package:

__STATIC_INLINE mem_block_t *MemBlockPtr (void *mem, uint32_t offset) {
  uint32_t     addr;
  mem_block_t *ptr;

  //lint --e{923} --e{9078} "cast between pointer and unsigned int" [MISRA Note 8]
  addr = (uint32_t)mem + offset;
  ptr  = (mem_block_t *)addr;

  return ptr;
}

References