This commit is contained in:
Willy-JL
2024-06-11 22:46:09 +02:00
62 changed files with 1625 additions and 1133 deletions

View File

@@ -73,10 +73,11 @@ void furi_hal_init(void) {
void furi_hal_switch(void* address) {
__set_BASEPRI(0);
asm volatile("ldr r3, [%0] \n"
"msr msp, r3 \n"
"ldr r3, [%1] \n"
"mov pc, r3 \n"
// This code emulates system reset: sets MSP and calls Reset ISR
asm volatile("ldr r3, [%0] \n" // Load SP from new vector to r3
"msr msp, r3 \n" // Set MSP from r3
"ldr r3, [%1] \n" // Load Reset Handler address to r3
"mov pc, r3 \n" // Set PC from r3 (jump to Reset ISR)
:
: "r"(address), "r"(address + 0x4)
: "r3");

View File

@@ -8,6 +8,7 @@
#include <stm32wbxx.h>
#include <stm32wbxx_ll_hsem.h>
#include <stm32wb55_linker.h>
#include <hsem_map.h>
@@ -57,9 +58,6 @@
(((__VALUE__) >= FLASH_BASE) && ((__VALUE__) <= (FLASH_BASE + FLASH_SIZE - 8UL)) && \
(((__VALUE__) % 8UL) == 0UL))
/* Free flash space borders, exported by linker */
extern const void __free_flash_start__;
size_t furi_hal_flash_get_base(void) {
return FLASH_BASE;
}

View File

@@ -67,13 +67,12 @@ const IRQn_Type furi_hal_interrupt_irqn[FuriHalInterruptIdMax] = {
[FuriHalInterruptIdLpUart1] = LPUART1_IRQn,
};
__attribute__((always_inline)) static inline void
furi_hal_interrupt_call(FuriHalInterruptId index) {
FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_call(FuriHalInterruptId index) {
furi_check(furi_hal_interrupt_isr[index].isr);
furi_hal_interrupt_isr[index].isr(furi_hal_interrupt_isr[index].context);
}
__attribute__((always_inline)) static inline void
FURI_ALWAYS_STATIC_INLINE void
furi_hal_interrupt_enable(FuriHalInterruptId index, uint16_t priority) {
NVIC_SetPriority(
furi_hal_interrupt_irqn[index],
@@ -81,23 +80,19 @@ __attribute__((always_inline)) static inline void
NVIC_EnableIRQ(furi_hal_interrupt_irqn[index]);
}
__attribute__((always_inline)) static inline void
furi_hal_interrupt_clear_pending(FuriHalInterruptId index) {
FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_clear_pending(FuriHalInterruptId index) {
NVIC_ClearPendingIRQ(furi_hal_interrupt_irqn[index]);
}
__attribute__((always_inline)) static inline void
furi_hal_interrupt_get_pending(FuriHalInterruptId index) {
FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_get_pending(FuriHalInterruptId index) {
NVIC_GetPendingIRQ(furi_hal_interrupt_irqn[index]);
}
__attribute__((always_inline)) static inline void
furi_hal_interrupt_set_pending(FuriHalInterruptId index) {
FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_set_pending(FuriHalInterruptId index) {
NVIC_SetPendingIRQ(furi_hal_interrupt_irqn[index]);
}
__attribute__((always_inline)) static inline void
furi_hal_interrupt_disable(FuriHalInterruptId index) {
FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_disable(FuriHalInterruptId index) {
NVIC_DisableIRQ(furi_hal_interrupt_irqn[index]);
}
@@ -279,11 +274,11 @@ void MemManage_Handler(void) {
// from 0x00 to 1MB, see FuriHalMpuRegionNULL
furi_crash("NULL pointer dereference");
} else {
// write or read of MPU region 1 (FuriHalMpuRegionStack)
// write or read of MPU region 1 (FuriHalMpuRegionThreadStack)
furi_crash("MPU fault, possibly stack overflow");
}
} else if(FURI_BIT(SCB->CFSR, SCB_CFSR_MSTKERR_Pos)) {
// push to stack on MPU region 1 (FuriHalMpuRegionStack)
// push to stack on MPU region 1 (FuriHalMpuRegionThreadStack)
furi_crash("MemManage fault, possibly stack overflow");
}
@@ -318,9 +313,6 @@ void USB_LP_IRQHandler(void) {
#endif
}
void USB_HP_IRQHandler(void) {
}
void IPCC_C1_TX_IRQHandler(void) {
HW_IPCC_Tx_Handler();
}
@@ -347,4 +339,4 @@ void USART1_IRQHandler(void) {
void LPUART1_IRQHandler(void) {
furi_hal_interrupt_call(FuriHalInterruptIdLpUart1);
}
}

View File

@@ -1,6 +1,8 @@
#include <furi_hal_mpu.h>
#include <stm32wbxx_ll_cortex.h>
#include <stm32wb55_linker.h>
#define FURI_HAL_MPU_ATTRIBUTES \
(LL_MPU_ACCESS_BUFFERABLE | LL_MPU_ACCESS_CACHEABLE | LL_MPU_ACCESS_SHAREABLE | \
LL_MPU_TEX_LEVEL1 | LL_MPU_INSTRUCTION_ACCESS_ENABLE)
@@ -12,6 +14,10 @@ void furi_hal_mpu_init(void) {
// NULL pointer dereference protection
furi_hal_mpu_protect_no_access(FuriHalMpuRegionNULL, 0x00, FuriHalMPURegionSize1MB);
furi_hal_mpu_protect_no_access(
FuriHalMpuRegionMainStack,
(uint32_t)(&_stack_end - &_stack_size),
FuriHalMPURegionSize32B);
}
void furi_hal_mpu_enable(void) {
@@ -62,5 +68,5 @@ void furi_hal_mpu_set_stack_protection(uint32_t* stack) {
if(stack_ptr < (uint32_t)stack) stack_ptr += (mask + 1);
furi_hal_mpu_protect_read_only(
FuriHalMpuRegionStack, stack_ptr, FURI_HAL_MPU_STACK_PROTECT_REGION);
FuriHalMpuRegionThreadStack, stack_ptr, FURI_HAL_MPU_STACK_PROTECT_REGION);
}