From 31ff4a0bb585d7dbd56cd90264fd4a42d03a10eb Mon Sep 17 00:00:00 2001 From: dzid26 Date: Tue, 4 Jun 2024 14:38:46 +0100 Subject: [PATCH] enable unusedFunction per build - Bootstub --- board/drivers/clock_source.h | 2 + board/drivers/harness.h | 2 + board/drivers/registers.h | 5 +- board/drivers/timers.h | 12 +- board/drivers/usb.h | 4 + board/faults.h | 2 + board/jungle/main.c | 2 +- board/main.c | 2 +- board/stm32f4/board.h | 3 + board/stm32f4/lladc.h | 2 + board/stm32f4/stm32f4_config.h | 2 +- board/stm32h7/board.h | 2 + board/stm32h7/lladc.h | 2 + tests/misra/checkers.txt | 234 +++++++++++++++++++++++++++++++++ tests/misra/test_misra.sh | 2 +- 15 files changed, 267 insertions(+), 11 deletions(-) diff --git a/board/drivers/clock_source.h b/board/drivers/clock_source.h index 5d6fdc8a77b..b3833797188 100644 --- a/board/drivers/clock_source.h +++ b/board/drivers/clock_source.h @@ -1,9 +1,11 @@ #define CLOCK_SOURCE_PERIOD_MS 50U #define CLOCK_SOURCE_PULSE_LEN_MS 2U +#ifndef BOOTSTUB void clock_source_set_period(uint8_t period) { register_set(&(TIM1->ARR), ((period*10U) - 1U), 0xFFFFU); } +#endif void clock_source_init(void) { // Setup timer diff --git a/board/drivers/harness.h b/board/drivers/harness.h index f8f0ccb7d38..c555260d4c8 100644 --- a/board/drivers/harness.h +++ b/board/drivers/harness.h @@ -112,9 +112,11 @@ uint8_t harness_detect_orientation(void) { return ret; } +#ifndef BOOTSTUB void harness_tick(void) { harness.status = harness_detect_orientation(); } +#endif void harness_init(void) { // try to detect orientation diff --git a/board/drivers/registers.h b/board/drivers/registers.h index 5d5a4257d77..fc1ebe0964c 100644 --- a/board/drivers/registers.h +++ b/board/drivers/registers.h @@ -53,8 +53,8 @@ void register_clear_bits(volatile uint32_t *addr, uint32_t val) { register_set(addr, (~val), val); } -// To be called periodically -void check_registers(void){ +#ifndef BOOTSTUB +void check_registers_tick(void){ for(uint16_t i=0U; iPSC), (psc-1), 0xFFFFU); register_set(&(TIM->DIER), TIM_DIER_UIE, 0x5F5FU); @@ -5,11 +6,17 @@ void timer_init(TIM_TypeDef *TIM, int psc) { TIM->SR = 0; } +void tick_timer_init(void) { + timer_init(TICK_TIMER, (uint16_t)((15.25*APB2_TIMER_FREQ)/8U)); + NVIC_EnableIRQ(TICK_TIMER_IRQ); +} + void microsecond_timer_init(void) { MICROSECOND_TIMER->PSC = (APB1_TIMER_FREQ - 1U); MICROSECOND_TIMER->CR1 = TIM_CR1_CEN; MICROSECOND_TIMER->EGR = TIM_EGR_UG; } +#endif uint32_t microsecond_timer_get(void) { return MICROSECOND_TIMER->CNT; @@ -24,8 +31,3 @@ void interrupt_timer_init(void) { INTERRUPT_TIMER->SR = 0; NVIC_EnableIRQ(INTERRUPT_TIMER_IRQ); } - -void tick_timer_init(void) { - timer_init(TICK_TIMER, (uint16_t)((15.25*APB2_TIMER_FREQ)/8U)); - NVIC_EnableIRQ(TICK_TIMER_IRQ); -} diff --git a/board/drivers/usb.h b/board/drivers/usb.h index a719910d777..39c79c42310 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -464,11 +464,13 @@ char to_hex_char(uint8_t a) { return ret; } +#ifndef BOOTSTUB void usb_tick(void) { uint16_t current_frame_num = (USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF_Msk) >> USB_OTG_DSTS_FNSOF_Pos; usb_enumerated = (current_frame_num != usb_last_frame_num); usb_last_frame_num = current_frame_num; } +#endif void usb_setup(void) { int resp_len; @@ -906,6 +908,7 @@ void usb_irqhandler(void) { //USBx->GINTMSK = 0xFFFFFFFF & ~(USB_OTG_GINTMSK_NPTXFEM | USB_OTG_GINTMSK_PTXFEM | USB_OTG_GINTSTS_SOF | USB_OTG_GINTSTS_EOPF); } +#ifndef BOOTSTUB void can_tx_comms_resume_usb(void) { ENTER_CRITICAL(); if (!outep3_processing && (USBx_OUTEP(3U)->DOEPCTL & USB_OTG_DOEPCTL_NAKSTS) != 0U) { @@ -914,3 +917,4 @@ void can_tx_comms_resume_usb(void) { } EXIT_CRITICAL(); } +#endif diff --git a/board/faults.h b/board/faults.h index dc6c1f2aa40..6b4ce2d5a4b 100644 --- a/board/faults.h +++ b/board/faults.h @@ -50,6 +50,7 @@ void fault_occurred(uint32_t fault) { faults |= fault; } +#ifndef BOOTSTUB void fault_recovered(uint32_t fault) { if ((PERMANENT_FAULTS & fault) == 0U) { faults &= ~fault; @@ -57,3 +58,4 @@ void fault_recovered(uint32_t fault) { print("Cannot recover from a permanent fault!\n"); } } +#endif diff --git a/board/jungle/main.c b/board/jungle/main.c index f8e3cfcb8be..82a9820d624 100644 --- a/board/jungle/main.c +++ b/board/jungle/main.c @@ -85,7 +85,7 @@ void tick_handler(void) { current_board->board_tick(); // check registers - check_registers(); + check_registers_tick(); // turn off the blue LED, turned on by CAN current_board->set_led(LED_BLUE, false); diff --git a/board/main.c b/board/main.c index 4bd784bf0a8..f13dc2127ec 100644 --- a/board/main.c +++ b/board/main.c @@ -269,7 +269,7 @@ void tick_handler(void) { } // check registers - check_registers(); + check_registers_tick(); // set ignition_can to false after 2s of no CAN seen if (ignition_can_cnt > 2U) { diff --git a/board/stm32f4/board.h b/board/stm32f4/board.h index bf95d58eaa9..24dcb6c7e9b 100644 --- a/board/stm32f4/board.h +++ b/board/stm32f4/board.h @@ -7,8 +7,11 @@ // ///// Board definition and detection ///// // #include "stm32f4/lladc.h" #include "drivers/harness.h" + +#ifndef BOOTSTUB #include "drivers/fan.h" #include "stm32f4/llfan.h" +#endif #include "drivers/clock_source.h" #include "boards/white.h" #include "boards/grey.h" diff --git a/board/stm32f4/lladc.h b/board/stm32f4/lladc.h index c2df10f1b18..71a7940b2dd 100644 --- a/board/stm32f4/lladc.h +++ b/board/stm32f4/lladc.h @@ -1,11 +1,13 @@ void register_set(volatile uint32_t *addr, uint32_t val, uint32_t mask); +#ifndef BOOTSTUB void adc_init(void) { register_set(&(ADC->CCR), ADC_CCR_TSVREFE | ADC_CCR_VBATE, 0xC30000U); register_set(&(ADC1->CR2), ADC_CR2_ADON, 0xFF7F0F03U); register_set(&(ADC1->SMPR1), ADC_SMPR1_SMP12 | ADC_SMPR1_SMP13, 0x7FFFFFFU); } +#endif uint16_t adc_get_raw(uint8_t channel) { // Select channel diff --git a/board/stm32f4/stm32f4_config.h b/board/stm32f4/stm32f4_config.h index ffca898c5de..e9f793baa3f 100644 --- a/board/stm32f4/stm32f4_config.h +++ b/board/stm32f4/stm32f4_config.h @@ -61,7 +61,7 @@ #include "stm32f4/llspi.h" #endif -#if !defined(BOOTSTUB) +#ifndef BOOTSTUB #include "drivers/uart.h" #include "stm32f4/lluart.h" #endif diff --git a/board/stm32h7/board.h b/board/stm32h7/board.h index c8e6f3a9689..8cb10ca99e1 100644 --- a/board/stm32h7/board.h +++ b/board/stm32h7/board.h @@ -7,8 +7,10 @@ // ///// Board definition and detection ///// // #include "stm32h7/lladc.h" #include "drivers/harness.h" +#ifndef BOOTSTUB #include "drivers/fan.h" #include "stm32h7/llfan.h" +#endif #include "drivers/fake_siren.h" #include "drivers/clock_source.h" #include "boards/red.h" diff --git a/board/stm32h7/lladc.h b/board/stm32h7/lladc.h index 7d818f27af1..dc86bf2f045 100644 --- a/board/stm32h7/lladc.h +++ b/board/stm32h7/lladc.h @@ -1,4 +1,5 @@ +#ifndef BOOTSTUB void adc_init(void) { ADC1->CR &= ~(ADC_CR_DEEPPWD); //Reset deep-power-down mode ADC1->CR |= ADC_CR_ADVREGEN; // Enable ADC regulator @@ -13,6 +14,7 @@ void adc_init(void) { ADC1->CR |= ADC_CR_ADEN; while(!(ADC1->ISR & ADC_ISR_ADRDY)); } +#endif uint16_t adc_get_raw(uint8_t channel) { uint16_t res = 0U; diff --git a/tests/misra/checkers.txt b/tests/misra/checkers.txt index 6bfaf032d45..5394415ca35 100644 --- a/tests/misra/checkers.txt +++ b/tests/misra/checkers.txt @@ -1099,3 +1099,237 @@ Not available, Cppcheck Premium is not used Misra C++ 2023 -------------- Not available, Cppcheck Premium is not used + + + + + +TEST variant options: +--enable=unusedFunction --suppress=unknownMacro --force -UDEBUG -UDEBUG_COMMS -UDEBUG_FAULTS -UDEBUG_FAN -UDEBUG_SPI -UDEBUG_UART -UDEBUG_USB /board/bootstub.c + + +Critical errors +--------------- +No critical errors, all files were checked. +Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives. + + +Open source checkers +-------------------- +No Check64BitPortability::pointerassignment require:portability +No CheckAssert::assertWithSideEffects require:warning +No CheckAutoVariables::assignFunctionArg require:style,warning +Yes CheckAutoVariables::autoVariables +Yes CheckAutoVariables::checkVarLifetime +No CheckBool::checkAssignBoolToFloat require:style,c++ +Yes CheckBool::checkAssignBoolToPointer +No CheckBool::checkBitwiseOnBoolean require:style,inconclusive +No CheckBool::checkComparisonOfBoolExpressionWithInt require:warning +No CheckBool::checkComparisonOfBoolWithBool require:style,c++ +No CheckBool::checkComparisonOfBoolWithInt require:warning,c++ +No CheckBool::checkComparisonOfFuncReturningBool require:style,c++ +No CheckBool::checkIncrementBoolean require:style +Yes CheckBool::pointerArithBool +No CheckBool::returnValueOfFunctionReturningBool require:style +No CheckBoost::checkBoostForeachModification +Yes CheckBufferOverrun::analyseWholeProgram +No CheckBufferOverrun::argumentSize require:warning +Yes CheckBufferOverrun::arrayIndex +No CheckBufferOverrun::arrayIndexThenCheck +Yes CheckBufferOverrun::bufferOverflow +Yes CheckBufferOverrun::negativeArraySize +Yes CheckBufferOverrun::objectIndex +No CheckBufferOverrun::pointerArithmetic require:portability +No CheckBufferOverrun::stringNotZeroTerminated require:warning,inconclusive +Yes CheckClass::analyseWholeProgram +No CheckClass::checkConst require:style,inconclusive +No CheckClass::checkConstructors require:style,warning +No CheckClass::checkCopyConstructors require:warning +No CheckClass::checkDuplInheritedMembers require:warning +No CheckClass::checkExplicitConstructors require:style +No CheckClass::checkMemset +No CheckClass::checkMissingOverride require:style,c++03 +No CheckClass::checkReturnByReference require:performance +No CheckClass::checkSelfInitialization +No CheckClass::checkThisUseAfterFree require:warning +No CheckClass::checkUnsafeClassRefMember require:warning,safeChecks +No CheckClass::checkUselessOverride require:style +No CheckClass::checkVirtualFunctionCallInConstructor require:warning +No CheckClass::initializationListUsage require:performance +No CheckClass::initializerListOrder require:style,inconclusive +No CheckClass::operatorEqRetRefThis require:style +No CheckClass::operatorEqToSelf require:warning +No CheckClass::privateFunctions require:style +No CheckClass::thisSubtraction require:warning +No CheckClass::virtualDestructor +No CheckCondition::alwaysTrueFalse require:style +No CheckCondition::assignIf require:style +No CheckCondition::checkAssignmentInCondition require:style +No CheckCondition::checkBadBitmaskCheck require:style +No CheckCondition::checkCompareValueOutOfTypeRange require:style,platform +No CheckCondition::checkDuplicateConditionalAssign require:style +No CheckCondition::checkIncorrectLogicOperator require:style,warning +No CheckCondition::checkInvalidTestForOverflow require:warning +No CheckCondition::checkModuloAlwaysTrueFalse require:warning +No CheckCondition::checkPointerAdditionResultNotNull require:warning +No CheckCondition::clarifyCondition require:style +No CheckCondition::comparison require:style +No CheckCondition::duplicateCondition require:style +No CheckCondition::multiCondition require:style +No CheckCondition::multiCondition2 require:warning +No CheckExceptionSafety::checkCatchExceptionByValue require:style +No CheckExceptionSafety::checkRethrowCopy require:style +No CheckExceptionSafety::deallocThrow require:warning +No CheckExceptionSafety::destructors require:warning +No CheckExceptionSafety::nothrowThrows +No CheckExceptionSafety::rethrowNoCurrentException +No CheckExceptionSafety::unhandledExceptionSpecification require:style,inconclusive +No CheckFunctions::checkIgnoredReturnValue require:style,warning +No CheckFunctions::checkMathFunctions require:style,warning,c99,c++11 +Yes CheckFunctions::checkMissingReturn +Yes CheckFunctions::checkProhibitedFunctions +Yes CheckFunctions::invalidFunctionUsage +No CheckFunctions::memsetInvalid2ndParam require:warning,portability +No CheckFunctions::memsetZeroBytes require:warning +No CheckFunctions::returnLocalStdMove require:performance,c++11 +No CheckFunctions::useStandardLibrary require:style +No CheckIO::checkCoutCerrMisusage require:c +Yes CheckIO::checkFileUsage +Yes CheckIO::checkWrongPrintfScanfArguments +No CheckIO::invalidScanf +Yes CheckLeakAutoVar::check +No CheckMemoryLeakInClass::check +Yes CheckMemoryLeakInFunction::checkReallocUsage +Yes CheckMemoryLeakNoVar::check +No CheckMemoryLeakNoVar::checkForUnsafeArgAlloc +Yes CheckMemoryLeakStructMember::check +Yes CheckNullPointer::analyseWholeProgram +Yes CheckNullPointer::arithmetic +Yes CheckNullPointer::nullConstantDereference +Yes CheckNullPointer::nullPointer +No CheckOther::checkAccessOfMovedVariable require:c++11,warning +No CheckOther::checkCastIntToCharAndBack require:warning +No CheckOther::checkCharVariable require:warning,portability +Yes CheckOther::checkComparePointers +No CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse require:warning +No CheckOther::checkConstPointer require:style +No CheckOther::checkConstVariable require:style,c++ +No CheckOther::checkDuplicateBranch require:style,inconclusive +No CheckOther::checkDuplicateExpression require:style,warning +Yes CheckOther::checkEvaluationOrder +No CheckOther::checkFuncArgNamesDifferent require:style,warning,inconclusive +No CheckOther::checkIncompleteArrayFill require:warning,portability,inconclusive +No CheckOther::checkIncompleteStatement require:warning +No CheckOther::checkInterlockedDecrement require:windows-platform +Yes CheckOther::checkInvalidFree +No CheckOther::checkKnownArgument require:style +No CheckOther::checkKnownPointerToBool require:style +No CheckOther::checkMisusedScopedObject require:style,c++ +No CheckOther::checkModuloOfOne require:style +No CheckOther::checkNanInArithmeticExpression require:style +Yes CheckOther::checkNegativeBitwiseShift +Yes CheckOther::checkOverlappingWrite +No CheckOther::checkPassByReference require:performance,c++ +No CheckOther::checkRedundantAssignment require:style +No CheckOther::checkRedundantCopy require:c++,performance,inconclusive +No CheckOther::checkRedundantPointerOp require:style +No CheckOther::checkShadowVariables require:style +No CheckOther::checkSignOfUnsignedVariable require:style +No CheckOther::checkSuspiciousCaseInSwitch require:warning,inconclusive +No CheckOther::checkSuspiciousSemicolon require:warning,inconclusive +No CheckOther::checkUnreachableCode require:style +No CheckOther::checkUnusedLabel require:style,warning +No CheckOther::checkVarFuncNullUB require:portability +No CheckOther::checkVariableScope require:style,notclang +Yes CheckOther::checkZeroDivision +No CheckOther::clarifyCalculation require:style +No CheckOther::clarifyStatement require:warning +No CheckOther::invalidPointerCast require:portability +No CheckOther::redundantBitwiseOperationInSwitch require:warning +No CheckOther::warningOldStylePointerCast require:style,c++ +No CheckPostfixOperator::postfixOperator require:performance +No CheckSizeof::checkSizeofForArrayParameter require:warning +No CheckSizeof::checkSizeofForNumericParameter require:warning +No CheckSizeof::checkSizeofForPointerSize require:warning +No CheckSizeof::sizeofCalculation require:warning +No CheckSizeof::sizeofFunction require:warning +No CheckSizeof::sizeofVoid require:portability +No CheckSizeof::sizeofsizeof require:warning +No CheckSizeof::suspiciousSizeofCalculation require:warning,inconclusive +No CheckStl::checkDereferenceInvalidIterator require:warning +No CheckStl::checkDereferenceInvalidIterator2 +No CheckStl::checkFindInsert require:performance +No CheckStl::checkMutexes require:warning +No CheckStl::erase +No CheckStl::eraseIteratorOutOfBounds +No CheckStl::if_find require:warning,performance +No CheckStl::invalidContainer +No CheckStl::iterators +No CheckStl::knownEmptyContainer require:style +No CheckStl::misMatchingContainerIterator +No CheckStl::misMatchingContainers +No CheckStl::missingComparison require:warning +No CheckStl::negativeIndex +No CheckStl::outOfBounds +No CheckStl::outOfBoundsIndexExpression +No CheckStl::redundantCondition require:style +No CheckStl::size require:performance,c++03 +No CheckStl::stlBoundaries +No CheckStl::stlOutOfBounds +No CheckStl::string_c_str +No CheckStl::useStlAlgorithm require:style +No CheckStl::uselessCalls require:performance,warning +No CheckString::checkAlwaysTrueOrFalseStringCompare require:warning +No CheckString::checkIncorrectStringCompare require:warning +No CheckString::checkSuspiciousStringCompare require:warning +No CheckString::overlappingStrcmp require:warning +Yes CheckString::sprintfOverlappingData +Yes CheckString::strPlusChar +Yes CheckString::stringLiteralWrite +Yes CheckType::checkFloatToIntegerOverflow +Yes CheckType::checkIntegerOverflow +No CheckType::checkLongCast require:style +No CheckType::checkSignConversion require:warning +Yes CheckType::checkTooBigBitwiseShift +Yes CheckUninitVar::check +Yes CheckUninitVar::valueFlowUninit +Yes CheckUnusedFunctions::check +No CheckUnusedVar::checkFunctionVariableUsage require:style +No CheckUnusedVar::checkStructMemberUsage require:style +Yes CheckVaarg::va_list_usage +Yes CheckVaarg::va_start_argument + + +Premium checkers +---------------- +Not available, Cppcheck Premium is not used + + +Autosar +------- +Not available, Cppcheck Premium is not used + + +Cert C +------ +Not available, Cppcheck Premium is not used + + +Cert C++ +-------- +Not available, Cppcheck Premium is not used + + +Misra C +------- +Misra is not enabled + + +Misra C++ 2008 +-------------- +Not available, Cppcheck Premium is not used + + +Misra C++ 2023 +-------------- +Not available, Cppcheck Premium is not used diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index b2bf631033c..7b8dc444f2f 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -77,7 +77,7 @@ UNUSED_FUNCTION_OPTS="--enable=unusedFunction --suppress=unknownMacro --force $U printf "\n${GREEN}** unusedFunctions **${NC}\n" cppcheck $UNUSED_FUNCTION_OPTS $PANDA_DIR/board/main.c -DPANDA -UBOOTSTUB -UPANDA_JUNGLE -# cppcheck $UNUSED_FUNCTION_OPTS $PANDA_DIR/board/bootstub.c +cppcheck $UNUSED_FUNCTION_OPTS $PANDA_DIR/board/bootstub.c # cppcheck $UNUSED_FUNCTION_OPTS $PANDA_DIR/board/jungle/main.c