API Reference¶
Complete reference for all EmbSec SDK functions, organized by module.
Core Functions¶
System Initialization¶
Initialize the EmbSec environment. Must be called before using any other SDK functions.- Configures system clock to 80MHz
- Initializes UART0 for console I/O (115200 baud)
- Sets up SysTick timer
- Configures basic GPIO
- Returns:
trueif initialized,falseotherwise
System Control¶
Perform a software reset of the microcontroller. Enable interrupts globally. Disable interrupts globally. Memory barrier to ensure all memory operations complete before continuing.Timing¶
Get system tick count in milliseconds since boot. Delay for specified milliseconds (blocking).Version¶
Get SDK version string in format "major.minor.patch".UART Functions¶
Basic I/O¶
Initialize UART for console I/O (called byembsec_init()). Send a single character to UART. Get a single character from UART (blocking). Check if a character is available. String I/O¶
Send a null-terminated string to UART. Get a line of input from UART.- Reads until newline or buffer full
- Null-terminates the string
- Newline not included in buffer
- Returns: Pointer to buffer on success, NULL on error
Formatted I/O¶
Printf-style formatted output.- Returns: Number of characters printed
- Returns: Number of characters printed
Buffer Management¶
Flush UART transmit buffer (wait until all data transmitted). Clear UART receive buffer (discard pending data).GPIO Functions¶
Pin Configuration¶
Initialize GPIO for LEDs and switches (called byembsec_init()). Configure a GPIO pin. port: GPIO port ('A' through 'F')pin: Pin mask (e.g., 0x01 for pin 0)dir: Direction (EMBSEC_GPIO_INPUT or EMBSEC_GPIO_OUTPUT)
Pin Operations¶
Write to a GPIO pin.value:truefor high,falsefor low
- Returns:
trueif high,falseif low
LED Control¶
Control onboard LEDs.led: LED mask (EMBSEC_LED_RED, EMBSEC_LED_BLUE, EMBSEC_LED_GREEN)on:trueto turn on,falseto turn off
Switch Input¶
Read switch state.sw: Switch mask (EMBSEC_SW1 or EMBSEC_SW2)- Returns:
trueif pressed,falseif released
Timer Functions¶
Millisecond Timing¶
Initialize timer subsystem (called byembsec_init()). Get milliseconds since system start (wraps after ~49 days). Non-blocking delay check. - Returns:
trueif delay elapsed,falseotherwise
Microsecond Timing¶
Get microseconds since system start (wraps after ~71 minutes). Delay for specified microseconds (blocking).One-shot Timer¶
Start a one-shot timer with callback. Stop the one-shot timer. Check if timer is active.Performance Measurement¶
Start performance counter.- Returns: Counter start value
- Returns: Elapsed CPU cycles
Cryptographic Functions¶
SHA-256 Hashing¶
Calculate SHA-256 hash in one operation. Initialize SHA-256 context for incremental hashing. Update SHA-256 context with data. Finalize SHA-256 hash.HMAC¶
void embsec_hmac_sha256(const uint8_t *key, size_t key_len,
const uint8_t *data, size_t data_len,
uint8_t hmac[32])
Utility Functions¶
Convert bytes to hexadecimal string.- Output buffer must be at least
2*len+1bytes
- Returns: Number of bytes written, or -1 on error
- Returns: 0 if equal, non-zero if different
Flag Functions¶
Flag Generation¶
Generate cryptographically secure flag.- Uses hardware ID + timestamp + lab salt
- Format:
EMBSEC{hash_output}
Utility Functions¶
Get hardware ID (unique per device). Get timestamp in milliseconds since boot. Print flag to console. Validate flag format (checks forEMBSEC{...}). Constants and Macros¶
GPIO Pin Definitions¶
#define EMBSEC_LED_RED 0x02 // PF1
#define EMBSEC_LED_BLUE 0x04 // PF2
#define EMBSEC_LED_GREEN 0x08 // PF3
#define EMBSEC_SW1 0x10 // PF4
#define EMBSEC_SW2 0x01 // PF0
Cryptographic Sizes¶
Version Macros¶
#define EMBSEC_VERSION_MAJOR 1
#define EMBSEC_VERSION_MINOR 0
#define EMBSEC_VERSION_PATCH 0
#define EMBSEC_VERSION_STRING "1.0.0"
// Version checking
#define EMBSEC_VERSION_CHECK(major, minor, patch) ...