Skip to content

Commit

Permalink
[ext] fix example undefined behavior type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
hshose committed Mar 20, 2024
1 parent 907aa6b commit 77a2df1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions examples/nucleo_g474re/json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ main()

// put BSON in reserved flash
uint32_t err{0};
const size_t page_start = Flash::getPage(reinterpret_cast<uint32_t>(&__flash_reserved_start)) + 1;
const size_t page_start =
Flash::getPage(reinterpret_cast<uint32_t>(&__flash_reserved_start));
const size_t num_bytes = alice_binary.size();
const size_t flash_page_size = Flash::getSize(page_start);
const size_t end_page = page_start + (num_bytes + flash_page_size - 1) / flash_page_size;
Expand Down Expand Up @@ -144,12 +145,12 @@ main()
<< ", num of bytes (payload): " << unpadded_size
<< ", num of bytes (padded): " << alice_binary.size() << "... ";

for (uint32_t src_addr = reinterpret_cast<uint32_t>(&alice_binary[0]),
dst_addr{reinterpret_cast<uint32_t>(Flash::getAddr(page_start))};
src_addr < (reinterpret_cast<uint32_t>(&alice_binary[0]) + alice_binary.size());
src_addr += sizeof(Flash::MaxWordType), dst_addr += sizeof(Flash::MaxWordType))
const auto flash_write_base_addr{reinterpret_cast<uint32_t>(Flash::getAddr(page_start))};
for (size_t ii = 0; ii < alice_binary.size(); ii += sizeof(Flash::MaxWordType))
{
err |= Flash::program(dst_addr, *(Flash::MaxWordType*)src_addr);
Flash::MaxWordType outdata;
memcpy(&outdata, &alice_binary[ii], sizeof(Flash::MaxWordType));
err |= Flash::program(flash_write_base_addr + ii, outdata);
}
if (err != 0)
{
Expand All @@ -161,7 +162,8 @@ main()
MODM_LOG_INFO.flush();

// we can now read BSON back from flash, first 4 bytes entry is the size
uint32_t read_len = *(reinterpret_cast<uint32_t*>(Flash::getAddr(page_start)));
uint32_t read_len;
memcpy(&read_len, Flash::getAddr(page_start), sizeof(read_len));

// read the actual data
MODM_LOG_INFO << "\nReading BSON of size " << read_len << " from flash: ";
Expand Down
4 changes: 2 additions & 2 deletions src/modm/platform/core/cortex/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def prepare(module, options):
minimum=0,
maximum=hex(flash_size),
default=0))

module.add_option(
NumericOption(
name="linkerscript.flash_reserved",
Expand Down Expand Up @@ -311,7 +311,7 @@ def validate(env):
.format(flash_offset_option_name,
flash_offset,
bit_alignment))

flash_size = env.get(":platform:core:boot2_size", 0)
flash_reserved_option_name = "modm:platform:cortex-m:linkerscript.flash_reserved"
flash_reserved = env[flash_reserved_option_name]
Expand Down

0 comments on commit 77a2df1

Please sign in to comment.