Skip to content

Fix #236: add basic mechanism for flash-based mfg data #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CatenaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Copyright notice:
#define CATENA_ARDUINO_PLATFORM_VERSION_CALC(major, minor, patch, local) \
(((major) << 24u) | ((minor) << 16u) | ((patch) << 8u) | (local))

#define CATENA_ARDUINO_PLATFORM_VERSION CATENA_ARDUINO_PLATFORM_VERSION_CALC(0, 17, 0, 50) /* v0.17.0.50 */
#define CATENA_ARDUINO_PLATFORM_VERSION CATENA_ARDUINO_PLATFORM_VERSION_CALC(0, 17, 0, 60) /* v0.17.0.60 */

#define CATENA_ARDUINO_PLATFORM_VERSION_GET_MAJOR(v) \
(((v) >> 24u) & 0xFFu)
Expand Down
114 changes: 114 additions & 0 deletions src/Catena_FlashParam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*

Name: Catena_FlashParam.h

Function:
Layout of the flash parameter page for MCCI Catena devices.

Copyright and License:
See accompanying LICENSE file for copyright and license information.

Author:
Terry Moore, MCCI Corporation December 2019

*/

#ifndef _Catena_FlashParam_h_
#define _Catena_FlashParam_h_

#include <cstdint>
#include <cstring>
#include <mcciadk_guid.h>

namespace McciCatena {

class FlashParamsStm32L0_t
{
public:
// address of first byte in flash
static constexpr std::uint32_t kFlashBase = 0x08000000;
// address of last byte in flash
static constexpr std::uint32_t kFlashTop = 0x0802FFFF;
// number of bytes in a protection page
static constexpr std::uint32_t kFlashSectorSize = 0x1000;
// number of bytes in a paramter page
static constexpr unsigned kFlashPageSize = 128;
// {b39bc7ac-3e7a-4ac8-92a3-d9535dc6a123}
static const MCCIADK_GUID_WIRE kPageEndSignature1_Guid;
static constexpr std::uint32_t getU32(const std::uint8_t *p) { return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); }
static void putU32(std::uint8_t *p, std::uint32_t v)
{
p[0] = std::uint8_t(v >> 0);
p[1] = std::uint8_t(v >> 8);
p[2] = std::uint8_t(v >> 16);
p[3] = std::uint8_t(v >> 24);
}

// common layout for any descriptor.
struct ParamDesc_t
{
std::uint8_t uLen; // the length of this item
std::uint8_t uType; // the type of this item
};

// the end-of-memory signature.
struct PageEndSignature1_t
{
std::uint8_t ParamPointer[4]; // byte pointer to parameter; little-endiand
MCCIADK_GUID_WIRE Guid; // identification of the page -- kGuid.

std::uint32_t getParamPointer() const
{
return getU32(this->ParamPointer);
}

void setParamPointer(std::uint32_t ptr)
{
putU32(this->ParamPointer, ptr);
}

static constexpr bool isValidParamPointer(std::uint32_t p)
{
return (kFlashBase <= p && p < kPageEndSignature1Address - sizeof(ParamDesc_t));
}
};

static constexpr std::uint32_t kPageEndSignature1Address = kFlashTop + 1 - sizeof(PageEndSignature1_t);

enum class ParamDescId : std::uint8_t
{
Board = 1, // this is a board descriptor.
};

struct ParamBoard_t : public ParamDesc_t
{
std::uint8_t SerialNumber[8]; // the serial number for this device
std::uint8_t Model[4]; // the model ID for this device.
std::uint8_t ECN[4]; // ECN info for this device.

std::uint32_t getModel() const { return getU32(this->Model); }
std::uint32_t getECN() const { return getU32(this->ECN); }

void setModel(std::uint32_t model)
{
putU32(this->Model, model);
}
void setECN(std::uint32_t ecn)
{
putU32(this->ECN, ecn);
}
void getSerialNumber(std::uint8_t mySerial[8]) const
{
std::memcpy(mySerial, this->SerialNumber, sizeof(this->SerialNumber));
}
void setSerialNumber(const std::uint8_t mySerial[8])
{
std::memcpy(this->SerialNumber, mySerial, sizeof(this->SerialNumber));
}
};

};

} // namespace McciCatena

#endif // _Catena_FlashParam_h_
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*

Name: CatenaStm32L0_FlashParams_kPageEndSignature1_Guid.cpp

Function:
Defines the value of the page-end signature GUID.

Copyright and License:
See accompanying LICENSE file for copyright and license information.

Author:
Terry Moore, MCCI Corporation Demember 2019

*/

#include <Catena_FlashParam.h>
#include <mcciadk_baselib.h>

using namespace McciCatena;

#ifdef ARDUINO_ARCH_STM32

const MCCIADK_GUID_WIRE FlashParamsStm32L0_t::kPageEndSignature1_Guid
{
MCCIADK_GUID_BYTES_INIT(0xb39bc7ac, 0x3e7a, 0x4ac8, 0x92, 0xa3, 0xd9, 0x53, 0x5d, 0xc6, 0xa1, 0x23)
};

#endif