[FL-1490] FuriHal: crypto api. Crypto cli tool. (#702)
* FuriHal: crypto layer * Furi: add crash routine. * FuriHal: crypto api. Crypto: cli command to manipulate secure enclave and encrypt/decrypt plain text. * DeviceInfo: secure enclave verification. * Rename original to enclave_valid * Update expected enclave signature to match production keys * F7: remove unused files
This commit is contained in:
parent
95d9140d24
commit
66f9d946ae
@ -39,6 +39,7 @@ extern int32_t music_player_app(void* p);
|
||||
|
||||
// On system start hooks declaration
|
||||
extern void bt_cli_init();
|
||||
extern void crypto_cli_init();
|
||||
extern void ibutton_cli_init();
|
||||
extern void irda_cli_init();
|
||||
extern void lfrfid_cli_init();
|
||||
@ -171,6 +172,9 @@ const size_t FLIPPER_APPS_COUNT = sizeof(FLIPPER_APPS) / sizeof(FlipperApplicati
|
||||
|
||||
// On system start hooks
|
||||
const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = {
|
||||
#ifdef SRV_CLI
|
||||
crypto_cli_init,
|
||||
#endif
|
||||
irda_cli_init,
|
||||
#ifdef APP_NFC
|
||||
nfc_cli_init,
|
||||
|
@ -7,6 +7,15 @@
|
||||
#include <notification/notification-messages.h>
|
||||
#include <shci.h>
|
||||
|
||||
#define ENCLAVE_SIGNATURE_KEY_SLOT 1
|
||||
#define ENCLAVE_SIGNATURE_SIZE 16
|
||||
static const uint8_t enclave_signature_iv[16] =
|
||||
{0x32, 0xe6, 0xa7, 0x85, 0x20, 0xae, 0x0b, 0xf0, 0x00, 0xb6, 0x30, 0x9b, 0xd5, 0x42, 0x9e, 0xa6};
|
||||
static const uint8_t enclave_signature_input[ENCLAVE_SIGNATURE_SIZE] =
|
||||
{0xdc, 0x76, 0x15, 0x1e, 0x69, 0xe8, 0xdc, 0xd3, 0x4a, 0x71, 0x0b, 0x42, 0x71, 0xe0, 0xa9, 0x78};
|
||||
static const uint8_t enclave_signature_expected[ENCLAVE_SIGNATURE_SIZE] =
|
||||
{0x6b, 0x31, 0xc, 0xac, 0x3f, 0x68, 0x79, 0x76, 0x43, 0xc4, 0xfe, 0xe0, 0x25, 0x53, 0x64, 0xc7};
|
||||
|
||||
/*
|
||||
* Device Info Command
|
||||
* This command is intended to be used by humans and machines
|
||||
@ -85,6 +94,18 @@ void cli_command_device_info(Cli* cli, string_t args, void* context) {
|
||||
printf("%02X", ble_mac[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
// Signature verification
|
||||
uint8_t buffer[ENCLAVE_SIGNATURE_SIZE];
|
||||
bool enclave_valid = false;
|
||||
if(furi_hal_crypto_store_load_key(ENCLAVE_SIGNATURE_KEY_SLOT, enclave_signature_iv)) {
|
||||
if(furi_hal_crypto_encrypt(enclave_signature_input, buffer, ENCLAVE_SIGNATURE_SIZE)) {
|
||||
enclave_valid =
|
||||
memcmp(buffer, enclave_signature_expected, ENCLAVE_SIGNATURE_SIZE) == 0;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(ENCLAVE_SIGNATURE_KEY_SLOT);
|
||||
}
|
||||
printf("enclave_valid : %s\r\n", enclave_valid ? "true" : "false");
|
||||
} else {
|
||||
printf("radio_alive : false\r\n");
|
||||
}
|
||||
|
284
applications/crypto/crypto_cli.c
Normal file
284
applications/crypto/crypto_cli.c
Normal file
@ -0,0 +1,284 @@
|
||||
#include <furi-hal.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <cli/cli.h>
|
||||
|
||||
void crypto_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("crypto <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
printf(
|
||||
"\tencrypt <key_slot:int> <iv:hex>\t - Using key from secure enclave and IV encrypt plain text with AES256CBC and encode to hex\r\n");
|
||||
printf(
|
||||
"\tdecrypt <key_slot:int> <iv:hex>\t - Using key from secure enclave and IV decrypt hex encoded encrypted with AES256CBC data to plain text\r\n");
|
||||
printf("\thas_key <key_slot:int>\t - Check if secure enclave has key in slot\r\n");
|
||||
printf(
|
||||
"\tstore_key <key_type:str> <key_size:int> <key_data:hex>\t - Store key in secure enclave, returns allocated slot number !!! NON-REVERSABLE OPERATION - READ MANUAL FIRST !!!\r\n");
|
||||
};
|
||||
|
||||
void crypto_cli_encrypt(Cli* cli, string_t args) {
|
||||
int key_slot = 0;
|
||||
bool key_loaded = false;
|
||||
uint8_t iv[16];
|
||||
|
||||
do {
|
||||
if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
|
||||
printf("Incorrect or missing slot, expected int 1-100");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, iv, 16)) {
|
||||
printf("Incorrect or missing IV, expected 16 bytes in hex");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
printf("Unable to load key from slot %d", key_slot);
|
||||
break;
|
||||
}
|
||||
key_loaded = true;
|
||||
|
||||
printf("Enter plain text and press Ctrl+C to complete encryption:\r\n");
|
||||
|
||||
string_t input;
|
||||
string_init(input);
|
||||
char c;
|
||||
while(cli_read(cli, (uint8_t*)&c, 1) == 1) {
|
||||
if(c == CliSymbolAsciiETX) {
|
||||
printf("\r\n");
|
||||
break;
|
||||
} else if(c >= 0x20 && c < 0x7F) {
|
||||
putc(c, stdout);
|
||||
fflush(stdout);
|
||||
string_push_back(input, c);
|
||||
} else if(c == CliSymbolAsciiCR) {
|
||||
printf("\r\n");
|
||||
string_push_back(input, '\n');
|
||||
}
|
||||
}
|
||||
|
||||
size_t size = string_size(input);
|
||||
if(size > 0) {
|
||||
// C-string null termination and block alignments
|
||||
size++;
|
||||
size_t remain = size % 16;
|
||||
if(remain) {
|
||||
size = size - remain + 16;
|
||||
}
|
||||
string_reserve(input, size);
|
||||
uint8_t* output = furi_alloc(size);
|
||||
if(!furi_hal_crypto_encrypt((const uint8_t*)string_get_cstr(input), output, size)) {
|
||||
printf("Failed to encrypt input");
|
||||
} else {
|
||||
printf("Hex-encoded encrypted data:\r\n");
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
printf("%02x", output[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
free(output);
|
||||
} else {
|
||||
printf("No input");
|
||||
}
|
||||
|
||||
string_clear(input);
|
||||
} while(0);
|
||||
|
||||
if(key_loaded) {
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
}
|
||||
}
|
||||
|
||||
void crypto_cli_decrypt(Cli* cli, string_t args) {
|
||||
int key_slot = 0;
|
||||
bool key_loaded = false;
|
||||
uint8_t iv[16];
|
||||
|
||||
do {
|
||||
if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
|
||||
printf("Incorrect or missing slot, expected int 1-100");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, iv, 16)) {
|
||||
printf("Incorrect or missing IV, expected 16 bytes in hex");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
printf("Unable to load key from slot %d", key_slot);
|
||||
break;
|
||||
}
|
||||
key_loaded = true;
|
||||
|
||||
printf("Enter Hex-encoded data and press Ctrl+C to complete decryption:\r\n");
|
||||
|
||||
string_t hex_input;
|
||||
string_init(hex_input);
|
||||
char c;
|
||||
while(cli_read(cli, (uint8_t*)&c, 1) == 1) {
|
||||
if(c == CliSymbolAsciiETX) {
|
||||
printf("\r\n");
|
||||
break;
|
||||
} else if(c >= 0x20 && c < 0x7F) {
|
||||
putc(c, stdout);
|
||||
fflush(stdout);
|
||||
string_push_back(hex_input, c);
|
||||
} else if(c == CliSymbolAsciiCR) {
|
||||
printf("\r\n");
|
||||
string_push_back(hex_input, '\n');
|
||||
}
|
||||
}
|
||||
|
||||
string_strim(hex_input);
|
||||
size_t hex_size = string_size(hex_input);
|
||||
if(hex_size > 0 && hex_size % 2 == 0) {
|
||||
size_t size = hex_size / 2;
|
||||
uint8_t* input = furi_alloc(size);
|
||||
uint8_t* output = furi_alloc(size);
|
||||
|
||||
if(args_read_hex_bytes(hex_input, input, size) &&
|
||||
furi_hal_crypto_decrypt(input, output, size)) {
|
||||
printf("Decrypted data:\r\n");
|
||||
printf("%s\r\n", output);
|
||||
|
||||
} else {
|
||||
printf("Failed to decrypt input");
|
||||
}
|
||||
|
||||
free(input);
|
||||
free(output);
|
||||
} else {
|
||||
printf("Invalid or empty input");
|
||||
}
|
||||
|
||||
string_clear(hex_input);
|
||||
} while(0);
|
||||
|
||||
if(key_loaded) {
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
}
|
||||
}
|
||||
|
||||
void crypto_cli_has_key(Cli* cli, string_t args) {
|
||||
int key_slot = 0;
|
||||
uint8_t iv[16];
|
||||
|
||||
do {
|
||||
if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
|
||||
printf("Incorrect or missing slot, expected int 1-100");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
printf("Unable to load key from slot %d", key_slot);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Successfully loaded key from slot %d", key_slot);
|
||||
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
} while(0);
|
||||
}
|
||||
|
||||
void crypto_cli_store_key(Cli* cli, string_t args) {
|
||||
int key_size = 0;
|
||||
string_t key_type;
|
||||
string_init(key_type);
|
||||
|
||||
uint8_t data[32 + 12] = {};
|
||||
FuriHalCryptoKey key;
|
||||
key.data = data;
|
||||
size_t data_size = 0;
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, key_type)) {
|
||||
printf("Incorrect or missing key type, expected master, simple or encrypted");
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(key_type, "master") == 0) {
|
||||
key.type = FuriHalCryptoKeyTypeMaster;
|
||||
} else if(string_cmp_str(key_type, "simple") == 0) {
|
||||
key.type = FuriHalCryptoKeyTypeSimple;
|
||||
} else if(string_cmp_str(key_type, "encrypted") == 0) {
|
||||
key.type = FuriHalCryptoKeyTypeEncrypted;
|
||||
data_size += 12;
|
||||
} else {
|
||||
printf("Incorrect or missing key type, expected master, simple or encrypted");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_int_and_trim(args, &key_size)) {
|
||||
printf("Incorrect or missing key size, expected 128 or 256");
|
||||
break;
|
||||
}
|
||||
|
||||
if(key_size == 128) {
|
||||
key.size = FuriHalCryptoKeySize128;
|
||||
data_size += 16;
|
||||
} else if(key_size == 256) {
|
||||
key.size = FuriHalCryptoKeySize256;
|
||||
data_size += 32;
|
||||
} else {
|
||||
printf("Incorrect or missing key size, expected 128 or 256");
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, data, data_size)) {
|
||||
printf("Incorrect or missing key data, expected hex encoded key with or without IV.");
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t slot;
|
||||
if(furi_hal_crypto_store_add_key(&key, &slot)) {
|
||||
printf("Success. Stored to slot: %d", slot);
|
||||
} else {
|
||||
printf("Failure");
|
||||
}
|
||||
} while(0);
|
||||
|
||||
string_clear(key_type);
|
||||
}
|
||||
|
||||
void crypto_cli(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
crypto_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "encrypt") == 0) {
|
||||
crypto_cli_encrypt(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "decrypt") == 0) {
|
||||
crypto_cli_decrypt(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "has_key") == 0) {
|
||||
crypto_cli_has_key(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "store_key") == 0) {
|
||||
crypto_cli_store_key(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
crypto_cli_print_usage();
|
||||
} while(false);
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
|
||||
void crypto_cli_init() {
|
||||
Cli* cli = furi_record_open("cli");
|
||||
cli_add_command(cli, "crypto", CliCommandFlagDefault, crypto_cli, NULL);
|
||||
furi_record_close("cli");
|
||||
}
|
@ -116,7 +116,7 @@ void canvas_set_font(Canvas* canvas, Font font) {
|
||||
} else if(font == FontKeyboard) {
|
||||
u8g2_SetFont(&canvas->fb, u8g2_font_profont11_mf);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ void canvas_draw_str_aligned(
|
||||
x -= (u8g2_GetStrWidth(&canvas->fb, str) / 2);
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ void canvas_draw_str_aligned(
|
||||
y += (u8g2_GetAscent(&canvas->fb) / 2);
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ ValueMutex* menu_init() {
|
||||
ValueMutex* menu_mutex = furi_alloc(sizeof(ValueMutex));
|
||||
if(menu_mutex == NULL || !init_mutex(menu_mutex, menu, sizeof(Menu))) {
|
||||
printf("[menu_task] cannot create menu mutex\r\n");
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
// OpenGui record
|
||||
|
@ -20,7 +20,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
|
||||
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
|
||||
snprintf(preset_str, sizeof(preset_str), "FM");
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
subghz_receiver_add_data_statusbar(
|
||||
subghz->subghz_receiver, frequency_str, preset_str, string_get_cstr(history_stat_str));
|
||||
|
@ -44,7 +44,7 @@ const void subghz_scene_receiver_info_on_enter(void* context) {
|
||||
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
|
||||
snprintf(buffer_str, sizeof(buffer_str), "FM");
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
widget_add_string_element(
|
||||
subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
|
||||
|
@ -39,7 +39,7 @@ static void subghz_scene_transmitter_update_data_show(void* context) {
|
||||
} else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
|
||||
snprintf(preset_str, sizeof(preset_str), "FM");
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
subghz_transmitter_add_data_to_show(
|
||||
|
@ -20,7 +20,7 @@ void subghz_begin(FuriHalSubGhzPreset preset) {
|
||||
uint32_t subghz_rx(void* context, uint32_t frequency) {
|
||||
furi_assert(context);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
SubGhzWorker* worker = context;
|
||||
|
||||
@ -37,7 +37,7 @@ uint32_t subghz_rx(void* context, uint32_t frequency) {
|
||||
|
||||
uint32_t subghz_tx(uint32_t frequency) {
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
|
@ -3,10 +3,7 @@
|
||||
#include <furi-hal-console.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void __furi_abort(void);
|
||||
|
||||
void __furi_print_name(void) {
|
||||
furi_hal_console_puts("\r\n\033[0;31m[E]");
|
||||
if(task_is_isr_context()) {
|
||||
furi_hal_console_puts("[ISR] ");
|
||||
} else {
|
||||
@ -19,13 +16,6 @@ void __furi_print_name(void) {
|
||||
furi_hal_console_puts("] ");
|
||||
}
|
||||
}
|
||||
furi_hal_console_puts("\033[0m");
|
||||
}
|
||||
|
||||
void __furi_check(void) {
|
||||
__furi_print_name();
|
||||
furi_hal_console_puts("assertion failed\r\n");
|
||||
__furi_abort();
|
||||
}
|
||||
|
||||
void __furi_abort(void) {
|
||||
@ -33,4 +23,13 @@ void __furi_abort(void) {
|
||||
asm("bkpt 1");
|
||||
while(1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void furi_crash(const char* message) {
|
||||
furi_hal_console_puts("\r\n\033[0;31m[CRASH]");
|
||||
__furi_print_name();
|
||||
furi_hal_console_puts(message ? message : "Programming Error");
|
||||
furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n");
|
||||
furi_hal_console_puts("\033[0m\r\n");
|
||||
__furi_abort();
|
||||
}
|
||||
|
@ -4,40 +4,18 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Find how to how get function's pretty name
|
||||
#ifndef __FURI_CHECK_FUNC
|
||||
// Use g++'s demangled names in C++
|
||||
#if defined __cplusplus && defined __GNUC__
|
||||
#define __FURI_CHECK_FUNC __PRETTY_FUNCTION__
|
||||
|
||||
// C99 requires the use of __func__
|
||||
#elif __STDC_VERSION__ >= 199901L
|
||||
#define __FURI_CHECK_FUNC __func__
|
||||
|
||||
// Older versions of gcc don't have __func__ but can use __FUNCTION__
|
||||
#elif __GNUC__ >= 2
|
||||
#define __FURI_CHECK_FUNC __FUNCTION__
|
||||
|
||||
// failed to detect __func__ support
|
||||
#else
|
||||
#define __FURI_CHECK_FUNC ((char*)0)
|
||||
#endif
|
||||
#endif
|
||||
// !__FURI_CHECK_FUNC
|
||||
|
||||
// We have two levels of assertion
|
||||
// One - furi_check, which always runs, the only difference is in the level of debug information
|
||||
// The second is furi_assert, which doesn't compile in release mode
|
||||
#define furi_check(__e) ((__e) ? (void)0 : __furi_check())
|
||||
/** Check condition and crash if check failed */
|
||||
#define furi_check(__e) ((__e) ? (void)0 : furi_crash("fury_check failed\r\n"))
|
||||
|
||||
/** Only in debug build: Assert condition and crash if assert failed */
|
||||
#ifdef NDEBUG
|
||||
#define furi_assert(__e) ((void)0)
|
||||
#else
|
||||
#define furi_assert(__e) ((__e) ? (void)0 : __furi_check())
|
||||
#define furi_assert(__e) ((__e) ? (void)0 : furi_crash("furi_assert failed\r\n"))
|
||||
#endif
|
||||
// !NDEBUG
|
||||
|
||||
void __furi_check(void);
|
||||
/** Crash system */
|
||||
void furi_crash(const char* message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file aes.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the aes.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AES_H__
|
||||
#define __AES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern CRYP_HandleTypeDef hcryp1;
|
||||
extern CRYP_HandleTypeDef hcryp2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_AES1_Init(void);
|
||||
void MX_AES2_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AES_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pka.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the pka.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PKA_H__
|
||||
#define __PKA_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern PKA_HandleTypeDef hpka;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_PKA_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PKA_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,50 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rf.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rf.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RF_H__
|
||||
#define __RF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RF_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RF_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rng.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rng.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RNG_H__
|
||||
#define __RNG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern RNG_HandleTypeDef hrng;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RNG_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RNG_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,127 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file aes.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the AES instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "aes.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
CRYP_HandleTypeDef hcryp1;
|
||||
__ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = {
|
||||
0x00000000,0x00000000,0x00000000,0x00000000};
|
||||
CRYP_HandleTypeDef hcryp2;
|
||||
__ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = {
|
||||
0x00000000,0x00000000,0x00000000,0x00000000};
|
||||
|
||||
/* AES1 init function */
|
||||
void MX_AES1_Init(void)
|
||||
{
|
||||
|
||||
hcryp1.Instance = AES1;
|
||||
hcryp1.Init.DataType = CRYP_DATATYPE_32B;
|
||||
hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
|
||||
hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
|
||||
hcryp1.Init.Algorithm = CRYP_AES_ECB;
|
||||
hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
|
||||
hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
/* AES2 init function */
|
||||
void MX_AES2_Init(void)
|
||||
{
|
||||
|
||||
hcryp2.Instance = AES2;
|
||||
hcryp2.Init.DataType = CRYP_DATATYPE_32B;
|
||||
hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
|
||||
hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
|
||||
hcryp2.Init.Algorithm = CRYP_AES_ECB;
|
||||
hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
|
||||
hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
|
||||
{
|
||||
|
||||
if(crypHandle->Instance==AES1)
|
||||
{
|
||||
/* USER CODE BEGIN AES1_MspInit 0 */
|
||||
|
||||
/* USER CODE END AES1_MspInit 0 */
|
||||
/* AES1 clock enable */
|
||||
__HAL_RCC_AES1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN AES1_MspInit 1 */
|
||||
|
||||
/* USER CODE END AES1_MspInit 1 */
|
||||
}
|
||||
else if(crypHandle->Instance==AES2)
|
||||
{
|
||||
/* USER CODE BEGIN AES2_MspInit 0 */
|
||||
|
||||
/* USER CODE END AES2_MspInit 0 */
|
||||
/* AES2 clock enable */
|
||||
__HAL_RCC_AES2_CLK_ENABLE();
|
||||
/* USER CODE BEGIN AES2_MspInit 1 */
|
||||
|
||||
/* USER CODE END AES2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
|
||||
{
|
||||
|
||||
if(crypHandle->Instance==AES1)
|
||||
{
|
||||
/* USER CODE BEGIN AES1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END AES1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_AES1_CLK_DISABLE();
|
||||
/* USER CODE BEGIN AES1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END AES1_MspDeInit 1 */
|
||||
}
|
||||
else if(crypHandle->Instance==AES2)
|
||||
{
|
||||
/* USER CODE BEGIN AES2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END AES2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_AES2_CLK_DISABLE();
|
||||
/* USER CODE BEGIN AES2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END AES2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pka.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the PKA instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "pka.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
PKA_HandleTypeDef hpka;
|
||||
|
||||
/* PKA init function */
|
||||
void MX_PKA_Init(void)
|
||||
{
|
||||
|
||||
hpka.Instance = PKA;
|
||||
if (HAL_PKA_Init(&hpka) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle)
|
||||
{
|
||||
|
||||
if(pkaHandle->Instance==PKA)
|
||||
{
|
||||
/* USER CODE BEGIN PKA_MspInit 0 */
|
||||
|
||||
/* USER CODE END PKA_MspInit 0 */
|
||||
/* PKA clock enable */
|
||||
__HAL_RCC_PKA_CLK_ENABLE();
|
||||
/* USER CODE BEGIN PKA_MspInit 1 */
|
||||
|
||||
/* USER CODE END PKA_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle)
|
||||
{
|
||||
|
||||
if(pkaHandle->Instance==PKA)
|
||||
{
|
||||
/* USER CODE BEGIN PKA_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END PKA_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_PKA_CLK_DISABLE();
|
||||
/* USER CODE BEGIN PKA_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END PKA_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rf.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RF instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rf.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* RF init function */
|
||||
void MX_RF_Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rng.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RNG instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rng.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
RNG_HandleTypeDef hrng;
|
||||
|
||||
/* RNG init function */
|
||||
void MX_RNG_Init(void)
|
||||
{
|
||||
|
||||
hrng.Instance = RNG;
|
||||
if (HAL_RNG_Init(&hrng) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle)
|
||||
{
|
||||
|
||||
if(rngHandle->Instance==RNG)
|
||||
{
|
||||
/* USER CODE BEGIN RNG_MspInit 0 */
|
||||
|
||||
/* USER CODE END RNG_MspInit 0 */
|
||||
/* RNG clock enable */
|
||||
__HAL_RCC_RNG_CLK_ENABLE();
|
||||
/* USER CODE BEGIN RNG_MspInit 1 */
|
||||
|
||||
/* USER CODE END RNG_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle)
|
||||
{
|
||||
|
||||
if(rngHandle->Instance==RNG)
|
||||
{
|
||||
/* USER CODE BEGIN RNG_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RNG_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RNG_CLK_DISABLE();
|
||||
/* USER CODE BEGIN RNG_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RNG_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,6 +1,6 @@
|
||||
#include <furi-hal-clock.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include <main.h>
|
||||
#include <stm32wbxx_ll_pwr.h>
|
||||
#include <stm32wbxx_ll_rcc.h>
|
||||
#include <stm32wbxx_ll_utils.h>
|
||||
@ -107,6 +107,12 @@ void furi_hal_clock_init() {
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_AES1);
|
||||
|
||||
// AHB3
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PKA);
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_RNG);
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_AES2);
|
||||
|
||||
// APB1
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
|
||||
@ -114,6 +120,8 @@ void furi_hal_clock_init() {
|
||||
|
||||
// APB2
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
|
||||
FURI_LOG_I("FuriHalClock", "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_clock_switch_to_hsi() {
|
||||
|
69
firmware/targets/f6/furi-hal/furi-hal-crypto.c
Normal file
69
firmware/targets/f6/furi-hal/furi-hal-crypto.c
Normal file
@ -0,0 +1,69 @@
|
||||
#include <furi-hal-crypto.h>
|
||||
#include <furi.h>
|
||||
#include <shci.h>
|
||||
|
||||
CRYP_HandleTypeDef crypt;
|
||||
|
||||
void furi_hal_crypto_init() {
|
||||
FURI_LOG_I("FuriHalCrypto", "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
furi_assert(key);
|
||||
furi_assert(slot);
|
||||
|
||||
SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
|
||||
|
||||
if (key->type == FuriHalCryptoKeyTypeMaster) {
|
||||
pParam.KeyType = KEYTYPE_MASTER;
|
||||
} else if (key->type == FuriHalCryptoKeyTypeSimple) {
|
||||
pParam.KeyType = KEYTYPE_SIMPLE;
|
||||
} else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
|
||||
pParam.KeyType = KEYTYPE_ENCRYPTED;
|
||||
} else {
|
||||
furi_crash("Incorrect key type");
|
||||
}
|
||||
|
||||
if (key->size == FuriHalCryptoKeySize128) {
|
||||
pParam.KeySize = KEYSIZE_16;
|
||||
} else if (key->size == FuriHalCryptoKeySize256) {
|
||||
pParam.KeySize = KEYSIZE_32;
|
||||
} else {
|
||||
furi_crash("Incorrect key size");
|
||||
}
|
||||
|
||||
return SHCI_C2_FUS_StoreUsrKey(&pParam, slot) == SHCI_Success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
|
||||
furi_assert(slot > 0 && slot <= 100);
|
||||
|
||||
crypt.Instance = AES1;
|
||||
crypt.Init.DataType = CRYP_DATATYPE_32B;
|
||||
crypt.Init.KeySize = CRYP_KEYSIZE_256B;
|
||||
crypt.Init.Algorithm = CRYP_AES_CBC;
|
||||
crypt.Init.pInitVect = (uint32_t*)iv;
|
||||
crypt.Init.pKey = NULL;
|
||||
|
||||
furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
|
||||
|
||||
if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
|
||||
return true;
|
||||
} else {
|
||||
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_unload_key(uint8_t slot) {
|
||||
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
|
||||
return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size) {
|
||||
return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size) {
|
||||
return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
|
||||
}
|
@ -41,7 +41,7 @@ void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR is
|
||||
}
|
||||
furi_hal_tim_tim1_isr = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel,
|
||||
} else if (dma == DMA2) {
|
||||
furi_hal_dma_channel_isr[1][channel] = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) {
|
||||
static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE1(DMA1);
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
|
||||
LL_DMA_ClearFlag_TC1(DMA1);
|
||||
@ -261,7 +261,7 @@ static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
static void furi_hal_irda_tx_dma_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE2(DMA1);
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
LL_DMA_ClearFlag_HT2(DMA1);
|
||||
@ -277,7 +277,7 @@ static void furi_hal_irda_tx_dma_isr() {
|
||||
} else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
|
||||
/* fallthrough */
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
@ -557,7 +557,7 @@ static void furi_hal_irda_async_tx_free_resources(void) {
|
||||
|
||||
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
furi_assert(furi_hal_irda_state == IrdaStateIdle);
|
||||
|
@ -252,7 +252,7 @@ void furi_hal_rfid_set_emulate_pulse(uint32_t pulse) {
|
||||
LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -276,7 +276,7 @@ void furi_hal_rfid_set_read_pulse(uint32_t pulse) {
|
||||
LFRFID_TIM.Instance->CCR4 = pulse;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
|
||||
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
|
||||
}else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
|
||||
} else if(value >= 778999847 && value <= 928000000) {
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPath868);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -424,7 +424,7 @@ void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void furi_hal_version_init() {
|
||||
case FuriHalVersionOtpVersion1:
|
||||
furi_hal_version_load_otp_v1();
|
||||
break;
|
||||
default: furi_check(0);
|
||||
default: furi_crash(NULL);
|
||||
}
|
||||
FURI_LOG_I("FuriHalVersion", "Init OK");
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
#include <furi-hal.h>
|
||||
|
||||
#include <aes.h>
|
||||
#include <comp.h>
|
||||
#include <pka.h>
|
||||
#include <rf.h>
|
||||
#include <rng.h>
|
||||
#include <rtc.h>
|
||||
#include <tim.h>
|
||||
#include <usb_device.h>
|
||||
@ -34,16 +30,8 @@ void furi_hal_init() {
|
||||
FURI_LOG_I("HAL", "TIM16 OK");
|
||||
MX_COMP1_Init();
|
||||
FURI_LOG_I("HAL", "COMP1 OK");
|
||||
MX_RF_Init();
|
||||
FURI_LOG_I("HAL", "RF OK");
|
||||
MX_PKA_Init();
|
||||
FURI_LOG_I("HAL", "PKA OK");
|
||||
MX_RNG_Init();
|
||||
FURI_LOG_I("HAL", "RNG OK");
|
||||
MX_AES1_Init();
|
||||
FURI_LOG_I("HAL", "AES1 OK");
|
||||
MX_AES2_Init();
|
||||
FURI_LOG_I("HAL", "AES2 OK");
|
||||
|
||||
furi_hal_crypto_init();
|
||||
|
||||
// VCP + USB
|
||||
furi_hal_vcp_init();
|
||||
|
@ -1,445 +1,444 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file startup_stm32wb55xx_cm4.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32WB55xx devices vector table GCC toolchain.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M4 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.fpu softvfp
|
||||
.thumb
|
||||
|
||||
.global g_pfnVectors
|
||||
.global Default_Handler
|
||||
|
||||
/* start address for the initialization values of the .data section.
|
||||
defined in linker script */
|
||||
.word _sidata
|
||||
/* start address for the .data section. defined in linker script */
|
||||
.word _sdata
|
||||
/* end address for the .data section. defined in linker script */
|
||||
.word _edata
|
||||
/* start address for the .bss section. defined in linker script */
|
||||
.word _sbss
|
||||
/* end address for the .bss section. defined in linker script */
|
||||
.word _ebss
|
||||
/* start address for the .MB_MEM2 section. defined in linker script */
|
||||
.word _sMB_MEM2
|
||||
/* end address for the .MB_MEM2 section. defined in linker script */
|
||||
.word _eMB_MEM2
|
||||
|
||||
/* INIT_BSS macro is used to fill the specified region [start : end] with zeros */
|
||||
.macro INIT_BSS start, end
|
||||
ldr r0, =\start
|
||||
ldr r1, =\end
|
||||
movs r3, #0
|
||||
bl LoopFillZerobss
|
||||
.endm
|
||||
|
||||
/* INIT_DATA macro is used to copy data in the region [start : end] starting from 'src' */
|
||||
.macro INIT_DATA start, end, src
|
||||
ldr r0, =\start
|
||||
ldr r1, =\end
|
||||
ldr r2, =\src
|
||||
movs r3, #0
|
||||
bl LoopCopyDataInit
|
||||
.endm
|
||||
|
||||
.section .text.data_initializers
|
||||
CopyDataInit:
|
||||
ldr r4, [r2, r3]
|
||||
str r4, [r0, r3]
|
||||
adds r3, r3, #4
|
||||
|
||||
LoopCopyDataInit:
|
||||
adds r4, r0, r3
|
||||
cmp r4, r1
|
||||
bcc CopyDataInit
|
||||
bx lr
|
||||
|
||||
FillZerobss:
|
||||
str r3, [r0]
|
||||
adds r0, r0, #4
|
||||
|
||||
LoopFillZerobss:
|
||||
cmp r0, r1
|
||||
bcc FillZerobss
|
||||
bx lr
|
||||
|
||||
.section .text.Reset_Handler
|
||||
.weak Reset_Handler
|
||||
.type Reset_Handler, %function
|
||||
Reset_Handler:
|
||||
ldr r0, =_estack
|
||||
mov sp, r0 /* set stack pointer */
|
||||
/* Call the clock system intitialization function.*/
|
||||
bl SystemInit
|
||||
|
||||
/* Copy the data segment initializers from flash to SRAM */
|
||||
INIT_DATA _sdata, _edata, _sidata
|
||||
|
||||
/* Zero fill the bss segments. */
|
||||
INIT_BSS _sbss, _ebss
|
||||
INIT_BSS _sMB_MEM2, _eMB_MEM2
|
||||
|
||||
/* Call static constructors */
|
||||
bl __libc_init_array
|
||||
/* Call the application s entry point.*/
|
||||
bl main
|
||||
|
||||
LoopForever:
|
||||
b LoopForever
|
||||
|
||||
.size Reset_Handler, .-Reset_Handler
|
||||
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor receives an
|
||||
* unexpected interrupt. This simply enters an infinite loop, preserving
|
||||
* the system state for examination by a debugger.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
.section .text.Default_Handler,"ax",%progbits
|
||||
Default_Handler:
|
||||
Infinite_Loop:
|
||||
b Infinite_Loop
|
||||
.size Default_Handler, .-Default_Handler
|
||||
/******************************************************************************
|
||||
*
|
||||
* The minimal vector table for a Cortex-M4. Note that the proper constructs
|
||||
* must be placed on this to ensure that it ends up at physical address
|
||||
* 0x0000.0000.
|
||||
*
|
||||
******************************************************************************/
|
||||
.section .isr_vector,"a",%progbits
|
||||
.type g_pfnVectors, %object
|
||||
.size g_pfnVectors, .-g_pfnVectors
|
||||
|
||||
|
||||
g_pfnVectors:
|
||||
.word _estack
|
||||
.word Reset_Handler
|
||||
.word NMI_Handler
|
||||
.word HardFault_Handler
|
||||
.word MemManage_Handler
|
||||
.word BusFault_Handler
|
||||
.word UsageFault_Handler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word SVC_Handler
|
||||
.word DebugMon_Handler
|
||||
.word 0
|
||||
.word PendSV_Handler
|
||||
.word SysTick_Handler
|
||||
.word WWDG_IRQHandler
|
||||
.word PVD_PVM_IRQHandler
|
||||
.word TAMP_STAMP_LSECSS_IRQHandler
|
||||
.word RTC_WKUP_IRQHandler
|
||||
.word FLASH_IRQHandler
|
||||
.word RCC_IRQHandler
|
||||
.word EXTI0_IRQHandler
|
||||
.word EXTI1_IRQHandler
|
||||
.word EXTI2_IRQHandler
|
||||
.word EXTI3_IRQHandler
|
||||
.word EXTI4_IRQHandler
|
||||
.word DMA1_Channel1_IRQHandler
|
||||
.word DMA1_Channel2_IRQHandler
|
||||
.word DMA1_Channel3_IRQHandler
|
||||
.word DMA1_Channel4_IRQHandler
|
||||
.word DMA1_Channel5_IRQHandler
|
||||
.word DMA1_Channel6_IRQHandler
|
||||
.word DMA1_Channel7_IRQHandler
|
||||
.word ADC1_IRQHandler
|
||||
.word USB_HP_IRQHandler
|
||||
.word USB_LP_IRQHandler
|
||||
.word C2SEV_PWR_C2H_IRQHandler
|
||||
.word COMP_IRQHandler
|
||||
.word EXTI9_5_IRQHandler
|
||||
.word TIM1_BRK_IRQHandler
|
||||
.word TIM1_UP_TIM16_IRQHandler
|
||||
.word TIM1_TRG_COM_TIM17_IRQHandler
|
||||
.word TIM1_CC_IRQHandler
|
||||
.word TIM2_IRQHandler
|
||||
.word PKA_IRQHandler
|
||||
.word I2C1_EV_IRQHandler
|
||||
.word I2C1_ER_IRQHandler
|
||||
.word I2C3_EV_IRQHandler
|
||||
.word I2C3_ER_IRQHandler
|
||||
.word SPI1_IRQHandler
|
||||
.word SPI2_IRQHandler
|
||||
.word USART1_IRQHandler
|
||||
.word LPUART1_IRQHandler
|
||||
.word SAI1_IRQHandler
|
||||
.word TSC_IRQHandler
|
||||
.word EXTI15_10_IRQHandler
|
||||
.word RTC_Alarm_IRQHandler
|
||||
.word CRS_IRQHandler
|
||||
.word PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
|
||||
.word IPCC_C1_RX_IRQHandler
|
||||
.word IPCC_C1_TX_IRQHandler
|
||||
.word HSEM_IRQHandler
|
||||
.word LPTIM1_IRQHandler
|
||||
.word LPTIM2_IRQHandler
|
||||
.word LCD_IRQHandler
|
||||
.word QUADSPI_IRQHandler
|
||||
.word AES1_IRQHandler
|
||||
.word AES2_IRQHandler
|
||||
.word RNG_IRQHandler
|
||||
.word FPU_IRQHandler
|
||||
.word DMA2_Channel1_IRQHandler
|
||||
.word DMA2_Channel2_IRQHandler
|
||||
.word DMA2_Channel3_IRQHandler
|
||||
.word DMA2_Channel4_IRQHandler
|
||||
.word DMA2_Channel5_IRQHandler
|
||||
.word DMA2_Channel6_IRQHandler
|
||||
.word DMA2_Channel7_IRQHandler
|
||||
.word DMAMUX1_OVR_IRQHandler
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Provide weak aliases for each Exception handler to the Default_Handler.
|
||||
* As they are weak aliases, any function with the same name will override
|
||||
* this definition.
|
||||
*
|
||||
*******************************************************************************/
|
||||
.weak NMI_Handler
|
||||
.thumb_set NMI_Handler,Default_Handler
|
||||
|
||||
.weak HardFault_Handler
|
||||
.thumb_set HardFault_Handler,Default_Handler
|
||||
|
||||
.weak MemManage_Handler
|
||||
.thumb_set MemManage_Handler,Default_Handler
|
||||
|
||||
.weak BusFault_Handler
|
||||
.thumb_set BusFault_Handler,Default_Handler
|
||||
|
||||
.weak UsageFault_Handler
|
||||
.thumb_set UsageFault_Handler,Default_Handler
|
||||
|
||||
.weak SVC_Handler
|
||||
.thumb_set SVC_Handler,Default_Handler
|
||||
|
||||
.weak DebugMon_Handler
|
||||
.thumb_set DebugMon_Handler,Default_Handler
|
||||
|
||||
.weak PendSV_Handler
|
||||
.thumb_set PendSV_Handler,Default_Handler
|
||||
|
||||
.weak SysTick_Handler
|
||||
.thumb_set SysTick_Handler,Default_Handler
|
||||
|
||||
.weak WWDG_IRQHandler
|
||||
.thumb_set WWDG_IRQHandler,Default_Handler
|
||||
|
||||
.weak PVD_PVM_IRQHandler
|
||||
.thumb_set PVD_PVM_IRQHandler,Default_Handler
|
||||
|
||||
.weak TAMP_STAMP_LSECSS_IRQHandler
|
||||
.thumb_set TAMP_STAMP_LSECSS_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_WKUP_IRQHandler
|
||||
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak FLASH_IRQHandler
|
||||
.thumb_set FLASH_IRQHandler,Default_Handler
|
||||
|
||||
.weak RCC_IRQHandler
|
||||
.thumb_set RCC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI0_IRQHandler
|
||||
.thumb_set EXTI0_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI1_IRQHandler
|
||||
.thumb_set EXTI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI2_IRQHandler
|
||||
.thumb_set EXTI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI3_IRQHandler
|
||||
.thumb_set EXTI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI4_IRQHandler
|
||||
.thumb_set EXTI4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel1_IRQHandler
|
||||
.thumb_set DMA1_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel2_IRQHandler
|
||||
.thumb_set DMA1_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel3_IRQHandler
|
||||
.thumb_set DMA1_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel4_IRQHandler
|
||||
.thumb_set DMA1_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel5_IRQHandler
|
||||
.thumb_set DMA1_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel6_IRQHandler
|
||||
.thumb_set DMA1_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel7_IRQHandler
|
||||
.thumb_set DMA1_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak ADC1_IRQHandler
|
||||
.thumb_set ADC1_IRQHandler,Default_Handler
|
||||
|
||||
.weak USB_HP_IRQHandler
|
||||
.thumb_set USB_HP_IRQHandler,Default_Handler
|
||||
|
||||
.weak USB_LP_IRQHandler
|
||||
.thumb_set USB_LP_IRQHandler,Default_Handler
|
||||
|
||||
.weak C2SEV_PWR_C2H_IRQHandler
|
||||
.thumb_set C2SEV_PWR_C2H_IRQHandler,Default_Handler
|
||||
|
||||
.weak COMP_IRQHandler
|
||||
.thumb_set COMP_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI9_5_IRQHandler
|
||||
.thumb_set EXTI9_5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_BRK_IRQHandler
|
||||
.thumb_set TIM1_BRK_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_UP_TIM16_IRQHandler
|
||||
.thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_TRG_COM_TIM17_IRQHandler
|
||||
.thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_CC_IRQHandler
|
||||
.thumb_set TIM1_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM2_IRQHandler
|
||||
.thumb_set TIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak PKA_IRQHandler
|
||||
.thumb_set PKA_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_EV_IRQHandler
|
||||
.thumb_set I2C1_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_ER_IRQHandler
|
||||
.thumb_set I2C1_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_EV_IRQHandler
|
||||
.thumb_set I2C3_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_ER_IRQHandler
|
||||
.thumb_set I2C3_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI1_IRQHandler
|
||||
.thumb_set SPI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI2_IRQHandler
|
||||
.thumb_set SPI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART1_IRQHandler
|
||||
.thumb_set USART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPUART1_IRQHandler
|
||||
.thumb_set LPUART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SAI1_IRQHandler
|
||||
.thumb_set SAI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak TSC_IRQHandler
|
||||
.thumb_set TSC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI15_10_IRQHandler
|
||||
.thumb_set EXTI15_10_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_Alarm_IRQHandler
|
||||
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
|
||||
|
||||
.weak CRS_IRQHandler
|
||||
.thumb_set CRS_IRQHandler,Default_Handler
|
||||
|
||||
.weak PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
|
||||
.thumb_set PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler,Default_Handler
|
||||
|
||||
.weak IPCC_C1_RX_IRQHandler
|
||||
.thumb_set IPCC_C1_RX_IRQHandler,Default_Handler
|
||||
|
||||
.weak IPCC_C1_TX_IRQHandler
|
||||
.thumb_set IPCC_C1_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak HSEM_IRQHandler
|
||||
.thumb_set HSEM_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM1_IRQHandler
|
||||
.thumb_set LPTIM1_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM2_IRQHandler
|
||||
.thumb_set LPTIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak LCD_IRQHandler
|
||||
.thumb_set LCD_IRQHandler,Default_Handler
|
||||
|
||||
.weak QUADSPI_IRQHandler
|
||||
.thumb_set QUADSPI_IRQHandler,Default_Handler
|
||||
|
||||
.weak AES1_IRQHandler
|
||||
.thumb_set AES1_IRQHandler,Default_Handler
|
||||
|
||||
.weak AES2_IRQHandler
|
||||
.thumb_set AES2_IRQHandler,Default_Handler
|
||||
|
||||
.weak RNG_IRQHandler
|
||||
.thumb_set RNG_IRQHandler,Default_Handler
|
||||
|
||||
.weak FPU_IRQHandler
|
||||
.thumb_set FPU_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel1_IRQHandler
|
||||
.thumb_set DMA2_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel2_IRQHandler
|
||||
.thumb_set DMA2_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel3_IRQHandler
|
||||
.thumb_set DMA2_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel4_IRQHandler
|
||||
.thumb_set DMA2_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel5_IRQHandler
|
||||
.thumb_set DMA2_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel6_IRQHandler
|
||||
.thumb_set DMA2_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel7_IRQHandler
|
||||
.thumb_set DMA2_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMAMUX1_OVR_IRQHandler
|
||||
.thumb_set DMAMUX1_OVR_IRQHandler,Default_Handler
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file startup_stm32wb55xx_cm4.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32WB55xx devices vector table GCC toolchain.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M4 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019-2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.fpu softvfp
|
||||
.thumb
|
||||
|
||||
.global g_pfnVectors
|
||||
.global Default_Handler
|
||||
|
||||
/* start address for the initialization values of the .data section.
|
||||
defined in linker script */
|
||||
.word _sidata
|
||||
/* start address for the .data section. defined in linker script */
|
||||
.word _sdata
|
||||
/* end address for the .data section. defined in linker script */
|
||||
.word _edata
|
||||
/* start address for the .bss section. defined in linker script */
|
||||
.word _sbss
|
||||
/* end address for the .bss section. defined in linker script */
|
||||
.word _ebss
|
||||
/* start address for the .MB_MEM2 section. defined in linker script */
|
||||
.word _sMB_MEM2
|
||||
/* end address for the .MB_MEM2 section. defined in linker script */
|
||||
.word _eMB_MEM2
|
||||
|
||||
/* INIT_BSS macro is used to fill the specified region [start : end] with zeros */
|
||||
.macro INIT_BSS start, end
|
||||
ldr r0, =\start
|
||||
ldr r1, =\end
|
||||
movs r3, #0
|
||||
bl LoopFillZerobss
|
||||
.endm
|
||||
|
||||
/* INIT_DATA macro is used to copy data in the region [start : end] starting from 'src' */
|
||||
.macro INIT_DATA start, end, src
|
||||
ldr r0, =\start
|
||||
ldr r1, =\end
|
||||
ldr r2, =\src
|
||||
movs r3, #0
|
||||
bl LoopCopyDataInit
|
||||
.endm
|
||||
|
||||
.section .text.data_initializers
|
||||
CopyDataInit:
|
||||
ldr r4, [r2, r3]
|
||||
str r4, [r0, r3]
|
||||
adds r3, r3, #4
|
||||
|
||||
LoopCopyDataInit:
|
||||
adds r4, r0, r3
|
||||
cmp r4, r1
|
||||
bcc CopyDataInit
|
||||
bx lr
|
||||
|
||||
FillZerobss:
|
||||
str r3, [r0]
|
||||
adds r0, r0, #4
|
||||
|
||||
LoopFillZerobss:
|
||||
cmp r0, r1
|
||||
bcc FillZerobss
|
||||
bx lr
|
||||
|
||||
.section .text.Reset_Handler
|
||||
.weak Reset_Handler
|
||||
.type Reset_Handler, %function
|
||||
Reset_Handler:
|
||||
ldr r0, =_estack
|
||||
mov sp, r0 /* set stack pointer */
|
||||
/* Call the clock system intitialization function.*/
|
||||
bl SystemInit
|
||||
|
||||
/* Copy the data segment initializers from flash to SRAM */
|
||||
INIT_DATA _sdata, _edata, _sidata
|
||||
|
||||
/* Zero fill the bss segments. */
|
||||
INIT_BSS _sbss, _ebss
|
||||
INIT_BSS _sMB_MEM2, _eMB_MEM2
|
||||
|
||||
/* Call static constructors */
|
||||
bl __libc_init_array
|
||||
/* Call the application s entry point.*/
|
||||
bl main
|
||||
|
||||
LoopForever:
|
||||
b LoopForever
|
||||
|
||||
.size Reset_Handler, .-Reset_Handler
|
||||
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor receives an
|
||||
* unexpected interrupt. This simply enters an infinite loop, preserving
|
||||
* the system state for examination by a debugger.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
.section .text.Default_Handler,"ax",%progbits
|
||||
Default_Handler:
|
||||
Infinite_Loop:
|
||||
b Infinite_Loop
|
||||
.size Default_Handler, .-Default_Handler
|
||||
/******************************************************************************
|
||||
*
|
||||
* The minimal vector table for a Cortex-M4. Note that the proper constructs
|
||||
* must be placed on this to ensure that it ends up at physical address
|
||||
* 0x0000.0000.
|
||||
*
|
||||
******************************************************************************/
|
||||
.section .isr_vector,"a",%progbits
|
||||
.type g_pfnVectors, %object
|
||||
.size g_pfnVectors, .-g_pfnVectors
|
||||
|
||||
|
||||
g_pfnVectors:
|
||||
.word _estack
|
||||
.word Reset_Handler
|
||||
.word NMI_Handler
|
||||
.word HardFault_Handler
|
||||
.word MemManage_Handler
|
||||
.word BusFault_Handler
|
||||
.word UsageFault_Handler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word SVC_Handler
|
||||
.word DebugMon_Handler
|
||||
.word 0
|
||||
.word PendSV_Handler
|
||||
.word SysTick_Handler
|
||||
.word WWDG_IRQHandler
|
||||
.word PVD_PVM_IRQHandler
|
||||
.word TAMP_STAMP_LSECSS_IRQHandler
|
||||
.word RTC_WKUP_IRQHandler
|
||||
.word FLASH_IRQHandler
|
||||
.word RCC_IRQHandler
|
||||
.word EXTI0_IRQHandler
|
||||
.word EXTI1_IRQHandler
|
||||
.word EXTI2_IRQHandler
|
||||
.word EXTI3_IRQHandler
|
||||
.word EXTI4_IRQHandler
|
||||
.word DMA1_Channel1_IRQHandler
|
||||
.word DMA1_Channel2_IRQHandler
|
||||
.word DMA1_Channel3_IRQHandler
|
||||
.word DMA1_Channel4_IRQHandler
|
||||
.word DMA1_Channel5_IRQHandler
|
||||
.word DMA1_Channel6_IRQHandler
|
||||
.word DMA1_Channel7_IRQHandler
|
||||
.word ADC1_IRQHandler
|
||||
.word USB_HP_IRQHandler
|
||||
.word USB_LP_IRQHandler
|
||||
.word C2SEV_PWR_C2H_IRQHandler
|
||||
.word COMP_IRQHandler
|
||||
.word EXTI9_5_IRQHandler
|
||||
.word TIM1_BRK_IRQHandler
|
||||
.word TIM1_UP_TIM16_IRQHandler
|
||||
.word TIM1_TRG_COM_TIM17_IRQHandler
|
||||
.word TIM1_CC_IRQHandler
|
||||
.word TIM2_IRQHandler
|
||||
.word PKA_IRQHandler
|
||||
.word I2C1_EV_IRQHandler
|
||||
.word I2C1_ER_IRQHandler
|
||||
.word I2C3_EV_IRQHandler
|
||||
.word I2C3_ER_IRQHandler
|
||||
.word SPI1_IRQHandler
|
||||
.word SPI2_IRQHandler
|
||||
.word USART1_IRQHandler
|
||||
.word LPUART1_IRQHandler
|
||||
.word SAI1_IRQHandler
|
||||
.word TSC_IRQHandler
|
||||
.word EXTI15_10_IRQHandler
|
||||
.word RTC_Alarm_IRQHandler
|
||||
.word CRS_IRQHandler
|
||||
.word PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
|
||||
.word IPCC_C1_RX_IRQHandler
|
||||
.word IPCC_C1_TX_IRQHandler
|
||||
.word HSEM_IRQHandler
|
||||
.word LPTIM1_IRQHandler
|
||||
.word LPTIM2_IRQHandler
|
||||
.word LCD_IRQHandler
|
||||
.word QUADSPI_IRQHandler
|
||||
.word AES1_IRQHandler
|
||||
.word AES2_IRQHandler
|
||||
.word RNG_IRQHandler
|
||||
.word FPU_IRQHandler
|
||||
.word DMA2_Channel1_IRQHandler
|
||||
.word DMA2_Channel2_IRQHandler
|
||||
.word DMA2_Channel3_IRQHandler
|
||||
.word DMA2_Channel4_IRQHandler
|
||||
.word DMA2_Channel5_IRQHandler
|
||||
.word DMA2_Channel6_IRQHandler
|
||||
.word DMA2_Channel7_IRQHandler
|
||||
.word DMAMUX1_OVR_IRQHandler
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Provide weak aliases for each Exception handler to the Default_Handler.
|
||||
* As they are weak aliases, any function with the same name will override
|
||||
* this definition.
|
||||
*
|
||||
*******************************************************************************/
|
||||
.weak NMI_Handler
|
||||
.thumb_set NMI_Handler,Default_Handler
|
||||
|
||||
.weak HardFault_Handler
|
||||
.thumb_set HardFault_Handler,Default_Handler
|
||||
|
||||
.weak MemManage_Handler
|
||||
.thumb_set MemManage_Handler,Default_Handler
|
||||
|
||||
.weak BusFault_Handler
|
||||
.thumb_set BusFault_Handler,Default_Handler
|
||||
|
||||
.weak UsageFault_Handler
|
||||
.thumb_set UsageFault_Handler,Default_Handler
|
||||
|
||||
.weak SVC_Handler
|
||||
.thumb_set SVC_Handler,Default_Handler
|
||||
|
||||
.weak DebugMon_Handler
|
||||
.thumb_set DebugMon_Handler,Default_Handler
|
||||
|
||||
.weak PendSV_Handler
|
||||
.thumb_set PendSV_Handler,Default_Handler
|
||||
|
||||
.weak SysTick_Handler
|
||||
.thumb_set SysTick_Handler,Default_Handler
|
||||
|
||||
.weak WWDG_IRQHandler
|
||||
.thumb_set WWDG_IRQHandler,Default_Handler
|
||||
|
||||
.weak PVD_PVM_IRQHandler
|
||||
.thumb_set PVD_PVM_IRQHandler,Default_Handler
|
||||
|
||||
.weak TAMP_STAMP_LSECSS_IRQHandler
|
||||
.thumb_set TAMP_STAMP_LSECSS_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_WKUP_IRQHandler
|
||||
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak FLASH_IRQHandler
|
||||
.thumb_set FLASH_IRQHandler,Default_Handler
|
||||
|
||||
.weak RCC_IRQHandler
|
||||
.thumb_set RCC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI0_IRQHandler
|
||||
.thumb_set EXTI0_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI1_IRQHandler
|
||||
.thumb_set EXTI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI2_IRQHandler
|
||||
.thumb_set EXTI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI3_IRQHandler
|
||||
.thumb_set EXTI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI4_IRQHandler
|
||||
.thumb_set EXTI4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel1_IRQHandler
|
||||
.thumb_set DMA1_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel2_IRQHandler
|
||||
.thumb_set DMA1_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel3_IRQHandler
|
||||
.thumb_set DMA1_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel4_IRQHandler
|
||||
.thumb_set DMA1_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel5_IRQHandler
|
||||
.thumb_set DMA1_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel6_IRQHandler
|
||||
.thumb_set DMA1_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel7_IRQHandler
|
||||
.thumb_set DMA1_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak ADC1_IRQHandler
|
||||
.thumb_set ADC1_IRQHandler,Default_Handler
|
||||
|
||||
.weak USB_HP_IRQHandler
|
||||
.thumb_set USB_HP_IRQHandler,Default_Handler
|
||||
|
||||
.weak USB_LP_IRQHandler
|
||||
.thumb_set USB_LP_IRQHandler,Default_Handler
|
||||
|
||||
.weak C2SEV_PWR_C2H_IRQHandler
|
||||
.thumb_set C2SEV_PWR_C2H_IRQHandler,Default_Handler
|
||||
|
||||
.weak COMP_IRQHandler
|
||||
.thumb_set COMP_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI9_5_IRQHandler
|
||||
.thumb_set EXTI9_5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_BRK_IRQHandler
|
||||
.thumb_set TIM1_BRK_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_UP_TIM16_IRQHandler
|
||||
.thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_TRG_COM_TIM17_IRQHandler
|
||||
.thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_CC_IRQHandler
|
||||
.thumb_set TIM1_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM2_IRQHandler
|
||||
.thumb_set TIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak PKA_IRQHandler
|
||||
.thumb_set PKA_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_EV_IRQHandler
|
||||
.thumb_set I2C1_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_ER_IRQHandler
|
||||
.thumb_set I2C1_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_EV_IRQHandler
|
||||
.thumb_set I2C3_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_ER_IRQHandler
|
||||
.thumb_set I2C3_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI1_IRQHandler
|
||||
.thumb_set SPI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI2_IRQHandler
|
||||
.thumb_set SPI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART1_IRQHandler
|
||||
.thumb_set USART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPUART1_IRQHandler
|
||||
.thumb_set LPUART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SAI1_IRQHandler
|
||||
.thumb_set SAI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak TSC_IRQHandler
|
||||
.thumb_set TSC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI15_10_IRQHandler
|
||||
.thumb_set EXTI15_10_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_Alarm_IRQHandler
|
||||
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
|
||||
|
||||
.weak CRS_IRQHandler
|
||||
.thumb_set CRS_IRQHandler,Default_Handler
|
||||
|
||||
.weak PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler
|
||||
.thumb_set PWR_SOTF_BLEACT_802ACT_RFPHASE_IRQHandler,Default_Handler
|
||||
|
||||
.weak IPCC_C1_RX_IRQHandler
|
||||
.thumb_set IPCC_C1_RX_IRQHandler,Default_Handler
|
||||
|
||||
.weak IPCC_C1_TX_IRQHandler
|
||||
.thumb_set IPCC_C1_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak HSEM_IRQHandler
|
||||
.thumb_set HSEM_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM1_IRQHandler
|
||||
.thumb_set LPTIM1_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM2_IRQHandler
|
||||
.thumb_set LPTIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak LCD_IRQHandler
|
||||
.thumb_set LCD_IRQHandler,Default_Handler
|
||||
|
||||
.weak QUADSPI_IRQHandler
|
||||
.thumb_set QUADSPI_IRQHandler,Default_Handler
|
||||
|
||||
.weak AES1_IRQHandler
|
||||
.thumb_set AES1_IRQHandler,Default_Handler
|
||||
|
||||
.weak AES2_IRQHandler
|
||||
.thumb_set AES2_IRQHandler,Default_Handler
|
||||
|
||||
.weak RNG_IRQHandler
|
||||
.thumb_set RNG_IRQHandler,Default_Handler
|
||||
|
||||
.weak FPU_IRQHandler
|
||||
.thumb_set FPU_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel1_IRQHandler
|
||||
.thumb_set DMA2_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel2_IRQHandler
|
||||
.thumb_set DMA2_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel3_IRQHandler
|
||||
.thumb_set DMA2_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel4_IRQHandler
|
||||
.thumb_set DMA2_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel5_IRQHandler
|
||||
.thumb_set DMA2_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel6_IRQHandler
|
||||
.thumb_set DMA2_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel7_IRQHandler
|
||||
.thumb_set DMA2_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMAMUX1_OVR_IRQHandler
|
||||
.thumb_set DMAMUX1_OVR_IRQHandler,Default_Handler
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
@ -53,12 +53,9 @@ C_SOURCES += \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rng.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
|
||||
@ -81,7 +78,6 @@ CFLAGS += \
|
||||
-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
|
||||
-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
|
||||
C_SOURCES += \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file aes.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the aes.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AES_H__
|
||||
#define __AES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern CRYP_HandleTypeDef hcryp1;
|
||||
extern CRYP_HandleTypeDef hcryp2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_AES1_Init(void);
|
||||
void MX_AES2_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AES_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pka.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the pka.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PKA_H__
|
||||
#define __PKA_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern PKA_HandleTypeDef hpka;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_PKA_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PKA_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,50 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rf.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rf.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RF_H__
|
||||
#define __RF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RF_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RF_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rng.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rng.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RNG_H__
|
||||
#define __RNG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern RNG_HandleTypeDef hrng;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RNG_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RNG_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,127 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file aes.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the AES instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "aes.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
CRYP_HandleTypeDef hcryp1;
|
||||
__ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = {
|
||||
0x00000000,0x00000000,0x00000000,0x00000000};
|
||||
CRYP_HandleTypeDef hcryp2;
|
||||
__ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = {
|
||||
0x00000000,0x00000000,0x00000000,0x00000000};
|
||||
|
||||
/* AES1 init function */
|
||||
void MX_AES1_Init(void)
|
||||
{
|
||||
|
||||
hcryp1.Instance = AES1;
|
||||
hcryp1.Init.DataType = CRYP_DATATYPE_32B;
|
||||
hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
|
||||
hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
|
||||
hcryp1.Init.Algorithm = CRYP_AES_ECB;
|
||||
hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
|
||||
hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
/* AES2 init function */
|
||||
void MX_AES2_Init(void)
|
||||
{
|
||||
|
||||
hcryp2.Instance = AES2;
|
||||
hcryp2.Init.DataType = CRYP_DATATYPE_32B;
|
||||
hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
|
||||
hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
|
||||
hcryp2.Init.Algorithm = CRYP_AES_ECB;
|
||||
hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
|
||||
hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
|
||||
{
|
||||
|
||||
if(crypHandle->Instance==AES1)
|
||||
{
|
||||
/* USER CODE BEGIN AES1_MspInit 0 */
|
||||
|
||||
/* USER CODE END AES1_MspInit 0 */
|
||||
/* AES1 clock enable */
|
||||
__HAL_RCC_AES1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN AES1_MspInit 1 */
|
||||
|
||||
/* USER CODE END AES1_MspInit 1 */
|
||||
}
|
||||
else if(crypHandle->Instance==AES2)
|
||||
{
|
||||
/* USER CODE BEGIN AES2_MspInit 0 */
|
||||
|
||||
/* USER CODE END AES2_MspInit 0 */
|
||||
/* AES2 clock enable */
|
||||
__HAL_RCC_AES2_CLK_ENABLE();
|
||||
/* USER CODE BEGIN AES2_MspInit 1 */
|
||||
|
||||
/* USER CODE END AES2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
|
||||
{
|
||||
|
||||
if(crypHandle->Instance==AES1)
|
||||
{
|
||||
/* USER CODE BEGIN AES1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END AES1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_AES1_CLK_DISABLE();
|
||||
/* USER CODE BEGIN AES1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END AES1_MspDeInit 1 */
|
||||
}
|
||||
else if(crypHandle->Instance==AES2)
|
||||
{
|
||||
/* USER CODE BEGIN AES2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END AES2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_AES2_CLK_DISABLE();
|
||||
/* USER CODE BEGIN AES2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END AES2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pka.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the PKA instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "pka.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
PKA_HandleTypeDef hpka;
|
||||
|
||||
/* PKA init function */
|
||||
void MX_PKA_Init(void)
|
||||
{
|
||||
|
||||
hpka.Instance = PKA;
|
||||
if (HAL_PKA_Init(&hpka) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle)
|
||||
{
|
||||
|
||||
if(pkaHandle->Instance==PKA)
|
||||
{
|
||||
/* USER CODE BEGIN PKA_MspInit 0 */
|
||||
|
||||
/* USER CODE END PKA_MspInit 0 */
|
||||
/* PKA clock enable */
|
||||
__HAL_RCC_PKA_CLK_ENABLE();
|
||||
/* USER CODE BEGIN PKA_MspInit 1 */
|
||||
|
||||
/* USER CODE END PKA_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle)
|
||||
{
|
||||
|
||||
if(pkaHandle->Instance==PKA)
|
||||
{
|
||||
/* USER CODE BEGIN PKA_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END PKA_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_PKA_CLK_DISABLE();
|
||||
/* USER CODE BEGIN PKA_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END PKA_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rf.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RF instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rf.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* RF init function */
|
||||
void MX_RF_Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rng.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RNG instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rng.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
RNG_HandleTypeDef hrng;
|
||||
|
||||
/* RNG init function */
|
||||
void MX_RNG_Init(void)
|
||||
{
|
||||
|
||||
hrng.Instance = RNG;
|
||||
if (HAL_RNG_Init(&hrng) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle)
|
||||
{
|
||||
|
||||
if(rngHandle->Instance==RNG)
|
||||
{
|
||||
/* USER CODE BEGIN RNG_MspInit 0 */
|
||||
|
||||
/* USER CODE END RNG_MspInit 0 */
|
||||
/* RNG clock enable */
|
||||
__HAL_RCC_RNG_CLK_ENABLE();
|
||||
/* USER CODE BEGIN RNG_MspInit 1 */
|
||||
|
||||
/* USER CODE END RNG_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle)
|
||||
{
|
||||
|
||||
if(rngHandle->Instance==RNG)
|
||||
{
|
||||
/* USER CODE BEGIN RNG_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RNG_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RNG_CLK_DISABLE();
|
||||
/* USER CODE BEGIN RNG_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RNG_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,6 +1,6 @@
|
||||
#include <furi-hal-clock.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include <main.h>
|
||||
#include <stm32wbxx_ll_pwr.h>
|
||||
#include <stm32wbxx_ll_rcc.h>
|
||||
#include <stm32wbxx_ll_utils.h>
|
||||
@ -107,6 +107,12 @@ void furi_hal_clock_init() {
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_AES1);
|
||||
|
||||
// AHB3
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PKA);
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_RNG);
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_AES2);
|
||||
|
||||
// APB1
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
|
||||
@ -114,6 +120,8 @@ void furi_hal_clock_init() {
|
||||
|
||||
// APB2
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
|
||||
FURI_LOG_I("FuriHalClock", "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_clock_switch_to_hsi() {
|
||||
|
69
firmware/targets/f7/furi-hal/furi-hal-crypto.c
Normal file
69
firmware/targets/f7/furi-hal/furi-hal-crypto.c
Normal file
@ -0,0 +1,69 @@
|
||||
#include <furi-hal-crypto.h>
|
||||
#include <furi.h>
|
||||
#include <shci.h>
|
||||
|
||||
CRYP_HandleTypeDef crypt;
|
||||
|
||||
void furi_hal_crypto_init() {
|
||||
FURI_LOG_I("FuriHalCrypto", "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
furi_assert(key);
|
||||
furi_assert(slot);
|
||||
|
||||
SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
|
||||
|
||||
if (key->type == FuriHalCryptoKeyTypeMaster) {
|
||||
pParam.KeyType = KEYTYPE_MASTER;
|
||||
} else if (key->type == FuriHalCryptoKeyTypeSimple) {
|
||||
pParam.KeyType = KEYTYPE_SIMPLE;
|
||||
} else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
|
||||
pParam.KeyType = KEYTYPE_ENCRYPTED;
|
||||
} else {
|
||||
furi_crash("Incorrect key type");
|
||||
}
|
||||
|
||||
if (key->size == FuriHalCryptoKeySize128) {
|
||||
pParam.KeySize = KEYSIZE_16;
|
||||
} else if (key->size == FuriHalCryptoKeySize256) {
|
||||
pParam.KeySize = KEYSIZE_32;
|
||||
} else {
|
||||
furi_crash("Incorrect key size");
|
||||
}
|
||||
|
||||
return SHCI_C2_FUS_StoreUsrKey(&pParam, slot) == SHCI_Success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
|
||||
furi_assert(slot > 0 && slot <= 100);
|
||||
|
||||
crypt.Instance = AES1;
|
||||
crypt.Init.DataType = CRYP_DATATYPE_32B;
|
||||
crypt.Init.KeySize = CRYP_KEYSIZE_256B;
|
||||
crypt.Init.Algorithm = CRYP_AES_CBC;
|
||||
crypt.Init.pInitVect = (uint32_t*)iv;
|
||||
crypt.Init.pKey = NULL;
|
||||
|
||||
furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
|
||||
|
||||
if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
|
||||
return true;
|
||||
} else {
|
||||
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_unload_key(uint8_t slot) {
|
||||
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
|
||||
return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size) {
|
||||
return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size) {
|
||||
return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
|
||||
}
|
@ -41,7 +41,7 @@ void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR is
|
||||
}
|
||||
furi_hal_tim_tim1_isr = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel,
|
||||
} else if (dma == DMA2) {
|
||||
furi_hal_dma_channel_isr[1][channel] = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) {
|
||||
static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE1(DMA1);
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
|
||||
LL_DMA_ClearFlag_TC1(DMA1);
|
||||
@ -261,7 +261,7 @@ static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
static void furi_hal_irda_tx_dma_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE2(DMA1);
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
LL_DMA_ClearFlag_HT2(DMA1);
|
||||
@ -277,7 +277,7 @@ static void furi_hal_irda_tx_dma_isr() {
|
||||
} else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
|
||||
/* fallthrough */
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
@ -557,7 +557,7 @@ static void furi_hal_irda_async_tx_free_resources(void) {
|
||||
|
||||
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
furi_assert(furi_hal_irda_state == IrdaStateIdle);
|
||||
|
@ -261,7 +261,7 @@ void furi_hal_rfid_set_emulate_pulse(uint32_t pulse) {
|
||||
LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -285,7 +285,7 @@ void furi_hal_rfid_set_read_pulse(uint32_t pulse) {
|
||||
LFRFID_TIM.Instance->CCR4 = pulse;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
|
||||
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
|
||||
}else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
|
||||
} else if(value >= 778999847 && value <= 928000000) {
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPath868);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@ -424,7 +424,7 @@ void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void furi_hal_version_init() {
|
||||
case FuriHalVersionOtpVersion1:
|
||||
furi_hal_version_load_otp_v1();
|
||||
break;
|
||||
default: furi_check(0);
|
||||
default: furi_crash(NULL);
|
||||
}
|
||||
FURI_LOG_I("FuriHalVersion", "Init OK");
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
#include <furi-hal.h>
|
||||
|
||||
#include <aes.h>
|
||||
#include <comp.h>
|
||||
#include <pka.h>
|
||||
#include <rf.h>
|
||||
#include <rng.h>
|
||||
#include <rtc.h>
|
||||
#include <tim.h>
|
||||
#include <usb_device.h>
|
||||
@ -34,16 +30,8 @@ void furi_hal_init() {
|
||||
FURI_LOG_I("HAL", "TIM16 OK");
|
||||
MX_COMP1_Init();
|
||||
FURI_LOG_I("HAL", "COMP1 OK");
|
||||
MX_RF_Init();
|
||||
FURI_LOG_I("HAL", "RF OK");
|
||||
MX_PKA_Init();
|
||||
FURI_LOG_I("HAL", "PKA OK");
|
||||
MX_RNG_Init();
|
||||
FURI_LOG_I("HAL", "RNG OK");
|
||||
MX_AES1_Init();
|
||||
FURI_LOG_I("HAL", "AES1 OK");
|
||||
MX_AES2_Init();
|
||||
FURI_LOG_I("HAL", "AES2 OK");
|
||||
|
||||
furi_hal_crypto_init();
|
||||
|
||||
// VCP + USB
|
||||
furi_hal_vcp_init();
|
||||
|
@ -53,12 +53,9 @@ C_SOURCES += \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rng.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
|
||||
@ -81,7 +78,6 @@ CFLAGS += \
|
||||
-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
|
||||
-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
|
||||
C_SOURCES += \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
|
||||
|
66
firmware/targets/furi-hal-include/furi-hal-crypto.h
Normal file
66
firmware/targets/furi-hal-include/furi-hal-crypto.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/** FuriHalCryptoKey Type */
|
||||
typedef enum {
|
||||
FuriHalCryptoKeyTypeMaster, /**< Master key */
|
||||
FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
|
||||
FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
|
||||
} FuriHalCryptoKeyType;
|
||||
|
||||
/** FuriHalCryptoKey Size in bits */
|
||||
typedef enum {
|
||||
FuriHalCryptoKeySize128,
|
||||
FuriHalCryptoKeySize256,
|
||||
} FuriHalCryptoKeySize;
|
||||
|
||||
/** FuriHalCryptoKey */
|
||||
typedef struct {
|
||||
FuriHalCryptoKeyType type;
|
||||
FuriHalCryptoKeySize size;
|
||||
uint8_t* data;
|
||||
} FuriHalCryptoKey;
|
||||
|
||||
/** Initialize cryptography layer
|
||||
* This includes AES engines, PKA and RNG
|
||||
*/
|
||||
void furi_hal_crypto_init();
|
||||
|
||||
/** Store key in crypto storage
|
||||
* @param key - FuriHalCryptoKey to store. Only Master, Simple or Encrypted
|
||||
* @param slot - pinter to int where store slot number will be saved
|
||||
* @return true on success
|
||||
*/
|
||||
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
|
||||
|
||||
/** Init AES engine and load key from crypto store
|
||||
* @param slot - store slot number
|
||||
* @return true on success
|
||||
*/
|
||||
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
|
||||
|
||||
/** Unload key engine and deinit AES engine
|
||||
* @param slot - store slot number
|
||||
* @return true on success
|
||||
*/
|
||||
bool furi_hal_crypto_store_unload_key(uint8_t slot);
|
||||
|
||||
|
||||
/** Encrypt data
|
||||
* @param input - pointer to input data
|
||||
* @param output - pointer to output data
|
||||
* @param size - input/output buffer size in bytes
|
||||
* @return true on success
|
||||
*/
|
||||
bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size);
|
||||
|
||||
/** Decrypt data
|
||||
* @param input - pointer to input data
|
||||
* @param output - pointer to output data
|
||||
* @param size - input/output buffer size in bytes
|
||||
* @return true on success
|
||||
*/
|
||||
bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size);
|
@ -6,6 +6,7 @@ template <unsigned int N> struct STOP_EXTERNING_ME {};
|
||||
|
||||
#include "furi-hal-boot.h"
|
||||
#include "furi-hal-clock.h"
|
||||
#include "furi-hal-crypto.h"
|
||||
#include "furi-hal-console.h"
|
||||
#include "furi-hal-os.h"
|
||||
#include "furi-hal-i2c.h"
|
||||
|
@ -36,7 +36,7 @@ template <class TState, class TEvent> AppTemplate<TState, TEvent>::AppTemplate()
|
||||
// TODO: use plain os mutex?
|
||||
if(!init_mutex(&state_mutex, &state, sizeof(TState))) {
|
||||
printf("cannot create mutex\n");
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
// open gui
|
||||
|
@ -75,7 +75,7 @@ FuriHalIrdaTxGetDataState irda_get_data_callback (void* context, uint32_t* durat
|
||||
state = FuriHalIrdaTxGetDataStateLastDone;
|
||||
}
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
@ -14,6 +14,22 @@ size_t args_length(string_t args) {
|
||||
return string_size(args);
|
||||
}
|
||||
|
||||
bool args_read_int_and_trim(string_t args, int* value) {
|
||||
size_t cmd_length = args_get_first_word_length(args);
|
||||
|
||||
if(cmd_length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sscanf(string_get_cstr(args), "%d", value) == 1) {
|
||||
string_right(args, cmd_length);
|
||||
string_strim(args);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool args_read_string_and_trim(string_t args, string_t word) {
|
||||
size_t cmd_length = args_get_first_word_length(args);
|
||||
|
||||
|
@ -8,6 +8,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Extract int value and trim arguments string
|
||||
*
|
||||
* @param args - arguments string
|
||||
* @param word first argument, output
|
||||
* @return true - success
|
||||
* @return false - arguments string does not contain int
|
||||
*/
|
||||
bool args_read_int_and_trim(string_t args, int* value);
|
||||
|
||||
/**
|
||||
* @brief Extract first argument from arguments string and trim arguments string
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user