3

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.

buch
  • 33
  • 2
  • 1
    You need to escape the `*` in a regular expression to make it literal. – Barmar Jan 05 '22 at 16:08
  • I believe the linked post is an exact duplicate. If it didn't answer the question, then please let me know. TL;DR: you have to skip this advisory rule when dealing with hardware register maps. But there must be a volatile somewhere. – Lundin Jan 05 '22 at 17:28
  • 1
    Hi @Lundin, my question is more related on how to use the "egrep" option in Pc-lint. I know it is an advisory rule, and it will be waived, but to analyze in a better way my code I want to exclude useless warning. – buch Jan 07 '22 at 07:44

1 Answers1

0

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
Sercan
  • 4,739
  • 3
  • 17
  • 36
  • Since ST supposedly claims MISRA compliance, there should be documentation somewhere listing deviations or which advisory rules that were ignored. – Lundin Jan 05 '22 at 17:30