diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 968ee3ecf8..713dfae1c7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -100,7 +100,7 @@ jobs: - name: Build FW run: ${{ env.RUN }} "scons -j$(nproc)" - name: Run MISRA C:2012 analysis - timeout-minutes: 1 + timeout-minutes: 2 run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh" - name: MISRA mutation tests timeout-minutes: 4 diff --git a/board/drivers/uart.h b/board/drivers/uart.h index 01d8c2ac05..127a28dbd7 100644 --- a/board/drivers/uart.h +++ b/board/drivers/uart.h @@ -151,20 +151,6 @@ void print(const char *a) { } } -void putui(uint32_t i) { - uint32_t i_copy = i; - char str[11]; - uint8_t idx = 10; - str[idx] = '\0'; - idx--; - do { - str[idx] = (i_copy % 10U) + 0x30U; - idx--; - i_copy /= 10; - } while (i_copy != 0U); - print(&str[idx + 1U]); -} - void puthx(uint32_t i, uint8_t len) { const char c[] = "0123456789abcdef"; for (int pos = ((int)len * 4) - 4; pos > -4; pos -= 4) { diff --git a/board/drivers/watchdog.h b/board/drivers/watchdog.h index 89cf01e07e..e69de29bb2 100644 --- a/board/drivers/watchdog.h +++ b/board/drivers/watchdog.h @@ -1,24 +0,0 @@ -typedef enum { - WATCHDOG_50_MS = (400U - 1U), - WATCHDOG_500_MS = 4000U, -} WatchdogTimeout; - -void watchdog_feed(void) { - IND_WDG->KR = 0xAAAAU; -} - -void watchdog_init(WatchdogTimeout timeout) { - // enable watchdog - IND_WDG->KR = 0xCCCCU; - IND_WDG->KR = 0x5555U; - - // 32KHz / 4 prescaler = 8000Hz - register_set(&(IND_WDG->PR), 0x0U, IWDG_PR_PR_Msk); - register_set(&(IND_WDG->RLR), timeout, IWDG_RLR_RL_Msk); - - // wait for watchdog to be updated - while (IND_WDG->SR != 0U); - - // start the countdown - watchdog_feed(); -} diff --git a/board/jungle/main.c b/board/jungle/main.c index 0359be9684..3cf4be7db3 100644 --- a/board/jungle/main.c +++ b/board/jungle/main.c @@ -1,31 +1,30 @@ // ********************* Includes ********************* -#include "board/config.h" +#include "../config.h" -#include "board/safety.h" +#include "../safety.h" -#include "board/drivers/pwm.h" -#include "board/drivers/usb.h" +#include "../drivers/pwm.h" +#include "../drivers/usb.h" -#include "board/early_init.h" -#include "board/provision.h" +#include "../early_init.h" +#include "../provision.h" -#include "board/health.h" +#include "../health.h" #include "jungle_health.h" -#include "board/drivers/can_common.h" +#include "../drivers/can_common.h" #ifdef STM32H7 - #include "board/drivers/fdcan.h" + #include "../drivers/fdcan.h" #else - #include "board/drivers/bxcan.h" + #include "../drivers/bxcan.h" #endif -#include "board/obj/gitversion.h" +#include "../obj/gitversion.h" -#include "board/can_comms.h" +#include "../can_comms.h" #include "main_comms.h" - // ********************* Serial debugging ********************* void debug_ring_callback(uart_ring *ring) { diff --git a/board/stm32f4/lluart.h b/board/stm32f4/lluart.h index ffe7e74da0..02b54c9159 100644 --- a/board/stm32f4/lluart.h +++ b/board/stm32f4/lluart.h @@ -45,10 +45,6 @@ void uart_rx_ring(uart_ring *q){ EXIT_CRITICAL(); } -void uart_send_break(uart_ring *u) { - while ((u->uart->CR1 & USART_CR1_SBK) != 0); - u->uart->CR1 |= USART_CR1_SBK; -} // This read after reading SR clears all error interrupts. We don't want compiler warnings, nor optimizations #define UART_READ_DR(uart) volatile uint8_t t = (uart)->DR; UNUSED(t); @@ -78,8 +74,6 @@ void uart_interrupt_handler(uart_ring *q) { EXIT_CRITICAL(); } -void USART2_IRQ_Handler(void) { uart_interrupt_handler(&uart_ring_debug); } - // ***************************** Hardware setup ***************************** #define DIV_(_PCLK_, _BAUD_) (((_PCLK_) * 25U) / (4U * (_BAUD_))) diff --git a/board/stm32h7/lldac.h b/board/stm32h7/lldac.h index 5726f62413..e69de29bb2 100644 --- a/board/stm32h7/lldac.h +++ b/board/stm32h7/lldac.h @@ -1,42 +0,0 @@ -void dac_init(DAC_TypeDef *dac, uint8_t channel, bool dma) { - register_set(&dac->CR, 0U, 0xFFFFU); - register_set(&dac->MCR, 0U, 0xFFFFU); - - switch(channel) { - case 1: - if (dma) { - register_set_bits(&dac->CR, DAC_CR_DMAEN1); - // register_set(&DAC->CR, (6U << DAC_CR_TSEL1_Pos), DAC_CR_TSEL1); - register_set_bits(&dac->CR, DAC_CR_TEN1); - } else { - register_clear_bits(&dac->CR, DAC_CR_DMAEN1); - } - register_set_bits(&dac->CR, DAC_CR_EN1); - break; - case 2: - if (dma) { - register_set_bits(&dac->CR, DAC_CR_DMAEN2); - } else { - register_clear_bits(&dac->CR, DAC_CR_DMAEN2); - } - register_set_bits(&dac->CR, DAC_CR_EN2); - break; - default: - break; - } -} - -// Set channel 1 value, in mV -void dac_set(DAC_TypeDef *dac, uint8_t channel, uint32_t value) { - uint32_t raw_val = MAX(MIN(value * (1UL << 8U) / 3300U, (1UL << 8U)), 0U); - switch(channel) { - case 1: - register_set(&dac->DHR8R1, raw_val, 0xFFU); - break; - case 2: - register_set(&dac->DHR8R2, raw_val, 0xFFU); - break; - default: - break; - } -} diff --git a/tests/misra/suppressions.txt b/tests/misra/suppressions.txt index d5b14c836a..e13dbf7677 100644 --- a/tests/misra/suppressions.txt +++ b/tests/misra/suppressions.txt @@ -15,6 +15,8 @@ unmatchedSuppression # All interrupt handlers are defined, including ones we don't use unusedFunction:*/interrupt_handlers*.h +unknownMacro + # all of the below suppressions are from new checks introduced after updating # cppcheck from 2.5 -> 2.13. they are listed here to separate the update from # fixing the violations and all are intended to be removed soon after diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index 9fdbea1df7..2f6d6b0791 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -45,17 +45,22 @@ cppcheck() { fi } -PANDA_OPTS="--enable=all --disable=unusedFunction -DPANDA --addon=misra" +PANDA_OPTS="--enable=all --disable=unusedFunction -DPANDA -DUID_BASE --addon=misra" printf "\n${GREEN}** PANDA F4 CODE **${NC}\n" -cppcheck $PANDA_OPTS -DSTM32F4 -DUID_BASE $PANDA_DIR/board/main.c +cppcheck $PANDA_OPTS -DSTM32F4 $PANDA_DIR/board/main.c printf "\n${GREEN}** PANDA H7 CODE **${NC}\n" -cppcheck $PANDA_OPTS -DSTM32H7 -DUID_BASE $PANDA_DIR/board/main.c +cppcheck $PANDA_OPTS -DSTM32H7 $PANDA_DIR/board/main.c # unused needs to run globally -#printf "\n${GREEN}** UNUSED ALL CODE **${NC}\n" -#cppcheck --enable=unusedFunction --quiet $PANDA_DIR/board/ +UNUSED_FUNCTION_OPTS="--enable=unusedFunction --quiet -DPANDA -DFINAL_PROVISIONING" + +printf "\n${GREEN}** UNUSED H7 CODE **${NC}\n" +cppcheck $UNUSED_FUNCTION_OPTS -DSTM32H7 $(find $PANDA_DIR/board/ -type f -name '*.[ch]') + +printf "\n${GREEN}** UNUSED F4 CODE **${NC}\n" +cppcheck $UNUSED_FUNCTION_OPTS -DSTM32F4 $(find $PANDA_DIR/board/ -type f -name '*.[ch]') printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n" diff --git a/tests/misra/test_mutation.py b/tests/misra/test_mutation.py index 9e778e88b6..0858c5d71e 100755 --- a/tests/misra/test_mutation.py +++ b/tests/misra/test_mutation.py @@ -56,6 +56,8 @@ r"$a #define auto 1\n", # misra-c2012-20.5 r"$a #define TEST 1\n#undef TEST\n", + # unusedFunction + r"$a void test(void) {}", ] all_files = glob.glob('board/**', root_dir=ROOT, recursive=True)