Skip to content

Commit 0e34eeb

Browse files
fix: align flash writes to 16 bytes (#80)
* fix: align flash writes to 16 bytes * Wait for flash initialization done * FlexHttpClient: Move attaching of websocket * FirmwareReceptorResetTarget: Use timers instead of HAL_Delay * Set starting * Update container * Flush aligned buffer on end of reception * Reset when reception is completely stopped * Update amp-hal-st
1 parent f00cf1e commit 0e34eeb

21 files changed

+234
-53
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v6.0.1@sha256:0b238dbdd0e39a9704fc5317269f654b8bfd23868bad9491e806ae417d645352
1+
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v6.0.2@sha256:36afaaa5ba4bc4e9bb471012db9733c26a210e315ddb33600f73bb9532b02a25 # 6.0.2
22

33
HEALTHCHECK NONE

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- target: "stm32f407"
2626
configuration: "MinSizeRel"
2727
runs-on: [ubuntu-latest]
28-
container: ghcr.io/philips-software/amp-devcontainer-cpp:v5.6.1@sha256:04cda0c73cd01f0d97879aba7871c5118147ea0478616c49e8c0643653fbbc8b # 5.6.1
28+
container: ghcr.io/philips-software/amp-devcontainer-cpp:v6.0.2@sha256:36afaaa5ba4bc4e9bb471012db9733c26a210e315ddb33600f73bb9532b02a25 # 6.0.2
2929
steps:
3030
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
3131
if: ${{ matrix.target == 'windows' }}
@@ -34,7 +34,7 @@ jobs:
3434
path: /winsdk
3535
key: cache-winsdk
3636
- if: ${{ matrix.target == 'windows' && steps.cache-winsdk.outputs.cache-hit != 'true' }}
37-
run: xwin --accept-license splat --preserve-ms-arch-notation --include-debug-libs && mv .xwin-cache/splat/ /winsdk
37+
run: xwin --accept-license --sdk-version "10.0.26100" --crt-version "14.43.17.13" splat --preserve-ms-arch-notation --include-debug-libs && mv .xwin-cache/splat/ /winsdk
3838
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3939
with:
4040
persist-credentials: false

Dockerfile.flex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/philips-software/amp-devcontainer-cpp:5.1.4@sha256:46239906460dedb3baf3c33d9275f3de4f17d7a237fc136c2013b021589a6dbd AS builder
1+
FROM ghcr.io/philips-software/amp-devcontainer-cpp:v6.0.2@sha256:36afaaa5ba4bc4e9bb471012db9733c26a210e315ddb33600f73bb9532b02a25 AS builder
22

33
HEALTHCHECK NONE
44

postmaster/flex/FlexHttpClient.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ namespace application
5151
tracer.Trace() << infra::ByteRangeAsString(stream.ContiguousRange());
5252
}
5353

54+
void FlexHttpClient::BodyComplete()
55+
{
56+
inBodyComplete = true;
57+
HttpClientBasic::BodyComplete();
58+
inBodyComplete = false;
59+
}
60+
5461
void FlexHttpClient::Done()
5562
{
5663
tracer.Trace() << "Done";
57-
58-
httpClient->Attach(infra::UnOwnedSharedPtr(webSocketInitiation));
5964
}
6065

6166
void FlexHttpClient::Error(bool intermittentFailure)
@@ -69,5 +74,8 @@ namespace application
6974
void FlexHttpClient::CloseConnection()
7075
{
7176
Subject().Detach();
77+
78+
if (inBodyComplete)
79+
httpClient->Attach(infra::UnOwnedSharedPtr(webSocketInitiation));
7280
}
7381
}

postmaster/flex/FlexHttpClient.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace application
2121
void StatusAvailable(services::HttpStatusCode statusCode) override;
2222
void HeaderAvailable(services::HttpHeader header) override;
2323
void BodyAvailable(infra::SharedPtr<infra::StreamReader>&& reader);
24+
void BodyComplete() override;
2425
void Done() override;
2526
void Error(bool intermittentFailure) override;
2627
void CloseConnection() override;
@@ -32,6 +33,7 @@ namespace application
3233

3334
services::HttpClient* httpClient = nullptr;
3435
bool detached = false;
36+
bool inBodyComplete = false;
3537
};
3638
}
3739

postmaster/instantiations/TargetProgrammer.hpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#ifndef POSTMASTER_TARGET_PROGRAMMER_HPP
22
#define POSTMASTER_TARGET_PROGRAMMER_HPP
33

4+
#include "infra/event/EventDispatcher.hpp"
45
#include "infra/util/Function.hpp"
56
#include "postmaster/instantiations/UartCreator.hpp"
67
#include "postmaster/programmer/FirmwareReceptorReporting.hpp"
78
#include "postmaster/programmer/FirmwareReceptorResetTarget.hpp"
89
#include "postmaster/programmer/FirmwareReceptorToFlash.hpp"
10+
#include "postmaster/programmer/FlashAligner.hpp"
911
#include "postmaster/programmer/HttpPageFirmware.hpp"
1012
#include "services/st_util/FlashOnStBootloaderCommunicator.hpp"
1113
#include "services/st_util/StBootloaderCommunicatorUart.hpp"
@@ -21,7 +23,13 @@ namespace main_
2123
, firmwareReceptorReporting(receptorResetTarget, receiving)
2224
, stateCreator([this]() -> application::FirmwareReceptor&
2325
{
24-
state.Emplace(this->uartProgrammerCreator, infra::emptyFunction, [this](infra::BoundedConstString reason)
26+
really_assert(!state);
27+
state.Emplace(
28+
this->uartProgrammerCreator, [this]()
29+
{
30+
state->firmwareReceptorToFlash.FlashInitializationDone();
31+
},
32+
[this](infra::BoundedConstString reason)
2533
{
2634
this->page.Close();
2735
this->page.ResetReceptor(reason);
@@ -31,7 +39,13 @@ namespace main_
3139
},
3240
[this]()
3341
{
34-
state = infra::none;
42+
state->Stop();
43+
// The state is not destroyed immediately; any scheduled UART data must first be processed. By scheduling
44+
// this as an event, other events are first handled
45+
infra::EventDispatcher::Instance().Schedule([this]()
46+
{
47+
state = infra::none;
48+
});
3549
})
3650
{
3751
this->page.SetReceptor(firmwareReceptorReporting);
@@ -55,12 +69,21 @@ namespace main_
5569
, communicator(*serial, onInitialized, onError)
5670
{}
5771

72+
void Stop()
73+
{
74+
communicator.Stop();
75+
}
76+
5877
infra::ProxyCreator<UartCreator&> serial;
5978

6079
services::StBootloaderCommunicatorUart communicator;
6180
std::array<uint32_t, 12> sectors{ 0x8000, 0x8000, 0x8000, 0x8000, 0x20000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000 };
6281
services::FlashHeterogeneousOnStBootloaderCommunicator communicatorFlash{ sectors, communicator };
63-
application::FirmwareReceptorToFlash firmwareReceptorToFlash{ communicatorFlash };
82+
services::FlashAligner::WithAlignment<16> alignedFlash{ communicatorFlash };
83+
application::FirmwareReceptorToFlash firmwareReceptorToFlash{ alignedFlash, [this](const infra::Function<void()>& onDone)
84+
{
85+
alignedFlash.Flush(onDone);
86+
} };
6487
};
6588

6689
UartCreator& uartProgrammerCreator;

postmaster/programmer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ target_sources(postmaster.programmer PRIVATE
1515
FirmwareReceptorResetWhenDone.hpp
1616
FirmwareReceptorToFlash.cpp
1717
FirmwareReceptorToFlash.hpp
18+
FlashAligner.cpp
19+
FlashAligner.hpp
1820
HttpPageFirmware.cpp
1921
HttpPageFirmware.hpp
2022
TargetUartConnection.cpp

postmaster/programmer/FirmwareReceptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace application
1717
public:
1818
virtual void ReceptionStarted() = 0;
1919
virtual void DataReceived(infra::SharedPtr<infra::StreamReaderWithRewinding>&& reader) = 0;
20-
virtual void ReceptionStopped() = 0;
20+
virtual void ReceptionStopped(const infra::Function<void()>& onDone) = 0;
2121
};
2222
}
2323

0 commit comments

Comments
 (0)