Skip to content

Commit

Permalink
Significant refactor. Add U0 hal. Add prototype crypto impl for U0.
Browse files Browse the repository at this point in the history
  • Loading branch information
chintal committed Sep 21, 2024
1 parent a549f38 commit 4ce529e
Show file tree
Hide file tree
Showing 43 changed files with 869 additions and 206 deletions.
13 changes: 13 additions & 0 deletions family.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Import('env')
from os.path import join, realpath

# Private flags for the current "hal-stm32" source files
defines = env.get("CPPDEFINES", [])

if "STM32U0" in defines:
print("Using ststm32 u0xx HAL implementation")
env.Replace(SRC_FILTER=["+<hal_platform/common/*.*>", "+<hal_platform/u0xx/*.*>"])

elif "STM32F4" in defines:
print("Using ststm32 f4xx HAL implementation")
env.Replace(SRC_FILTER=["+<hal_platform/common/*.*>", "+<hal_platform/f4xx/*.*>"])
5 changes: 4 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"name": "ebs-ds",
"version": "^0.2.0"
}
]
],
"build": {
"extraScript": "family.py"
}
}
5 changes: 2 additions & 3 deletions src/hal_platform/core_handlers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/core_handlers.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/core_handlers.h)
5 changes: 2 additions & 3 deletions src/hal_platform/core_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/core_impl.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/core_impl.h)
2 changes: 2 additions & 0 deletions src/hal_platform/crypto_handlers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "families.h"
#include STRINGIFY(FAMILY/crypto_handlers.h)
2 changes: 2 additions & 0 deletions src/hal_platform/crypto_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "families.h"
#include STRINGIFY(FAMILY/crypto_impl.h)
5 changes: 2 additions & 3 deletions src/hal_platform/eeprom_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/eeprom_impl.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/eeprom_impl.h)
5 changes: 2 additions & 3 deletions src/hal_platform/entropy_handlers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/entropy_handlers.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/entropy_handlers.h)
5 changes: 2 additions & 3 deletions src/hal_platform/entropy_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/entropy_impl.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/entropy_impl.h)
5 changes: 2 additions & 3 deletions src/hal_platform/exti.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/exti.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/exti.h)
5 changes: 2 additions & 3 deletions src/hal_platform/exti_handlers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/exti_handlers.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/exti_handlers.h)
20 changes: 20 additions & 0 deletions src/hal_platform/families.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


#ifndef __FAMILIES_H
#define __FAMILIES_H

#if defined STM32F4
#define FAMILY f4xx
#elif defined STM32U0
#define FAMILY u0xx
#elif defined STM32H7
#define FAMILY h7xx
#else
#error "STM32 family not recognized"
#endif

// Stringify macros to construct file paths dynamically
#define STRINGIFY(x) STRINGIFY2(x)
#define STRINGIFY2(x) #x

#endif
5 changes: 2 additions & 3 deletions src/hal_platform/gpio_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/gpio_impl.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/gpio_impl.h)
5 changes: 2 additions & 3 deletions src/hal_platform/id_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/id_impl.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/id_impl.h)
5 changes: 2 additions & 3 deletions src/hal_platform/shared_handlers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/shared_handlers.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/shared_handlers.h)
5 changes: 2 additions & 3 deletions src/hal_platform/timer_handlers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/timer_handlers.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/timer_handlers.h)
5 changes: 2 additions & 3 deletions src/hal_platform/timer_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#ifdef STM32F4
#include "f4xx/timer_impl.h"
#endif
#include "families.h"
#include STRINGIFY(FAMILY/timer_impl.h)
74 changes: 74 additions & 0 deletions src/hal_platform/u0xx/core_handlers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@


#include "core_handlers.h"
#include <irq_handlers.h>

volatile uint8_t __core_handler_inclusion;

#if uC_CORE_ENABLED

/**
* @name Cortex-M4 Processor Interruption and Exception Handlers
*/
/**@{*/
/**
* @brief This function handles Non maskable interrupt.
*
* Just drops to the failure state. Debug and inspect the stack.
*/
void NMI_Handler(void){
die();
}

/**
* @brief This function handles Hard Fault interrupt.
*
* Just drops to the failure state. Debug and inspect the stack.
*/
void HardFault_Handler(void){
die();
}

/**
* @brief This function handles System Service Call via SWI Instruction.
*
* A System Service architecture needs to be implemented?
*
*/
void SVC_Handler(void){
;
}

/**
* @brief This function handles Pendable Request for System Service.
*
*/
void PendSV_Handler(void){
;
}

#endif

#if uC_SYSTICK_TIMER_ENABLED

/**
* @brief This function handles System Tick Timer Interrupts.
*/
void SysTick_Handler(void) {
// HAL IncTick is only needed if we're using HAL timing primitives
// (directly or indirectly). Ideally, most of those uses should
// be modified to use the considerably faster EBS systick.
//
// Switching the STM32 HAL to use the EBS systick can probably be
// done using the weak functions it provides.
//
// For now, keeping both running.
HAL_IncTick();
#if APP_USE_CORE_SYSTICK
#ifdef uC_SYSTICK_TIMER_IRQH
uC_SYSTICK_TIMER_IRQH();
#endif
#endif
}

#endif
48 changes: 48 additions & 0 deletions src/hal_platform/u0xx/crypto_handlers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@


#ifndef CRYPTO_HANDLERS_H
#define CRYPTO_HANDLERS_H

#include <hal/uc/crypto.h>


#if uC_CRYPTO_ENABLED

static inline void crypto_isr(void) {
// Datasheet talks about an ICR register, but it does not
// show up in the register maps. The MCU headers include
// the register, but does not have all the bits. The bit
// named is shown in the CR register drawing.
// Trusting the tables in the datasheet instead of the text.
//AES->ICR |= AES_ICR_CCF;
AES->CR |= 0x1UL << 7; // Set AES_CR.CCF per refman pp538

uint8_t ingest_len = 16;
uint8_t no_release = 0;

switch (crypto_state.ctx->phase)
{
case CRYPTO_CTX_PHASE_PREPKEY:
if (crypto_state.ctx->profile->header_size){
crypto_set_ctx_phase(crypto_state.ctx, CRYPTO_CTX_PHASE_HEADER);
} else {
crypto_set_ctx_phase(crypto_state.ctx, CRYPTO_CTX_PHASE_PAYLOAD);
}
ingest_len = 0;
AES->CR |= AES_CR_EN;
break;
default:
break;
}

crypto_state.state = CRYPTO_READY;
if (crypto_state.ctx->ingest_cb){
no_release = crypto_state.ctx->ingest_cb(crypto_state.ctx, ingest_len);
}
if (!no_release){
crypto_state.state = CRYPTO_BUSY;
}
}

#endif
#endif
Loading

0 comments on commit 4ce529e

Please sign in to comment.