KETCube
Macros | Functions | Variables
ketCube_mcu.c File Reference

This file contains the KETCube MCU implementations. More...

#include "debug.h"
#include "ketCube_mcu.h"
#include "ketCube_resetMan.h"
#include "ketCube_coreCfg.h"
#include "timeServer.h"
#include "stm32l0xx_hal_pwr.h"
#include "ketCube_gpio.h"
#include "ketCube_spi.h"
#include "ketCube_uart.h"
#include "ketCube_radio.h"

Macros

#define BACKUP_PRIMASK()   uint32_t primask_bit= __get_PRIMASK()
 
#define DISABLE_IRQ()   __disable_irq()
 
#define ENABLE_IRQ()   __enable_irq()
 
#define RESTORE_PRIMASK()   __set_PRIMASK(primask_bit)
 
#define ID1   ( 0x1FF80050 )
 Unique Devices IDs register set ( STM32L0xxx ) More...
 
#define ID2   ( 0x1FF80054 )
 
#define ID3   ( 0x1FF80064 )
 
#define SYSHND_CTRL   (*(volatile unsigned int*) (0xE000ED24u))
 
#define NVIC_MFSR   (*(volatile unsigned char*) (0xE000ED28u))
 
#define NVIC_BFSR   (*(volatile unsigned char*) (0xE000ED29u))
 
#define NVIC_UFSR   (*(volatile unsigned short*)(0xE000ED2Au))
 
#define NVIC_HFSR   (*(volatile unsigned int*) (0xE000ED2Cu))
 
#define NVIC_DFSR   (*(volatile unsigned int*) (0xE000ED30u))
 
#define NVIC_BFAR   (*(volatile unsigned int*) (0xE000ED38u))
 
#define NVIC_AFSR   (*(volatile unsigned int*) (0xE000ED3Cu))
 

Functions

uint32_t ketCube_MCU_GetRandomSeed (void)
 This function return a random seed. More...
 
void ketCube_MCU_GetUniqueId (uint8_t *id)
 This function returns a unique MCU ID. More...
 
void ketCube_MCU_SetSleepMode (ketCube_mcu_LPMode_t mode)
 Select sleep mode. More...
 
ketCube_mcu_LPMode_t ketCube_MCU_GetSleepMode (void)
 Get current sleep mode. More...
 
void ketCube_MCU_EnableSleep (void)
 Enable low power mode ... More...
 
void ketCube_MCU_DisableSleep (void)
 Disable low power mode ... More...
 
bool ketCube_MCU_IsSleepEnabled (void)
 Disable low power mode ... More...
 
static void ketCube_MCU_ExitStopMode (void)
 Exists Low Power Stop Mode. More...
 
void ketCube_MCU_EnterStopMode (void)
 Enters Low Power Stop Mode. More...
 
void ketCube_MCU_EnterSleepMode (void)
 Enters Low Power Sleep Mode. More...
 
void ketCube_MCU_ExitSleepMode (void)
 Exit Low Power Sleep Mode. More...
 
void ketCube_MCU_Sleep (void)
 Handle KETCube LowPower mode(s) More...
 
void ketCube_MCU_ClockConfig (void)
 Clock Configuration The system Clock is configured as follows: System Clock source = PLL (HSI) SYSCLK(Hz) = 32000000 HCLK(Hz) = 32000000 AHB Prescaler = 1 APB1 Prescaler = 1 APB2 Prescaler = 1 HSI Frequency(Hz) = 16000000 PLLMUL = 6 PLLDIV = 3 Flash Latency(WS) = 1. More...
 
void ketCube_MCU_SleepClockConfig (void)
 Clock Configuration The system Clock is configured as follows: System Clock source = MSI MSI(Hz) = 65000. More...
 
void ketCube_MCU_RunClockConfig (void)
 Clock Configuration The system Clock is configured as follows: System Clock source = MSI HSI(Hz) = 32000000. More...
 
void ketCube_MCU_WD_Monitor (void *context)
 Monitor WakeUp reasoning. More...
 
void ketCube_MCU_WD_Init (void)
 KETCube Watchdog (IWDG) Setup. More...
 
void ketCube_MCU_WD_Reset (void)
 KETCube Watchdog (IWDG) Reset. More...
 
static void ketCube_VoltageDet_Init (void)
 KETCube Voltage Detector init. More...
 
void PVD_IRQHandler (void)
 Programmable Voltage Detector (PVD) IRQ. More...
 
void HAL_PWR_PVDCallback (void)
 Programmable Voltage Detector (PVD) Callback. More...
 
void HAL_MspInit (void)
 Initializes the MSP. More...
 
void HardFaultHandler (unsigned int *pStack)
 Advanced HardFault handler. More...
 
void ketCube_MCU_DumpHardFaultRegs (ketCube_MCU_HardFaultRegs_t *HardFaultRegs)
 Dump HardFault Register Content. More...
 

Variables

static volatile bool enableSleep = TRUE
 
static TimerEvent_t KETCube_WDCheckTimer
 
static IWDG_HandleTypeDef hiwdg
 
PWR_PVDTypeDef sConfigPVD = {0}
 
volatile bool ketCube_MCU_PVD_Det = FALSE
 
static volatile bool ketCube_MCU_WD_timWake = FALSE
 
volatile ketCube_mcu_LPMode_t ketCube_MCU_LPMode = KETCUBE_MCU_LPMODE_SLEEP
 Low-Power mode selection. More...
 
static volatile bool HardFaultHandler_ContinueA = TRUE
 Set THIS variables to FALSE if you would like to debug HardFault with debug probe instead of using KETCube's way. More...
 
static volatile bool HardFaultHandler_ContinueB = TRUE
 Set THIS variables to FALSE if you would like to debug HardFault with debug probe instead of using KETCube's way. More...
 

Detailed Description

This file contains the KETCube MCU implementations.

Author
Jan Belohoubek
Version
alpha
Date
2019-12-10
Attention

© Copyright (c) 2019 University of West Bohemia in Pilsen All rights reserved.

Developed by: The SmartCampus Team Department of Technologies and Measurement www.smartcampus.cz | www.zcu.cz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.

Macro Definition Documentation

◆ BACKUP_PRIMASK

#define BACKUP_PRIMASK ( )    uint32_t primask_bit= __get_PRIMASK()

◆ DISABLE_IRQ

#define DISABLE_IRQ ( )    __disable_irq()

◆ ENABLE_IRQ

#define ENABLE_IRQ ( )    __enable_irq()

◆ ID1

#define ID1   ( 0x1FF80050 )

Unique Devices IDs register set ( STM32L0xxx )

◆ ID2

#define ID2   ( 0x1FF80054 )

◆ ID3

#define ID3   ( 0x1FF80064 )

◆ NVIC_AFSR

#define NVIC_AFSR   (*(volatile unsigned int*) (0xE000ED3Cu))

◆ NVIC_BFAR

#define NVIC_BFAR   (*(volatile unsigned int*) (0xE000ED38u))

◆ NVIC_BFSR

#define NVIC_BFSR   (*(volatile unsigned char*) (0xE000ED29u))

◆ NVIC_DFSR

#define NVIC_DFSR   (*(volatile unsigned int*) (0xE000ED30u))

◆ NVIC_HFSR

#define NVIC_HFSR   (*(volatile unsigned int*) (0xE000ED2Cu))

◆ NVIC_MFSR

#define NVIC_MFSR   (*(volatile unsigned char*) (0xE000ED28u))

◆ NVIC_UFSR

#define NVIC_UFSR   (*(volatile unsigned short*)(0xE000ED2Au))

◆ RESTORE_PRIMASK

#define RESTORE_PRIMASK ( )    __set_PRIMASK(primask_bit)

◆ SYSHND_CTRL

#define SYSHND_CTRL   (*(volatile unsigned int*) (0xE000ED24u))

Function Documentation

◆ HAL_MspInit()

void HAL_MspInit ( void  )

Initializes the MSP.

Return values
None

◆ HAL_PWR_PVDCallback()

void HAL_PWR_PVDCallback ( void  )

Programmable Voltage Detector (PVD) Callback.

Todo:
The ketCube_MCU_PVD_Det flag should be used to trigger an action and after triggering it, it should be cleared

◆ HardFaultHandler()

void HardFaultHandler ( unsigned int *  pStack)

Advanced HardFault handler.

Note
The Segger's appnote https://www.segger.com/downloads/application-notes/AN00016 has been used to define this handler

◆ ketCube_MCU_EnterSleepMode()

void ketCube_MCU_EnterSleepMode ( void  )

Enters Low Power Sleep Mode.

Note
ARM exits the function when waking up

◆ ketCube_MCU_EnterStopMode()

void ketCube_MCU_EnterStopMode ( void  )

Enters Low Power Stop Mode.

Note
ARM exists the function when waking up

◆ ketCube_MCU_ExitSleepMode()

void ketCube_MCU_ExitSleepMode ( void  )

Exit Low Power Sleep Mode.

◆ ketCube_MCU_ExitStopMode()

static void ketCube_MCU_ExitStopMode ( void  )
static

Exists Low Power Stop Mode.

Note
Enable the pll at 32MHz

◆ ketCube_MCU_WD_Monitor()

void ketCube_MCU_WD_Monitor ( void *  context)

Monitor WakeUp reasoning.

Note
Do not remove this function, as it prevents optimization of safe-timer

◆ ketCube_VoltageDet_Init()

static void ketCube_VoltageDet_Init ( void  )
static

KETCube Voltage Detector init.

Note
Some KETCube parts are not operationalunder certain voltage. E.g. HDC1080 is not opperational below 2V7 (HDC2080 will be used in next platform release, thus 1V62 will be the minimal voltage level for RHT sensor).
Below 1V9 is realy "dangerous" voltage, thus PWR_PVDLEVEL_0 is used as a default value

◆ PVD_IRQHandler()

void PVD_IRQHandler ( void  )

Programmable Voltage Detector (PVD) IRQ.

Variable Documentation

◆ enableSleep

volatile bool enableSleep = TRUE
static

◆ HardFaultHandler_ContinueA

volatile bool HardFaultHandler_ContinueA = TRUE
static

Set THIS variables to FALSE if you would like to debug HardFault with debug probe instead of using KETCube's way.

◆ HardFaultHandler_ContinueB

volatile bool HardFaultHandler_ContinueB = TRUE
static

Set THIS variables to FALSE if you would like to debug HardFault with debug probe instead of using KETCube's way.

◆ hiwdg

IWDG_HandleTypeDef hiwdg
static

◆ ketCube_MCU_PVD_Det

volatile bool ketCube_MCU_PVD_Det = FALSE

◆ ketCube_MCU_WD_timWake

volatile bool ketCube_MCU_WD_timWake = FALSE
static

◆ KETCube_WDCheckTimer

TimerEvent_t KETCube_WDCheckTimer
static

◆ sConfigPVD

PWR_PVDTypeDef sConfigPVD = {0}