Skip to content

Commit

Permalink
Merge branch 'main' into feature/ble-out-of-band
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielsantosphilips authored Dec 16, 2024
2 parents 06bf735 + e2eca6b commit 24f3eac
Show file tree
Hide file tree
Showing 41 changed files with 963 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v5.5.0@sha256:7ae21bad4d2ad32497e8d395615742074598c829f5c0a575ebfc8cf35ea14a0e
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v5.5.1@sha256:d4c3ac71b832a967d5de37fa115679fc1c9f22313deac2d2bf8d8f575be85062

HEALTHCHECK NONE
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ jobs:
with:
configurePreset: "host"
buildPreset: "host-Debug-WithPackage"
#testPreset: "host"
testPreset: "host"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=sccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=sccache']"
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: hal_st
path: build/host/hal_st-*-Linux.tar.gz
if-no-files-found: error
#- name: Upload test logs
# if: ${{ failure() }}
# uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
# with:
# name: test-logs
# path: build/host/Testing/Temporary/
- name: Upload test logs
if: ${{ failure() }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: test-logs
path: build/host/Testing/Temporary/
host_build_test:
name: Host Build & Test
runs-on: ${{ matrix.os }}
Expand All @@ -58,14 +58,14 @@ jobs:
with:
configurePreset: "host-single-Debug"
buildPreset: "host-single-Debug"
#testPreset: "host-single-Debug"
testPreset: "host-single-Debug"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=sccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=sccache']"
#- name: Upload test logs
# if: ${{ failure() }}
# uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
# with:
# name: test-logs
# path: build/host/Testing/Temporary/
- name: Upload test logs
if: ${{ failure() }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: test-logs
path: build/host/Testing/Temporary/
embedded_build:
name: Embedded Build
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linting-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: oxsecurity/megalinter/flavors/c_cpp@d8c95fc6f2237031fb9e9322b0f97100168afa6e # v8.2.0
- uses: oxsecurity/megalinter/flavors/c_cpp@1fc052d03c7a43c78fe0fee19c9d648b749e0c01 # v8.3.0
env:
APPLY_FIXES: all
VALIDATE_ALL_CODEBASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: git diff
- uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
- uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
if: ${{ success() || failure() }}
with:
sarif_file: megalinter-reports/megalinter-report.sarif
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
results_format: sarif
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
publish_results: true
- uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
- uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
with:
sarif_file: scorecards.sarif
Empty file added .gitmodules
Empty file.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()

option(CMAKE_COMPILE_WARNING_AS_ERROR "Enable warnings-as-error" ON)
option(HALST_BUILD_TESTS "Enable building the tests" Off)
option(HALST_INCLUDE_DEFAULT_INIT "Include default initialization code; turn off when providing custom initialization" ON)
option(HALST_BUILD_EXAMPLES "Enable build of the examples" OFF)
option(HALST_BUILD_EXAMPLES_FREERTOS "Enable build of the FreeRTOS example" OFF)
set(HALST_XML_GPIO "" CACHE STRING "XML GPIO table")
set(HALST_XML_STM32 "" CACHE STRING "XML STM32 table")

if (HALST_BUILD_TESTS)
# CTest cannot be included before the first project() statement, but amp-embedded-infa-lib
# needs to see that test utilities need to be built.
set(BUILD_TESTING On)
endif()

if (HALST_STANDALONE)
set(EMIL_INCLUDE_FREERTOS ${HALST_BUILD_EXAMPLES_FREERTOS})

Expand Down Expand Up @@ -49,6 +56,11 @@ else()
set(HALST_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()

if (HALST_BUILD_TESTS)
include(CTest)
emil_enable_testing()
endif()

add_subdirectory(st)
add_subdirectory(hal_st)
add_subdirectory(hal_st_lwip)
Expand Down
9 changes: 5 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"inherits": "defaults",
"cacheVariables": {
"CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo;MinSizeRel",
"EMIL_BUILD_ECHO_COMPILERS": true,
"EMIL_FETCH_ECHO_COMPILERS": false
"HALST_BUILD_TESTS": true
},
"generator": "Ninja Multi-Config"
},
Expand All @@ -27,15 +26,17 @@
"displayName": "Configuration for Host Tooling and Tests, Single Config Generator, Debug",
"inherits": "defaults",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"HALST_BUILD_TESTS": true
}
},
{
"name": "host-single-MinSizeRel",
"displayName": "Configuration for Host Tooling and Tests, Single Config Generator, MinSizeRel",
"inherits": "defaults",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "MinSizeRel"
"CMAKE_BUILD_TYPE": "MinSizeRel",
"HALST_BUILD_TESTS": true
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions hal_st/cortex/InterruptCortex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace hal
}
else if (irq == -13 /*HardFault_IRQn*/)
;
else if (irq == NonMaskableInt_IRQn)
;
else if (irq == PendSV_IRQn)
;
else if (irq == SysTick_IRQn)
Expand Down
4 changes: 2 additions & 2 deletions hal_st/stm32fxxx/AdcDmaMultiChannelStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ namespace hal
auto result = HAL_ADCEx_Calibration_Start(&adc.Handle(), ADC_SINGLE_ENDED);
assert(result == HAL_OK);
#elif defined(IS_ADC_CALFACT)
auto result = HAL_ADCEx_Calibration_Start(&adc.Handle());
auto result = HAL_ADCEx_Calibration_Start(&adc.Handle());
assert(result == HAL_OK);
#endif

LL_ADC_REG_SetDMATransfer(adc.Handle().Instance, LL_ADC_REG_DMA_TRANSFER_LIMITED);
}

void AdcDmaMultiChannelStmBase::Measure(const infra::Function<void(infra::MemoryRange<uint16_t>)>& onDone)
void AdcDmaMultiChannelStmBase::Measure(const infra::Function<void(Samples)>& onDone)
{
this->onDone = onDone;

Expand Down
8 changes: 6 additions & 2 deletions hal_st/stm32fxxx/AdcDmaMultiChannelStm.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#ifndef HAL_ST_ADC_DMA_MULTI_CHANNEL_HPP
#define HAL_ST_ADC_DMA_MULTI_CHANNEL_HPP

#include "hal/interfaces/AdcMultiChannel.hpp"

Check failure on line 4 in hal_st/stm32fxxx/AdcDmaMultiChannelStm.hpp

View workflow job for this annotation

GitHub Actions / Embedded Build (RelWithDebInfo, 10.3-2021.10, stm32wb55)

hal/interfaces/AdcMultiChannel.hpp: No such file or directory
#include "hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp"
#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/GpioStm.hpp"
#include "infra/util/AutoResetFunction.hpp"
#include <array>
#include <cstddef>

/// @brief This ADC implementation supports multiple channels with DMA transfer and software trigger.
/// DMA transfer is one shot mode.
namespace hal
{
class AdcDmaMultiChannelStmBase
: public AdcMultiChannel
{
public:
AdcDmaMultiChannelStmBase(
infra::MemoryRange<uint16_t> buffer, infra::MemoryRange<AnalogPinStm> analogPins, AdcStm& adc,
DmaStm::ReceiveStream& receiveStream);

void Measure(const infra::Function<void(infra::MemoryRange<uint16_t>)>& onDone);
void Measure(const infra::Function<void(Samples)>& onDone) override;

constexpr static std::size_t MaxChannels{ 16 };

Expand All @@ -29,7 +33,7 @@ namespace hal
infra::MemoryRange<AnalogPinStm> analogPins;
AdcStm& adc;
ReceiveDmaChannel dmaStream;
infra::AutoResetFunction<void(infra::MemoryRange<uint16_t>)> onDone;
infra::AutoResetFunction<void(Samples)> onDone;

void TransferDone();
};
Expand Down
1 change: 1 addition & 0 deletions hal_st/stm32fxxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target_include_directories(hal_st.stm32fxxx PUBLIC
target_link_libraries(hal_st.stm32fxxx PUBLIC
hal.interfaces
infra.timer
services.util
st.hal_driver
hal_st.cortex
)
Expand Down
2 changes: 1 addition & 1 deletion hal_st/stm32fxxx/FlashInternalStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace hal
infra::EventDispatcher::Instance().Schedule(onDone);
}

FlashInternalStm::FlashInternalStm(infra::MemoryRange<uint32_t> sectorSizes, infra::ConstByteRange flashMemory)
FlashInternalStm::FlashInternalStm(infra::MemoryRange<const uint32_t> sectorSizes, infra::ConstByteRange flashMemory)
: FlashInternalStmBase(flashMemory)
, sectorSizes(sectorSizes)
{}
Expand Down
4 changes: 2 additions & 2 deletions hal_st/stm32fxxx/FlashInternalStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace hal
: public FlashInternalStmBase
{
public:
FlashInternalStm(infra::MemoryRange<uint32_t> sectorSizes, infra::ConstByteRange flashMemory);
FlashInternalStm(infra::MemoryRange<const uint32_t> sectorSizes, infra::ConstByteRange flashMemory);

uint32_t NumberOfSectors() const override;
uint32_t SizeOfSector(uint32_t sectorIndex) const override;
uint32_t SectorOfAddress(uint32_t address) const override;
uint32_t AddressOfSector(uint32_t sectorIndex) const override;

private:
infra::MemoryRange<uint32_t> sectorSizes;
infra::MemoryRange<const uint32_t> sectorSizes;
};

class FlashHomogeneousInternalStm
Expand Down
1 change: 1 addition & 0 deletions integration_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ add_subdirectory(logic)
add_subdirectory(tested)
add_subdirectory(tester)
add_subdirectory(runner)
add_subdirectory(flasher)
21 changes: 21 additions & 0 deletions integration_test/flasher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_executable(integration_test.flasher)
emil_build_for(integration_test.flasher HOST All)

target_sources(integration_test.flasher PRIVATE
Main.cpp
)

target_link_libraries(integration_test.flasher PRIVATE
args
integration_test.logic
hal.generic
services.network_instantiations
)

if (EMIL_BUILD_WIN)
target_link_libraries(integration_test.flasher PRIVATE hal.windows)
endif()

if (EMIL_BUILD_UNIX OR EMIL_BUILD_DARWIN)
target_link_libraries(integration_test.flasher PRIVATE hal.unix)
endif()
130 changes: 130 additions & 0 deletions integration_test/flasher/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "args.hxx"
#include "generated/echo/Testing.pb.hpp"
#include "generated/echo/TracingFlash.pb.hpp"
#include "generated/echo/TracingTesting.pb.hpp"
#include "hal/generic/FileSystemGeneric.hpp"
#include "hal/generic/TimerServiceGeneric.hpp"
#include "integration_test/logic/Flash.hpp"
#include "services/network_instantiations/EchoInstantiation.hpp"
#include "services/network_instantiations/NetworkAdapter.hpp"
#include "services/tracer/GlobalTracer.hpp"
#include "services/tracer/TracerOnIoOutputInfrastructure.hpp"

namespace
{
const std::array<uint32_t, 12> stm32f767SectorSizes{ { 32 * 1024,
32 * 1024,
32 * 1024,
32 * 1024,
128 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024 } };
}

class FirmwareSender
{
public:
FirmwareSender(const std::vector<uint8_t>& firmware, services::Echo& echo)
: firmware(firmware)
, flash(echo, infra::MakeRange(stm32f767SectorSizes))
, tester(echo)
{
tester.RequestSend([this]()
{
tester.SetTestedMode(testing::TestedMode::reset);
tester.RequestSend([this]()
{
tester.SetTestedMode(testing::TestedMode::programming);

services::GlobalTracer().Trace() << "Erasing chip...";
flash.EraseAll([this]()
{
services::GlobalTracer().Trace() << "Writing firmware...";
flash.WriteBuffer(infra::MakeRange(this->firmware), 0, [this]()
{
services::GlobalTracer().Trace() << "Uploading done";
done = true;
});
});
});
});
}

bool Done() const
{
return done;
}

private:
std::vector<uint8_t> firmware;
application::FlashProxy flash;
testing::TesterProxy tester;
bool done = false;

infra::TimerSingleShot timeoutTimer{ std::chrono::minutes(2), [this]()
{
done = true;
} };
};

struct FlashTracer
{
FlashTracer(services::TracingEchoOnStreams& echoTracer)
: testerTracer(echoTracer)
, testerObserverTracer(echoTracer)
, flashTracer(echoTracer)
, flashResultTracer(echoTracer)
{}

testing::TesterTracer testerTracer;
testing::TesterObserverTracer testerObserverTracer;
flash::FlashTracer flashTracer;
flash::FlashResultTracer flashResultTracer;
};

int main(int argc, char** argv)
{
args::ArgumentParser parser("Flasher");
args::Group positionals(parser, "Positional arguments:");
args::Positional<std::string> targetArgument(positionals, "target", "COM port or hostname", args::Options::Required);
args::Positional<std::string> firmwareArgument(positionals, "firmware", "Binary firmware with which the target attached to Postmaster is upgraded");
args::HelpFlag help(parser, "help", "display this help menu.", { 'h', "help" });

try
{
parser.ParseCLI(argc, argv);

static hal::TimerServiceGeneric timerService;
static main_::TracerOnIoOutputInfrastructure tracer;
static main_::NetworkAdapter network;
static hal::FileSystemGeneric fileSystem;

auto firmware = firmwareArgument ? fileSystem.ReadBinaryFile(args::get(firmwareArgument)) : std::vector<uint8_t>{};
auto [echo, echoTracer] = application::OpenTracingEcho(args::get(targetArgument), network.ConnectionFactoryWithNameResolver(), tracer.tracer);

FlashTracer flashTracer(*echoTracer);
FirmwareSender sender(firmware, *echo);

network.ExecuteUntil([&]()
{
return sender.Done();
});
}
catch (const args::Help&)
{
std::cout << parser;
return 1;
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
return 1;
}

return 0;
}
Loading

0 comments on commit 24f3eac

Please sign in to comment.